Export Smoke Utils
[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 <common/utils/subprocess.h>
6
7 #include <common/utils/file_util.h>
8
9 #include <gtest/gtest.h>
10 #include <gtest/gtest-death-test.h>
11
12 #include "unit_tests/smoke_utils.h"
13
14
15 namespace common_installer {
16
17 class SmokeEnvironment : public testing::Environment {
18  public:
19   explicit SmokeEnvironment(ci::RequestMode mode) {\
20     request_mode_ = mode;
21   }
22   void SetUp() override {
23     if (request_mode_ == ci::RequestMode::USER) {
24       ASSERT_TRUE(AddTestUser(kNormalUserName));
25     } else {
26       kTestUserId = kGlobalUserUid;
27       kTestGroupId = kGlobalUserGid;
28       kTestUserIdStr = std::to_string(kTestUserId);
29     }
30     backups_ = SetupBackupDirectories();
31     for (auto& path : backups_)
32       BackupPath(path);
33   }
34   void TearDown() override {
35     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
36                 (request_mode_ == ci::RequestMode::USER &&
37                 kGlobalUserUid != kTestUserId));
38     UninstallAllSmokeApps(request_mode_);
39     for (auto& path : backups_)
40       RestorePath(path);
41     if (request_mode_ == ci::RequestMode::USER)
42       ASSERT_TRUE(DeleteTestUser(kNormalUserName));
43   }
44
45  private:
46   ci::RequestMode request_mode_;
47   std::vector<bf::path> backups_;
48 };
49
50 class SmokeTest : public testing::Test {
51 };
52
53 class PreloadSmokeTest : public testing::Test {
54   void SetUp() override {
55     ASSERT_EQ(kGlobalUserUid, kTestUserId);
56   }
57 };
58
59 TEST_F(SmokeTest, InstallationMode) {
60   bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
61   std::string pkgid = "smokewgt03";
62   std::string appid = "smokewgt03.InstallationMode";
63   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
64   ValidatePackage(pkgid, {appid});
65 }
66
67 TEST_F(SmokeTest, UpdateMode) {
68   bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
69   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
70   std::string pkgid = "smokewgt04";
71   std::string appid = "smokewgt04.UpdateMode";
72   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
73   AddDataFiles(pkgid, kTestUserId);
74   ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
75   ValidatePackage(pkgid, {appid});
76
77   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
78   ValidateDataFiles(pkgid, kTestUserId);
79 }
80
81 TEST_F(SmokeTest, DeinstallationMode) {
82   bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
83   std::string pkgid = "smokewgt05";
84   std::string appid = "smokewgt05.DeinstallationMode";
85   ASSERT_EQ(Install(path, PackageType::WGT),
86             ci::AppInstaller::Result::OK);
87   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
88             ci::AppInstaller::Result::OK);
89   CheckPackageNonExistance(pkgid, {appid});
90 }
91
92 TEST_F(SmokeTest, RDSMode) {
93   bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
94   std::string pkgid = "smokewgt11";
95   std::string appid = "smokewgt11.RDSMode";
96   bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
97   bf::path sdk_expected_directory =
98       bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
99   bs::error_code error;
100   bf::create_directories(sdk_expected_directory.parent_path(), error);
101   ASSERT_FALSE(error);
102   ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
103   ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
104             ci::AppInstaller::Result::OK);
105   ValidatePackage(pkgid, {appid});
106
107   // Check delta modifications
108   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
109       "res" / "wgt" / "DELETED"));
110   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
111       "res" / "wgt" / "ADDED"));
112   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n"));
113 }
114
115 TEST_F(SmokeTest, EnablePkg) {
116   bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
117   std::string pkgid = "smokewgt22";
118   ASSERT_EQ(Install(path, PackageType::WGT),
119             ci::AppInstaller::Result::OK);
120   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
121             ci::AppInstaller::Result::OK);
122   ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
123             ci::AppInstaller::Result::OK);
124
125   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
126       ci::GetRequestMode(kTestUserId),
127       kTestUserId));
128 }
129
130 TEST_F(SmokeTest, DisablePkg) {
131   bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
132   std::string pkgid = "smokewgt21";
133   std::string appid = "smokewgt21.DisablePkg";
134   ASSERT_EQ(Install(path, PackageType::WGT),
135             ci::AppInstaller::Result::OK);
136   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
137             ci::AppInstaller::Result::OK);
138   ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
139   ValidatePackage(pkgid, {appid});
140 }
141
142 TEST_F(SmokeTest, DeltaMode) {
143   bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
144   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
145   std::string pkgid = "smokewgt17";
146   std::string appid = "smokewgt17.DeltaMode";
147   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
148             ci::AppInstaller::Result::OK);
149   ValidatePackage(pkgid, {appid});
150
151   // Check delta modifications
152   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
153       "res" / "wgt" / "DELETED"));
154   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
155       "res" / "wgt" / "ADDED"));
156   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
157       "res" / "wgt" / "css" / "style.css"));
158   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
159       "res" / "wgt" / "images" / "tizen_32.png"));
160   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
161       "res" / "wgt" / "js" / "main.js"));
162   ASSERT_TRUE(ValidateFileContentInPackage(
163       pkgid, "res/wgt/MODIFIED", "version 2\n"));
164 }
165
166 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
167   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
168   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
169   backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
170   ASSERT_NE(backend_crash.Wait(), 0);
171
172   std::string pkgid = "smokewgt09";
173   std::string appid = "smokewgt09.RecoveryModeForInstallation";
174   bf::path recovery_file = FindRecoveryFile();
175   ASSERT_FALSE(recovery_file.empty());
176   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
177       ci::AppInstaller::Result::OK);
178   CheckPackageNonExistance(pkgid, {appid});
179 }
180
181 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
182   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
183   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
184   RemoveAllRecoveryFiles();
185   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
186   std::string pkgid = "smokewgt10";
187   std::string appid = "smokewgt10.RecoveryModeForUpdate";
188   AddDataFiles(pkgid, kTestUserId);
189   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
190   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
191   ASSERT_NE(backend_crash.Wait(), 0);
192
193   bf::path recovery_file = FindRecoveryFile();
194   ASSERT_FALSE(recovery_file.empty());
195   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
196             ci::AppInstaller::Result::OK);
197   ValidatePackage(pkgid, {appid});
198
199   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
200   ValidateDataFiles(pkgid, kTestUserId);
201 }
202
203 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
204   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
205   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
206   RemoveAllRecoveryFiles();
207   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
208   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
209   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
210   ASSERT_NE(backend_crash.Wait(), 0);
211
212   std::string pkgid = "smokewgt30";
213   std::string appid = "smokewgt30.RecoveryModeForDelta";
214   bf::path recovery_file = FindRecoveryFile();
215   ASSERT_FALSE(recovery_file.empty());
216   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
217             ci::AppInstaller::Result::OK);
218   ValidatePackage(pkgid, {appid});
219
220   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
221 }
222
223 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
224   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
225   RemoveAllRecoveryFiles();
226   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
227   backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
228   ASSERT_NE(backend_crash.Wait(), 0);
229
230   std::string pkgid = "smokewgt31";
231   std::string appid = "smokewgt31.RecoveryModeForMountInstall";
232   bf::path recovery_file = FindRecoveryFile();
233   ASSERT_FALSE(recovery_file.empty());
234   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
235             ci::AppInstaller::Result::OK);
236   CheckPackageNonExistance(pkgid, {appid});
237 }
238
239 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
240   bf::path path_old =
241       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
242   bf::path path_new =
243       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
244   std::string pkgid = "smokewgt32";
245   std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
246   RemoveAllRecoveryFiles();
247   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
248             ci::AppInstaller::Result::OK);
249   AddDataFiles(pkgid, kTestUserId);
250   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
251   backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
252   ASSERT_NE(backend_crash.Wait(), 0);
253
254   // Filesystem may be mounted after crash
255   ScopedTzipInterface poweroff_unmount_interface(pkgid);
256   poweroff_unmount_interface.Release();
257
258   bf::path recovery_file = FindRecoveryFile();
259   ASSERT_FALSE(recovery_file.empty());
260   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
261             ci::AppInstaller::Result::OK);
262
263   ScopedTzipInterface interface(pkgid);
264   ValidatePackage(pkgid, {appid});
265   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
266   ValidateDataFiles(pkgid, kTestUserId);
267 }
268
269 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
270   // pkgid: smokewgt08
271   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
272   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
273 }
274
275 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
276   // pkgid: smokewgt12
277   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
278   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
279 }
280
281 TEST_F(SmokeTest, InstallationMode_Rollback) {
282   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
283   std::string pkgid = "smokewgt06";
284   std::string appid = "smokewgt06.InstallationModeRollback";
285   ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
286             ci::AppInstaller::Result::ERROR);
287   CheckPackageNonExistance(pkgid, {appid});
288 }
289
290 TEST_F(SmokeTest, UpdateMode_Rollback) {
291   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
292   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
293   std::string pkgid = "smokewgt07";
294   std::string appid = "smokewgt07.UpdateModeRollback";
295   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
296   AddDataFiles(pkgid, kTestUserId);
297   ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
298                     ci::AppInstaller::Result::ERROR);
299   ValidatePackage(pkgid, {appid});
300
301   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
302   ValidateDataFiles(pkgid, kTestUserId);
303 }
304
305 TEST_F(SmokeTest, DeltaMode_Rollback) {
306   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
307   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
308   std::string pkgid = "smokewgt01";
309   std::string appid = "smokewgt01.DeltaMode";
310   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
311   AddDataFiles(pkgid, kTestUserId);
312   ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
313             ci::AppInstaller::Result::ERROR);
314
315   ValidatePackage(pkgid, {appid});
316   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
317                                            "version 1\n"));
318   ValidateDataFiles(pkgid, kTestUserId);
319   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
320                          "res/wgt/DELETED"));
321   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
322                           "res/wgt/ADDED"));
323 }
324
325 TEST_F(SmokeTest, InstallationMode_Hybrid) {
326   bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
327   std::string pkgid = "smokehyb01";
328   // Excutable for native app doesn't create symlink
329   std::string appid1 = "smokehyb01.Web";
330   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
331   ValidatePackage(pkgid, {appid1});
332 }
333
334 TEST_F(SmokeTest, UpdateMode_Hybrid) {
335   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
336   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
337   std::string pkgid = "smokehyb02";
338   std::string appid1 = "smokehyb02.Web";
339   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
340             ci::AppInstaller::Result::OK);
341 //  AddDataFiles(pkgid, kTestUserId);
342   ASSERT_EQ(Install(path_new, PackageType::HYBRID),
343             ci::AppInstaller::Result::OK);
344   ValidatePackage(pkgid, {appid1});
345
346   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
347   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
348 //  ValidateDataFiles(pkgid, kTestUserId);
349 }
350
351 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
352   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
353   std::string pkgid = "smokehyb03";
354   std::string appid1 = "smokehyb03.Web";
355   ASSERT_EQ(Install(path, PackageType::HYBRID),
356             ci::AppInstaller::Result::OK);
357   ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
358             ci::AppInstaller::Result::OK);
359   CheckPackageNonExistance(pkgid, {appid1});
360 }
361
362 TEST_F(SmokeTest, DeltaMode_Hybrid) {
363   bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
364   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
365   std::string pkgid = "smokehyb04";
366   std::string appid1 = "smokehyb04.Web";
367   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
368             ci::AppInstaller::Result::OK);
369   ValidatePackage(pkgid, {appid1});
370
371   // Check delta modifications
372   bf::path root_path = ci::GetRootAppPath(false,
373       kTestUserId);
374   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
375   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
376   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
377   ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
378   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
379   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
380   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
381   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n"));  // NOLINT
382   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n"));  // NOLINT
383 }
384
385 TEST_F(SmokeTest, MountInstallationMode_Hybrid) {
386   bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
387   std::string pkgid = "smokehyb05";
388   std::string appid1 = "smokehyb05.web";
389   ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
390             ci::AppInstaller::Result::OK);
391   ScopedTzipInterface interface(pkgid);
392   ValidatePackage(pkgid, {appid1});
393 }
394
395 TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
396   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
397   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
398   std::string pkgid = "smokehyb06";
399   std::string appid1 = "smokehyb06.web";
400   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
401             ci::AppInstaller::Result::OK);
402   AddDataFiles(pkgid, kTestUserId);
403   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID),
404             ci::AppInstaller::Result::OK);
405   ScopedTzipInterface interface(pkgid);
406   ValidatePackage(pkgid, {appid1});
407
408   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
409   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n"));
410   ValidateDataFiles(pkgid, kTestUserId);
411 }
412
413 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
414   bf::path path = kSmokePackagesDirectory /
415       "InstallationMode_Rollback_Hybrid.wgt";
416   std::string pkgid = "smokehyb07";
417   std::string appid1 = "smokehyb07.web";
418   ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
419             ci::AppInstaller::Result::ERROR);
420   CheckPackageNonExistance(pkgid, {appid1});
421 }
422
423 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
424   bf::path path_old = kSmokePackagesDirectory /
425       "UpdateMode_Rollback_Hybrid.wgt";
426   bf::path path_new = kSmokePackagesDirectory /
427       "UpdateMode_Rollback_Hybrid_2.wgt";
428   std::string pkgid = "smokehyb08";
429   std::string appid1 = "smokehyb08.web";
430   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
431             ci::AppInstaller::Result::OK);
432   AddDataFiles(pkgid, kTestUserId);
433   ASSERT_EQ(Install(path_new, PackageType::HYBRID,
434       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
435   ValidatePackage(pkgid, {appid1});
436
437   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
438   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
439   ValidateDataFiles(pkgid, kTestUserId);
440 }
441
442 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
443   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
444   bf::path delta_package = kSmokePackagesDirectory /
445       "DeltaMode_Rollback_Hybrid.delta";
446   std::string pkgid = "smokehyb11";
447   std::string appid1 = "smokehyb11.web";
448   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
449   AddDataFiles(pkgid, kTestUserId);
450   ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
451             ci::AppInstaller::Result::ERROR);
452
453   ValidatePackage(pkgid, {appid1});
454   // Check delta modifications
455   bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
456   ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
457   ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
458   ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
459   ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
460   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
461                                            "version 1\n"));
462   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
463                                            "version 1\n"));
464   ValidateDataFiles(pkgid, kTestUserId);
465 }
466
467 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
468   bf::path path = kSmokePackagesDirectory /
469       "MountInstallationMode_Rollback_Hybrid.wgt";
470   std::string pkgid = "smokehyb09";
471   std::string appid1 = "smokehyb09.web";
472   ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
473       ci::AppInstaller::Result::ERROR);
474   ScopedTzipInterface interface(pkgid);
475   CheckPackageNonExistance(pkgid, {appid1});
476 }
477
478 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
479   bf::path path_old = kSmokePackagesDirectory /
480       "MountUpdateMode_Rollback_Hybrid.wgt";
481   bf::path path_new = kSmokePackagesDirectory /
482       "MountUpdateMode_Rollback_Hybrid_2.wgt";
483   std::string pkgid = "smokehyb10";
484   std::string appid1 = "smokehyb10.web";
485   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
486             ci::AppInstaller::Result::OK);
487   AddDataFiles(pkgid, kTestUserId);
488   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID,
489       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
490   ScopedTzipInterface interface(pkgid);
491   ValidatePackage(pkgid, {appid1});
492
493   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
494   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
495   ValidateDataFiles(pkgid, kTestUserId);
496 }
497
498 TEST_F(SmokeTest, MountInstallationMode) {
499   bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
500   std::string pkgid = "smokewgt28";
501   std::string appid = "smokewgt28.InstallationMode";
502   ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
503   ScopedTzipInterface interface(pkgid);
504   ValidatePackage(pkgid, {appid});
505 }
506
507 TEST_F(SmokeTest, MountUpdateMode) {
508   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
509   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
510   std::string pkgid = "smokewgt29";
511   std::string appid = "smokewgt29.UpdateMode";
512   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
513             ci::AppInstaller::Result::OK);
514   AddDataFiles(pkgid, kTestUserId);
515   ASSERT_EQ(MountInstall(path_new, PackageType::WGT),
516             ci::AppInstaller::Result::OK);
517   ScopedTzipInterface interface(pkgid);
518   ValidatePackage(pkgid, {appid});
519
520   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
521   ValidateDataFiles(pkgid, kTestUserId);
522 }
523
524 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
525   bf::path path =
526       kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
527   std::string pkgid = "smokewgt33";
528   std::string appid = "smokewgt33.web";
529   ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
530             ci::AppInstaller::Result::ERROR);
531   ScopedTzipInterface interface(pkgid);
532   CheckPackageNonExistance(pkgid, {appid});
533 }
534
535 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
536   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
537   bf::path path_new =
538       kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
539   std::string pkgid = "smokewgt34";
540   std::string appid = "smokewgt34.web";
541   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
542             ci::AppInstaller::Result::OK);
543   AddDataFiles(pkgid, kTestUserId);
544   ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
545       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
546   ScopedTzipInterface interface(pkgid);
547   ValidatePackage(pkgid, {appid});
548
549   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
550   ValidateDataFiles(pkgid, kTestUserId);
551 }
552
553 TEST_F(SmokeTest, UserDefinedPlugins) {
554   bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
555   std::string pkgid = "smokewgt02";
556   std::string appid = "smokewgt02.SimpleEcho";
557   std::string call_privilege = "http://tizen.org/privilege/call";
558   std::string location_privilege = "http://tizen.org/privilege/location";
559   std::string power_privilege = "http://tizen.org/privilege/power";
560
561   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
562   ValidatePackage(pkgid, {appid});
563   std::vector<std::string> res;
564   ASSERT_TRUE(ci::QueryPrivilegesForPkgId(pkgid, kTestUserId, &res));
565   ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
566   ASSERT_TRUE(std::find(res.begin(), res.end(), location_privilege)
567           != res.end());
568   ASSERT_TRUE(std::find(res.begin(), res.end(), power_privilege) != res.end());
569 }
570
571 TEST_F(SmokeTest, InstallExternalMode) {
572   ASSERT_TRUE(CheckAvailableExternalPath());
573   bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
574   std::string pkgid = "smokewgt35";
575   std::string appid = "smokewgt35.web";
576   ASSERT_EQ(InstallExternal(path, PackageType::WGT),
577       ci::AppInstaller::Result::OK);
578   ValidateExternalPackage(pkgid, {appid});
579 }
580
581 TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
582   ASSERT_TRUE(CheckAvailableExternalPath());
583   bf::path path =
584       kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
585   std::string pkgid = "smokewgt36";
586   std::string appid = "smokewgt36.web";
587   bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
588   ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path,
589       PackageType::WGT), ci::AppInstaller::Result::OK);
590   ValidateExternalPackage(pkgid, {appid});
591 }
592
593 TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
594   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
595   bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
596   std::string pkgid = "smokewgt37";
597   std::string appid = "smokewgt37.InstallationModePreload";
598   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
599             ci::AppInstaller::Result::OK);
600   ValidatePackage(pkgid, {appid}, true);
601 }
602
603 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
604   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
605   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
606   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
607   std::string pkgid = "smokewgt38";
608   std::string appid = "smokewgt38.UpdateModePreload";
609   ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
610             ci::AppInstaller::Result::OK);
611   AddDataFiles(pkgid, kTestUserId);
612   ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
613             ci::AppInstaller::Result::OK);
614   ValidatePackage(pkgid, {appid}, true);
615
616   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
617                                            true));
618   ValidateDataFiles(pkgid, kTestUserId);
619 }
620
621 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
622   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
623   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
624   std::string pkgid = "smokewgt39";
625   std::string appid = "smokewgt39.DeinstallationModePreload";
626   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
627             ci::AppInstaller::Result::OK);
628   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
629             ci::AppInstaller::Result::OK);
630   CheckPackageReadonlyNonExistance(pkgid, {appid});
631 }
632
633 TEST_F(SmokeTest, SharedRes24) {
634   bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
635   std::string pkgid = "smokeSh2xx";
636   std::string appid = "smokeSh2xx.SharedRes24";
637   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
638   ValidatePackage(pkgid, {appid});
639   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
640   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
641   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
642 }
643
644 TEST_F(SmokeTest, SharedRes30) {
645   bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
646   std::string pkgid = "smokeSh3xx";
647   std::string appid = "smokeSh3xx.SharedRes30";
648   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
649   ValidatePackage(pkgid, {appid});
650   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
651   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
652   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
653 }
654
655 TEST_F(SmokeTest, SharedRes30Delta) {
656   bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
657   bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
658   std::string pkgid = "smokeSh3De";
659   std::string appid = "smokeSh3De.SharedRes30Delta";
660   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
661             ci::AppInstaller::Result::OK);
662   ValidatePackage(pkgid, {appid});
663   // Check delta modifications
664   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
665   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
666   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
667   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
668   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
669 }
670
671 TEST_F(SmokeTest, SharedRes30Hybrid) {
672   bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
673   std::string pkgid = "smokeSh3Hy";
674   std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
675   std::string appid2 = "sharedres30hybridserivce";
676   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
677   ValidatePackage(pkgid, {appid1, appid2});
678   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
679   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
680   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
681   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK"));  // NOLINT
682   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK"));  // NOLINT
683 }
684
685 TEST_F(SmokeTest, SharedRes30HybridDelta) {
686   bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
687   bf::path delta_package = kSmokePackagesDirectory /
688       "SharedRes30HybridDelta.delta";
689   std::string pkgid = "smokeSh3HD";
690   std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
691   std::string appid2 = "sharedres30hybriddeltaserivce";
692   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
693             ci::AppInstaller::Result::OK);
694   ValidatePackage(pkgid, {appid1, appid2});
695   // Check delta modifications
696   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
697   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
698   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
699   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
700   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
701   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
702   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
703 }
704
705 }  // namespace common_installer
706
707 int main(int argc,  char** argv) {
708   ci::RequestMode request_mode = ParseRequestMode(argc, argv);
709   if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
710     std::cout << "Skip tests for preload request" << std::endl;
711     ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
712   }
713   testing::InitGoogleTest(&argc, argv);
714   testing::Environment *env = testing::AddGlobalTestEnvironment(
715       new common_installer::SmokeEnvironment(request_mode));
716   return RUN_ALL_TESTS();
717 }