[smoke-test] enable/disable pkg 91/82091/2
authorPiotr Ganicz <p.ganicz@samsung.com>
Thu, 28 Jul 2016 11:29:14 +0000 (13:29 +0200)
committerPiotr Ganicz <p.ganicz@samsung.com>
Fri, 29 Jul 2016 13:38:40 +0000 (15:38 +0200)
I've made also small refactor

Change-Id: I7c8a98eee2d182a69b4d32fd3e62b102e94e5183

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

index a5c5c87..44841e2 100644 (file)
@@ -228,15 +228,14 @@ ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
   }
   return installer->Run();
 }
-
-ci::AppInstaller::Result Install(const bf::path& path,
-                                 RequestResult mode = RequestResult::NORMAL) {
-  const char* argv[] = {"", "-i", path.c_str()};
+ci::AppInstaller::Result CallBackend(int argc,
+                                     const char* argv[],
+                                     RequestResult mode) {
   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) {
@@ -245,6 +244,11 @@ ci::AppInstaller::Result Install(const bf::path& path,
   }
   return RunInstallerWithPkgrmgr(pkgmgr, mode);
 }
+ci::AppInstaller::Result Install(const bf::path& path,
+                                 RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-i", path.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
+}
 
 ci::AppInstaller::Result Update(const bf::path& path_old,
                                 const bf::path& path_new,
@@ -259,18 +263,7 @@ ci::AppInstaller::Result Update(const bf::path& path_old,
 ci::AppInstaller::Result MountInstall(const bf::path& path,
                                  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, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
@@ -286,36 +279,26 @@ ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
                                    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, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result Clear(const bf::path& path,
                                  RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-c", 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, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
+ci::AppInstaller::Result EnablePackage(const std::string& path,
+                                 RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-A", path.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
+}
+
+ci::AppInstaller::Result DisablePackage(const std::string& path,
+                                 RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-D", path.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
+}
 
 ci::AppInstaller::Result Reinstall(const bf::path& path,
                                    const bf::path& delta_dir,
@@ -325,17 +308,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, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
@@ -350,17 +323,7 @@ ci::AppInstaller::Result DeltaInstall(const bf::path& path,
 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
                                  RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-b", recovery_file.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, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
 }  // namespace
@@ -472,6 +435,25 @@ TEST_F(SmokeTest, DeinstallationMode_Tpk) {
   CheckPackageNonExistance(pkgid, appid);
 }
 
+TEST_F(SmokeTest, EnablePkg) {
+  bf::path path = kSmokePackagesDirectory / "EnablePkg.tpk";
+  std::string pkgid = "smokeapp22";
+  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(EnablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+}
+
+TEST_F(SmokeTest, DisablePkg) {
+  bf::path path = kSmokePackagesDirectory / "DisablePkg.tpk";
+  std::string pkgid = "smokeapp23";
+  std::string appid = "smokeapp23.DisablePkg";
+  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+  ValidatePackageFS(pkgid, {appid});
+}
+
 TEST_F(SmokeTest, ClearMode_Tpk) {
   bf::path path = kSmokePackagesDirectory / "ClearMode_Tpk.tpk";
   std::string pkgid = "smokeapp21";
diff --git a/src/unit_tests/test_samples/smoke/DisablePkg.tpk b/src/unit_tests/test_samples/smoke/DisablePkg.tpk
new file mode 100644 (file)
index 0000000..4461ea9
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/DisablePkg.tpk differ
diff --git a/src/unit_tests/test_samples/smoke/EnablePkg.tpk b/src/unit_tests/test_samples/smoke/EnablePkg.tpk
new file mode 100644 (file)
index 0000000..0600d14
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/EnablePkg.tpk differ