Testsuite cleanup in smoke tests 27/46227/4
authorTomasz Iwanek <t.iwanek@samsung.com>
Tue, 18 Aug 2015 07:29:06 +0000 (09:29 +0200)
committerPawel Sikorski <p.sikorski@samsung.com>
Tue, 18 Aug 2015 15:38:44 +0000 (08:38 -0700)
Change-Id: I5033d45052bdb6f3d2fa92426b51af11da345120

src/unit_tests/CMakeLists.txt
src/unit_tests/smoke_test.cc

index 321560e..2cc3bdf 100644 (file)
@@ -36,7 +36,7 @@ ENDFOREACH(test)
 # GTEST_MAIN_LIBRARIES is needed.
 target_link_libraries(signature_unittest PUBLIC ${TARGET_LIBNAME_COMMON} ${GTEST_MAIN_LIBRARIES})
 target_link_libraries(xml_parser_unittest PUBLIC ${TARGET_LIBNAME_PARSER} ${GTEST_MAIN_LIBRARIES})
-target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_WGT} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_WGT})
 
 FOREACH(test ${TESTS})
   INSTALL(TARGETS ${test} DESTINATION ${BINDIR}/${DESTINATION_DIR})
index f0551f2..a113fb1 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <array>
 #include <cstdio>
+#include <cstdlib>
 
 #include "common/backup_paths.h"
 #include "common/pkgmgr_interface.h"
@@ -31,6 +32,11 @@ namespace ci = common_installer;
 
 namespace {
 
+const char kApplicationDir[] = ".applications";
+const char kApplicationDirBackup[] = ".applications.bck";
+const char KUserAppsDir[] = "apps_rw";
+const char KUserAppsDirBackup[] = "apps_rw.bck";
+
 enum class RequestResult {
   NORMAL,
   FAIL,
@@ -276,7 +282,37 @@ ci::AppInstaller::Result Recover(const bf::path& recovery_file,
 
 namespace wgt {
 
-// TODO(t.iwanek): before tests cleanup...
+class SmokeEnvironment : public testing::Environment {
+ public:
+  explicit SmokeEnvironment(const bf::path& home) : home_(home) {
+  }
+  void SetUp() override {
+    bs::error_code error;
+    bf::remove_all(home_ / kApplicationDirBackup, error);
+    bf::remove_all(home_ / KUserAppsDirBackup, error);
+    if (bf::exists(home_ / KUserAppsDir)) {
+      bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
+      assert(!error);
+    }
+    if (bf::exists(home_ / kApplicationDir)) {
+      bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error);
+      assert(!error);
+    }
+  }
+  void TearDown() override {
+    bs::error_code error;
+    bf::remove_all(home_ / kApplicationDir, error);
+    bf::remove_all(home_ / KUserAppsDir, error);
+    if (bf::exists(home_ / KUserAppsDirBackup))
+      bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error);
+    if (bf::exists(home_ / kApplicationDirBackup))
+      bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error);
+  }
+
+ private:
+  bf::path home_;
+};
+
 class SmokeTest : public testing::Test {
 };
 
@@ -394,3 +430,14 @@ TEST_F(SmokeTest, DeinstallationMode_Rollback) {
 }
 
 }  // namespace wgt
+
+int main(int argc,  char** argv) {
+  testing::InitGoogleTest(&argc, argv);
+  const char* directory = getenv("HOME");
+  if (!directory) {
+    LOG(ERROR) << "Cannot get $HOME value";
+    return 1;
+  }
+  testing::AddGlobalTestEnvironment(new wgt::SmokeEnvironment(directory));
+  return RUN_ALL_TESTS();
+}