Implement FilterParcelable
authorIlho Kim <ilho159.kim@samsung.com>
Wed, 10 Feb 2021 06:51:41 +0000 (15:51 +0900)
committer김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 <ilho159.kim@samsung.com>
Tue, 16 Feb 2021 09:22:33 +0000 (18:22 +0900)
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/parcel/filter_parcelable.cc
src/common/parcel/filter_parcelable.hh
src/pkgmgrinfo_private.h
test/unit_tests/parcel_utils.cc
test/unit_tests/parcel_utils.hh
test/unit_tests/test_parcel.cc

index cdfc226..01380b6 100644 (file)
 #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() {
index f5675ee..7bd4d6e 100644 (file)
@@ -20,20 +20,27 @@ class EXPORT_API FilterParcelable : public AbstractParcelable {
    public:
     std::unique_ptr<AbstractParcelable> CreateParcel();
   };
-  std::unique_ptr<pkgmgrinfo_filter_x> GetFilter();
-  bool SetFilter(std::unique_ptr<pkgmgrinfo_filter_x> filter);
-  std::unique_ptr<AbstractParcelable> Deserialize(std::vector<unsigned char> data);
-
-  virtual void WriteToParcel(tizen_base::Parcel* parcel) const {
-    parcel->WriteString("test");
-    parcel->WriteUInt32(32);
-  }
-
-  virtual void ReadFromParcel(tizen_base::Parcel* parcel) {
-    std::string a = parcel->ReadString();
-    unsigned int b;
-    parcel->ReadUInt32(&b);
-  }
+
+  FilterParcelable() = default;
+  FilterParcelable(pkgmgrinfo_filter_x *filter, int flag);
+  ~FilterParcelable();
+  const pkgmgrinfo_filter_x* GetFilter();
+  int GetFlag();
+
+  void WriteToParcel(tizen_base::Parcel* parcel) const override;
+  void ReadFromParcel(tizen_base::Parcel* parcel) override;
+
+ private:
+  bool WriteFilter(tizen_base::Parcel* parcel, pkgmgrinfo_filter_x *filter) const;
+  bool WritePkgmgrInfoNode(tizen_base::Parcel* parcel, pkgmgrinfo_node_x *node) const;
+  bool WritePkgmgrInfoMetadataNode(tizen_base::Parcel* parcel, pkgmgrinfo_metadata_node_x *node) const;
+  void ReadFilter(tizen_base::Parcel* parcel);
+  pkgmgrinfo_node_x *ReadPkgmgrInfoNode(tizen_base::Parcel *parcel);
+  pkgmgrinfo_metadata_node_x *ReadPkgmgrInfoMetadataNode(tizen_base::Parcel* parcel);
+
+  uid_t uid_;
+  pkgmgrinfo_filter_x *filter_;
+  int flag_;
 };
 
 }  // namespace parcel
index 47d4dc3..e4fa4dd 100644 (file)
 #include "pkgmgrinfo_type.h"
 #include "pkgmgrinfo_basic.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #ifndef DEPRECATED
 #define DEPRECATED     __attribute__ ((__deprecated__))
 #endif
@@ -343,4 +347,8 @@ static inline uid_t _getuid(void)
                return uid;
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif  /* __PKGMGRINFO_PRIVATE_H__ */
index 2275760..1a95515 100644 (file)
@@ -37,6 +37,15 @@ bool IS_STR_EQ(const char *a, const char *b) {
     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)));
@@ -214,8 +223,7 @@ bool IsEqualApplication(application_x *applicationA,
   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);
@@ -225,8 +233,7 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -239,8 +246,7 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -250,9 +256,8 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -260,9 +265,8 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -271,9 +275,8 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -282,8 +285,8 @@ bool IsEqualApplication(application_x *applicationA,
     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) {
@@ -293,9 +296,8 @@ bool IsEqualApplication(application_x *applicationA,
     }
   }
 
-  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);
@@ -303,9 +305,8 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -315,8 +316,8 @@ bool IsEqualApplication(application_x *applicationA,
     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) {
@@ -326,9 +327,8 @@ bool IsEqualApplication(application_x *applicationA,
     }
   }
 
-  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);
@@ -347,8 +347,7 @@ bool IsEqualApplication(application_x *applicationA,
 
 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]))
@@ -498,8 +497,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
   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);
@@ -512,8 +510,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -523,8 +520,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -535,8 +531,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -546,8 +541,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -556,8 +550,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -567,8 +560,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -578,8 +570,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -589,8 +580,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -601,8 +591,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
@@ -617,8 +606,7 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
 
 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]))
@@ -627,3 +615,68 @@ bool IsEqualPackages(const std::vector<package_x *>&packagesA,
 
   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;
+  }
+}
index 4e88a80..739a19c 100644 (file)
@@ -17,6 +17,7 @@
 #include <vector>
 
 #include "pkgmgrinfo_basic.h"
+#include "pkgmgrinfo_private.h"
 
 application_x *GetTestApplication(std::string appid);
 
@@ -27,3 +28,8 @@ package_x *GetTestPackage(std::string pkgid);
 
 bool IsEqualPackages(const std::vector<package_x *>&packagesA,
     const std::vector<package_x *>&packagesB);
+
+pkgmgrinfo_filter_x *GetTestFilter();
+
+bool IsEqualFilter(const pkgmgrinfo_filter_x *filterA,
+    const pkgmgrinfo_filter_x *filterB);
index a668254..b5376fd 100644 (file)
@@ -141,3 +141,18 @@ TEST_F(ParcelTest, PkgInfoParcelable) {
   EXPECT_TRUE(IsEqualPackages(
       origin_parcelable.GetPkgInfo(), new_parcelable.GetPkgInfo()));
 }
+
+TEST_F(ParcelTest, FilterParcelable) {
+  tizen_base::Parcel parcel;
+  pkgmgrinfo_filter_x *filter = GetTestFilter();
+  int flag = 0b101010;
+
+  pp::FilterParcelable origin_parcelable(filter, flag);
+  pp::FilterParcelable new_parcelable;
+  parcel.WriteParcelable(origin_parcelable);
+  parcel.ReadParcelable(&new_parcelable);
+
+  EXPECT_TRUE(IsEqualFilter(
+      origin_parcelable.GetFilter(), new_parcelable.GetFilter()));
+  EXPECT_EQ(origin_parcelable.GetFlag(), new_parcelable.GetFlag());
+}