Clear data smoke test 85/61785/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 10 Mar 2016 11:58:31 +0000 (12:58 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 6 Apr 2016 11:36:03 +0000 (04:36 -0700)
Change-Id: I7f3fc5c333c247b9c9fcd64b172bd2a9acc89b94

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

index 799ad2b63f2946bbfde5c8f37aef2f6a617e0dea..79098d2ada05d5604e6632c70373536408180603 100644 (file)
@@ -50,6 +50,14 @@ enum class RequestResult {
   FAIL
 };
 
+bool TouchFile(const bf::path& path) {
+  FILE* f = fopen(path.c_str(), "w+");
+  if (!f)
+    return false;
+  fclose(f);
+  return true;
+}
+
 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
  public:
   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
@@ -133,7 +141,8 @@ void ValidatePackageFS(const std::string& pkgid, const std::string& appid) {
 
   bf::path manifest_path =
       bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
-  bf::path icon_path = bf::path(getIconPath(getuid(), false)) / (appid + ".png");
+  bf::path icon_path =
+      bf::path(getIconPath(getuid(), false)) / (appid + ".png");
   ASSERT_TRUE(bf::exists(manifest_path));
   ASSERT_TRUE(bf::exists(icon_path));
 
@@ -153,7 +162,8 @@ void PackageCheckCleanup(const std::string& pkgid, const std::string& appid) {
 
   bf::path manifest_path =
       bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
-  bf::path icon_path = bf::path(getIconPath(getuid(), false)) / (appid + ".png");
+  bf::path icon_path =
+      bf::path(getIconPath(getuid(), false)) / (appid + ".png");
   ASSERT_FALSE(bf::exists(manifest_path));
   ASSERT_FALSE(bf::exists(icon_path));
 
@@ -244,6 +254,24 @@ ci::AppInstaller::Result Uninstall(const std::string& pkgid,
   return RunInstallerWithPkgrmgr(pkgmgr, 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);
+}
+
+
 ci::AppInstaller::Result Reinstall(const bf::path& path,
                                    const bf::path& delta_dir,
                                    RequestResult mode = RequestResult::NORMAL) {
@@ -382,6 +410,23 @@ TEST_F(SmokeTest, DeinstallationMode_Tpk) {
   CheckPackageNonExistance(pkgid, appid);
 }
 
+TEST_F(SmokeTest, ClearMode_Tpk) {
+  bf::path path = kSmokePackagesDirectory / "ClearMode_Tpk.tpk";
+  std::string pkgid = "smokeapp21";
+  std::string appid = "smokeapp21.ClearModeTpk";
+  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
+  bf::path root_path = ci::GetRootAppPath(false);
+  bs::error_code error;
+  bf::create_directory(root_path / pkgid / "data" / "dir", error);
+  ASSERT_FALSE(error);
+  ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file"));
+  ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file"));
+  ASSERT_EQ(Clear(pkgid), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid});
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file"));
+}
+
 TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
   RemoveAllRecoveryFiles();
diff --git a/src/unit_tests/test_samples/smoke/ClearMode_Tpk.tpk b/src/unit_tests/test_samples/smoke/ClearMode_Tpk.tpk
new file mode 100644 (file)
index 0000000..4fafecb
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/ClearMode_Tpk.tpk differ