Fix unit test 18/242618/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 28 Aug 2020 09:26:32 +0000 (18:26 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 28 Aug 2020 09:26:32 +0000 (18:26 +0900)
- Supress build warning.
- Add negative unittest for identifying pkg type.

Change-Id: Ib679b47ab5196675bb0271cb068f3bbfed68d9f1
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
test/smoke_test/unified_recovery_test.cc
test/unit_tests/test_samples/kkk-recovery-123456 [new file with mode: 0644]
test/unit_tests/test_samples/tgt-recovery-123456 [new file with mode: 0644]
test/unit_tests/test_unified_installer_factory.cc

index 5da7784a77ba05a5aa747ac5009e8d2612ee5fd6..c044c6617b387b2eb28fa656c4e1e9935649f9cf 100644 (file)
@@ -57,8 +57,9 @@ class SmokeEnvironment : public testing::Environment {
   }
 
   void SetUp() override {
-    if (request_mode_ == ci::RequestMode::USER)
+    if (request_mode_ == ci::RequestMode::USER) {
       ASSERT_TRUE(AddTestUser(&test_user));
+    }
     if (no_backup_)
       return;
     backups_ = SetupBackupDirectories(test_user.uid);
@@ -73,8 +74,9 @@ class SmokeEnvironment : public testing::Environment {
 
   void TearDown() override {
     test_count++;
-    if (request_mode_ == ci::RequestMode::USER)
+    if (request_mode_ == ci::RequestMode::USER) {
       ASSERT_TRUE(DeleteTestUser());
+    }
     if (no_backup_)
       return;
     if (backup_type_ == BackupType::MOVE) {
diff --git a/test/unit_tests/test_samples/kkk-recovery-123456 b/test/unit_tests/test_samples/kkk-recovery-123456
new file mode 100644 (file)
index 0000000..8286f65
--- /dev/null
@@ -0,0 +1,4 @@
+NEW
+/opt/usr/share/package-unpacked/unpack-265cd0
+vHhZK6lhQg
+false
diff --git a/test/unit_tests/test_samples/tgt-recovery-123456 b/test/unit_tests/test_samples/tgt-recovery-123456
new file mode 100644 (file)
index 0000000..9b58d3c
--- /dev/null
@@ -0,0 +1,4 @@
+NEW
+/opt/usr/share/package-unpacked/unpack-265cd0
+org.example.tpk40sample2
+false
index a130f2893533f0c27474850f4ec19dc4ec16c20e..2b201e6f3995ce10a06ecd42383479fba09cff99 100644 (file)
@@ -155,6 +155,9 @@ TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromFilename) {
 
   pkgmgrinfo_pkginfo_h handle1 = calloc(1, sizeof(manifest_x));
   pkgmgrinfo_pkginfo_h handle2 = calloc(1, sizeof(manifest_x));
+  if (handle1 == nullptr || handle2 == nullptr) {
+    EXPECT_TRUE(false) << "Out of memory";
+  }
 
   EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
       pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
@@ -193,11 +196,68 @@ TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromFilename) {
   for (int idx = 0; idx < 2; idx++) {
     std::unique_ptr<common_installer::AppInstaller> installer =
         factory->CreateInstaller(pkgmgr, idx);
-    // TODO(jungh.yeon): Need to add ways about validating instance.
     EXPECT_NE(installer, nullptr);
   }
 }
 
+TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_WrongRecoveryFile) {
+  std::vector<std::string> arguments =
+      {"unified-backend", "-b", "test_samples/kkk-recovery-123456",
+      "test_samples/tgt-recovery-123456"};
+  std::vector<char*> argv;
+  for (const auto& arg : arguments)
+    argv.push_back(const_cast<char*>(
+            reinterpret_cast<const char*>(arg.data())));
+  argv.push_back(nullptr);
+
+  pkgmgrinfo_pkginfo_h handle1 = calloc(1, sizeof(manifest_x));
+  pkgmgrinfo_pkginfo_h handle2 = calloc(1, sizeof(manifest_x));
+  if (handle1 == nullptr || handle2 == nullptr) {
+    EXPECT_TRUE(false) << "Out of memory";
+  }
+
+  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+      pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+          StrEq("test_samples/kkk-recovery-123456"), _, _)).
+          WillOnce(DoAll(
+                  SetArgPointee<2>(
+                      reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
+                  Return(PMINFO_R_OK)));
+  EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+      pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
+          StrEq("test_samples/tgt-recovery-123456"), _, _)).
+          WillOnce(DoAll(
+                  SetArgPointee<2>(
+                      reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
+                  Return(PMINFO_R_OK)));
+
+  TestPkgmgrInstaller pkgmgr_installer;
+  EXPECT_CALL(GetMock<GumMock>(),
+      gum_user_get_sync(_, _)).
+          WillRepeatedly(Invoke(__gum_user_get_sync_fake));
+
+  auto pkgmgr = common_installer::PkgMgrInterface::Create(
+      argv.size() - 1,
+      argv.data(),
+      &pkgmgr_installer,
+      nullptr);
+  if (!pkgmgr) {
+    ASSERT_TRUE(false);
+  }
+
+  EXPECT_EQ(pkgmgr->GetRequestInfoCount(), 2);
+
+  std::unique_ptr<common_installer::UnifiedInstallerFactory>factory(
+      new common_installer::UnifiedInstallerFactory());
+
+  for (int idx = 0; idx < 2; idx++) {
+    std::unique_ptr<common_installer::AppInstaller> installer =
+        factory->CreateInstaller(pkgmgr, idx);
+    // TODO(jungh.yeon): Need to add ways about validating instance.
+    EXPECT_EQ(installer, nullptr);
+  }
+}
+
 TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromPkgFile) {
   std::vector<std::string> arguments =
       {"unified-backend", "-i", "test_samples/test-tpk-pkg.tpk",
@@ -252,3 +312,4 @@ TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromPkgFile) {
     EXPECT_NE(installer, nullptr);
   }
 }
+