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