Improve coverage 91/240591/3
authorInkyun Kil <inkyun.kil@samsung.com>
Mon, 10 Aug 2020 01:00:49 +0000 (10:00 +0900)
committerJunghoon Park <jh9216.park@samsung.com>
Tue, 11 Aug 2020 02:27:23 +0000 (02:27 +0000)
- Add unittest for get_path_array

Change-Id: I6fab8943fbfd8201a3467d66a5fb9d3b02e95908
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
test/unit_tests/test_theme.cc

index cebaa2a..7139e96 100644 (file)
@@ -401,9 +401,9 @@ TEST_F(ThemeTest, Theme_GetPath) {
   b.Add("/stringkey", "value");
 
   ThemeInfo default_theme(b);
-  ThemeInfo test_theme(b_);
-  test_theme.MergeDefault(default_theme);
-
+  std::shared_ptr<ThemeInfo> test_theme(new ThemeInfo(b_));
+  test_theme->MergeDefault(default_theme);
+  theme_h handle = static_cast<void*>(&test_theme);
 
   int handle1 = 1;
   int handle2 = 2;
@@ -434,8 +434,51 @@ TEST_F(ThemeTest, Theme_GetPath) {
                   SetArgPointee<1>(const_cast<char*>(root_path2)),
                   Return(PMINFO_R_OK)));
 
-  EXPECT_EQ("/opt/usr/globalapps/test_pkgid/shared/res/preview.png",
-      test_theme.GetPath("/preview"));
-  EXPECT_EQ("/opt/usr/globalapps/default_pkgid/shared/res/default_resource.png",
-      test_theme.GetPath("/test_resource"));
+  char *path, *path2;
+  int ret = theme_get_path(handle, "/preview", &path);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_STREQ("/opt/usr/globalapps/test_pkgid/shared/res/preview.png", path);
+
+  ret = theme_get_path(handle, "/test_resource", &path2);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_STREQ("/opt/usr/globalapps/default_pkgid/shared/res/default_resource.png",
+      path2);
+
+  if (path)
+    free(path);
+  if (path2)
+    free(path2);
 }
+
+TEST_F(ThemeTest, Theme_GetPathArray) {
+  std::shared_ptr<ThemeInfo> test_theme(new ThemeInfo(b_));
+  theme_h handle = static_cast<void*>(&test_theme);
+
+  int handle1 = 1;
+  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+      pkgmgrinfo_pkginfo_get_usr_pkginfo(StrEq("testpkgid"), _, _)).
+          WillOnce(DoAll(
+                  SetArgPointee<2>(
+                      reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
+                  Return(PMINFO_R_OK)));
+  char root_path1[] = "/opt/usr/globalapps/test_pkgid";
+  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+      pkgmgrinfo_pkginfo_get_root_path(
+          reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1), _)).
+          WillOnce(DoAll(
+                  SetArgPointee<1>(const_cast<char*>(root_path1)),
+                  Return(PMINFO_R_OK)));
+
+  char **strarr;
+  int count;
+  int ret = theme_get_path_array(handle, "/arraykey", &strarr, &count);
+
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
+  EXPECT_STREQ("/opt/usr/globalapps/test_pkgid/str1", strarr[0]);
+  EXPECT_STREQ("/opt/usr/globalapps/test_pkgid/str2", strarr[1]);
+  EXPECT_EQ(count, 2);
+
+  for (int i = 0; i < count; i++)
+    if (strarr[i])
+      free(strarr[i]);
+}
\ No newline at end of file