Adjust to change in PkgmgrInterface 44/59444/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 16 Feb 2016 09:18:31 +0000 (10:18 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Tue, 16 Feb 2016 13:00:41 +0000 (14:00 +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/wgt-backend-ut/smoke_test
 # install, update, uninstall and wgt package by wgt-backend directly

Change-Id: I89c72f9be7d6695d629c6e9d292c4f8e82a7d138

src/unit_tests/smoke_test.cc
src/wgt_backend/wgt_backend.cc

index f23d98b..39d8dd7 100644 (file)
@@ -48,6 +48,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;
@@ -209,11 +225,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),
-                                  query_interface.get());
+                                  &pkgmgr_installer, query_interface.get());
   if (!pkgmgr) {
     LOG(ERROR) << "Failed to initialize pkgmgr interface";
     return ci::AppInstaller::Result::UNKNOWN;
@@ -234,11 +251,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;
@@ -254,11 +272,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;
@@ -278,11 +297,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;
@@ -304,10 +324,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);
     }
   }
index 3d59c2e..14639c6 100644 (file)
 namespace ci = common_installer;
 
 int main(int argc, char** argv) {
+  ci::PkgmgrInstaller pkgmgr_installer;
   wgt::WgtAppQueryInterface query_interface;
-  auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &query_interface);
+  auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
+                                            &query_interface);
   if (!pkgmgr) {
     LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
     return EINVAL;