Revert "[SmokeTest] Add request mode choice"
[platform/core/appfw/wgt-backend.git] / src / unit_tests / smoke_test.cc
index 844fa1c..d52b00b 100644 (file)
@@ -30,6 +30,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <vector>
+#include <regex>
 
 #include "hybrid/hybrid_installer.h"
 #include "wgt/wgt_app_query_interface.h"
@@ -160,7 +161,8 @@ void RemoveAllRecoveryFiles() {
   for (auto& dir_entry : boost::make_iterator_range(
          bf::directory_iterator(root_path), bf::directory_iterator())) {
     if (bf::is_regular_file(dir_entry)) {
-      if (dir_entry.path().string().find("/recovery") != std::string::npos) {
+      if (dir_entry.path().string().find("/wgt-recovery")
+          != std::string::npos) {
         bs::error_code error;
         bf::remove(dir_entry.path(), error);
       }
@@ -174,7 +176,8 @@ bf::path FindRecoveryFile() {
   for (auto& dir_entry : boost::make_iterator_range(
          bf::directory_iterator(root_path), bf::directory_iterator())) {
     if (bf::is_regular_file(dir_entry)) {
-      if (dir_entry.path().string().find("/recovery") != std::string::npos) {
+      if (dir_entry.path().string().find("/wgt-recovery")
+          != std::string::npos) {
         return dir_entry.path();
       }
     }
@@ -312,8 +315,10 @@ void ValidatePackageFS(const std::string& pkgid,
       bf::path rw_dir_path = rw_dir;
       is_rw_dir |= ci::MakeRelativePath(iter->path(), package_path) == rw_dir_path;
     }
-    if (is_rw_dir || iter->path().filename() == ".mmc")
+    if (is_rw_dir || iter->path().filename() == ".mmc") {
+      iter.no_push();
       continue;
+    }
     struct stat stats;
     stat(iter->path().c_str(), &stats);
     ASSERT_EQ(uid, stats.st_uid) << "Invalid uid: " << iter->path();
@@ -707,11 +712,15 @@ void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) {
         bf::directory_iterator(dir), bf::directory_iterator())) {
       if (dir_entry.path().string().find("smoke") != std::string::npos &&
           bf::is_directory(dir_entry)) {
-        if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
-            is_preload, RequestResult::NORMAL) !=
-            ci::AppInstaller::Result::OK) {
-          LOG(ERROR) << "Cannot uninstall smoke test app: "
-              << dir_entry.path().filename().string();
+        std::string package = dir_entry.path().filename().string();
+        std::regex pkg_regex("smoke[a-zA-Z]{3,}[1-9]{2,}");
+        if (std::regex_match(package, pkg_regex)) {
+          if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
+              is_preload, RequestResult::NORMAL) !=
+              ci::AppInstaller::Result::OK) {
+            LOG(ERROR) << "Cannot uninstall smoke test app: "
+                << dir_entry.path().filename().string();
+          }
         }
       }
     }
@@ -965,11 +974,13 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
 }
 
 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
+  // pkgid: smokewgt08
   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
 }
 
 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
+  // pkgid: smokewgt12
   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
 }
@@ -1326,6 +1337,77 @@ TEST_F(SmokeTest, DeinstallationMode_Preload) {
   CheckPackageReadonlyNonExistance(pkgid, {appid});
 }
 
+TEST_F(SmokeTest, SharedRes24) {
+  bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
+  std::string pkgid = "smokeSh2xx";
+  std::string appid = "smokeSh2xx.SharedRes24";
+  ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid});
+  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30) {
+  bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
+  std::string pkgid = "smokeSh3xx";
+  std::string appid = "smokeSh3xx.SharedRes30";
+  ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid});
+  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30Delta) {
+  bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
+  bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
+  std::string pkgid = "smokeSh3De";
+  std::string appid = "smokeSh3De.SharedRes30Delta";
+  ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid});
+  // Check delta modifications
+  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30Hybrid) {
+  bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
+  std::string pkgid = "smokeSh3Hy";
+  std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
+  std::string appid2 = "sharedres30hybridserivce";
+  ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid1, appid2});
+  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK"));  // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30HybridDelta) {
+  bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
+  bf::path delta_package = kSmokePackagesDirectory / "SharedRes30HybridDelta.delta";
+  std::string pkgid = "smokeSh3HD";
+  std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
+  std::string appid2 = "sharedres30hybriddeltaserivce";
+  ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
+            ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid1, appid2});
+  // Check delta modifications
+  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
+  ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
+  ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
+}
+
 }  // namespace common_installer
 
 int main(int argc,  char** argv) {