modify smoke-test setup for consideration of user-db change.
[platform/core/appfw/wgt-backend.git] / src / unit_tests / smoke_test.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <boost/filesystem/operations.hpp>
6 #include <boost/filesystem/path.hpp>
7 #include <boost/range/iterator_range.hpp>
8 #include <boost/system/error_code.hpp>
9 #include <common/paths.h>
10 #include <common/pkgmgr_interface.h>
11 #include <common/pkgmgr_query.h>
12 #include <common/request.h>
13 #include <common/step/configuration/step_fail.h>
14 #include <common/tzip_interface.h>
15 #include <common/utils/subprocess.h>
16 #include <gtest/gtest.h>
17 #include <gtest/gtest-death-test.h>
18 #include <pkgmgr-info.h>
19 #include <signal.h>
20 #include <unistd.h>
21 #include <tzplatform_config.h>
22
23 #include <array>
24 #include <cstdio>
25 #include <cstdlib>
26 #include <vector>
27
28 #include "hybrid/hybrid_installer.h"
29 #include "wgt/wgt_app_query_interface.h"
30 #include "wgt/wgt_installer.h"
31
32 #define SIZEOFARRAY(ARR)                                                       \
33   sizeof(ARR) / sizeof(ARR[0])                                                 \
34
35 namespace bf = boost::filesystem;
36 namespace bs = boost::system;
37 namespace ci = common_installer;
38
39 namespace {
40
41 const bf::path kSmokePackagesDirectory =
42     "/usr/share/wgt-backend-ut/test_samples/smoke/";
43
44 const char kApplicationDir[] = ".applications";
45 const char kApplicationDirBackup[] = ".applications.bck";
46 const char KUserAppsDir[] = "apps_rw";
47 const char KUserAppsDirBackup[] = "apps_rw.bck";
48 const char kUserDataBaseDir[] = "/opt/dbspace/user";
49
50 enum class RequestResult {
51   NORMAL,
52   FAIL
53 };
54
55 class ScopedTzipInterface {
56  public:
57   explicit ScopedTzipInterface(const std::string& pkgid)
58       : pkg_path_(bf::path(ci::GetRootAppPath(false)) / pkgid),
59         interface_(ci::GetMountLocation(pkg_path_)) {
60     interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
61   }
62
63   ~ScopedTzipInterface() {
64     interface_.UnmountZip();
65   }
66
67  private:
68   bf::path pkg_path_;
69   ci::TzipInterface interface_;
70 };
71
72 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
73  public:
74   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
75                              ci::InstallationMode* mode) {
76     *installer = pkgmgr_installer_offline_new();
77     if (!*installer)
78       return false;
79     *mode = ci::InstallationMode::ONLINE;
80     return true;
81   }
82
83   bool ShouldCreateSignal() const {
84     return false;
85   }
86 };
87
88 enum class PackageType {
89   WGT,
90   HYBRID
91 };
92
93 bool TouchFile(const bf::path& path) {
94   FILE* f = fopen(path.c_str(), "w+");
95   if (!f)
96     return false;
97   fclose(f);
98   return true;
99 }
100
101 void RemoveAllRecoveryFiles() {
102   bf::path root_path = ci::GetRootAppPath(false);
103   if (!bf::exists(root_path))
104     return;
105   for (auto& dir_entry : boost::make_iterator_range(
106          bf::directory_iterator(root_path), bf::directory_iterator())) {
107     if (bf::is_regular_file(dir_entry)) {
108       if (dir_entry.path().string().find("/recovery") != std::string::npos) {
109         bs::error_code error;
110         bf::remove(dir_entry.path(), error);
111       }
112     }
113   }
114 }
115
116 bf::path FindRecoveryFile() {
117   bf::path root_path = ci::GetRootAppPath(false);
118   for (auto& dir_entry : boost::make_iterator_range(
119          bf::directory_iterator(root_path), bf::directory_iterator())) {
120     if (bf::is_regular_file(dir_entry)) {
121       if (dir_entry.path().string().find("/recovery") != std::string::npos) {
122         return dir_entry.path();
123       }
124     }
125   }
126   return {};
127 }
128
129 bool ValidateFileContentInPackage(const std::string& pkgid,
130                                   const std::string& relative,
131                                   const std::string& expected) {
132   bf::path root_path = ci::GetRootAppPath(false);
133   bf::path file_path = root_path / pkgid / relative;
134   if (!bf::exists(file_path)) {
135     LOG(ERROR) << file_path << " doesn't exist";
136     return false;
137   }
138   FILE* handle = fopen(file_path.c_str(), "r");
139   if (!handle) {
140     LOG(ERROR) << file_path << " cannot  be open";
141     return false;
142   }
143   std::string content;
144   std::array<char, 200> buffer;
145   while (fgets(buffer.data(), buffer.size(), handle)) {
146     content += buffer.data();
147   }
148   fclose(handle);
149   return content == expected;
150 }
151
152 void ValidatePackageFS(const std::string& pkgid,
153                        const std::vector<std::string>& appids) {
154   bf::path root_path = ci::GetRootAppPath(false);
155   bf::path package_path = root_path / pkgid;
156   bf::path data_path = package_path / "data";
157   bf::path shared_path = package_path / "shared";
158   bf::path cache_path = package_path / "cache";
159   ASSERT_TRUE(bf::exists(root_path));
160   ASSERT_TRUE(bf::exists(package_path));
161   ASSERT_TRUE(bf::exists(data_path));
162   ASSERT_TRUE(bf::exists(shared_path));
163   ASSERT_TRUE(bf::exists(cache_path));
164
165   bf::path manifest_path =
166       bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
167   ASSERT_TRUE(bf::exists(manifest_path));
168
169   for (auto& appid : appids) {
170     bf::path binary_path = package_path / "bin" / appid;
171     ASSERT_TRUE(bf::exists(binary_path));
172   }
173
174   bf::path widget_root_path = package_path / "res" / "wgt";
175   bf::path config_path = widget_root_path / "config.xml";
176   ASSERT_TRUE(bf::exists(widget_root_path));
177   ASSERT_TRUE(bf::exists(config_path));
178
179   bf::path private_tmp_path = package_path / "tmp";
180   ASSERT_TRUE(bf::exists(private_tmp_path));
181
182   // backups should not exist
183   bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
184   bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
185   ASSERT_FALSE(bf::exists(package_backup));
186   ASSERT_FALSE(bf::exists(manifest_backup));
187 }
188
189 void PackageCheckCleanup(const std::string& pkgid,
190                          const std::vector<std::string>&) {
191   bf::path root_path = ci::GetRootAppPath(false);
192   bf::path package_path = root_path / pkgid;
193   ASSERT_FALSE(bf::exists(package_path));
194
195   bf::path manifest_path =
196       bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
197   ASSERT_FALSE(bf::exists(manifest_path));
198
199   // backups should not exist
200   bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
201   bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
202   ASSERT_FALSE(bf::exists(package_backup));
203   ASSERT_FALSE(bf::exists(manifest_backup));
204 }
205
206 void ValidatePackage(const std::string& pkgid,
207                      const std::vector<std::string>& appids) {
208   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
209   ValidatePackageFS(pkgid, appids);
210 }
211
212 void CheckPackageNonExistance(const std::string& pkgid,
213                               const std::vector<std::string>& appids) {
214   ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
215   PackageCheckCleanup(pkgid, appids);
216 }
217
218 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
219   std::unique_ptr<ci::AppQueryInterface> query_interface(
220       new wgt::WgtAppQueryInterface());
221   return query_interface;
222 }
223
224 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
225                                                   PackageType type) {
226   switch (type) {
227     case PackageType::WGT:
228       return std::unique_ptr<ci::AppInstaller>(new wgt::WgtInstaller(pkgmgr));
229     case PackageType::HYBRID:
230       return std::unique_ptr<ci::AppInstaller>(
231           new hybrid::HybridInstaller(pkgmgr));
232     default:
233       LOG(ERROR) << "Unknown installer type";
234       return nullptr;
235   }
236 }
237
238 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
239                                                  PackageType type,
240                                                  RequestResult mode) {
241   std::unique_ptr<ci::AppInstaller> installer = CreateInstaller(pkgmgr, type);
242   switch (mode) {
243   case RequestResult::FAIL:
244     installer->AddStep<ci::configuration::StepFail>();
245     break;
246   default:
247     break;
248   }
249   return installer->Run();
250 }
251 ci::AppInstaller::Result CallBackend(int argc,
252                                      const char* argv[],
253                                      PackageType type,
254                                      RequestResult mode = RequestResult::NORMAL
255                                      ) {
256   TestPkgmgrInstaller pkgmgr_installer;
257   std::unique_ptr<ci::AppQueryInterface> query_interface =
258       CreateQueryInterface();
259   auto pkgmgr =
260       ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
261                                   &pkgmgr_installer, query_interface.get());
262   if (!pkgmgr) {
263     LOG(ERROR) << "Failed to initialize pkgmgr interface";
264     return ci::AppInstaller::Result::UNKNOWN;
265   }
266   return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
267 }
268
269 ci::AppInstaller::Result Install(const bf::path& path,
270                                  PackageType type,
271                                  RequestResult mode = RequestResult::NORMAL) {
272   const char* argv[] = {"", "-i", path.c_str()};
273   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
274 }
275
276 ci::AppInstaller::Result Update(const bf::path& path_old,
277                                 const bf::path& path_new,
278                                 PackageType type,
279                                 RequestResult mode = RequestResult::NORMAL) {
280   if (Install(path_old, type) != ci::AppInstaller::Result::OK) {
281     LOG(ERROR) << "Failed to install application. Cannot update";
282     return ci::AppInstaller::Result::UNKNOWN;
283   }
284   return Install(path_new, type, mode);
285 }
286
287 ci::AppInstaller::Result MountInstall(const bf::path& path,
288     PackageType type, RequestResult mode = RequestResult::NORMAL) {
289   const char* argv[] = {"", "-w", path.c_str()};
290   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
291 }
292
293 ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
294     const bf::path& path_new, PackageType type,
295     RequestResult mode = RequestResult::NORMAL) {
296   if (MountInstall(path_old, type) != ci::AppInstaller::Result::OK) {
297     LOG(ERROR) << "Failed to mount-install application. Cannot mount-update";
298     return ci::AppInstaller::Result::UNKNOWN;
299   }
300   return MountInstall(path_new, type, mode);
301 }
302
303 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
304                                    PackageType type,
305                                    RequestResult mode = RequestResult::NORMAL) {
306   const char* argv[] = {"", "-d", pkgid.c_str()};
307   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
308 }
309
310 ci::AppInstaller::Result Reinstall(const bf::path& path,
311                                    const bf::path& delta_dir,
312                                    PackageType type,
313                                    RequestResult mode = RequestResult::NORMAL) {
314   if (Install(path, type) != ci::AppInstaller::Result::OK) {
315     LOG(ERROR) << "Failed to install application. Cannot perform RDS";
316     return ci::AppInstaller::Result::UNKNOWN;
317   }
318   const char* argv[] = {"", "-r", delta_dir.c_str()};
319   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
320 }
321
322 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
323     const bf::path& delta_package, PackageType type) {
324   if (Install(path, type) != ci::AppInstaller::Result::OK) {
325     LOG(ERROR) << "Failed to install application. Cannot perform delta update";
326     return ci::AppInstaller::Result::UNKNOWN;
327   }
328   return Install(delta_package, type);
329 }
330
331 ci::AppInstaller::Result Clear(const std::string& pkgid,
332                                    PackageType type,
333                                    RequestResult mode = RequestResult::NORMAL) {
334   const char* argv[] = {"", "-c", pkgid.c_str()};
335   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
336 }
337
338 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
339                                   PackageType type,
340                                   RequestResult mode = RequestResult::NORMAL) {
341   const char* argv[] = {"", "-A", pkgid.c_str()};
342   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
343 }
344
345 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
346                                   PackageType type,
347                                   RequestResult mode = RequestResult::NORMAL) {
348   const char* argv[] = {"", "-D", pkgid.c_str()};
349   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
350 }
351
352 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
353                                  PackageType type,
354                                  RequestResult mode = RequestResult::NORMAL) {
355   const char* argv[] = {"", "-b", recovery_file.c_str()};
356   TestPkgmgrInstaller pkgmgr_installer;
357   std::unique_ptr<ci::AppQueryInterface> query_interface =
358       CreateQueryInterface();
359   auto pkgmgr =
360       ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
361                                   &pkgmgr_installer, query_interface.get());
362   if (!pkgmgr) {
363     LOG(ERROR) << "Failed to initialize pkgmgr interface";
364     return ci::AppInstaller::Result::UNKNOWN;
365   }
366   return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
367 }
368
369 }  // namespace
370
371 namespace common_installer {
372
373 class SmokeEnvironment : public testing::Environment {
374  public:
375   explicit SmokeEnvironment(const bf::path& home) : home_(home) {
376   }
377   void SetUp() override {
378     bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
379     bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
380
381     bs::error_code error;
382     bf::remove_all(home_ / kApplicationDirBackup, error);
383     bf::remove_all(home_ / KUserAppsDirBackup, error);
384     bf::remove_all(UserDBDirBackup, error);
385     if (bf::exists(home_ / KUserAppsDir)) {
386       bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
387       if (error)
388         LOG(ERROR) << "Failed to setup test environment. Does some previous"
389                    << " test crashed? Directory: "
390                    << (home_ / KUserAppsDirBackup) << " should not exist.";
391       assert(!error);
392     }
393     if (bf::exists(home_ / kApplicationDir)) {
394       bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error);
395       if (error)
396         LOG(ERROR) << "Failed to setup test environment. Does some previous"
397                    << " test crashed? Directory: "
398                    << (home_ / kApplicationDirBackup) << " should not exist.";
399       assert(!error);
400     }
401     if (bf::exists(UserDBDir)) {
402       bf::rename(UserDBDir, UserDBDirBackup, error);
403       if (error)
404         LOG(ERROR) << "Failed to setup test environment. Does some previous"
405                    << " test crashed? Directory: "
406                    << UserDBDirBackup << " should not exist.";
407       assert(!error);
408     }
409   }
410   void TearDown() override {
411     bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
412     bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
413
414     bs::error_code error;
415     bf::remove_all(home_ / kApplicationDir, error);
416     bf::remove_all(home_ / KUserAppsDir, error);
417     bf::remove_all(UserDBDir, error);
418     if (bf::exists(home_ / KUserAppsDirBackup))
419       bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error);
420     if (bf::exists(home_ / kApplicationDirBackup))
421       bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error);
422     if (bf::exists(UserDBDirBackup))
423       bf::rename(UserDBDirBackup, UserDBDir, error);
424   }
425
426  private:
427   bf::path home_;
428 };
429
430 class SmokeTest : public testing::Test {
431 };
432
433 TEST_F(SmokeTest, InstallationMode) {
434   bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
435   std::string pkgid = "smokeapp03";
436   std::string appid = "smokeapp03.InstallationMode";
437   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
438   ValidatePackage(pkgid, {appid});
439 }
440
441 TEST_F(SmokeTest, UpdateMode) {
442   bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
443   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
444   std::string pkgid = "smokeapp04";
445   std::string appid = "smokeapp04.UpdateMode";
446   ASSERT_EQ(Update(path_old, path_new, PackageType::WGT),
447             ci::AppInstaller::Result::OK);
448   ValidatePackage(pkgid, {appid});
449
450   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
451 }
452
453 TEST_F(SmokeTest, DeinstallationMode) {
454   bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
455   std::string pkgid = "smokeapp05";
456   std::string appid = "smokeapp05.DeinstallationMode";
457   ASSERT_EQ(Install(path, PackageType::WGT),
458             ci::AppInstaller::Result::OK);
459   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
460   CheckPackageNonExistance(pkgid, {appid});
461 }
462
463 TEST_F(SmokeTest, RDSMode) {
464   bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
465   bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
466   std::string pkgid = "smokeapp11";
467   std::string appid = "smokeapp11.RDSMode";
468   ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT),
469             ci::AppInstaller::Result::OK);
470   ValidatePackage(pkgid, {appid});
471
472   // Check delta modifications
473   bf::path root_path = ci::GetRootAppPath(false);
474   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
475   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
476   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
477 }
478
479 TEST_F(SmokeTest, EnablePkg) {
480   bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
481   std::string pkgid = "smokeapp22";
482   ASSERT_EQ(Install(path, PackageType::WGT),
483             ci::AppInstaller::Result::OK);
484   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
485             ci::AppInstaller::Result::OK);
486   ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
487             ci::AppInstaller::Result::OK);
488
489   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
490 }
491
492 TEST_F(SmokeTest, DisablePkg) {
493   bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
494   std::string pkgid = "smokeapp21";
495   std::string appid = "smokeapp21.DisablePkg";
496   ASSERT_EQ(Install(path, PackageType::WGT),
497             ci::AppInstaller::Result::OK);
498   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
499             ci::AppInstaller::Result::OK);
500   ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
501   ValidatePackageFS(pkgid, {appid});
502 }
503
504 TEST_F(SmokeTest, ClearMode) {
505   bf::path path = kSmokePackagesDirectory / "ClearMode.wgt";
506   std::string pkgid = "smokeapp20";
507   std::string appid = "smokeapp20.ClearMode";
508   ASSERT_EQ(Install(path, PackageType::WGT),
509             ci::AppInstaller::Result::OK);
510   bf::path root_path = ci::GetRootAppPath(false);
511   bs::error_code error;
512   bf::create_directory(root_path / pkgid / "data" / "dir", error);
513   ASSERT_FALSE(error);
514   ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file"));
515   ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file"));
516   ASSERT_EQ(Clear(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
517   ValidatePackage(pkgid, {appid});
518   ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file"));
519   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file"));
520 }
521
522 TEST_F(SmokeTest, DeltaMode) {
523   bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
524   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
525   std::string pkgid = "smokeapp17";
526   std::string appid = "smokeapp17.DeltaMode";
527   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
528             ci::AppInstaller::Result::OK);
529   ValidatePackage(pkgid, {appid});
530
531   // Check delta modifications
532   bf::path root_path = ci::GetRootAppPath(false);
533   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
534   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
535   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
536   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
537   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
538   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
539 }
540
541 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
542   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
543   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
544   backend_crash.Run("-i", path.string());
545   ASSERT_NE(backend_crash.Wait(), 0);
546
547   std::string pkgid = "smokeapp09";
548   std::string appid = "smokeapp09.RecoveryModeForInstallation";
549   bf::path recovery_file = FindRecoveryFile();
550   ASSERT_FALSE(recovery_file.empty());
551   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
552       ci::AppInstaller::Result::OK);
553   CheckPackageNonExistance(pkgid, {appid});
554 }
555
556 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
557   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
558   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
559   RemoveAllRecoveryFiles();
560   Subprocess backend_test("/usr/bin/wgt-backend");
561   backend_test.Run("-i", path_old.string());
562   ASSERT_EQ(backend_test.Wait(), 0);
563   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
564   backend_crash.Run("-i", path_new.string());
565   ASSERT_NE(backend_crash.Wait(), 0);
566
567   std::string pkgid = "smokeapp10";
568   std::string appid = "smokeapp10.RecoveryModeForUpdate";
569   bf::path recovery_file = FindRecoveryFile();
570   ASSERT_FALSE(recovery_file.empty());
571   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
572             ci::AppInstaller::Result::OK);
573   ValidatePackage(pkgid, {appid});
574
575   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
576 }
577
578 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
579   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
580   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
581 }
582
583 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
584   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
585   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
586 }
587
588 TEST_F(SmokeTest, InstallationMode_Rollback) {
589   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
590   std::string pkgid = "smokeapp06";
591   std::string appid = "smokeapp06.InstallationModeRollback";
592   ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
593             ci::AppInstaller::Result::ERROR);
594   CheckPackageNonExistance(pkgid, {appid});
595 }
596
597 TEST_F(SmokeTest, UpdateMode_Rollback) {
598   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
599   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
600   std::string pkgid = "smokeapp07";
601   std::string appid = "smokeapp07.UpdateModeRollback";
602   ASSERT_EQ(Update(path_old, path_new, PackageType::WGT, RequestResult::FAIL),
603                    ci::AppInstaller::Result::ERROR);
604   ValidatePackage(pkgid, {appid});
605
606   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
607 }
608
609 TEST_F(SmokeTest, InstallationMode_Hybrid) {
610   bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
611   std::string pkgid = "smokehyb01";
612   std::string appid1 = "smokehyb01.Web";
613   std::string appid2 = "smokehyb01.Native";
614   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
615   ValidatePackage(pkgid, {appid1, appid2});
616 }
617
618 TEST_F(SmokeTest, UpdateMode_Hybrid) {
619   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
620   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
621   std::string pkgid = "smokehyb02";
622   std::string appid1 = "smokehyb02.Web";
623   std::string appid2 = "smokehyb02.Native";
624   ASSERT_EQ(Update(path_old, path_new, PackageType::HYBRID),
625             ci::AppInstaller::Result::OK);
626   ValidatePackage(pkgid, {appid1, appid2});
627
628   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
629   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
630 }
631
632 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
633   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
634   std::string pkgid = "smokehyb03";
635   std::string appid1 = "smokehyb03.Web";
636   std::string appid2 = "smokehyb03.Native";
637   ASSERT_EQ(Install(path, PackageType::HYBRID),
638             ci::AppInstaller::Result::OK);
639   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
640   CheckPackageNonExistance(pkgid, {appid1, appid2});
641 }
642
643 TEST_F(SmokeTest, DeltaMode_Hybrid) {
644   bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
645   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
646   std::string pkgid = "smokehyb04";
647   std::string appid1 = "smokehyb04.Web";
648   std::string appid2 = "smokehyb04.Native";
649   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
650             ci::AppInstaller::Result::OK);
651   ValidatePackage(pkgid, {appid1, appid2});
652
653   // Check delta modifications
654   bf::path root_path = ci::GetRootAppPath(false);
655   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
656   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
657   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
658   ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
659   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
660   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
661   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
662   ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
663   ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n");
664 }
665
666 TEST_F(SmokeTest, MountInstallationMode) {
667   bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
668   std::string pkgid = "smokeapp28";
669   std::string appid = "smokeapp28.InstallationMode";
670   ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
671   ScopedTzipInterface interface(pkgid);
672   ValidatePackage(pkgid, {appid});
673 }
674
675 TEST_F(SmokeTest, MountUpdateMode) {
676   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
677   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
678   std::string pkgid = "smokeapp29";
679   std::string appid = "smokeapp29.UpdateMode";
680   ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT),
681             ci::AppInstaller::Result::OK);
682   ScopedTzipInterface interface(pkgid);
683   ValidatePackage(pkgid, {appid});
684
685   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
686 }
687
688 }  // namespace common_installer
689
690 int main(int argc,  char** argv) {
691   testing::InitGoogleTest(&argc, argv);
692   const char* directory = getenv("HOME");
693   if (!directory) {
694     LOG(ERROR) << "Cannot get $HOME value";
695     return 1;
696   }
697   testing::AddGlobalTestEnvironment(
698       new common_installer::SmokeEnvironment(directory));
699   return RUN_ALL_TESTS();
700 }