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