Adjust to change in PkgmgrInterface 43/59443/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 16 Feb 2016 08:57:43 +0000 (09:57 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 16 Feb 2016 12:57:17 +0000 (13:57 +0100)
Following changes need to be submitted together:
 - https://review.tizen.org/gerrit/59442
 - https://review.tizen.org/gerrit/59443
 - https://review.tizen.org/gerrit/59444

To verify:
 $ /usr/bin/tpk-backend-ut/smoke_test
 # install, update, uninstall and tpk package by tpk-backend directly

Change-Id: If10851e17dace1610a75f571b750dbf3bbfd80ca

src/tpk/tpk_backend.cc
src/unit_tests/smoke_test.cc

index 8e3479e..87a68f2 100644 (file)
 namespace ci = common_installer;
 
 int main(const int argc, char* argv[]) {
+  ci::PkgmgrInstaller pkgmgr_installer;
   tpk::TpkAppQueryInterface interface;
-  ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &interface);
+  ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv,
+                                                     &pkgmgr_installer,
+                                                     &interface);
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to create pkgmgr interface";
     return -1;
index 2f8256e..9c58eff 100644 (file)
@@ -50,6 +50,22 @@ enum class RequestResult {
   CRASH
 };
 
+class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
+ public:
+  bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
+                             ci::InstallationMode* mode) {
+    *installer = pkgmgr_installer_new();
+    if (!*installer)
+      return false;
+    *mode = ci::InstallationMode::ONLINE;
+    return true;
+  }
+
+  bool ShouldCreateSignal() const {
+    return false;
+  }
+};
+
 class StepCrash : public ci::Step {
  public:
   using Step::Step;
@@ -203,10 +219,12 @@ ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
 ci::AppInstaller::Result Install(const bf::path& path,
                                  RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-i", 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";
@@ -228,11 +246,12 @@ ci::AppInstaller::Result Update(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),
-                                  query_interface.get());
+                                  &pkgmgr_installer, query_interface.get());
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return ci::AppInstaller::Result::UNKNOWN;
@@ -248,11 +267,12 @@ 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),
-                                  query_interface.get());
+                                  &pkgmgr_installer, query_interface.get());
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return ci::AppInstaller::Result::UNKNOWN;
@@ -272,11 +292,12 @@ 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),
-                                  query_interface.get());
+                                  &pkgmgr_installer, query_interface.get());
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return ci::AppInstaller::Result::UNKNOWN;
@@ -298,10 +319,18 @@ class SmokeEnvironment : public testing::Environment {
     bf::remove_all(home_ / KUserAppsDirBackup, error);
     if (bf::exists(home_ / KUserAppsDir)) {
       bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
+      if (error)
+        LOG(ERROR) << "Failed to setup test environment. Does some previous"
+                   << " test crashed? Directory: "
+                   << (home_ / KUserAppsDirBackup) << " should not exist.";
       assert(!error);
     }
     if (bf::exists(home_ / kApplicationDir)) {
       bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error);
+      if (error)
+        LOG(ERROR) << "Failed to setup test environment. Does some previous"
+                   << " test crashed? Directory: "
+                   << (home_ / kApplicationDirBackup) << " should not exist.";
       assert(!error);
     }
   }