*/
#include "abstract_parcel.hh"
+#include <cstring>
+
namespace pkgmgr_common {
namespace parcel {
-bool AbstractParcel::WriteInt(int i) { return true; }
+AbstractParcel::AbstractParcel(const unsigned char* buf, unsigned int size)
+ : data_(buf, buf + size) {}
+
+AbstractParcel::~AbstractParcel() {}
-bool AbstractParcel::WriteString(const char* str) { return true; }
+int AbstractParcel::ReadInt() {
+ int d = 0;
+ unsigned char* p = reinterpret_cast<unsigned char*>(&d);
-bool AbstractParcel::ReadInt() { return true; }
+ if (reader_ + sizeof(int) > data_.size())
+ return d;
+ std::copy(&data_[reader_], &data_[reader_] + sizeof(int), p);
+ reader_ += sizeof(int);
+ return d;
+}
-bool AbstractParcel::ReadString() { return true; }
+char* AbstractParcel::ReadString() {
+ int l = ReadInt();
-const std::vector<unsigned char>& AbstractParcel::Serialize() { return data_; }
+ if (l < 0)
+ return nullptr;
+ if (l == 0)
+ return strdup("");
+ if (reader_ + l > data_.size())
+ return nullptr;
+ if (data_[reader_ + l - 1] != 0)
+ return nullptr;
+ const char* str = reinterpret_cast<const char*>(&data_[reader_]);
+ reader_ += l;
+
+ return strdup(str);
+}
+bool AbstractParcel::ReadParcelRaw(const unsigned char **buf,
+ unsigned int *size) {
+ int l = ReadInt();
+
+ if (l <= 0)
+ return true;
+ if (reader_ + l > data_.size())
+ return false;
+ const unsigned char* str =
+ reinterpret_cast<const unsigned char*>(&data_[reader_]);
+ reader_ += l;
+
+ *buf = str;
+ *size = l;
+
+ return true;
+}
+
+void AbstractParcel::Write(const unsigned char* buf, unsigned int size) {
+ std::copy(buf, buf + size, std::back_inserter(data_));
+}
+
+void AbstractParcel::WriteInt(int i) {
+ unsigned char* p = reinterpret_cast<unsigned char*>(&i);
+
+ std::copy(p, p + sizeof(int), std::back_inserter(data_));
+}
+
+void AbstractParcel::WriteString(const char* str) {
+ int l;
+ if (str == nullptr)
+ l = -1;
+ else if (std::strlen(str) == 0)
+ l = 0;
+ else
+ l = std::strlen(str) + 1;
+
+ WriteInt(l);
+ if (l > 0)
+ std::copy(str, str + l, std::back_inserter(data_));
+}
-std::unique_ptr<AbstractParcel> AbstractParcel::Deserialize(
- std::vector<unsigned char> data) {
- return nullptr;
+void AbstractParcel::WriteParcel(std::unique_ptr<AbstractParcel> parcel) {
+ auto serialized = parcel->Serialize();
+ const unsigned char *ptr = &serialized[0];
+ int len = serialized.size();
+ WriteInt(len);
+ if (len > 0)
+ Write(ptr, len);
}
uid_t AbstractParcel::GetUid() { return uid_; }
public:
class EXPORT_API IFactory {
public:
- virtual std::unique_ptr<AbstractParcel> CreateParcel() = 0;
+ virtual std::unique_ptr<AbstractParcel> CreateParcel(std::vector<unsigned char> data) = 0;
};
- const std::vector<unsigned char>& Serialize();
- virtual std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+
+ AbstractParcel() = default;
+ AbstractParcel(const unsigned char* buf, unsigned int size);
+
+ virtual ~AbstractParcel();
+ virtual const std::vector<unsigned char>& Serialize() = 0;
uid_t GetUid();
void SetUid(uid_t uid);
ReqType GetReqType();
protected:
- bool ReadString();
- bool ReadInt();
- bool WriteString(const char* str);
- bool WriteInt(int i);
+ char* ReadString();
+ int ReadInt();
+ bool ReadParcelRaw(const unsigned char **buf, unsigned int *size);
+ void Write(const unsigned char* buf, unsigned int size);
+ void WriteString(const char* str);
+ void WriteInt(int i);
+ void WriteParcel(std::unique_ptr<AbstractParcel> parcel);
std::vector<unsigned char> data_;
return nullptr;
}
+const std::vector<unsigned char>& AppCtrlPrivInfoParcel::Serialize() { return data_; }
+
std::unique_ptr<AbstractParcel> AppCtrlPrivInfoParcel::Factory::CreateParcel() {
return nullptr;
}
bool SetResult(std::string app_control, std::string privilege);
std::vector<std::string> GetResultAppControl();
std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+ virtual const std::vector<unsigned char>& Serialize() override;
};
} // namespace parcel
namespace pkgmgr_common {
namespace parcel {
-std::vector<std::unique_ptr<pkgmgr_appinfo_x>> AppInfoParcel::GetAppInfoList() {
- return {};
+void AppInfoParcel::WriteLabel(GList* label) {
+ int size = g_list_length(label);
+ WriteInt(size);
+
+ for (GList* tmp = label; tmp; tmp = tmp->next) {
+ label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+ WriteString(ptr->lang);
+ WriteString(ptr->name);
+ WriteString(ptr->text);
+ }
+}
+
+void AppInfoParcel::WriteIcon(GList* icon) {
+ int size = g_list_length(icon);
+ WriteInt(size);
+
+ for (GList* tmp = icon; tmp; tmp = tmp->next) {
+ icon_x* ptr = reinterpret_cast<icon_x*>(tmp->data);
+ WriteString(ptr->text);
+ WriteString(ptr->lang);
+ WriteString(ptr->section);
+ WriteString(ptr->size);
+ WriteString(ptr->resolution);
+ WriteString(ptr->dpi);
+ }
+}
+void AppInfoParcel::WriteImage(GList* image) {
+ int size = g_list_length(image);
+ WriteInt(size);
+
+ for (GList* tmp = image; tmp; tmp = tmp->next) {
+ image_x* ptr = reinterpret_cast<image_x*>(tmp->data);
+ WriteString(ptr->text);
+ WriteString(ptr->lang);
+ WriteString(ptr->section);
+ }
+}
+void AppInfoParcel::WriteCategory(GList* category) {
+ int size = g_list_length(category);
+ WriteInt(size);
+ for (GList* tmp = category; tmp; tmp = tmp->next) {
+ WriteString(reinterpret_cast<char *>(tmp->data));
+ }
+}
+void AppInfoParcel::WriteMetadata(GList* metadata) {
+ int size = g_list_length(metadata);
+ WriteInt(size);
+
+ for (GList* tmp = metadata; tmp; tmp = tmp->next) {
+ metadata_x* ptr = reinterpret_cast<metadata_x*>(tmp->data);
+ WriteString(ptr->key);
+ WriteString(ptr->value);
+ }
+}
+
+void AppInfoParcel::WritePermission(GList* permission) {
+// int size = g_list_length(permission);
+// WriteInt(size);
+//
+// for (GList* tmp = permission; tmp; tmp = tmp->next) {
+// label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();//
+// }
+}
+
+void AppInfoParcel::WriteLaunchConditions(GList* launchconditions) {
+// int size = g_list_length(launchconditions);
+// WriteInt(size);
+//
+// for (GList* tmp = launchconditions; tmp; tmp = tmp->next) {
+// label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();//
+// }
+}
+
+void AppInfoParcel::WriteNotification(GList* notification) {
+// int size = g_list_length(notification);
+// WriteInt(size);
+//
+// for (GList* tmp = notification; tmp; tmp = tmp->next) {
+// label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();//
+// }
+}
+
+void AppInfoParcel::WriteDatashare(GList* datashare) {
+// int size = g_list_length(datashare);
+// WriteInt(size);
+//
+// for (GList* tmp = datashare; tmp; tmp = tmp->next) {
+// label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();//
+// }
+}
+
+void AppInfoParcel::WriteDatacontrol(GList* datacontrol) {
+ int size = g_list_length(datacontrol);
+ WriteInt(size);
+
+ for (GList* tmp = datacontrol; tmp; tmp = tmp->next) {
+ datacontrol_x* ptr = reinterpret_cast<datacontrol_x*>(tmp->data);
+ WriteString(ptr->providerid);
+ WriteString(ptr->access);
+ WriteString(ptr->type);
+ WriteString(ptr->trusted);
+ WriteInt(g_list_length(ptr->privileges));
+ for (GList* tmp = ptr->privileges; tmp; tmp = tmp->next)
+ WriteString(reinterpret_cast<char *>(tmp->data));
+ }
+}
+
+void AppInfoParcel::WriteBackgroundCategory(GList* backgroundcategory) {
+ int size = g_list_length(backgroundcategory);
+ WriteInt(size);
+ for (GList* tmp = backgroundcategory; tmp; tmp = tmp->next)
+ WriteString(reinterpret_cast<char *>(tmp->data));
+}
+
+void AppInfoParcel::WriteAppcontrol(GList* appcontrol) {
+ int size = g_list_length(appcontrol);
+ WriteInt(size);
+
+ for (GList* tmp = appcontrol; tmp; tmp = tmp->next) {
+ appcontrol_x* ptr = reinterpret_cast<appcontrol_x*>(tmp->data);
+ WriteString(ptr->operation);
+ WriteString(ptr->uri);
+ WriteString(ptr->mime);
+ WriteString(ptr->visibility);
+ WriteString(ptr->id);
+ WriteInt(g_list_length(ptr->privileges));
+ for (GList* tmp = ptr->privileges; tmp; tmp = tmp->next)
+ WriteString(reinterpret_cast<char *>(tmp->data));
+ }
+}
+
+void AppInfoParcel::WriteSplashscreens(GList* splashscreens) {
+ int size = g_list_length(splashscreens);
+ WriteInt(size);
+
+ for (GList* tmp = splashscreens; tmp; tmp = tmp->next) {
+ splashscreen_x* ptr = reinterpret_cast<splashscreen_x*>(tmp->data);
+ WriteString(ptr->src);
+ WriteString(ptr->type);
+ WriteString(ptr->dpi);
+ WriteString(ptr->orientation);
+ WriteString(ptr->indicatordisplay);
+ WriteString(ptr->operation);
+ WriteString(ptr->color_depth);
+ }
+}
+
+void AppInfoParcel::ReadLabel(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+ label->lang = ReadString();
+ label->name = ReadString();
+ label->text = ReadString();
+
+ *list = g_list_append(*list, label);
+ }
+}
+
+void AppInfoParcel::ReadIcon(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+ icon->text = ReadString();
+ icon->lang = ReadString();
+ icon->section = ReadString();
+ icon->size = ReadString();
+ icon->resolution = ReadString();
+ icon->dpi = ReadString();
+
+ *list = g_list_append(*list, icon);
+ }
+}
+
+void AppInfoParcel::ReadImage(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ image_x* image = reinterpret_cast<image_x*>(calloc(1, sizeof(image_x)));
+ image->text = ReadString();
+ image->lang = ReadString();
+ image->section = ReadString();
+
+ *list = g_list_append(*list, image);
+ }
+}
+
+void AppInfoParcel::ReadCategory(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ *list = g_list_append(*list, ReadString());
+ }
}
-bool AppInfoParcel::SetAppInfoList(
- std::vector<std::unique_ptr<pkgmgr_appinfo_x>> applications) {
+void AppInfoParcel::ReadMetadata(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ metadata_x* metadata = reinterpret_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
+ metadata->key = ReadString();
+ metadata->value = ReadString();
+
+ *list = g_list_append(*list, metadata);
+ }
+}
+
+void AppInfoParcel::ReadPermission(GList** list) {
+// int size = ReadInt();
+//
+// for (int i = 0; i < size; ++i) {
+// label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();
+//
+// *list = g_list_append(*list, label);
+// }
+}
+
+void AppInfoParcel::ReadLaunchConditions(GList** list) {
+// int size = ReadInt();
+//
+// for (int i = 0; i < size; ++i) {
+// label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();
+//
+// *list = g_list_append(*list, label);
+// }
+}
+
+void AppInfoParcel::ReadNotification(GList** list) {
+// int size = ReadInt();
+//
+// for (int i = 0; i < size; ++i) {
+// label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();
+//
+// *list = g_list_append(*list, label);
+// }
+}
+
+void AppInfoParcel::ReadDatashare(GList** list) {
+// int size = ReadInt();
+//
+// for (int i = 0; i < size; ++i) {
+// label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+// label->lang = ReadString();
+// label->name = ReadString();
+// label->text = ReadString();
+//
+// *list = g_list_append(*list, label);
+// }
+}
+
+void AppInfoParcel::ReadDatacontrol(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ datacontrol_x* datacontrol = reinterpret_cast<datacontrol_x*>(calloc(1, sizeof(datacontrol_x)));
+ datacontrol->providerid = ReadString();
+ datacontrol->access = ReadString();
+ datacontrol->type = ReadString();
+ datacontrol->trusted = ReadString();
+ int privilege_size = ReadInt();
+ for (int i = 0; i < privilege_size; ++i) {
+ datacontrol->privileges = g_list_append(datacontrol->privileges, ReadString());
+ }
+
+ *list = g_list_append(*list, datacontrol);
+ }
+}
+void AppInfoParcel::ReadBackgroundCategory(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ *list = g_list_append(*list, ReadString());
+ }
+}
+void AppInfoParcel::ReadAppcontrol(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ appcontrol_x* appcontrol = reinterpret_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
+ appcontrol->operation = ReadString();
+ appcontrol->uri = ReadString();
+ appcontrol->mime = ReadString();
+ appcontrol->visibility = ReadString();
+ appcontrol->id = ReadString();
+ int privilege_len = ReadInt();
+ for (int i = 0; i < privilege_len; ++i)
+ appcontrol->privileges = g_list_append(appcontrol->privileges, ReadString());
+
+ *list = g_list_append(*list, appcontrol);
+ }
+}
+void AppInfoParcel::ReadSplashscreens(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ splashscreen_x* splashscreen = reinterpret_cast<splashscreen_x*>(calloc(1, sizeof(splashscreen_x)));
+ splashscreen->src = ReadString();
+ splashscreen->type = ReadString();
+ splashscreen->dpi = ReadString();
+ splashscreen->orientation = ReadString();
+ splashscreen->indicatordisplay = ReadString();
+ splashscreen->operation = ReadString();
+ splashscreen->color_depth = ReadString();
+
+ *list = g_list_append(*list, splashscreen);
+ }
+}
+
+AppInfoParcel::AppInfoParcel(
+ const unsigned char* buf, unsigned int size) : AbstractParcel(buf, size) {}
+
+AppInfoParcel::AppInfoParcel(std::vector<application_x *>&& app_list)
+ : app_list_(std::move(app_list)) {}
+
+const std::vector<application_x *> AppInfoParcel::GetAppInfo() {
+ return app_list_;
+}
+
+const std::vector<unsigned char>& AppInfoParcel::Serialize() {
+ WriteInt(app_list_.size());
+
+ for (auto app : app_list_) {
+ WriteApplication(app);
+ }
+
+ return data_;
+}
+
+application_x *AppInfoParcel::ReadApplication() {
+ application_x* application =
+ reinterpret_cast<application_x*>(calloc(1, sizeof(application_x)));
+
+ application->appid = ReadString();
+ application->exec = ReadString();
+ application->nodisplay = ReadString();
+ application->multiple = ReadString();
+ application->taskmanage = ReadString();
+ application->type = ReadString();
+ application->categories = ReadString();
+ application->extraid = ReadString();
+ application->hwacceleration = ReadString();
+ application->screenreader = ReadString();
+ application->mainapp = ReadString();
+ application->package = ReadString();
+ application->recentimage = ReadString();
+ application->launchcondition = ReadString();
+ application->indicatordisplay = ReadString();
+ application->portraitimg = ReadString();
+ application->landscapeimg = ReadString();
+ application->effectimage_type = ReadString();
+ application->guestmode_visibility = ReadString();
+ application->component = ReadString();
+ application->permission_type = ReadString();
+ application->component_type = ReadString();
+ application->preload = ReadString();
+ application->submode = ReadString();
+ application->submode_mainid = ReadString();
+ application->process_pool = ReadString();
+ application->installed_storage = ReadString();
+ application->autorestart = ReadString();
+ application->onboot = ReadString();
+ application->support_disable = ReadString();
+ application->ui_gadget = ReadString();
+ application->launch_mode = ReadString();
+ application->support_ambient = ReadString();
+ application->setup_appid = ReadString();
+ application->alias_appid = ReadString();
+ application->effective_appid = ReadString();
+ application->package_type = ReadString();
+ application->tep_name = ReadString();
+ application->zip_mount_file = ReadString();
+ application->root_path = ReadString();
+ application->api_version = ReadString();
+ application->for_all_users = ReadString();
+ application->is_disabled = ReadString();
+ application->splash_screen_display = ReadString();
+ application->external_path = ReadString();
+ application->package_system = ReadString();
+ application->removable = ReadString();
+ application->package_installed_time = ReadString();
+ application->support_mode = ReadString();
+ ReadLabel(&application->label);
+ ReadIcon(&application->icon);
+ ReadImage(&application->image);
+ ReadCategory(&application->category);
+ ReadMetadata(&application->metadata);
+ //ReadPermission(&application->permission);
+ //ReadLaunchConditions(&application->launchconditions);
+ //ReadNotification(&application->notification);
+ //ReadDatashare(&application->datashare);
+ ReadDatacontrol(&application->datacontrol);
+ ReadBackgroundCategory(&application->background_category);
+ ReadAppcontrol(&application->appcontrol);
+ ReadSplashscreens(&application->splashscreens);
+
+ return application;
+}
+
+bool AppInfoParcel::WriteApplication(application_x *application) {
+ WriteString(application->appid);
+ WriteString(application->exec);
+ WriteString(application->nodisplay);
+ WriteString(application->multiple);
+ WriteString(application->taskmanage);
+ WriteString(application->type);
+ WriteString(application->categories);
+ WriteString(application->extraid);
+ WriteString(application->hwacceleration);
+ WriteString(application->screenreader);
+ WriteString(application->mainapp);
+ WriteString(application->package);
+ WriteString(application->recentimage);
+ WriteString(application->launchcondition);
+ WriteString(application->indicatordisplay);
+ WriteString(application->portraitimg);
+ WriteString(application->landscapeimg);
+ WriteString(application->effectimage_type);
+ WriteString(application->guestmode_visibility);
+ WriteString(application->component);
+ WriteString(application->permission_type);
+ WriteString(application->component_type);
+ WriteString(application->preload);
+ WriteString(application->submode);
+ WriteString(application->submode_mainid);
+ WriteString(application->process_pool);
+ WriteString(application->installed_storage);
+ WriteString(application->autorestart);
+ WriteString(application->onboot);
+ WriteString(application->support_disable);
+ WriteString(application->ui_gadget);
+ WriteString(application->launch_mode);
+ WriteString(application->support_ambient);
+ WriteString(application->setup_appid);
+ WriteString(application->alias_appid);
+ WriteString(application->effective_appid);
+ WriteString(application->package_type);
+ WriteString(application->tep_name);
+ WriteString(application->zip_mount_file);
+ WriteString(application->root_path);
+ WriteString(application->api_version);
+ WriteString(application->for_all_users);
+ WriteString(application->is_disabled);
+ WriteString(application->splash_screen_display);
+ WriteString(application->external_path);
+ WriteString(application->package_system);
+ WriteString(application->removable);
+ WriteString(application->package_installed_time);
+ WriteString(application->support_mode);
+
+ WriteLabel(application->label);
+ WriteIcon(application->icon);
+ WriteImage(application->image);
+ WriteCategory(application->category);
+ WriteMetadata(application->metadata);
+ //WritePermission(application->permission);
+ //WriteLaunchConditions(application->launchconditions);
+ //WriteNotification(application->notification);
+ //WriteDatashare(application->datashare);
+ WriteDatacontrol(application->datacontrol);
+ WriteBackgroundCategory(application->background_category);
+ WriteAppcontrol(application->appcontrol);
+ WriteSplashscreens(application->splashscreens);
+
return true;
}
-std::unique_ptr<AbstractParcel> AppInfoParcel::Deserialize(
- std::vector<unsigned char> data) {
- return nullptr;
+std::unique_ptr<AppInfoParcel>
+ AppInfoParcel::Create(const unsigned char* buf, unsigned int size) {
+ AppInfoParcel parcel(buf, size);
+ std::vector<application_x *> app_list;
+
+ int len = parcel.ReadInt();
+
+ for (int i = 0; i < len ; ++i) {
+ app_list.emplace_back(parcel.ReadApplication());
+ }
+
+ return std::make_unique<AppInfoParcel>(std::move(app_list));
}
std::unique_ptr<AbstractParcel> AppInfoParcel::Factory::CreateParcel() {
public:
std::unique_ptr<AbstractParcel> CreateParcel();
};
- std::vector<std::unique_ptr<pkgmgr_appinfo_x>> GetAppInfoList();
- bool SetAppInfoList(
- std::vector<std::unique_ptr<pkgmgr_appinfo_x>> applications);
- std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+
+ AppInfoParcel() = default;
+ AppInfoParcel(const unsigned char* buf, unsigned int size);
+ AppInfoParcel(std::vector<application_x *>&& app_list);
+ const std::vector<application_x *> GetAppInfo();
+ const std::vector<unsigned char>& Serialize() override;
+ static std::unique_ptr<AppInfoParcel> Create(
+ const unsigned char* buf, unsigned int size);
+
+ private:
+ void WriteLabel(GList* label);
+ void WriteIcon(GList* icon);
+ void WriteImage(GList* image);
+ void WriteCategory(GList* category);
+ void WriteMetadata(GList* metadata);
+ void WritePermission(GList* permission);
+ void WriteLaunchConditions(GList* launchconditions);
+ void WriteNotification(GList* notification);
+ void WriteDatashare(GList* datashare);
+ void WriteDatacontrol(GList* datacontrol);
+ void WriteBackgroundCategory(GList* backgroundcategory);
+ void WriteAppcontrol(GList* appcontrol);
+ void WriteSplashscreens(GList* splashscreens);
+ bool WriteApplication(application_x *application);
+ void ReadLabel(GList** list);
+ void ReadIcon(GList** list);
+ void ReadImage(GList** list);
+ void ReadCategory(GList** list);
+ void ReadMetadata(GList** list);
+ void ReadPermission(GList** list);
+ void ReadLaunchConditions(GList** list);
+ void ReadNotification(GList** list);
+ void ReadDatashare(GList** list);
+ void ReadDatacontrol(GList** list);
+ void ReadBackgroundCategory(GList** list);
+ void ReadAppcontrol(GList** list);
+ void ReadSplashscreens(GList** list);
+ application_x *ReadApplication();
+
+ std::vector<application_x *> app_list_;
};
} // namespace parcel
return nullptr;
}
+const std::vector<unsigned char>& CertInfoParcel::Serialize() { return data_; }
+
std::unique_ptr<AbstractParcel> CertInfoParcel::Factory::CreateParcel() {
return nullptr;
}
std::unique_ptr<pkgmgr_certinfo_x> GetCertInfo();
bool SetCertInfo(std::unique_ptr<pkgmgr_certinfo_x> certinfo);
std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+ const std::vector<unsigned char>& Serialize() override;
};
} // namespace parcel
return nullptr;
}
+const std::vector<unsigned char>& DataCtrlInfoParcel::Serialize() { return data_; }
+
std::unique_ptr<AbstractParcel> DataCtrlInfoParcel::Factory::CreateParcel() {
return nullptr;
}
std::string GetQueryType();
std::vector<std::string> GetResultDataCtrlInfo();
std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+ const std::vector<unsigned char>& Serialize() override;
};
} // namespace parcel
return nullptr;
}
+const std::vector<unsigned char>& FilterParcel::Serialize() { return data_; }
+
std::unique_ptr<AbstractParcel> FilterParcel::Factory::CreateParcel() {
return nullptr;
}
std::unique_ptr<pkgmgrinfo_filter_x> GetFilter();
bool SetFilter(std::unique_ptr<pkgmgrinfo_filter_x> filter);
std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+ const std::vector<unsigned char>& Serialize() override;
};
} // namespace parcel
#include "pkgmgrinfo_private.h"
+#include "appinfo_parcel.hh"
+
namespace pkgmgr_common {
namespace parcel {
-std::vector<std::unique_ptr<pkgmgr_pkginfo_x>> PkgInfoParcel::GetPkgInfoList() {
- return {};
+void PkgInfoParcel::WriteIcon(GList* icon) {
+ int size = g_list_length(icon);
+ WriteInt(size);
+
+ for (GList* tmp = icon; tmp; tmp = tmp->next) {
+ icon_x* ptr = reinterpret_cast<icon_x*>(tmp->data);
+ WriteString(ptr->text);
+ WriteString(ptr->lang);
+ WriteString(ptr->section);
+ WriteString(ptr->size);
+ WriteString(ptr->resolution);
+ WriteString(ptr->dpi);
+ }
}
-bool PkgInfoParcel::SetPkgInfoList(
- std::vector<std::unique_ptr<pkgmgr_pkginfo_x>> packages) {
- return true;
+void PkgInfoParcel::WriteLabel(GList* label) {
+ int size = g_list_length(label);
+ WriteInt(size);
+
+ for (GList* tmp = label; tmp; tmp = tmp->next) {
+ label_x* ptr = reinterpret_cast<label_x*>(tmp->data);
+ WriteString(ptr->lang);
+ WriteString(ptr->name);
+ WriteString(ptr->text);
+ }
}
-std::unique_ptr<AbstractParcel> PkgInfoParcel::Deserialize(
- std::vector<unsigned char> data) {
- return nullptr;
+void PkgInfoParcel::WriteAuthor(GList* author) {
+ int size = g_list_length(author);
+ WriteInt(size);
+
+ for (GList* tmp = author; tmp; tmp = tmp->next) {
+ author_x* ptr = reinterpret_cast<author_x*>(tmp->data);
+ WriteString(ptr->email);
+ WriteString(ptr->href);
+ WriteString(ptr->text);
+ WriteString(ptr->lang);
+ }
+}
+
+void PkgInfoParcel::WriteDescription(GList* description) {
+ int size = g_list_length(description);
+ WriteInt(size);
+
+ for (GList* tmp = description; tmp; tmp = tmp->next) {
+ description_x* ptr = reinterpret_cast<description_x*>(tmp->data);
+ WriteString(ptr->name);
+ WriteString(ptr->text);
+ WriteString(ptr->lang);
+ }
+}
+
+void PkgInfoParcel::WriteLicense(GList* license) {
+ return;
+}
+
+void PkgInfoParcel::WritePrivileges(GList* privileges) {
+ int size = g_list_length(privileges);
+ WriteInt(size);
+
+ for (GList* tmp = privileges; tmp; tmp = tmp->next) {
+ privilege_x* ptr = reinterpret_cast<privilege_x*>(tmp->data);
+ WriteString(ptr->type);
+ WriteString(ptr->value);
+ }
+}
+
+void PkgInfoParcel::WriteAppdefinedPrivileges(
+ GList* appdefined_privileges) {
+ int size = g_list_length(appdefined_privileges);
+ WriteInt(size);
+
+ for (GList* tmp = appdefined_privileges; tmp; tmp = tmp->next) {
+ appdefined_privilege_x* ptr =
+ reinterpret_cast<appdefined_privilege_x*>(tmp->data);
+ WriteString(ptr->type);
+ WriteString(ptr->value);
+ WriteString(ptr->license);
+ }
+}
+
+void PkgInfoParcel::WriteProvidesAppdefinedPrivileges(
+ GList* provides_appdefined_privileges) {
+ int size = g_list_length(provides_appdefined_privileges);
+ WriteInt(size);
+
+ for (GList* tmp = provides_appdefined_privileges; tmp; tmp = tmp->next) {
+ appdefined_privilege_x* ptr =
+ reinterpret_cast<appdefined_privilege_x*>(tmp->data);
+ WriteString(ptr->type);
+ WriteString(ptr->value);
+ WriteString(ptr->license);
+ }
+}
+
+void PkgInfoParcel::WriteApplication(GList* application) {
+ std::vector<application_x *> app_vt;
+
+ for (GList* tmp = application; tmp; tmp = tmp->next) {
+ application_x* ptr = reinterpret_cast<application_x*>(tmp->data);
+ app_vt.push_back(ptr);
+ }
+
+ auto app_list = std::make_unique<AppInfoParcel>(std::move(app_vt));
+
+ WriteParcel(std::move(app_list));
+}
+
+void PkgInfoParcel::WriteCompatibility(
+ GList* compatibility) {
+ return;
+}
+
+void PkgInfoParcel::WriteDeviceprofile(
+ GList* deviceprofile) {
+ int size = g_list_length(deviceprofile);
+ WriteInt(size);
+
+ for (GList* tmp = deviceprofile; tmp; tmp = tmp->next)
+ WriteString(reinterpret_cast<char *>(tmp->data));
+}
+
+void PkgInfoParcel::WriteDependencies(GList* dependencies) {
+ int size = g_list_length(dependencies);
+ WriteInt(size);
+
+ for (GList* tmp = dependencies; tmp; tmp = tmp->next) {
+ dependency_x* ptr = reinterpret_cast<dependency_x*>(tmp->data);
+ WriteString(ptr->depends_on);
+ WriteString(ptr->type);
+ WriteString(ptr->required_version);
+ }
+}
+
+void PkgInfoParcel::WritePlugin(GList* plugin) {
+ int size = g_list_length(plugin);
+ WriteInt(size);
+
+ for (GList* tmp = plugin; tmp; tmp = tmp->next) {
+ plugin_x* ptr = reinterpret_cast<plugin_x*>(tmp->data);
+ WriteString(ptr->pkgid);
+ WriteString(ptr->appid);
+ WriteString(ptr->plugin_type);
+ WriteString(ptr->plugin_name);
+ }
+}
+
+void PkgInfoParcel::WritePackage(package_x *package) {
+ WriteString(package->for_all_users);
+ WriteString(package->package);
+ WriteString(package->version);
+ WriteString(package->installlocation);
+ WriteString(package->ns);
+ WriteString(package->removable);
+ WriteString(package->preload);
+ WriteString(package->readonly);
+ WriteString(package->update);
+ WriteString(package->appsetting);
+ WriteString(package->system);
+ WriteString(package->type);
+ WriteString(package->package_size);
+ WriteString(package->installed_time);
+ WriteString(package->installed_storage);
+ WriteString(package->storeclient_id);
+ WriteString(package->mainapp_id);
+ WriteString(package->package_url);
+ WriteString(package->root_path);
+ WriteString(package->csc_path);
+ WriteString(package->nodisplay_setting);
+ WriteString(package->support_mode);
+ WriteString(package->support_disable);
+ WriteString(package->api_version);
+ WriteString(package->tep_name);
+ WriteString(package->zip_mount_file);
+ WriteString(package->backend_installer);
+ WriteString(package->external_path);
+ WriteString(package->use_system_certs);
+ WriteIcon(package->icon);
+ WriteLabel(package->label);
+ WriteAuthor(package->author);
+ WriteDescription(package->description);
+ //WriteLicense(package->license);
+ WritePrivileges(package->privileges);
+ WriteAppdefinedPrivileges(package->appdefined_privileges);
+ WriteProvidesAppdefinedPrivileges(package->provides_appdefined_privileges);
+ WriteApplication(package->application);
+ //WriteCompatibility(package->compatibility);
+ WriteDeviceprofile(package->deviceprofile);
+ WriteDependencies(package->dependencies);
+ WritePlugin(package->plugin);
+}
+
+void PkgInfoParcel::ReadIcon(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+ icon->text = ReadString();
+ icon->lang = ReadString();
+ icon->section = ReadString();
+ icon->size = ReadString();
+ icon->resolution = ReadString();
+ icon->dpi = ReadString();
+
+ *list = g_list_append(*list, icon);
+ }
+}
+
+void PkgInfoParcel::ReadLabel(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+ label->lang = ReadString();
+ label->name = ReadString();
+ label->text = ReadString();
+
+ *list = g_list_append(*list, label);
+ }
+}
+
+void PkgInfoParcel::ReadAuthor(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
+ author->email = ReadString();
+ author->href = ReadString();
+ author->text = ReadString();
+ author->lang = ReadString();
+
+ *list = g_list_append(*list, author);
+ }
+}
+
+void PkgInfoParcel::ReadDescription(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ description_x* description =
+ reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
+ description->name = ReadString();
+ description->text = ReadString();
+ description->lang = ReadString();
+
+ *list = g_list_append(*list, description);
+ }
+}
+
+void PkgInfoParcel::ReadLicense(GList** list) {
+ return;
+}
+
+void PkgInfoParcel::ReadPrivileges(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ privilege_x* privilege =
+ reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ privilege->type = ReadString();
+ privilege->value = ReadString();
+
+ *list = g_list_append(*list, privilege);
+ }
+}
+
+void PkgInfoParcel::ReadAppdefinedPrivileges(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ appdefined_privilege_x* appdefined_privilege =
+ reinterpret_cast<appdefined_privilege_x*>(
+ calloc(1, sizeof(appdefined_privilege_x)));
+ appdefined_privilege->type = ReadString();
+ appdefined_privilege->value = ReadString();
+ appdefined_privilege->license = ReadString();
+
+ *list = g_list_append(*list, appdefined_privilege);
+ }
+}
+
+void PkgInfoParcel::ReadProvidesAppdefinedPrivileges(
+ GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ appdefined_privilege_x* appdefined_privilege =
+ reinterpret_cast<appdefined_privilege_x*>(
+ calloc(1, sizeof(appdefined_privilege_x)));
+ appdefined_privilege->type = ReadString();
+ appdefined_privilege->value = ReadString();
+ appdefined_privilege->license = ReadString();
+
+ *list = g_list_append(*list, appdefined_privilege);
+ }
+}
+
+void PkgInfoParcel::ReadApplication(GList** list) {
+ const unsigned char *buf = nullptr;
+ unsigned int size = 0;
+ ReadParcelRaw(&buf, &size);
+ auto appinfo_parcel = AppInfoParcel::Create(buf, size);
+ auto appinfo_list = appinfo_parcel->GetAppInfo();
+
+ for (const auto& application : appinfo_list)
+ *list = g_list_append(*list, application);
+}
+
+void PkgInfoParcel::ReadCompatibility(GList** list) {
+ return;
+}
+
+void PkgInfoParcel::ReadDeviceprofile(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i)
+ *list = g_list_append(*list, ReadString());
+}
+
+void PkgInfoParcel::ReadDependencies(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ dependency_x* dependendy =
+ reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
+ dependendy->depends_on = ReadString();
+ dependendy->type = ReadString();
+ dependendy->required_version = ReadString();
+
+ *list = g_list_append(*list, dependendy);
+ }
+}
+
+void PkgInfoParcel::ReadPlugin(GList** list) {
+ int size = ReadInt();
+
+ for (int i = 0; i < size; ++i) {
+ plugin_x* plugin = reinterpret_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
+ plugin->pkgid = ReadString();
+ plugin->appid = ReadString();
+ plugin->plugin_type = ReadString();
+ plugin->plugin_name = ReadString();
+
+ *list = g_list_append(*list, plugin);
+ }
+}
+
+package_x *PkgInfoParcel::ReadPackage() {
+ package_x* package =
+ reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
+
+ package->for_all_users = ReadString();
+ package->package = ReadString();
+ package->version = ReadString();
+ package->installlocation = ReadString();
+ package->ns = ReadString();
+ package->removable = ReadString();
+ package->preload = ReadString();
+ package->readonly = ReadString();
+ package->update = ReadString();
+ package->appsetting = ReadString();
+ package->system = ReadString();
+ package->type = ReadString();
+ package->package_size = ReadString();
+ package->installed_time = ReadString();
+ package->installed_storage = ReadString();
+ package->storeclient_id = ReadString();
+ package->mainapp_id = ReadString();
+ package->package_url = ReadString();
+ package->root_path = ReadString();
+ package->csc_path = ReadString();
+ package->nodisplay_setting = ReadString();
+ package->support_mode = ReadString();
+ package->support_disable = ReadString();
+ package->api_version = ReadString();
+ package->tep_name = ReadString();
+ package->zip_mount_file = ReadString();
+ package->backend_installer = ReadString();
+ package->external_path = ReadString();
+ package->use_system_certs = ReadString();
+ ReadIcon(&package->icon);
+ ReadLabel(&package->label);
+ ReadAuthor(&package->author);
+ ReadDescription(&package->description);
+ //ReadLicense(&package->license);
+ ReadPrivileges(&package->privileges);
+ ReadAppdefinedPrivileges(&package->appdefined_privileges);
+ ReadProvidesAppdefinedPrivileges(&package->provides_appdefined_privileges);
+ ReadApplication(&package->application);
+ //ReadCompatibility(&package->compatibility);
+ ReadDeviceprofile(&package->deviceprofile);
+ ReadDependencies(&package->dependencies);
+ ReadPlugin(&package->plugin);
+
+ return package;
+}
+
+PkgInfoParcel::PkgInfoParcel(
+ const unsigned char* buf, unsigned int size) : AbstractParcel(buf, size) {}
+
+PkgInfoParcel::PkgInfoParcel(std::vector<package_x *>&& pkg_list)
+ : pkg_list_(std::move(pkg_list)) {}
+
+const std::vector<unsigned char>& PkgInfoParcel::Serialize() {
+ WriteInt(pkg_list_.size());
+
+ for (auto pkg : pkg_list_) {
+ WritePackage(pkg);
+ }
+
+ return data_;
+}
+
+const std::vector<package_x *> PkgInfoParcel::GetPkgInfo() {
+ return pkg_list_;
+}
+
+std::unique_ptr<PkgInfoParcel> PkgInfoParcel::Create(
+ const unsigned char* buf, unsigned int size) {
+ PkgInfoParcel parcel(buf, size);
+ std::vector<package_x *> pkg_list;
+
+ int len = parcel.ReadInt();
+
+ for (int i = 0; i < len ; ++i) {
+ pkg_list.emplace_back(parcel.ReadPackage());
+ }
+
+ return std::make_unique<PkgInfoParcel>(std::move(pkg_list));
}
std::unique_ptr<AbstractParcel> PkgInfoParcel::Factory::CreateParcel() {
#include <vector>
-#include "pkgmgrinfo_private.h"
+#include "pkgmgrinfo_basic.h"
namespace pkgmgr_common {
namespace parcel {
public:
std::unique_ptr<AbstractParcel> CreateParcel();
};
- std::vector<std::unique_ptr<pkgmgr_pkginfo_x>> GetPkgInfoList();
- bool SetPkgInfoList(std::vector<std::unique_ptr<pkgmgr_pkginfo_x>> packages);
- std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+
+ PkgInfoParcel() = default;
+ PkgInfoParcel(const unsigned char* buf, unsigned int size);
+ PkgInfoParcel(std::vector<package_x *>&& pkg_list);
+ const std::vector<package_x *> GetPkgInfo();
+ const std::vector<unsigned char>& Serialize() override;
+ static std::unique_ptr<PkgInfoParcel> Create(
+ const unsigned char* buf, unsigned int size);
+
+ private:
+ void WriteIcon(GList* icon);
+ void WriteLabel(GList* label);
+ void WriteAuthor(GList* author);
+ void WriteDescription(GList* description);
+ void WriteLicense(GList* license);
+ void WritePrivileges(GList* privileges);
+ void WriteAppdefinedPrivileges(GList* appdefined_privileges);
+ void WriteProvidesAppdefinedPrivileges(GList* provides_appdefined_privileges);
+ void WriteApplication(GList* application);
+ void WriteCompatibility(GList* compatibility);
+ void WriteDeviceprofile(GList* deviceprofile);
+ void WriteDependencies(GList* dependencies);
+ void WritePlugin(GList* plugin);
+ void WritePackage(package_x *package);
+ void ReadIcon(GList** list);
+ void ReadLabel(GList** list);
+ void ReadAuthor(GList** list);
+ void ReadDescription(GList** list);
+ void ReadLicense(GList** list);
+ void ReadPrivileges(GList** list);
+ void ReadAppdefinedPrivileges(GList** list);
+ void ReadProvidesAppdefinedPrivileges(GList** list);
+ void ReadApplication(GList** list);
+ void ReadCompatibility(GList** list);
+ void ReadDeviceprofile(GList** list);
+ void ReadDependencies(GList** list);
+ void ReadPlugin(GList** list);
+ package_x *ReadPackage();
+
+ std::vector<package_x *> pkg_list_;
};
} // namespace parcel
return nullptr;
}
+const std::vector<unsigned char>& StringParcel::Serialize() { return data_; }
+
std::unique_ptr<AbstractParcel> StringParcel::Factory::CreateParcel() {
return nullptr;
}
std::string GetString();
int GetInt();
std::unique_ptr<AbstractParcel> Deserialize(std::vector<unsigned char> data);
+ const std::vector<unsigned char>& Serialize() override;
};
} // namespace parcel
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "parcel_utils.hh"
+
+#include <cstdio>
+#include <iostream>
+
+#include "pkgmgrinfo_basic.h"
+
+bool IS_STR_EQ(const char *a, const char *b) {
+ if (a == nullptr && b == nullptr)
+ return true;
+ if (a == nullptr || b == nullptr)
+ return false;
+ return strcmp(a, b) == 0;
+}
+
+#define STR_EQ(str_a, str_b) do { \
+ if (!IS_STR_EQ(str_a, str_b)) { \
+ std::cout << #str_a << " is not equal to " << #str_b; \
+ return false; \
+ } \
+ return true; \
+} while (0);
+
+application_x *GetTestApplication(std::string appid) {
+ application_x *application;
+ application = reinterpret_cast<application_x*>(calloc(1, sizeof(application_x)));
+
+ application->appid = strdup(appid.c_str());
+ application->exec = strdup("test_exec");
+ application->nodisplay = strdup("test_nodisplay");
+ application->multiple = strdup("test_multiple");
+ application->taskmanage = strdup("test_taskmanage");
+ application->type = strdup("test_type");
+ application->categories = strdup("test_categories");
+ application->extraid = strdup("test_extraid");
+ application->hwacceleration = strdup("test_hwacceleration");
+ application->screenreader = strdup("test_screenreader");
+ application->mainapp = strdup("test_mainapp");
+ application->package = strdup("test_package");
+ application->recentimage = strdup("test_recentimage");
+ application->launchcondition = strdup("test_launchcondition");
+ application->indicatordisplay = strdup("test_indicatordisplay");
+ application->portraitimg = strdup("test_portraitimg");
+ application->landscapeimg = strdup("test_landscapeimg");
+ application->effectimage_type = strdup("test_effectimage_type");
+ application->guestmode_visibility = strdup("test_guestmode_visibility");
+ application->component = strdup("test_component");
+ application->permission_type = strdup("test_permission_type");
+ application->component_type = strdup("test_component_type");
+ application->preload = strdup("test_preload");
+ application->submode = strdup("test_submode");
+ application->submode_mainid = strdup("test_submode_mainid");
+ application->process_pool = strdup("test_process_pool");
+ application->installed_storage = strdup("test_installed_storage");
+ application->autorestart = strdup("test_autorestart");
+ application->onboot = strdup("test_onboot");
+ application->support_disable = strdup("test_support_disable");
+ application->ui_gadget = strdup("test_ui_gadget");
+ application->launch_mode = strdup("test_launch_mode");
+ application->support_ambient = strdup("test_support_ambient");
+ application->setup_appid = strdup("test_setup_appid");
+ application->alias_appid = strdup("test_alias_appid");
+ application->effective_appid = strdup("test_effective_appid");
+ application->package_type = strdup("test_package_type");
+ application->tep_name = strdup("test_tep_name");
+ application->zip_mount_file = strdup("test_zip_mount_file");
+ application->root_path = strdup("test_root_path");
+ application->api_version = strdup("test_api_version");
+ application->for_all_users = strdup("test_for_all_users");
+ application->is_disabled = strdup("test_is_disabled");
+ application->splash_screen_display = strdup("test_splash_screen_display");
+ application->external_path = strdup("test_external_path");
+ application->package_system = strdup("test_package_system");
+ application->removable = strdup("test_removable");
+ application->package_installed_time = strdup("test_package_installed_time");
+ application->support_mode = strdup("test_support_mode");
+
+
+ label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+ label->lang = strdup("test_lang");
+ label->name = strdup("test_name");
+ label->text = strdup("test_text");
+ application->label = g_list_append(application->label, label);
+
+ icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+ icon->text = strdup("test_text");
+ icon->lang = strdup("test_lang");
+ icon->section = strdup("test_section");
+ icon->size = strdup("test_size");
+ icon->resolution = strdup("test_resolution");
+ icon->dpi = strdup("test_dpi");
+ application->icon = g_list_append(application->icon, icon);
+
+ image_x* image = reinterpret_cast<image_x*>(calloc(1, sizeof(image_x)));
+ image->text = strdup("test_text");
+ image->lang = strdup("test_lang");
+ image->section = strdup("test_section");
+ application->image = g_list_append(application->image, image);
+
+ application->category =
+ g_list_append(application->category, strdup("test_category"));
+
+ metadata_x* metadata =
+ reinterpret_cast<metadata_x*>(calloc(1, sizeof(metadata_x)));
+ metadata->key = strdup("test_key");
+ metadata->value = strdup("test_value");
+ application->metadata = g_list_append(application->metadata, metadata);
+
+ datacontrol_x* datacontrol =
+ reinterpret_cast<datacontrol_x*>(calloc(1, sizeof(datacontrol_x)));
+ datacontrol->providerid = strdup("test_providerid");
+ datacontrol->access = strdup("test_access");
+ datacontrol->type = strdup("test_type");
+ datacontrol->trusted = strdup("test_trusted");
+ datacontrol->privileges = g_list_append(datacontrol->privileges,
+ strdup("test_datacontrol_privilege"));
+ application->datacontrol =
+ g_list_append(application->datacontrol, datacontrol);
+
+ application->background_category = g_list_append(
+ application->background_category, strdup("test_background_category"));
+
+ appcontrol_x* appcontrol =
+ reinterpret_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
+ appcontrol->operation = strdup("test_operation");
+ appcontrol->uri = strdup("test_uri");
+ appcontrol->mime = strdup("test_mime");
+ appcontrol->visibility = strdup("test_visibility");
+ appcontrol->id = strdup("test_id");
+ appcontrol->privileges = g_list_append(
+ appcontrol->privileges, strdup("test_appcontrol_privilege"));
+ application->appcontrol = g_list_append(application->appcontrol, appcontrol);
+
+ splashscreen_x* splashscreen =
+ reinterpret_cast<splashscreen_x*>(calloc(1, sizeof(splashscreen_x)));
+ splashscreen->src = strdup("test_src");
+ splashscreen->type = strdup("ttest_type");
+ splashscreen->dpi = strdup("test_dpi");
+ splashscreen->orientation = strdup("orientattest_orientation");
+ splashscreen->indicatordisplay = strdup("indicatordisptest_indicatordisplay");
+ splashscreen->operation = strdup("operattest_operation");
+ splashscreen->color_depth = strdup("color_detest_color_depth");
+ application->splashscreens =
+ g_list_append(application->splashscreens, splashscreen);
+
+ return application;
+}
+
+bool IsEqualApplication(application_x *applicationA,
+ application_x *applicationB) {
+ STR_EQ(applicationA->appid, applicationB->appid);
+ STR_EQ(applicationA->exec, applicationB->exec);
+ STR_EQ(applicationA->nodisplay, applicationB->nodisplay);
+ STR_EQ(applicationA->multiple, applicationB->multiple);
+ STR_EQ(applicationA->taskmanage, applicationB->taskmanage);
+ STR_EQ(applicationA->type, applicationB->type);
+ STR_EQ(applicationA->categories, applicationB->categories);
+ STR_EQ(applicationA->extraid, applicationB->extraid);
+ STR_EQ(applicationA->hwacceleration, applicationB->hwacceleration);
+ STR_EQ(applicationA->screenreader, applicationB->screenreader);
+ STR_EQ(applicationA->mainapp, applicationB->mainapp);
+ STR_EQ(applicationA->package, applicationB->package);
+ STR_EQ(applicationA->recentimage, applicationB->recentimage);
+ STR_EQ(applicationA->launchcondition, applicationB->launchcondition);
+ STR_EQ(applicationA->indicatordisplay, applicationB->indicatordisplay);
+ STR_EQ(applicationA->portraitimg, applicationB->portraitimg);
+ STR_EQ(applicationA->landscapeimg, applicationB->landscapeimg);
+ STR_EQ(applicationA->effectimage_type, applicationB->effectimage_type);
+ STR_EQ(applicationA->guestmode_visibility, applicationB->guestmode_visibility);
+ STR_EQ(applicationA->component, applicationB->component);
+ STR_EQ(applicationA->permission_type, applicationB->permission_type);
+ STR_EQ(applicationA->component_type, applicationB->component_type);
+ STR_EQ(applicationA->preload, applicationB->preload);
+ STR_EQ(applicationA->submode, applicationB->submode);
+ STR_EQ(applicationA->submode_mainid, applicationB->submode_mainid);
+ STR_EQ(applicationA->process_pool, applicationB->process_pool);
+ STR_EQ(applicationA->installed_storage, applicationB->installed_storage);
+ STR_EQ(applicationA->autorestart, applicationB->autorestart);
+ STR_EQ(applicationA->onboot, applicationB->onboot);
+ STR_EQ(applicationA->support_disable, applicationB->support_disable);
+ STR_EQ(applicationA->ui_gadget, applicationB->ui_gadget);
+ STR_EQ(applicationA->launch_mode, applicationB->launch_mode);
+ STR_EQ(applicationA->support_ambient, applicationB->support_ambient);
+ STR_EQ(applicationA->setup_appid, applicationB->setup_appid);
+ STR_EQ(applicationA->alias_appid, applicationB->alias_appid);
+ STR_EQ(applicationA->effective_appid, applicationB->effective_appid);
+ STR_EQ(applicationA->package_type, applicationB->package_type);
+ STR_EQ(applicationA->tep_name, applicationB->tep_name);
+ STR_EQ(applicationA->zip_mount_file, applicationB->zip_mount_file);
+ STR_EQ(applicationA->root_path, applicationB->root_path);
+ STR_EQ(applicationA->api_version, applicationB->api_version);
+ STR_EQ(applicationA->for_all_users, applicationB->for_all_users);
+ STR_EQ(applicationA->is_disabled, applicationB->is_disabled);
+ STR_EQ(applicationA->splash_screen_display, applicationB->splash_screen_display);
+ STR_EQ(applicationA->external_path, applicationB->external_path);
+ STR_EQ(applicationA->package_system, applicationB->package_system);
+ STR_EQ(applicationA->removable, applicationB->removable);
+ STR_EQ(applicationA->package_installed_time, applicationB->package_installed_time);
+ STR_EQ(applicationA->support_mode, applicationB->support_mode);
+
+ if (g_list_length(applicationA->label) != g_list_length(applicationB->label))
+ return false;
+ for (GList *a = applicationA->label, *b = applicationB->label;
+ a && b; a = a->next, b = b->next) {
+ label_x *label_a = reinterpret_cast<label_x *>(a->data);
+ label_x *label_b = reinterpret_cast<label_x *>(b->data);
+ STR_EQ(label_a->lang, label_b->lang);
+ STR_EQ(label_a->name, label_b->name);
+ STR_EQ(label_a->text, label_b->text);
+ }
+
+ if (g_list_length(applicationA->icon) != g_list_length(applicationB->icon))
+ return false;
+ for (GList *a = applicationA->icon, *b = applicationB->icon;
+ a && b; a = a->next, b = b->next) {
+ icon_x *icon_a = reinterpret_cast<icon_x *>(a->data);
+ icon_x *icon_b = reinterpret_cast<icon_x *>(b->data);
+ STR_EQ(icon_a->dpi, icon_b->dpi);
+ STR_EQ(icon_a->lang, icon_b->lang);
+ STR_EQ(icon_a->resolution, icon_b->resolution);
+ STR_EQ(icon_a->section, icon_b->section);
+ STR_EQ(icon_a->size, icon_b->size);
+ STR_EQ(icon_a->text, icon_b->text);
+ }
+
+ if (g_list_length(applicationA->image) != g_list_length(applicationB->image))
+ return false;
+ for (GList *a = applicationA->image, *b = applicationB->image;
+ a && b; a = a->next, b = b->next) {
+ image_x *image_a = reinterpret_cast<image_x *>(a->data);
+ image_x *image_b = reinterpret_cast<image_x *>(b->data);
+ STR_EQ(image_a->lang, image_b->lang);
+ STR_EQ(image_a->section, image_b->section);
+ STR_EQ(image_a->text, image_b->text);
+ }
+
+ if (g_list_length(applicationA->category) !=
+ g_list_length(applicationB->category))
+ return false;
+ for (GList *a = applicationA->category, *b = applicationB->category;
+ a && b; a = a->next, b = b->next) {
+ char *category_a = reinterpret_cast<char *>(a->data);
+ char *category_b = reinterpret_cast<char *>(b->data);
+ STR_EQ(category_a, category_b);
+ }
+
+ if (g_list_length(applicationA->metadata) !=
+ g_list_length(applicationB->metadata))
+ return false;
+ for (GList *a = applicationA->metadata, *b = applicationB->metadata;
+ a && b; a = a->next, b = b->next) {
+ metadata_x *metadata_a = reinterpret_cast<metadata_x *>(a->data);
+ metadata_x *metadata_b = reinterpret_cast<metadata_x *>(b->data);
+ STR_EQ(metadata_a->key, metadata_b->key);
+ STR_EQ(metadata_a->value, metadata_b->value);
+ }
+
+ if (g_list_length(applicationA->datacontrol) !=
+ g_list_length(applicationB->datacontrol))
+ return false;
+ for (GList *a = applicationA->datacontrol, *b = applicationB->datacontrol;
+ a && b; a = a->next, b = b->next) {
+ datacontrol_x *datacontrol_a = reinterpret_cast<datacontrol_x *>(a->data);
+ datacontrol_x *datacontrol_b = reinterpret_cast<datacontrol_x *>(b->data);
+ STR_EQ(datacontrol_a->access, datacontrol_b->access);
+ STR_EQ(datacontrol_a->providerid, datacontrol_b->providerid);
+ STR_EQ(datacontrol_a->trusted, datacontrol_b->trusted);
+ STR_EQ(datacontrol_a->type, datacontrol_b->type);
+ if (g_list_length(datacontrol_a->privileges)
+ != g_list_length(datacontrol_b->privileges))
+ return false;
+ for (GList *a = datacontrol_a->privileges, *b = datacontrol_b->privileges;
+ a && b; a = a->next, b = b->next) {
+ char *privilege_a = reinterpret_cast<char *>(a->data);
+ char *privilege_b = reinterpret_cast<char *>(b->data);
+ STR_EQ(privilege_a, privilege_b);
+ }
+ }
+
+ if (g_list_length(applicationA->background_category) !=
+ g_list_length(applicationB->background_category))
+ return false;
+ for (GList *a = applicationA->background_category, *b = applicationB->background_category;
+ a && b; a = a->next, b = b->next) {
+ char *background_category_a = reinterpret_cast<char *>(a->data);
+ char *background_category_b = reinterpret_cast<char *>(b->data);
+ STR_EQ(background_category_a, background_category_b);
+ }
+
+ if (g_list_length(applicationA->appcontrol) !=
+ g_list_length(applicationB->appcontrol))
+ return false;
+ for (GList *a = applicationA->appcontrol, *b = applicationB->appcontrol;
+ a && b; a = a->next, b = b->next) {
+ appcontrol_x *appcontrol_a = reinterpret_cast<appcontrol_x *>(a->data);
+ appcontrol_x *appcontrol_b = reinterpret_cast<appcontrol_x *>(b->data);
+ STR_EQ(appcontrol_a->id, appcontrol_b->id);
+ STR_EQ(appcontrol_a->mime, appcontrol_b->mime);
+ STR_EQ(appcontrol_a->operation, appcontrol_b->operation);
+ STR_EQ(appcontrol_a->uri, appcontrol_b->uri);
+ STR_EQ(appcontrol_a->visibility, appcontrol_b->visibility);
+ if (g_list_length(appcontrol_a->privileges)
+ != g_list_length(appcontrol_b->privileges))
+ return false;
+ for (GList *a = appcontrol_a->privileges, *b = appcontrol_b->privileges;
+ a && b; a = a->next, b = b->next) {
+ char *privilege_a = reinterpret_cast<char *>(a->data);
+ char *privilege_b = reinterpret_cast<char *>(b->data);
+ STR_EQ(privilege_a, privilege_b);
+ }
+ }
+
+ if (g_list_length(applicationA->splashscreens) !=
+ g_list_length(applicationB->splashscreens))
+ return false;
+ for (GList *a = applicationA->splashscreens, *b = applicationB->splashscreens;
+ a && b; a = a->next, b = b->next) {
+ splashscreen_x *splashscreen_a = reinterpret_cast<splashscreen_x *>(a->data);
+ splashscreen_x *splashscreen_b = reinterpret_cast<splashscreen_x *>(b->data);
+ STR_EQ(splashscreen_a->color_depth, splashscreen_b->color_depth);
+ STR_EQ(splashscreen_a->dpi, splashscreen_b->dpi);
+ STR_EQ(splashscreen_a->indicatordisplay, splashscreen_b->indicatordisplay);
+ STR_EQ(splashscreen_a->operation, splashscreen_b->operation);
+ STR_EQ(splashscreen_a->orientation, splashscreen_b->orientation);
+ STR_EQ(splashscreen_a->src, splashscreen_b->src);
+ STR_EQ(splashscreen_a->type, splashscreen_b->type);
+ }
+
+ return true;
+}
+
+bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
+ const std::vector<application_x *>& applicationsB) {
+ if (applicationsA.size() != applicationsB.size())
+ return false;
+
+ for (unsigned int i = 0; i < applicationsA.size(); ++i) {
+ if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
+ return false;
+ }
+
+ return true;
+}
+
+package_x *GetTestPackage(std::string pkgid) {
+ package_x *package;
+ package = reinterpret_cast<package_x*>(calloc(1, sizeof(package_x)));
+
+ package->for_all_users = strdup("test_for_all_users");
+ package->package = strdup("test_package");
+ package->version = strdup("test_version");
+ package->installlocation = strdup("test_installlocation");
+ package->ns = strdup("test_ns");
+ package->removable = strdup("test_removable");
+ package->preload = strdup("test_preload");
+ package->readonly = strdup("test_readonly");
+ package->update = strdup("test_update");
+ package->appsetting = strdup("test_appsetting");
+ package->system = strdup("test_system");
+ package->type = strdup("test_type");
+ package->package_size = strdup("test_package_size");
+ package->installed_time = strdup("test_installed_time");
+ package->installed_storage = strdup("test_installed_storage");
+ package->storeclient_id = strdup("test_storeclient_id");
+ package->mainapp_id = strdup("test_mainapp_id");
+ package->package_url = strdup("test_package_url");
+ package->root_path = strdup("test_root_path");
+ package->csc_path = strdup("test_csc_path");
+ package->nodisplay_setting = strdup("test_nodisplay_setting");
+ package->support_mode = strdup("test_support_mode");
+ package->support_disable = strdup("test_support_disable");
+ package->api_version = strdup("test_api_version");
+ package->tep_name = strdup("test_tep_name");
+ package->zip_mount_file = strdup("test_zip_mount_file");
+ package->backend_installer = strdup("test_backend_installer");
+ package->external_path = strdup("test_external_path");
+ package->use_system_certs = strdup("test_use_system_certs");
+
+ icon_x* icon = reinterpret_cast<icon_x*>(calloc(1, sizeof(icon_x)));
+ icon->text = strdup("test_text");
+ icon->lang = strdup("test_lang");
+ icon->section = strdup("test_section");
+ icon->size = strdup("test_size");
+ icon->resolution = strdup("test_resolution");
+ icon->dpi = strdup("test_dpi");
+ package->icon = g_list_append(package->icon, icon);
+
+
+ label_x* label = reinterpret_cast<label_x*>(calloc(1, sizeof(label_x)));
+ label->lang = strdup("test_lang");
+ label->name = strdup("test_name");
+ label->text = strdup("test_text");
+
+ package->label = g_list_append(package->label, label);
+
+ author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
+ author->email = strdup("test_email");
+ author->href = strdup("test_href");
+ author->text = strdup("test_text");
+ author->lang = strdup("test_lang");
+
+ package->author = g_list_append(package->author, author);
+
+ description_x* description = reinterpret_cast<description_x*>(calloc(1, sizeof(description_x)));
+ description->name = strdup("test_name");
+ description->text = strdup("test_text");
+ description->lang = strdup("test_lang");
+
+ package->description = g_list_append(package->description, description);
+
+ privilege_x* privilege = reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
+ privilege->type = strdup("test_type");
+ privilege->value = strdup("test_value");
+
+ package->privileges = g_list_append(package->privileges, privilege);
+
+ appdefined_privilege_x* appdefined_privilege = reinterpret_cast<appdefined_privilege_x*>(calloc(1, sizeof(appdefined_privilege_x)));
+ appdefined_privilege->type = strdup("test_type");
+ appdefined_privilege->value = strdup("test_value");
+ appdefined_privilege->license = strdup("test_license");
+
+ package->appdefined_privileges = g_list_append(package->appdefined_privileges, appdefined_privilege);
+
+ appdefined_privilege_x* provides_appdefined_privileges = reinterpret_cast<appdefined_privilege_x*>(calloc(1, sizeof(appdefined_privilege_x)));
+ provides_appdefined_privileges->type = strdup("test_type");
+ provides_appdefined_privileges->value = strdup("test_value");
+ provides_appdefined_privileges->license = strdup("test_license");
+
+ package->provides_appdefined_privileges = g_list_append(package->provides_appdefined_privileges, appdefined_privilege);
+
+ dependency_x* dependency = reinterpret_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
+ dependency->depends_on = strdup("test_depends_on");
+ dependency->type = strdup("test_type");
+ dependency->required_version = strdup("test_required_version");
+
+ package->dependencies = g_list_append(package->dependencies, dependency);
+
+ plugin_x* plugin = reinterpret_cast<plugin_x*>(calloc(1, sizeof(plugin_x)));
+ plugin->pkgid = strdup(pkgid.c_str());
+ plugin->appid = strdup("test_appid");
+ plugin->plugin_type = strdup("test_plugin_type");
+ plugin->plugin_name = strdup("test_plugin_name");
+
+ package->plugin = g_list_append(package->plugin, plugin);
+
+ package->application = g_list_append(package->application,
+ GetTestApplication("test_app1"));
+ package->application = g_list_append(package->application,
+ GetTestApplication("test_app2"));
+
+ return package;
+}
+
+bool IsEqualPackage(package_x *packageA, package_x *packageB) {
+ STR_EQ(packageA->for_all_users, packageB->for_all_users);
+ STR_EQ(packageA->package, packageB->package);
+ STR_EQ(packageA->version, packageB->version);
+ STR_EQ(packageA->installlocation, packageB->installlocation);
+ STR_EQ(packageA->ns, packageB->ns);
+ STR_EQ(packageA->removable, packageB->removable);
+ STR_EQ(packageA->preload, packageB->preload);
+ STR_EQ(packageA->readonly, packageB->readonly);
+ STR_EQ(packageA->update, packageB->update);
+ STR_EQ(packageA->appsetting, packageB->appsetting);
+ STR_EQ(packageA->system, packageB->system);
+ STR_EQ(packageA->type, packageB->type);
+ STR_EQ(packageA->package_size, packageB->package_size);
+ STR_EQ(packageA->installed_time, packageB->installed_time);
+ STR_EQ(packageA->installed_storage, packageB->installed_storage);
+ STR_EQ(packageA->storeclient_id, packageB->storeclient_id);
+ STR_EQ(packageA->mainapp_id, packageB->mainapp_id);
+ STR_EQ(packageA->package_url, packageB->package_url);
+ STR_EQ(packageA->root_path, packageB->root_path);
+ STR_EQ(packageA->csc_path, packageB->csc_path);
+ STR_EQ(packageA->nodisplay_setting, packageB->nodisplay_setting);
+ STR_EQ(packageA->support_mode, packageB->support_mode);
+ STR_EQ(packageA->support_disable, packageB->support_disable);
+ STR_EQ(packageA->api_version, packageB->api_version);
+ STR_EQ(packageA->tep_name, packageB->tep_name);
+ STR_EQ(packageA->zip_mount_file, packageB->zip_mount_file);
+ STR_EQ(packageA->backend_installer, packageB->backend_installer);
+ STR_EQ(packageA->external_path, packageB->external_path);
+ STR_EQ(packageA->use_system_certs, packageB->use_system_certs);
+
+ if (g_list_length(packageA->icon) != g_list_length(packageB->icon))
+ return false;
+ for (GList *a = packageA->icon, *b = packageB->icon;
+ a && b; a = a->next, b = b->next) {
+ icon_x *icon_a = reinterpret_cast<icon_x *>(a->data);
+ icon_x *icon_b = reinterpret_cast<icon_x *>(b->data);
+ STR_EQ(icon_a->dpi, icon_b->dpi);
+ STR_EQ(icon_a->lang, icon_b->lang);
+ STR_EQ(icon_a->resolution, icon_b->resolution);
+ STR_EQ(icon_a->section, icon_b->section);
+ STR_EQ(icon_a->size, icon_b->size);
+ STR_EQ(icon_a->text, icon_b->text);
+ }
+
+ if (g_list_length(packageA->label) != g_list_length(packageB->label))
+ return false;
+ for (GList *a = packageA->label, *b = packageB->label;
+ a && b; a = a->next, b = b->next) {
+ label_x *label_a = reinterpret_cast<label_x *>(a->data);
+ label_x *label_b = reinterpret_cast<label_x *>(b->data);
+ STR_EQ(label_a->lang, label_b->lang);
+ STR_EQ(label_a->name, label_b->name);
+ STR_EQ(label_a->text, label_b->text);
+ }
+
+ if (g_list_length(packageA->author) != g_list_length(packageB->author))
+ return false;
+ for (GList *a = packageA->author, *b = packageB->author;
+ a && b; a = a->next, b = b->next) {
+ author_x *author_a = reinterpret_cast<author_x *>(a->data);
+ author_x *author_b = reinterpret_cast<author_x *>(b->data);
+ STR_EQ(author_a->email, author_b->email);
+ STR_EQ(author_a->href, author_b->href);
+ STR_EQ(author_a->lang, author_b->lang);
+ STR_EQ(author_a->text, author_b->text);
+ }
+
+ if (g_list_length(packageA->description) != g_list_length(packageB->description))
+ return false;
+ for (GList *a = packageA->description, *b = packageB->description;
+ a && b; a = a->next, b = b->next) {
+ description_x *description_a = reinterpret_cast<description_x *>(a->data);
+ description_x *description_b = reinterpret_cast<description_x *>(b->data);
+ STR_EQ(description_a->lang, description_b->lang);
+ STR_EQ(description_a->name, description_b->name);
+ STR_EQ(description_a->text, description_b->text);
+ }
+
+ if (g_list_length(packageA->privileges) != g_list_length(packageB->privileges))
+ return false;
+ for (GList *a = packageA->privileges, *b = packageB->privileges;
+ a && b; a = a->next, b = b->next) {
+ privilege_x *privilege_a = reinterpret_cast<privilege_x *>(a->data);
+ privilege_x *privilege_b = reinterpret_cast<privilege_x *>(b->data);
+ STR_EQ(privilege_a->type, privilege_b->type);
+ STR_EQ(privilege_a->value, privilege_b->value);
+ }
+
+ if (g_list_length(packageA->appdefined_privileges) != g_list_length(packageB->appdefined_privileges))
+ return false;
+ for (GList *a = packageA->appdefined_privileges, *b = packageB->appdefined_privileges;
+ a && b; a = a->next, b = b->next) {
+ appdefined_privilege_x *privilege_a = reinterpret_cast<appdefined_privilege_x *>(a->data);
+ appdefined_privilege_x *privilege_b = reinterpret_cast<appdefined_privilege_x *>(b->data);
+ STR_EQ(privilege_a->license, privilege_b->license);
+ STR_EQ(privilege_a->type, privilege_b->type);
+ STR_EQ(privilege_a->value, privilege_b->value);
+ }
+
+ if (g_list_length(packageA->provides_appdefined_privileges) != g_list_length(packageB->provides_appdefined_privileges))
+ return false;
+ for (GList *a = packageA->provides_appdefined_privileges, *b = packageB->provides_appdefined_privileges;
+ a && b; a = a->next, b = b->next) {
+ appdefined_privilege_x *privilege_a = reinterpret_cast<appdefined_privilege_x *>(a->data);
+ appdefined_privilege_x *privilege_b = reinterpret_cast<appdefined_privilege_x *>(b->data);
+ STR_EQ(privilege_a->license, privilege_b->license);
+ STR_EQ(privilege_a->type, privilege_b->type);
+ STR_EQ(privilege_a->value, privilege_b->value);
+ }
+
+ if (g_list_length(packageA->dependencies) != g_list_length(packageB->dependencies))
+ return false;
+ for (GList *a = packageA->dependencies, *b = packageB->dependencies;
+ a && b; a = a->next, b = b->next) {
+ dependency_x *dependency_a = reinterpret_cast<dependency_x *>(a->data);
+ dependency_x *dependency_b = reinterpret_cast<dependency_x *>(b->data);
+ STR_EQ(dependency_a->depends_on, dependency_b->depends_on);
+ STR_EQ(dependency_a->required_version, dependency_b->required_version);
+ STR_EQ(dependency_a->type, dependency_b->type);
+ }
+
+ if (g_list_length(packageA->plugin) != g_list_length(packageB->plugin))
+ return false;
+ for (GList *a = packageA->plugin, *b = packageB->plugin;
+ a && b; a = a->next, b = b->next) {
+ plugin_x *plugin_a = reinterpret_cast<plugin_x *>(a->data);
+ plugin_x *plugin_b = reinterpret_cast<plugin_x *>(b->data);
+ STR_EQ(plugin_a->appid, plugin_b->appid);
+ STR_EQ(plugin_a->pkgid, plugin_b->pkgid);
+ STR_EQ(plugin_a->plugin_name, plugin_b->plugin_name);
+ STR_EQ(plugin_a->plugin_type, plugin_b->plugin_type);
+ }
+
+ if (g_list_length(packageA->application) != g_list_length(packageB->application))
+ return false;
+ for (GList *a = packageA->application, *b = packageB->application;
+ a && b; a = a->next, b = b->next) {
+ application_x *application_a = reinterpret_cast<application_x *>(a->data);
+ application_x *application_b = reinterpret_cast<application_x *>(b->data);
+
+ if (!IsEqualApplication(application_a, application_b))
+ return false;
+ }
+
+ return true;
+}
+
+bool IsEqualPackages(const std::vector<package_x *>&packagesA,
+ const std::vector<package_x *>&packagesB) {
+ if (packagesA.size() != packagesB.size())
+ return false;
+
+ for (unsigned int i = 0; i < packagesA.size(); ++i) {
+ if (!IsEqualPackage(packagesA[i], packagesB[i]))
+ return false;
+ }
+
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <string>
+#include <vector>
+
+#include "pkgmgrinfo_basic.h"
+
+application_x *GetTestApplication(std::string appid);
+
+bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
+ const std::vector<application_x *>& applicationsB);
+
+package_x *GetTestPackage(std::string pkgid);
+
+bool IsEqualPackages(const std::vector<package_x *>&packagesA,
+ const std::vector<package_x *>&packagesB);
#include "common/parcel/pkginfo_parcel.hh"
#include "common/parcel/string_parcel.hh"
+#include "pkgmgrinfo_basic.h"
+
+#include "parcel_utils.hh"
+
namespace pp = pkgmgr_common::parcel;
class ParcelTest : public ::testing::Test {
}
};
+TEST_F(ParcelTest, AppInfoParcel) {
+ std::vector<application_x *> origin_applications;
+
+ origin_applications.emplace_back(GetTestApplication("test_appid1"));
+ origin_applications.emplace_back(GetTestApplication("test_appid2"));
+ std::unique_ptr<pp::AppInfoParcel> origin_parcel =
+ std::make_unique<pp::AppInfoParcel>(std::move(origin_applications));
+ EXPECT_NE(origin_parcel, nullptr);
+
+ const std::vector<unsigned char> serialized = origin_parcel->Serialize();
+ EXPECT_NE(serialized.size(), 0);
+
+ auto new_parcel =
+ pp::AppInfoParcel::Create(&serialized[0], serialized.size());
+ EXPECT_NE(new_parcel, nullptr);
+
+ std::vector<application_x *> new_applications = new_parcel->GetAppInfo();
+ EXPECT_EQ(new_applications.size(), 2);
+ origin_applications = origin_parcel->GetAppInfo();
+
+ EXPECT_EQ(origin_applications.size(), new_applications.size());
+
+ EXPECT_TRUE(IsEqualApplications(origin_applications, new_applications));
+}
+
TEST_F(ParcelTest, PkgInfoParcel) {
- pp::PkgInfoParcel parcel;
- parcel.SetUid(10);
- EXPECT_EQ(parcel.GetUid(), 10);
+ std::vector<package_x *> origin_packages;
+
+ origin_packages.emplace_back(GetTestPackage("test_pkgid1"));
+ origin_packages.emplace_back(GetTestPackage("test_pkgid2"));
+ std::unique_ptr<pp::PkgInfoParcel> origin_parcel =
+ std::make_unique<pp::PkgInfoParcel>(std::move(origin_packages));
+ EXPECT_NE(origin_parcel, nullptr);
+
+ const std::vector<unsigned char> serialized = origin_parcel->Serialize();
+ EXPECT_NE(serialized.size(), 0);
+
+ auto new_parcel =
+ pp::PkgInfoParcel::Create(&serialized[0], serialized.size());
+ EXPECT_NE(new_parcel, nullptr);
+
+ std::vector<package_x *> new_packages = new_parcel->GetPkgInfo();
+ EXPECT_EQ(new_packages.size(), 2);
+ origin_packages = origin_parcel->GetPkgInfo();
+
+ EXPECT_EQ(origin_packages.size(), new_packages.size());
+
+ EXPECT_TRUE(IsEqualPackages(origin_packages, new_packages));
}