#include <vector>
#include "pkgmgrinfo_private.h"
+#include "pkgmgr-info.h"
namespace pkgmgr_common {
namespace parcel {
-std::unique_ptr<pkgmgrinfo_filter_x> FilterParcelable::GetFilter() { return {}; }
+FilterParcelable::FilterParcelable(pkgmgrinfo_filter_x *filter, int flag)
+ : filter_(filter), flag_(flag) {}
+
+FilterParcelable::~FilterParcelable() {
+ pkgmgrinfo_pkginfo_filter_destroy(filter_);
+}
+
+const pkgmgrinfo_filter_x *FilterParcelable::GetFilter() {
+ return filter_;
+}
+
+int FilterParcelable::GetFlag() {
+ return flag_;
+}
+
+void FilterParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
+ WriteInt(parcel, flag_);
+ WriteFilter(parcel, filter_);
+}
+
+void FilterParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
+ ReadInt(parcel, &flag_);
+ ReadFilter(parcel);
+}
+
+bool FilterParcelable::WriteFilter(
+ tizen_base::Parcel* parcel, pkgmgrinfo_filter_x *filter) const {
+ WriteInt(parcel, filter->uid);
+
+ WriteInt(parcel, g_slist_length(filter->list));
+ for (GSList *list = filter->list; list; list = list->next)
+ WritePkgmgrInfoNode(parcel, reinterpret_cast<pkgmgrinfo_node_x *>(list->data));
+
+ WriteInt(parcel, g_slist_length(filter->list_metadata));
+ for (GSList *list = filter->list_metadata; list; list = list->next)
+ WritePkgmgrInfoMetadataNode(parcel,
+ reinterpret_cast<pkgmgrinfo_metadata_node_x *>(list->data));
-bool FilterParcelable::SetFilter(std::unique_ptr<pkgmgrinfo_filter_x> filter) {
return true;
}
-std::unique_ptr<AbstractParcelable> FilterParcelable::Deserialize(
- std::vector<unsigned char> data) {
- return nullptr;
+void FilterParcelable::ReadFilter(tizen_base::Parcel* parcel) {
+ int val = 0;
+ filter_ = reinterpret_cast<pkgmgrinfo_filter_x *>(
+ calloc(1, sizeof(pkgmgrinfo_filter_x)));
+ ReadInt(parcel, &val);
+ filter_->uid = val;
+
+ ReadInt(parcel, &val);
+ for (int i = 0; i < val; ++i)
+ filter_->list = g_slist_append(filter_->list, ReadPkgmgrInfoNode(parcel));
+
+ ReadInt(parcel, &val);
+ for (int i = 0; i < val; ++i)
+ filter_->list_metadata = g_slist_append(filter_->list_metadata, ReadPkgmgrInfoMetadataNode(parcel));
+}
+
+bool FilterParcelable::WritePkgmgrInfoNode(tizen_base::Parcel* parcel, pkgmgrinfo_node_x *node) const {
+ WriteInt(parcel, node->prop);
+ WriteString(parcel, node->key);
+ WriteString(parcel, node->value);
+
+ return true;
+}
+
+pkgmgrinfo_node_x *FilterParcelable::ReadPkgmgrInfoNode(tizen_base::Parcel *parcel) {
+ pkgmgrinfo_node_x *node = reinterpret_cast<pkgmgrinfo_node_x *>(calloc(1, sizeof(pkgmgrinfo_node_x)));
+ ReadInt(parcel, &node->prop);
+ ReadString(parcel, &node->key);
+ ReadString(parcel, &node->value);
+
+ return node;
+}
+
+bool FilterParcelable::WritePkgmgrInfoMetadataNode(tizen_base::Parcel* parcel, pkgmgrinfo_metadata_node_x *node) const {
+ WriteString(parcel, node->key);
+ WriteString(parcel, node->value);
+
+ return true;
+}
+
+pkgmgrinfo_metadata_node_x *FilterParcelable::ReadPkgmgrInfoMetadataNode(tizen_base::Parcel* parcel) {
+ pkgmgrinfo_metadata_node_x *node = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
+ ReadString(parcel, &node->key);
+ ReadString(parcel, &node->value);
+
+ return node;
}
std::unique_ptr<AbstractParcelable> FilterParcelable::Factory::CreateParcel() {
return true; \
} while (0);
+#define INT_EQ(a, b) do { \
+ if (a != b) { \
+ std::cout << #a << "(" << a << ") is not equal to " \
+ << #b << "(" << b << ")" << std::endl; \
+ 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)));
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;
+ INT_EQ(g_list_length(applicationA->label), g_list_length(applicationB->label));
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);
STR_EQ(label_a->text, label_b->text);
}
- if (g_list_length(applicationA->icon) != g_list_length(applicationB->icon))
- return false;
+ INT_EQ(g_list_length(applicationA->icon), g_list_length(applicationB->icon));
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);
STR_EQ(icon_a->text, icon_b->text);
}
- if (g_list_length(applicationA->image) != g_list_length(applicationB->image))
- return false;
+ INT_EQ(g_list_length(applicationA->image), g_list_length(applicationB->image));
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);
STR_EQ(image_a->text, image_b->text);
}
- if (g_list_length(applicationA->category) !=
- g_list_length(applicationB->category))
- return false;
+ INT_EQ(g_list_length(applicationA->category),
+ g_list_length(applicationB->category));
for (GList *a = applicationA->category, *b = applicationB->category;
a && b; a = a->next, b = b->next) {
char *category_a = reinterpret_cast<char *>(a->data);
STR_EQ(category_a, category_b);
}
- if (g_list_length(applicationA->metadata) !=
- g_list_length(applicationB->metadata))
- return false;
+ INT_EQ(g_list_length(applicationA->metadata),
+ g_list_length(applicationB->metadata));
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);
STR_EQ(metadata_a->value, metadata_b->value);
}
- if (g_list_length(applicationA->datacontrol) !=
- g_list_length(applicationB->datacontrol))
- return false;
+ INT_EQ(g_list_length(applicationA->datacontrol),
+ g_list_length(applicationB->datacontrol));
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);
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))
+ INT_EQ(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) {
}
}
- if (g_list_length(applicationA->background_category) !=
- g_list_length(applicationB->background_category))
- return false;
+ INT_EQ(g_list_length(applicationA->background_category),
+ g_list_length(applicationB->background_category));
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);
STR_EQ(background_category_a, background_category_b);
}
- if (g_list_length(applicationA->appcontrol) !=
- g_list_length(applicationB->appcontrol))
- return false;
+ INT_EQ(g_list_length(applicationA->appcontrol),
+ g_list_length(applicationB->appcontrol));
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);
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))
+ INT_EQ(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) {
}
}
- if (g_list_length(applicationA->splashscreens) !=
- g_list_length(applicationB->splashscreens))
- return false;
+ INT_EQ(g_list_length(applicationA->splashscreens),
+ g_list_length(applicationB->splashscreens));
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);
bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
const std::vector<application_x *>& applicationsB) {
- if (applicationsA.size() != applicationsB.size())
- return false;
+ if (applicationsA.size() , applicationsB.size());
for (unsigned int i = 0; i < applicationsA.size(); ++i) {
if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
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;
+ INT_EQ(g_list_length(packageA->icon), g_list_length(packageB->icon));
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);
STR_EQ(icon_a->text, icon_b->text);
}
- if (g_list_length(packageA->label) != g_list_length(packageB->label))
- return false;
+ INT_EQ(g_list_length(packageA->label), g_list_length(packageB->label));
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);
STR_EQ(label_a->text, label_b->text);
}
- if (g_list_length(packageA->author) != g_list_length(packageB->author))
- return false;
+ INT_EQ(g_list_length(packageA->author), g_list_length(packageB->author));
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);
STR_EQ(author_a->text, author_b->text);
}
- if (g_list_length(packageA->description) != g_list_length(packageB->description))
- return false;
+ INT_EQ(g_list_length(packageA->description), g_list_length(packageB->description));
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);
STR_EQ(description_a->text, description_b->text);
}
- if (g_list_length(packageA->privileges) != g_list_length(packageB->privileges))
- return false;
+ INT_EQ(g_list_length(packageA->privileges), g_list_length(packageB->privileges));
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);
STR_EQ(privilege_a->value, privilege_b->value);
}
- if (g_list_length(packageA->appdefined_privileges) != g_list_length(packageB->appdefined_privileges))
- return false;
+ INT_EQ(g_list_length(packageA->appdefined_privileges), g_list_length(packageB->appdefined_privileges));
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);
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;
+ INT_EQ(g_list_length(packageA->provides_appdefined_privileges), g_list_length(packageB->provides_appdefined_privileges));
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);
STR_EQ(privilege_a->value, privilege_b->value);
}
- if (g_list_length(packageA->dependencies) != g_list_length(packageB->dependencies))
- return false;
+ INT_EQ(g_list_length(packageA->dependencies), g_list_length(packageB->dependencies));
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);
STR_EQ(dependency_a->type, dependency_b->type);
}
- if (g_list_length(packageA->plugin) != g_list_length(packageB->plugin))
- return false;
+ INT_EQ(g_list_length(packageA->plugin), g_list_length(packageB->plugin));
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);
STR_EQ(plugin_a->plugin_type, plugin_b->plugin_type);
}
- if (g_list_length(packageA->application) != g_list_length(packageB->application))
- return false;
+ INT_EQ(g_list_length(packageA->application), g_list_length(packageB->application));
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);
bool IsEqualPackages(const std::vector<package_x *>&packagesA,
const std::vector<package_x *>&packagesB) {
- if (packagesA.size() != packagesB.size())
- return false;
+ if (packagesA.size() != packagesB.size());
for (unsigned int i = 0; i < packagesA.size(); ++i) {
if (!IsEqualPackage(packagesA[i], packagesB[i]))
return true;
}
+
+pkgmgrinfo_filter_x *GetTestFilter() {
+ pkgmgrinfo_filter_x *filter;
+ pkgmgrinfo_node_x *node;
+ pkgmgrinfo_metadata_node_x *metadata_node;
+ filter = reinterpret_cast<pkgmgrinfo_filter_x*>(calloc(1, sizeof(pkgmgrinfo_filter_x)));
+
+ filter->uid = 1234;
+ node = reinterpret_cast<pkgmgrinfo_node_x *>(calloc(1, sizeof(pkgmgrinfo_node_x)));
+ node->prop = 4321;
+ node->key = strdup("test_key1");
+ node->value = strdup("test_value1");
+ filter->list = g_slist_append(filter->list, node);
+
+ node = reinterpret_cast<pkgmgrinfo_node_x *>(calloc(1, sizeof(pkgmgrinfo_node_x)));
+ node->prop = 4321;
+ node->key = strdup("test_key2");
+ node->value = strdup("test_value2");
+ filter->list = g_slist_append(filter->list, node);
+
+ metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
+ metadata_node->key = strdup("test_metadata_key1");
+ metadata_node->value = strdup("test_metadata_value1");
+ filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
+
+ metadata_node = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(calloc(1, sizeof(pkgmgrinfo_metadata_node_x)));
+ metadata_node->key = strdup("test_metadata_key2");
+ metadata_node->value = strdup("test_metadata_value2");
+ filter->list_metadata = g_slist_append(filter->list_metadata, metadata_node);
+
+ return filter;
+}
+
+bool IsEqualFilter(const pkgmgrinfo_filter_x *filterA,
+ const pkgmgrinfo_filter_x *filterB) {
+ std::cout << "asdfasdf" << std::endl;
+ INT_EQ(filterA->uid, filterB->uid);
+
+ std::cout << "asdfasdf" << std::endl;
+ INT_EQ(g_slist_length(filterA->list), g_slist_length(filterB->list));
+ std::cout << "asdfasdf" << std::endl;
+ for (GSList *a = filterA->list, *b = filterB->list;
+ a && b; a = a->next, b = b->next) {
+ pkgmgrinfo_node_x *node_a = reinterpret_cast<pkgmgrinfo_node_x *>(a->data);
+ pkgmgrinfo_node_x *node_b = reinterpret_cast<pkgmgrinfo_node_x *>(b->data);
+ std::cout << "aaaaa" << std::endl;
+ INT_EQ(node_a->prop, node_b->prop);
+ std::cout << "aaaaa" << std::endl;
+ STR_EQ(node_a->key, node_b->key);
+ std::cout << "aaaaa" << std::endl;
+ STR_EQ(node_a->value, node_b->value);
+ }
+
+ INT_EQ(g_slist_length(filterA->list_metadata), g_slist_length(filterB->list_metadata));
+ for (GSList *a = filterA->list_metadata, *b = filterB->list_metadata;
+ a && b; a = a->next, b = b->next) {
+ pkgmgrinfo_metadata_node_x *node_a = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(a->data);
+ pkgmgrinfo_metadata_node_x *node_b = reinterpret_cast<pkgmgrinfo_metadata_node_x *>(b->data);
+ std::cout << "bbbbbb" << std::endl;
+ STR_EQ(node_a->key, node_b->key);
+ std::cout << "bbbbbb" << std::endl;
+ STR_EQ(node_a->value, node_b->value);
+ std::cout << "bbbbbb" << std::endl;
+ }
+}