Smoke test for enable/disable pkg 90/82090/2
authorPiotr Ganicz <p.ganicz@samsung.com>
Thu, 28 Jul 2016 10:40:35 +0000 (12:40 +0200)
committerPiotr Ganicz <p.ganicz@samsung.com>
Fri, 29 Jul 2016 13:54:35 +0000 (15:54 +0200)
I've made also small refactor

Change-Id: I7a4a5083d7d92872fe531016efc53f3c05590a2f

src/unit_tests/smoke_test.cc
src/unit_tests/test_samples/smoke/DisablePkg.wgt [new file with mode: 0644]
src/unit_tests/test_samples/smoke/EnablePkg.wgt [new file with mode: 0644]

index 56dfb15..e95a092 100644 (file)
@@ -260,16 +260,16 @@ ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
   }
   return installer->Run();
 }
-
-ci::AppInstaller::Result Install(const bf::path& path,
-                                 PackageType type,
-                                 RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-i", path.c_str()};
+ci::AppInstaller::Result CallBackend(int argc,
+                                     const char* argv[],
+                                     PackageType type,
+                                     RequestResult mode = RequestResult::NORMAL
+                                     ) {
   TestPkgmgrInstaller pkgmgr_installer;
   std::unique_ptr<ci::AppQueryInterface> query_interface =
       CreateQueryInterface();
   auto pkgmgr =
-      ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
+      ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
                                   &pkgmgr_installer, query_interface.get());
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
@@ -278,6 +278,13 @@ ci::AppInstaller::Result Install(const bf::path& path,
   return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
 }
 
+ci::AppInstaller::Result Install(const bf::path& path,
+                                 PackageType type,
+                                 RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-i", path.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
 ci::AppInstaller::Result Update(const bf::path& path_old,
                                 const bf::path& path_new,
                                 PackageType type,
@@ -292,17 +299,7 @@ ci::AppInstaller::Result Update(const bf::path& path_old,
 ci::AppInstaller::Result MountInstall(const bf::path& path,
     PackageType type, RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-w", path.c_str()};
-  TestPkgmgrInstaller pkgmgr_installer;
-  std::unique_ptr<ci::AppQueryInterface> query_interface =
-      CreateQueryInterface();
-  auto pkgmgr =
-      ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
-                                  &pkgmgr_installer, query_interface.get());
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to initialize pkgmgr interface";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
@@ -319,17 +316,7 @@ ci::AppInstaller::Result Uninstall(const std::string& pkgid,
                                    PackageType type,
                                    RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-d", pkgid.c_str()};
-  TestPkgmgrInstaller pkgmgr_installer;
-  std::unique_ptr<ci::AppQueryInterface> query_interface =
-      CreateQueryInterface();
-  auto pkgmgr =
-      ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
-                                  &pkgmgr_installer, query_interface.get());
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to initialize pkgmgr interface";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result Reinstall(const bf::path& path,
@@ -341,17 +328,7 @@ ci::AppInstaller::Result Reinstall(const bf::path& path,
     return ci::AppInstaller::Result::UNKNOWN;
   }
   const char* argv[] = {"", "-r", delta_dir.c_str()};
-  TestPkgmgrInstaller pkgmgr_installer;
-  std::unique_ptr<ci::AppQueryInterface> query_interface =
-      CreateQueryInterface();
-  auto pkgmgr =
-      ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
-                                  &pkgmgr_installer, query_interface.get());
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to initialize pkgmgr interface";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
@@ -367,17 +344,21 @@ ci::AppInstaller::Result Clear(const std::string& pkgid,
                                    PackageType type,
                                    RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-c", pkgid.c_str()};
-  TestPkgmgrInstaller pkgmgr_installer;
-  std::unique_ptr<ci::AppQueryInterface> query_interface =
-      CreateQueryInterface();
-  auto pkgmgr =
-      ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
-                                  &pkgmgr_installer, query_interface.get());
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to initialize pkgmgr interface";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
+ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
+                                  PackageType type,
+                                  RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-A", pkgid.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
+ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
+                                  PackageType type,
+                                  RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-D", pkgid.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
@@ -489,6 +470,31 @@ TEST_F(SmokeTest, RDSMode) {
   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
 }
 
+TEST_F(SmokeTest, EnablePkg) {
+  bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
+  std::string pkgid = "smokeapp22";
+  ASSERT_EQ(Install(path, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+
+  ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+}
+
+TEST_F(SmokeTest, DisablePkg) {
+  bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
+  std::string pkgid = "smokeapp21";
+  std::string appid = "smokeapp21.DisablePkg";
+  ASSERT_EQ(Install(path, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ValidatePackageFS(pkgid, {appid});
+}
+
 TEST_F(SmokeTest, ClearMode) {
   bf::path path = kSmokePackagesDirectory / "ClearMode.wgt";
   std::string pkgid = "smokeapp20";
diff --git a/src/unit_tests/test_samples/smoke/DisablePkg.wgt b/src/unit_tests/test_samples/smoke/DisablePkg.wgt
new file mode 100644 (file)
index 0000000..3245443
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/DisablePkg.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/EnablePkg.wgt b/src/unit_tests/test_samples/smoke/EnablePkg.wgt
new file mode 100644 (file)
index 0000000..f91781e
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/EnablePkg.wgt differ