Implement appinfo db unit tests
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 28 May 2021 02:04:02 +0000 (11:04 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Tue, 1 Jun 2021 07:58:25 +0000 (16:58 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/server/pkginfo_internal.c
test/unit_tests/mock/mock_hook.h [new file with mode: 0644]
test/unit_tests/mock/module_mock.h [new file with mode: 0644]
test/unit_tests/mock/system_info_mock.cc [new file with mode: 0644]
test/unit_tests/mock/system_info_mock.h [new file with mode: 0644]
test/unit_tests/mock/test_fixture.cc [new file with mode: 0644]
test/unit_tests/mock/test_fixture.h [new file with mode: 0644]
test/unit_tests/parcel_utils.cc
test/unit_tests/parcel_utils.hh
test/unit_tests/test_db_handlers.cc
test/unit_tests/test_parcel.cc

index e1d1d1d..9f3b7b1 100644 (file)
@@ -2036,7 +2036,7 @@ static int __insert_application_info(sqlite3 *db, manifest_x *mfx)
 
                idx = 1;
                __BIND_TEXT(db, stmt, idx++, app->appid);
-               __BIND_TEXT(db, stmt, idx++, app->component_type);
+               __BIND_TEXT(db, stmt, idx++, app->component);
                __BIND_TEXT(db, stmt, idx++, app->exec);
                __BIND_TEXT(db, stmt, idx++, __get_bool(app->nodisplay, false));
                __BIND_TEXT(db, stmt, idx++, app->type);
diff --git a/test/unit_tests/mock/mock_hook.h b/test/unit_tests/mock/mock_hook.h
new file mode 100644 (file)
index 0000000..b57f369
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_MOCK_HOOK_H_
+#define TEST_UNIT_TESTS_MOCK_MOCK_HOOK_H_
+
+#define MOCK_HOOK_P0(MOCK_CLASS, f)                                            \
+    TestFixture::GetMock<MOCK_CLASS>().f()
+#define MOCK_HOOK_P1(MOCK_CLASS, f, p1)                                        \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1)
+#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2)                                    \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
+#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3)                                \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
+#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4)                            \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
+#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5)                        \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
+#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6)                    \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
+#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7)                \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7)
+#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8)            \
+    TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8)
+#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)  \
+    TestFixture::GetMock<MOCK_CLASS>().f(                                      \
+        p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
+
+#endif  // TEST_UNIT_TESTS_MOCK_MOCK_HOOK_H_
diff --git a/test/unit_tests/mock/module_mock.h b/test/unit_tests/mock/module_mock.h
new file mode 100644 (file)
index 0000000..b8163e9
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2020 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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_MODULE_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+  virtual ~ModuleMock() {}
+};
+
+#endif  // TEST_UNIT_TESTS_MOCK_MODULE_MOCK_H_
diff --git a/test/unit_tests/mock/system_info_mock.cc b/test/unit_tests/mock/system_info_mock.cc
new file mode 100644 (file)
index 0000000..7fce8c6
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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 "system_info_mock.h"
+
+#include <gio/gio.h>
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int system_info_get_platform_int(const char* key,
+    int* value) {
+  return MOCK_HOOK_P2(SystemInfoMock, system_info_get_platform_int,
+      key, value);
+}
diff --git a/test/unit_tests/mock/system_info_mock.h b/test/unit_tests/mock/system_info_mock.h
new file mode 100644 (file)
index 0000000..1544ff7
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_GIO_MOCK_H_
+#define TEST_UNIT_TESTS_MOCK_GIO_MOCK_H_
+
+#include <system_info.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class SystemInfoMock : public virtual ModuleMock {
+ public:
+  virtual ~SystemInfoMock() {}
+
+  MOCK_METHOD2(system_info_get_platform_int,
+      int(const char*, int*));
+};
+
+#endif  // TEST_UNIT_TESTS_MOCK_GIO_MOCK_H_
diff --git a/test/unit_tests/mock/test_fixture.cc b/test/unit_tests/mock/test_fixture.cc
new file mode 100644 (file)
index 0000000..27f5666
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 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 "test_fixture.h"
+
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
diff --git a/test/unit_tests/mock/test_fixture.h b/test/unit_tests/mock/test_fixture.h
new file mode 100644 (file)
index 0000000..2f64bab
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+#ifndef TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+#define TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "module_mock.h"
+
+class TestFixture : public ::testing::Test {
+ public:
+  explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
+    mock_ = std::move(mock);
+  }
+  virtual ~TestFixture() {
+    mock_.reset();
+  }
+
+  virtual void SetUp() {}
+  virtual void TearDown() {}
+
+  template <typename T>
+  static T& GetMock() {
+    auto ptr = dynamic_cast<T*>(mock_.get());
+    if (!ptr)
+      throw std::invalid_argument("The test does not provide mock of \"" +
+          std::string(typeid(T).name()) + "\"");
+    return *ptr;
+  }
+
+  static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif  // TEST_UNIT_TESTS_MOCK_TEST_FIXTURE_H_
index 44f142a..a8b2c99 100644 (file)
@@ -55,8 +55,6 @@ application_x *GetTestApplication(std::string appid) {
   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");
@@ -66,7 +64,6 @@ application_x *GetTestApplication(std::string appid) {
   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");
@@ -83,23 +80,20 @@ application_x *GetTestApplication(std::string appid) {
   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->package_type = strdup("test_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->for_all_users = strdup("false");
   application->is_disabled = strdup("false");
   application->splash_screen_display = strdup("test_splash_screen_display");
   application->external_path = strdup("test_external_path");
-  application->package_system = strdup("test_package_system");
+  application->package_system = strdup("test_system");
   application->removable = strdup("test_removable");
-  application->package_installed_time = strdup("test_package_installed_time");
+  application->package_installed_time = strdup("test_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");
@@ -112,15 +106,9 @@ application_x *GetTestApplication(std::string appid) {
   icon->section = strdup("test_section");
   icon->size = strdup("test_size");
   icon->resolution = strdup("test_resolution");
-  icon->dpi = strdup("test_dpi");
+  icon->dpi = strdup("ldpi");
   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"));
 
@@ -142,7 +130,7 @@ application_x *GetTestApplication(std::string appid) {
       g_list_append(application->datacontrol, datacontrol);
 
   application->background_category = g_list_append(
-      application->background_category, strdup("test_background_category"));
+      application->background_category, strdup("enable"));
 
   appcontrol_x* appcontrol =
       reinterpret_cast<appcontrol_x*>(calloc(1, sizeof(appcontrol_x)));
@@ -159,18 +147,74 @@ application_x *GetTestApplication(std::string appid) {
       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->dpi = strdup("ldpi");
+  splashscreen->orientation = strdup("portrait");
   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 IsEqualApplicationExtraInfo(application_x* applicationA,
+    application_x* applicationB) {
+  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->name, label_b->name);
+  }
+
+  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);
+    icon_x *icon_b = reinterpret_cast<icon_x *>(b->data);
+    STR_EQ(icon_a->dpi, icon_b->dpi);
+    STR_EQ(icon_a->resolution, icon_b->resolution);
+    STR_EQ(icon_a->section, icon_b->section);
+    STR_EQ(icon_a->size, icon_b->size);
+  }
+
+  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);
+    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);
+    INT_EQ(g_list_length(datacontrol_a->privileges)
+        , g_list_length(datacontrol_b->privileges));
+    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);
+    }
+  }
+
+  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);
+    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);
+    }
+  }
+
+
+  return true;
+}
+
 bool IsEqualApplication(application_x *applicationA,
     application_x *applicationB) {
   STR_EQ(applicationA->appid, applicationB->appid);
@@ -233,7 +277,6 @@ bool IsEqualApplication(application_x *applicationA,
     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);
   }
 
@@ -243,11 +286,7 @@ bool IsEqualApplication(application_x *applicationA,
       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);
   }
 
@@ -281,26 +320,6 @@ bool IsEqualApplication(application_x *applicationA,
     STR_EQ(metadata_a->value, metadata_b->value);
   }
 
-  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);
-    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);
-    INT_EQ(g_list_length(datacontrol_a->privileges)
-        , g_list_length(datacontrol_b->privileges));
-    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);
-    }
-  }
-
   INT_EQ(g_list_length(applicationA->background_category),
       g_list_length(applicationB->background_category));
   for (GList *a = applicationA->background_category,
@@ -322,14 +341,6 @@ 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);
-    INT_EQ(g_list_length(appcontrol_a->privileges)
-        , g_list_length(appcontrol_b->privileges));
-    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);
-    }
   }
 
   INT_EQ(g_list_length(applicationA->splashscreens),
@@ -342,7 +353,6 @@ bool IsEqualApplication(application_x *applicationA,
     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);
@@ -353,12 +363,24 @@ bool IsEqualApplication(application_x *applicationA,
   return true;
 }
 
-bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
+bool IsEqualApplicationsStructure(const std::vector<application_x *>& applicationsA,
     const std::vector<application_x *>& applicationsB) {
 
   for (unsigned int i = 0; i < applicationsA.size(); ++i) {
     if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
       return false;
+    if (!IsEqualApplicationExtraInfo(applicationsA[i], applicationsB[i]))
+      return false;
+  }
+
+  return true;
+}
+
+bool IsEqualApplicationsInfo(const std::vector<application_x *>& applicationsA,
+    const std::vector<application_x *>& applicationsB) {
+  for (unsigned int i = 0; i < applicationsA.size(); ++i) {
+    if (!IsEqualApplication(applicationsA[i], applicationsB[i]))
+      return false;
   }
 
   return true;
@@ -368,7 +390,7 @@ 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->for_all_users = strdup("false");
   package->package = strdup(pkgid.c_str());
   package->version = strdup("test_version");
   package->installlocation = strdup("test_installlocation");
@@ -404,7 +426,7 @@ package_x *GetTestPackage(std::string pkgid) {
   icon->section = strdup("test_section");
   icon->size = strdup("test_size");
   icon->resolution = strdup("test_resolution");
-  icon->dpi = strdup("test_dpi");
+  icon->dpi = strdup("ldpi");
   package->icon = g_list_append(package->icon, icon);
 
 
@@ -412,9 +434,9 @@ package_x *GetTestPackage(std::string pkgid) {
   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");
@@ -483,12 +505,95 @@ package_x *GetTestPackage(std::string pkgid) {
   return package;
 }
 
+bool IsEqualPackageExtraInfo(package_x *packageA, package_x *packageB) {
+  STR_EQ(packageA->ns, packageB->ns);
+  STR_EQ(packageA->backend_installer, packageB->backend_installer);
+  STR_EQ(packageA->use_system_certs, packageB->use_system_certs);
+
+  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->resolution, icon_b->resolution);
+    STR_EQ(icon_a->section, icon_b->section);
+    STR_EQ(icon_a->size, icon_b->size);
+  }
+
+  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);
+    label_x *label_b = reinterpret_cast<label_x *>(b->data);
+    STR_EQ(label_a->name, label_b->name);
+  }
+
+  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);
+    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);
+  }
+
+  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);
+    description_x *description_b = reinterpret_cast<description_x *>(b->data);
+    STR_EQ(description_a->name, description_b->name);
+  }
+
+  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);
+    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);
+  }
+
+  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);
+    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);
+  }
+
+  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);
+    application_x *application_b = reinterpret_cast<application_x *>(b->data);
+
+    if (!IsEqualApplication(application_a, application_b))
+      return false;
+    if (!IsEqualApplicationExtraInfo(application_a, application_b))
+      return false;
+  }
+
+  return true;
+}
+
 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);
@@ -510,20 +615,14 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
   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);
 
   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);
     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);
   }
 
@@ -533,21 +632,9 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
   }
 
-  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);
-    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);
-  }
-
   INT_EQ(g_list_length(packageA->description),
       g_list_length(packageB->description));
   for (GList *a = packageA->description, *b = packageB->description;
@@ -555,7 +642,6 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     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);
   }
 
@@ -583,20 +669,6 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     STR_EQ(privilege_a->value, privilege_b->value);
   }
 
-  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);
-    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);
-  }
-
   INT_EQ(g_list_length(packageA->dependencies),
       g_list_length(packageB->dependencies));
   for (GList *a = packageA->dependencies, *b = packageB->dependencies;
@@ -608,32 +680,25 @@ bool IsEqualPackage(package_x *packageA, package_x *packageB) {
     STR_EQ(dependency_a->type, dependency_b->type);
   }
 
-  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);
-    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);
-  }
+  return true;
+}
 
-  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);
-    application_x *application_b = reinterpret_cast<application_x *>(b->data);
+bool IsEqualPackagesStructure(const std::vector<package_x *>& packagesA,
+    const std::vector<package_x *>&packagesB) {
+  if (packagesA.size() != packagesB.size())
+    return false;
 
-    if (!IsEqualApplication(application_a, application_b))
+  for (unsigned int i = 0; i < packagesA.size(); ++i) {
+    if (!IsEqualPackage(packagesA[i], packagesB[i]))
+      return false;
+    if (!IsEqualPackageExtraInfo(packagesA[i], packagesB[i]))
       return false;
   }
 
   return true;
 }
 
-bool IsEqualPackages(const std::vector<package_x *>&packagesA,
+bool IsEqualPackagesInfo(const std::vector<package_x *>& packagesA,
     const std::vector<package_x *>&packagesB) {
   if (packagesA.size() != packagesB.size())
     return false;
index ebd670f..487afdc 100644 (file)
 
 application_x *GetTestApplication(std::string appid);
 
-bool IsEqualApplications(const std::vector<application_x *>& applicationsA,
+bool IsEqualApplicationsStructure(const std::vector<application_x *>& applicationsA,
+    const std::vector<application_x *>& applicationsB);
+
+bool IsEqualApplicationsInfo(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,
+bool IsEqualPackagesStructure(const std::vector<package_x *>&packagesA,
+    const std::vector<package_x *>&packagesB);
+
+bool IsEqualPackagesInfo(const std::vector<package_x *>&packagesA,
     const std::vector<package_x *>&packagesB);
 
 pkgmgrinfo_filter_x *GetTestFilter();
index 63fcdbb..9f197f5 100644 (file)
 
 #include <cstdio>
 
+#include "appinfo_db_handler.hh"
 #include "create_db_handler.hh"
 #include "db_type.hh"
 #include "parcel_utils.hh"
 #include "pkg_get_db_handler.hh"
 #include "pkg_set_db_handler.hh"
 #include "mock/file_mock.h"
+#include "mock/test_fixture.h"
+#include "mock/system_info_mock.h"
 
 #include "pkgmgr-info.h"
 #include "pkgmgrinfo_basic.h"
@@ -57,8 +60,21 @@ class PkgGetDBHandlerMock : public pkgmgr_server::database::PkgGetDBHandler {
   MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
 };
 
-class DBHandlerTest : public ::testing::Test {
+class Mocks : public :: testing::NiceMock<SystemInfoMock> {};
+
+class AppInfoDBHandlerMock : public pkgmgr_server::database::AppInfoDBHandler {
+ public:
+  AppInfoDBHandlerMock(uid_t uid, int pid) : pkgmgr_server::database::AppInfoDBHandler(uid, pid) {}
+
+  MOCK_METHOD0(Connect, bool());
+  MOCK_METHOD0(GetConnection, std::vector<std::pair<sqlite3*, uid_t>>());
+};
+
+class DBHandlerTest : public TestFixture {
  public:
+  DBHandlerTest() : TestFixture(std::make_unique<Mocks>()) {}
+  virtual ~DBHandlerTest() {}
+
   virtual void SetUp() {
     sqlite3 *db;
     ASSERT_EQ(sqlite3_open_v2(TEST_PARSER_DB, &db,
@@ -72,6 +88,10 @@ class DBHandlerTest : public ::testing::Test {
         .Times(2).WillRepeatedly(testing::Return(true));
     EXPECT_CALL(create_db_handler, GetConnection())
         .Times(2).WillRepeatedly(testing::Return(GetDBHandles()));
+    EXPECT_CALL(GetMock<SystemInfoMock>(),
+      system_info_get_platform_int(testing::_, testing::_))
+          .WillRepeatedly(testing::DoAll(
+                  testing::SetArgPointee<1>(120), testing::Return(0)));
     fopen_mock_setup(true);
     ASSERT_EQ(create_db_handler.Execute(), 0);
     fopen_mock_setup(false);
@@ -82,6 +102,9 @@ class DBHandlerTest : public ::testing::Test {
       sqlite3_close_v2(handle.first);
 
     ASSERT_EQ(remove(TEST_PARSER_DB), 0);
+    std::string journal_path(TEST_PARSER_DB);
+    journal_path += "-journal";
+    ASSERT_EQ(remove(journal_path.c_str()), 0);
   }
 
   const std::vector<std::pair<sqlite3*, uid_t>>& GetDBHandles() {
@@ -136,9 +159,63 @@ TEST_F(DBHandlerTest, PkgGetDBHandlerTest) {
 
   PkgGetDBHandlerMock pkg_get_db_handler(0, 0);
   pkg_get_db_handler.SetFilter(filter_ptr.get());
+  pkg_get_db_handler.SetLocale("test_lang");
 
   EXPECT_CALL(pkg_get_db_handler, Connect()).WillOnce(testing::Return(true));
   EXPECT_CALL(pkg_get_db_handler, GetConnection())
       .WillOnce(testing::Return(GetDBHandles()));
   ASSERT_EQ(pkg_get_db_handler.Execute(), 0);
+
+  auto lpkginfo_list = pkg_get_db_handler.GetPkgHandle();
+  ASSERT_EQ(lpkginfo_list.size(), 1);
+
+  auto test_pkginfo = GetTestPackage(pkgid);
+  std::vector<package_x*> rpkginfo_list;
+  rpkginfo_list.emplace_back(test_pkginfo);
+
+  ASSERT_EQ(IsEqualPackagesInfo(lpkginfo_list, rpkginfo_list), true);
+}
+
+TEST_F(DBHandlerTest, AppInfoDBHandlerTest) {
+  PkgSetDBHandlerMock pkg_set_db_handler(0, 0);
+  pkg_set_db_handler.SetWriteType(pkgmgr_common::PkgWriteType::Insert);
+  std::unique_ptr<package_x, decltype(pkgmgrinfo_basic_free_package)*> ptr(
+      GetTestPackage("test_package"), pkgmgrinfo_basic_free_package);
+  pkg_set_db_handler.SetPkgInfo(ptr.get());
+
+  EXPECT_CALL(pkg_set_db_handler, Connect()).WillOnce(testing::Return(true));
+  EXPECT_CALL(pkg_set_db_handler, GetConnection())
+      .WillOnce(testing::Return(GetDBHandles()));
+  ASSERT_EQ(pkg_set_db_handler.Execute(), 0);
+
+  pkgmgrinfo_appinfo_filter_h filter;
+  std::string appid = "test_app1";
+
+  ASSERT_EQ(pkgmgrinfo_appinfo_filter_create(&filter), PMINFO_R_OK);
+  std::unique_ptr<pkgmgrinfo_filter_x, decltype(
+      pkgmgrinfo_appinfo_filter_destroy)*> filter_ptr(
+          reinterpret_cast<pkgmgrinfo_filter_x *>(filter),
+              pkgmgrinfo_appinfo_filter_destroy);
+  ASSERT_EQ(pkgmgrinfo_appinfo_filter_add_string(filter,
+      PMINFO_APPINFO_PROP_APP_ID, appid.c_str()), PMINFO_R_OK);
+  ASSERT_EQ(pkgmgrinfo_appinfo_filter_add_bool(filter,
+      PMINFO_APPINFO_PROP_APP_DISABLE, false), PMINFO_R_OK);
+
+  AppInfoDBHandlerMock appinfo_db_handler(0, 0);
+  appinfo_db_handler.SetFilter(filter_ptr.get());
+
+  EXPECT_CALL(appinfo_db_handler, Connect()).WillOnce(testing::Return(true));
+  EXPECT_CALL(appinfo_db_handler, GetConnection())
+      .WillOnce(testing::Return(GetDBHandles()));
+  appinfo_db_handler.SetLocale("test_lang");
+  ASSERT_EQ(appinfo_db_handler.Execute(), 0);
+
+  auto lappinfo_list = appinfo_db_handler.GetAppHandle();
+  ASSERT_EQ(lappinfo_list.size(), 1);
+
+  auto test_appinfo = GetTestApplication(appid);
+  std::vector<application_x*> rappinfo_list;
+  rappinfo_list.emplace_back(test_appinfo);
+
+  ASSERT_EQ(IsEqualApplicationsInfo(lappinfo_list, rappinfo_list), true);
 }
index 993ad32..97a2739 100644 (file)
@@ -114,7 +114,7 @@ TEST_F(ParcelTest, AppInfoParcelable) {
   parcel.WriteParcelable(origin_parcelable);
   parcel.ReadParcelable(&new_parcelable);
 
-  EXPECT_TRUE(IsEqualApplications(origin_parcelable.GetAppInfo(),
+  EXPECT_TRUE(IsEqualApplicationsStructure(origin_parcelable.GetAppInfo(),
                                   new_parcelable.GetAppInfo()));
 }
 
@@ -129,7 +129,7 @@ TEST_F(ParcelTest, PkgInfoParcelable) {
   parcel.WriteParcelable(origin_parcelable);
   parcel.ReadParcelable(&new_parcelable);
 
-  EXPECT_TRUE(IsEqualPackages(origin_parcelable.GetPkgInfo(),
+  EXPECT_TRUE(IsEqualPackagesStructure(origin_parcelable.GetPkgInfo(),
                               new_parcelable.GetPkgInfo()));
 }