37790e0b7a2b4930d839be0c749471c924f28cac
[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 <boost/format.hpp>
10 #include <boost/program_options.hpp>
11
12 #include <common/paths.h>
13 #include <common/pkgmgr_interface.h>
14 #include <common/pkgmgr_query.h>
15 #include <common/request.h>
16 #include <common/step/configuration/step_fail.h>
17 #include <common/tzip_interface.h>
18 #include <common/utils/file_util.h>
19 #include <common/utils/subprocess.h>
20 #include <common/utils/user_util.h>
21 #include <gum/gum-user.h>
22 #include <gum/gum-user-service.h>
23 #include <gum/common/gum-user-types.h>
24
25 #include <gtest/gtest.h>
26 #include <gtest/gtest-death-test.h>
27 #include <pkgmgr-info.h>
28 #include <signal.h>
29 #include <unistd.h>
30 #include <tzplatform_config.h>
31 #include <vconf.h>
32 #include <vconf-internal-keys.h>
33 #include <getopt.h>
34
35 #include <array>
36 #include <cstdio>
37 #include <cstdlib>
38 #include <vector>
39 #include <regex>
40
41 #include "hybrid/hybrid_installer.h"
42 #include "wgt/wgt_app_query_interface.h"
43 #include "wgt/wgt_installer.h"
44
45 #define SIZEOFARRAY(ARR)                                                       \
46   sizeof(ARR) / sizeof(ARR[0])                                                 \
47
48 namespace bf = boost::filesystem;
49 namespace bs = boost::system;
50 namespace bo = boost::program_options;
51 namespace ci = common_installer;
52
53 namespace {
54 ci::RequestMode ParseRequestMode(int argc,  char** argv) {
55   bo::options_description desc("Available options");
56   desc.add_options()
57       ("request-mode", bo::value<std::string>(), "set request mode")
58       ("global-request,g", "set request mode to global")
59       ("user-request,u", "set request mode to user");
60
61   bo::variables_map vm;
62   bo::store(bo::parse_command_line(argc, argv, desc), vm);
63   bo::notify(vm);
64
65   if (vm.count("global-request")) {
66     std::cout << "Request mode was set to global." << std::endl;
67     return ci::RequestMode::GLOBAL;
68   }
69   if (vm.count("user-request")) {
70     std::cout << "Request mode was set to user." << std::endl;
71     return ci::RequestMode::USER;
72   }
73   if (vm.count("request-mode")) {
74     if (vm["request-mode"].as<std::string>() == "global") {
75       std::cout << "Request mode was set to global." << std::endl;
76       return ci::RequestMode::GLOBAL;
77     }
78     if (vm["request-mode"].as<std::string>() == "user") {
79       std::cout << "Request mode was set to user." << std::endl;
80       return ci::RequestMode::USER;
81     }
82     std::cout << "Cannot set request mode to "
83               << vm["request-mode"].as<std::string>() << std::endl;
84     std::cout << "Request mode was set to global." << std::endl;
85     return ci::RequestMode::GLOBAL;
86
87   }
88 }
89
90 const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
91 const uid_t kGlobalUserGid = tzplatform_getgid(TZ_SYS_GLOBALAPP_USER);
92 const uid_t kDefaultUserUid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
93 uid_t kTestUserId = kGlobalUserUid;
94 gid_t kTestGroupId = kGlobalUserGid;
95 std::string kTestUserIdStr = std::to_string(kTestUserId);
96 const char kNormalUserName[] = "smokeuser";
97 const char kSystemShareGroupName[] = "system_share";
98 const std::string& kDefaultUserIdStr = std::to_string(kDefaultUserUid);
99 const char kLegacyExtImageDir[] = "legacy_extimage_dir";
100 const char kMigrateTestDBName[] = "app2sd_migrate.db";
101
102 const bf::path kSmokePackagesDirectory =
103     "/usr/share/wgt-backend-ut/test_samples/smoke/";
104
105 enum RWDirectory {
106     DATA,
107     CACHE,
108     SHARED_CACHE,
109     SHARED_DATA,
110     SHARED_TRUSTED
111 };
112
113 const char* rwDirectories[] = {
114   "data",
115   "cache",
116   "shared/cache",
117   "shared/data",
118   "shared/trusted",
119 };
120
121 // common entries
122 const std::vector<std::string> kDBEntries = {
123   {".pkgmgr_parser.db"},
124   {".pkgmgr_parser.db-journal"},
125   {".pkgmgr_cert.db"},
126   {".pkgmgr_cert.db-journal"},
127   {".app2sd.db"},
128   {".app2sd.db-journal"},
129 };
130 // globaluser entries
131 const char kGlobalManifestDir[] = "/opt/share/packages";
132 const char kSkelDir[] = "/etc/skel/apps_rw";
133 const char kPreloadApps[] = "/usr/apps";
134 const char kPreloadManifestDir[] = "/usr/share/packages";
135 const char kPreloadIcons[] = "/usr/share/icons";
136
137 enum class RequestResult {
138   NORMAL,
139   FAIL
140 };
141
142 class ScopedTzipInterface {
143  public:
144   explicit ScopedTzipInterface(const std::string& pkgid)
145       : pkg_path_(bf::path(ci::GetRootAppPath(false,
146             kTestUserId)) / pkgid),
147         interface_(ci::GetMountLocation(pkg_path_)),
148         mounted_(true) {
149     interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
150   }
151
152   void Release() {
153     if (mounted_) {
154       interface_.UnmountZip();
155       mounted_ = false;
156     }
157   }
158
159   ~ScopedTzipInterface() {
160     Release();
161   }
162
163  private:
164   bf::path pkg_path_;
165   ci::TzipInterface interface_;
166   bool mounted_;
167 };
168
169 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
170  public:
171   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
172                              ci::InstallationMode* mode) {
173     *installer = pkgmgr_installer_offline_new();
174     if (!*installer)
175       return false;
176     *mode = ci::InstallationMode::ONLINE;
177     return true;
178   }
179
180   bool ShouldCreateSignal() const {
181     return false;
182   }
183 };
184
185 enum class PackageType {
186   WGT,
187   HYBRID
188 };
189
190 bool TouchFile(const bf::path& path) {
191   FILE* f = fopen(path.c_str(), "w+");
192   if (!f)
193     return false;
194   fclose(f);
195   return true;
196 }
197
198 bool AddUser(const char *user_name) {
199   GumUser* user = nullptr;
200   user = gum_user_create_sync(FALSE);
201   if (user == nullptr)
202     LOG(WARNING) << "Failed to create gum user! (user name: "
203                  << user_name << ")";
204   g_object_set(G_OBJECT(user), "username", user_name, "usertype",
205       GUM_USERTYPE_NORMAL, NULL);
206   gboolean rval = FALSE;
207   rval = gum_user_add_sync(user);
208   g_object_unref(user);
209   return rval;
210 }
211
212 bool DeleteUser(const char *user_name, bool rem_home_dir) {
213   bool rval = FALSE;
214   GumUser* guser = gum_user_get_by_name_sync(user_name, FALSE);
215   if(guser)
216     rval = gum_user_delete_sync(guser, rem_home_dir);
217   return rval;
218 }
219
220 bool AddTestUser(const char *user_name) {
221   std::cout << "Adding test user: " << user_name << std::endl;
222   bool ret = AddUser(user_name);
223   if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
224     kTestUserId = *uid;
225     kTestUserIdStr = std::to_string(kTestUserId);
226     std::cout << "User created properly: uid=" << *uid;
227     if (boost::optional<gid_t> gid = ci::GetGidByUid(*uid)) {
228       kTestGroupId = *gid;
229       std::cout << " gid=" << *gid;
230     }
231     std::cout << std::endl;
232     return true;
233   }
234   LOG(ERROR) << "Adding test user failed";
235   return false;
236 }
237
238 bool DeleteTestUser(const char *user_name) {
239   std::cout << "Deleting test user: " << user_name << std::endl;
240   uid_t test_uid;
241   if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name))
242     test_uid = *uid;
243   bool ret = DeleteUser(user_name, true);
244   if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name));
245   else {
246     std::cout << "User deleted properly: user_name=" << user_name
247               << " uid=" << test_uid << std::endl;
248     return true;
249   }
250   LOG(ERROR) << "Deleting test user failed";
251   return false;
252 }
253
254 void RemoveAllRecoveryFiles() {
255   bf::path root_path = ci::GetRootAppPath(false,
256       kTestUserId);
257   if (!bf::exists(root_path))
258     return;
259   for (auto& dir_entry : boost::make_iterator_range(
260          bf::directory_iterator(root_path), bf::directory_iterator())) {
261     if (bf::is_regular_file(dir_entry)) {
262       if (dir_entry.path().string().find("/wgt-recovery")
263           != std::string::npos) {
264         bs::error_code error;
265         bf::remove(dir_entry.path(), error);
266       }
267     }
268   }
269 }
270
271 bf::path FindRecoveryFile() {
272   bf::path root_path = ci::GetRootAppPath(false,
273       kTestUserId);
274   for (auto& dir_entry : boost::make_iterator_range(
275          bf::directory_iterator(root_path), bf::directory_iterator())) {
276     if (bf::is_regular_file(dir_entry)) {
277       if (dir_entry.path().string().find("/wgt-recovery")
278           != std::string::npos) {
279         return dir_entry.path();
280       }
281     }
282   }
283   return {};
284 }
285
286 bf::path GetPackageRoot(const std::string& pkgid, uid_t uid) {
287   bf::path root_path = ci::GetRootAppPath(false, uid);
288   return root_path / pkgid;
289 }
290
291 bool ValidateFileContentInPackage(const std::string& pkgid,
292                                   const std::string& relative,
293                                   const std::string& expected,
294                                   bool is_readonly = false) {
295   bf::path file_path = ci::GetRootAppPath(is_readonly, kTestUserId);
296   file_path = file_path / pkgid / relative;
297   if (!bf::exists(file_path)) {
298     LOG(ERROR) << file_path << " doesn't exist";
299     return false;
300   }
301   FILE* handle = fopen(file_path.c_str(), "r");
302   if (!handle) {
303     LOG(ERROR) << file_path << " cannot  be open";
304     return false;
305   }
306   std::string content;
307   std::array<char, 200> buffer;
308   while (fgets(buffer.data(), buffer.size(), handle)) {
309     content += buffer.data();
310   }
311   fclose(handle);
312   return content == expected;
313 }
314
315 void AddDataFiles(const std::string& pkgid, uid_t uid) {
316   if (uid == kGlobalUserUid) {
317     ci::UserList list = ci::GetUserList();
318     for (auto l : list) {
319       auto pkg_path = GetPackageRoot(pkgid, std::get<0>(l));
320       ASSERT_TRUE(TouchFile(pkg_path / "data" / "file1.txt"));
321       ASSERT_TRUE(TouchFile(pkg_path / "data" / "file2.txt"));
322     }
323   } else {
324     auto pkg_path = GetPackageRoot(pkgid, uid);
325     ASSERT_TRUE(TouchFile(pkg_path / "data" / "file1.txt"));
326     ASSERT_TRUE(TouchFile(pkg_path / "data" / "file2.txt"));
327   }
328 }
329
330 void ValidateDataFiles(const std::string& pkgid, uid_t uid) {
331   if (uid == kGlobalUserUid) {
332     ci::UserList list = ci::GetUserList();
333     for (auto l : list) {
334       auto pkg_path = GetPackageRoot(pkgid, std::get<0>(l));
335       ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
336       ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
337     }
338   } else {
339     auto pkg_path = GetPackageRoot(pkgid, uid);
340     ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
341     ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
342   }
343 }
344
345 void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) {
346   bf::path root_path = ci::GetRootAppPath(false, uid);
347   bf::path package_path = root_path / pkgid;
348   bf::path data_path = package_path / rwDirectories[DATA];
349   bf::path cache_path = package_path / rwDirectories[CACHE];
350   bf::path shared_data_path = package_path / rwDirectories[SHARED_DATA];
351
352   ASSERT_TRUE(bf::exists(data_path));
353   ASSERT_TRUE(bf::exists(cache_path));
354
355   struct stat stats;
356   stat(data_path.c_str(), &stats);
357   // gid of RW dirs should be system_share
358   boost::optional<gid_t> system_share =
359     ci::GetGidByGroupName(kSystemShareGroupName);
360   ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << data_path;
361   ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << data_path;
362   if (bf::exists(shared_data_path)) {
363     stat(shared_data_path.c_str(), &stats);
364     ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << shared_data_path;
365     ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: "
366       << shared_data_path;
367   }
368
369   stat(cache_path.c_str(), &stats);
370   ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << cache_path;
371   ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << cache_path;
372 }
373
374 void ValidatePackageFS(const std::string& pkgid,
375                        const std::vector<std::string>& appids,
376                        uid_t uid, gid_t gid, bool is_readonly) {
377   bf::path root_path = ci::GetRootAppPath(is_readonly, uid);
378   bf::path package_path = root_path / pkgid;
379   bf::path shared_path = package_path / "shared";
380   ASSERT_TRUE(bf::exists(root_path));
381   ASSERT_TRUE(bf::exists(package_path));
382   ASSERT_TRUE(bf::exists(shared_path));
383
384   bf::path manifest_path =
385       bf::path(getUserManifestPath(uid, is_readonly)) / (pkgid + ".xml");
386   ASSERT_TRUE(bf::exists(manifest_path));
387
388   for (auto& appid : appids) {
389     bf::path binary_path = package_path / "bin" / appid;
390     ASSERT_TRUE(bf::exists(binary_path));
391   }
392
393   bf::path widget_root_path = package_path / "res" / "wgt";
394   bf::path config_path = widget_root_path / "config.xml";
395   ASSERT_TRUE(bf::exists(widget_root_path));
396   ASSERT_TRUE(bf::exists(config_path));
397
398   bf::path private_tmp_path = package_path / "tmp";
399   ASSERT_TRUE(bf::exists(private_tmp_path));
400
401   // backups should not exist
402   bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
403   bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
404   ASSERT_FALSE(bf::exists(package_backup));
405   ASSERT_FALSE(bf::exists(manifest_backup));
406
407   for (bf::recursive_directory_iterator iter(package_path);
408       iter != bf::recursive_directory_iterator(); ++iter) {
409     if (bf::is_symlink(symlink_status(iter->path())))
410       continue;
411     bool is_rw_dir = false;
412     for(const auto rw_dir : rwDirectories) {
413       bf::path rw_dir_path = rw_dir;
414       is_rw_dir |= ci::MakeRelativePath(iter->path(), package_path) == rw_dir_path;
415     }
416     if (is_rw_dir || iter->path().filename() == ".mmc") {
417       iter.no_push();
418       continue;
419     }
420     struct stat stats;
421     stat(iter->path().c_str(), &stats);
422     ASSERT_EQ(uid, stats.st_uid) << "Invalid uid: " << iter->path();
423     ASSERT_EQ(gid, stats.st_gid) << "Invalid gid: " << iter->path();
424   }
425 }
426
427 void PackageCheckCleanup(const std::string& pkgid,
428     const std::vector<std::string>&, bool is_readonly = false) {
429   bf::path root_path = ci::GetRootAppPath(is_readonly, kTestUserId);
430   bf::path package_path = root_path / pkgid;
431   ASSERT_FALSE(bf::exists(package_path));
432
433   bf::path manifest_path = bf::path(getUserManifestPath(kTestUserId,
434       is_readonly)) / (pkgid + ".xml");
435   ASSERT_FALSE(bf::exists(manifest_path));
436
437   // backups should not exist
438   bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
439   bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
440   ASSERT_FALSE(bf::exists(package_backup));
441   ASSERT_FALSE(bf::exists(manifest_backup));
442 }
443
444 void ValidatePackage(const std::string& pkgid,
445     const std::vector<std::string>& appids, bool is_readonly = false) {
446   ASSERT_TRUE(ci::QueryIsPackageInstalled(
447       pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
448   ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId, is_readonly);
449   if (kTestUserId == kGlobalUserUid) {
450     ci::UserList list = ci::GetUserList();
451     for (auto& l : list)
452       ValidatePackageRWFS(pkgid, std::get<0>(l));
453   } else {
454     ValidatePackageRWFS(pkgid, kTestUserId);
455   }
456 }
457
458 void ValidateExternalPackageFS(const std::string& pkgid,
459                                const std::vector<std::string>& appids,
460                                uid_t uid, gid_t gid) {
461   ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0);
462   bf::path root_path = ci::GetRootAppPath(false, uid);
463   ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res"));
464   ValidatePackageFS(pkgid, appids, uid, gid, false);
465   ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0);
466 }
467
468 void ValidateExternalPackage(const std::string& pkgid,
469                              const std::vector<std::string>& appids) {
470   ASSERT_TRUE(ci::QueryIsPackageInstalled(
471       pkgid, ci::GetRequestMode(kTestUserId),
472       kTestUserId));
473   std::string storage = ci::QueryStorageForPkgId(pkgid, kTestUserId);
474   bf::path ext_mount_path = ci::GetExternalCardPath();
475   if (bf::is_empty(ext_mount_path)) {
476     LOG(INFO) << "Sdcard not exists!";
477     ASSERT_EQ(storage, "installed_internal");
478   } else {
479     ASSERT_EQ(storage, "installed_external");
480   }
481   ValidateExternalPackageFS(pkgid, appids, kTestUserId, kTestGroupId);
482   if (kTestUserId == kGlobalUserUid) {
483     ci::UserList list = ci::GetUserList();
484     for (auto& l : list)
485       ValidatePackageRWFS(pkgid, std::get<0>(l));
486   } else {
487     ValidatePackageRWFS(pkgid, kTestUserId);
488   }
489 }
490
491 void CheckPackageNonExistance(const std::string& pkgid,
492                               const std::vector<std::string>& appids) {
493   ASSERT_FALSE(ci::QueryIsPackageInstalled(
494       pkgid, ci::GetRequestMode(kTestUserId),
495       kTestUserId));
496   PackageCheckCleanup(pkgid, appids);
497   if (kTestUserId == kGlobalUserUid) {
498       ci::UserList list = ci::GetUserList();
499       bf::path skel_path(kSkelDir);
500       ASSERT_FALSE(bf::exists(skel_path / pkgid));
501       for (auto& l : list) {
502         bf::path root_path = ci::GetRootAppPath(false, std::get<0>(l));
503         bf::path package_path = root_path / pkgid;
504         ASSERT_FALSE(bf::exists(package_path));
505       }
506   }
507 }
508
509 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
510                                       const std::vector<std::string>& appids) {
511   ASSERT_FALSE(ci::QueryIsPackageInstalled(
512       pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
513   PackageCheckCleanup(pkgid, appids, true);
514 }
515
516 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
517   std::unique_ptr<ci::AppQueryInterface> query_interface(
518       new wgt::WgtAppQueryInterface());
519   return query_interface;
520 }
521
522 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
523                                                   PackageType type) {
524   switch (type) {
525     case PackageType::WGT:
526       return std::unique_ptr<ci::AppInstaller>(new wgt::WgtInstaller(pkgmgr));
527     case PackageType::HYBRID:
528       return std::unique_ptr<ci::AppInstaller>(
529           new hybrid::HybridInstaller(pkgmgr));
530     default:
531       LOG(ERROR) << "Unknown installer type";
532       return nullptr;
533   }
534 }
535
536 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
537                                                  PackageType type,
538                                                  RequestResult mode) {
539   std::unique_ptr<ci::AppInstaller> installer = CreateInstaller(pkgmgr, type);
540   switch (mode) {
541   case RequestResult::FAIL:
542     installer->AddStep<ci::configuration::StepFail>();
543     break;
544   default:
545     break;
546   }
547   return installer->Run();
548 }
549 ci::AppInstaller::Result CallBackend(int argc,
550                                      const char* argv[],
551                                      PackageType type,
552                                      RequestResult mode = RequestResult::NORMAL
553                                      ) {
554   TestPkgmgrInstaller pkgmgr_installer;
555   std::unique_ptr<ci::AppQueryInterface> query_interface =
556       CreateQueryInterface();
557   auto pkgmgr =
558       ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
559                                   &pkgmgr_installer, query_interface.get());
560   if (!pkgmgr) {
561     LOG(ERROR) << "Failed to initialize pkgmgr interface";
562     return ci::AppInstaller::Result::UNKNOWN;
563   }
564   return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
565 }
566
567 ci::AppInstaller::Result Install(const bf::path& path,
568                                  PackageType type,
569                                  RequestResult mode = RequestResult::NORMAL) {
570   const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
571   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
572 }
573
574 ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
575     RequestResult mode = RequestResult::NORMAL) {
576   const char* argv[] = {"", "-i", path.c_str(), "--preload"};
577   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
578 }
579
580 bool CheckAvailableExternalPath() {
581   bf::path ext_mount_path = ci::GetExternalCardPath();
582   LOG(DEBUG) << "ext_mount_path :" << ext_mount_path;
583   if (ext_mount_path.empty()) {
584     LOG(ERROR) << "Sdcard not exists!";
585     return false;
586   }
587   return true;
588 }
589
590 ci::AppInstaller::Result InstallExternal(const bf::path& path,
591                                  PackageType type,
592                                  RequestResult mode = RequestResult::NORMAL) {
593   int default_storage = 0;
594   vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
595                 &default_storage);
596   vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT, 1);
597
598   const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
599   ci::AppInstaller::Result result =
600                           CallBackend(SIZEOFARRAY(argv), argv, type, mode);
601
602   vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
603                 default_storage);
604   return result;
605 }
606
607 ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
608                                  const bf::path& path,
609                                  const bf::path& legacy_path,
610                                  PackageType type,
611                                  RequestResult mode = RequestResult::NORMAL) {
612   if (InstallExternal(path, type) != ci::AppInstaller::Result::OK) {
613     LOG(ERROR) << "Failed to install application. Cannot perform Migrate";
614     return ci::AppInstaller::Result::ERROR;
615   }
616
617   bf::path ext_mount_path = ci::GetExternalCardPath();
618   if (bf::is_empty(ext_mount_path)) {
619     LOG(ERROR) << "Sdcard not exists!";
620     return ci::AppInstaller::Result::ERROR;
621   }
622   bf::path app2sd_path = ext_mount_path / "app2sd";
623
624   char* image_name = app2ext_usr_getname_image(pkgid.c_str(),
625                      kGlobalUserUid);
626   if (!image_name) {
627     LOG(ERROR) << "Failed to get external image name";
628     return ci::AppInstaller::Result::ERROR;
629   }
630   bf::path org_image = app2sd_path / image_name;
631   free(image_name);
632
633   bs::error_code error;
634   bf::remove(org_image, error);
635   if (error) {
636     LOG(ERROR) << "Failed to remove org image";
637     return ci::AppInstaller::Result::ERROR;
638   }
639
640   bf::path db_path = tzplatform_getenv(TZ_SYS_DB);
641   bf::path app2sd_db = db_path / ".app2sd.db";
642   bf::path app2sd_db_journal = db_path / ".app2sd.db-journal";
643   bf::remove(app2sd_db, error);
644   if (error) {
645     LOG(ERROR) << "Failed to remove app2sd db";
646     return ci::AppInstaller::Result::ERROR;
647   }
648   bf::remove(app2sd_db_journal, error);
649   if (error) {
650     LOG(ERROR) << "Failed to remove app2sd journal db";
651     return ci::AppInstaller::Result::ERROR;
652   }
653
654   bf::path app2sd_migrate_db = legacy_path / kMigrateTestDBName;
655   if (!ci::CopyFile(app2sd_migrate_db, app2sd_db)) {
656     LOG(ERROR) << "Failed to copy test db";
657     return ci::AppInstaller::Result::ERROR;
658   }
659
660   bf::path legacy_src = legacy_path / pkgid;
661   bf::path legacy_dst = app2sd_path / pkgid;
662   if (!ci::CopyFile(legacy_src, legacy_dst)) {
663     LOG(ERROR) << "Failed to copy test image";
664     return ci::AppInstaller::Result::ERROR;
665   }
666   const char* argv[] = {"", "--migrate-extimg", pkgid.c_str(),
667                        "-u", kDefaultUserIdStr.c_str()};
668   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
669 }
670
671 ci::AppInstaller::Result MountInstall(const bf::path& path,
672     PackageType type, RequestResult mode = RequestResult::NORMAL) {
673   const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
674   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
675 }
676
677 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
678                                    PackageType type,
679                                    bool is_preload,
680                                    RequestResult mode = RequestResult::NORMAL) {
681   if (is_preload) {
682     const char* argv[] = {"", "-d", pkgid.c_str(), "--preload",
683         "--force-remove"};
684     return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
685   } else {
686     const char* argv[] = {"", "-d", pkgid.c_str(), "-u",
687         kTestUserIdStr.c_str()};
688     return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
689   }
690 }
691
692 ci::AppInstaller::Result RDSUpdate(const bf::path& path,
693                                    const std::string& pkgid,
694                                    PackageType type,
695                                    RequestResult mode = RequestResult::NORMAL) {
696   if (Install(path, type) != ci::AppInstaller::Result::OK) {
697     LOG(ERROR) << "Failed to install application. Cannot perform RDS";
698     return ci::AppInstaller::Result::UNKNOWN;
699   }
700   const char* argv[] = {"", "-r", pkgid.c_str(), "-u",
701                         kTestUserIdStr.c_str()};
702   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
703 }
704
705 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
706     const bf::path& delta_package, PackageType type) {
707   if (Install(path, type) != ci::AppInstaller::Result::OK) {
708     LOG(ERROR) << "Failed to install application. Cannot perform delta update";
709     return ci::AppInstaller::Result::UNKNOWN;
710   }
711   return Install(delta_package, type);
712 }
713
714 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
715                                   PackageType type,
716                                   RequestResult mode = RequestResult::NORMAL) {
717   const char* argv[] = {"", "-A", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
718   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
719 }
720
721 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
722                                   PackageType type,
723                                   RequestResult mode = RequestResult::NORMAL) {
724   const char* argv[] = {"", "-D", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
725   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
726 }
727
728 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
729                                  PackageType type,
730                                  RequestResult mode = RequestResult::NORMAL) {
731   const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
732                         kTestUserIdStr.c_str()};
733   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
734 }
735
736 void BackupPath(const bf::path& path) {
737   bf::path backup_path = path.string() + ".bck";
738   std::cout << "Backup path: " << path << " to " << backup_path << std::endl;
739   bs::error_code error;
740   bf::remove_all(backup_path, error);
741   if (error)
742     LOG(ERROR) << "Remove failed: " << backup_path
743                << " (" << error.message() << ")";
744   if (bf::exists(path)) {
745     bf::rename(path, backup_path, error);
746     if (error)
747       LOG(ERROR) << "Failed to setup test environment. Does some previous"
748                  << " test crashed? Path: "
749                  << backup_path << " should not exist.";
750     assert(!error);
751   }
752 }
753
754 void RestorePath(const bf::path& path) {
755   bf::path backup_path = path.string() + ".bck";
756   std::cout << "Restore path: " << path << " from " << backup_path << std::endl;
757   bs::error_code error;
758   bf::remove_all(path, error);
759   if (error)
760     LOG(ERROR) << "Remove failed: " << path
761                << " (" << error.message() << ")";
762   if (bf::exists(backup_path)) {
763     bf::rename(backup_path, path, error);
764     if (error)
765       LOG(ERROR) << "Failed to restore backup path: " << backup_path
766                  << " (" << error.message() << ")";
767   }
768 }
769
770 std::vector<bf::path> SetupBackupDirectories() {
771   std::vector<bf::path> entries;
772   bf::path db_dir = bf::path(tzplatform_getenv(TZ_SYS_DB));
773   if (kTestUserId != kGlobalUserUid)
774     db_dir = db_dir / "user" / std::to_string(kTestUserId);
775   for (auto e : kDBEntries) {
776     bf::path path = db_dir / e;
777     entries.emplace_back(path);
778   }
779
780   if (getuid() == 0) {
781     entries.emplace_back(kPreloadApps);
782     entries.emplace_back(kPreloadManifestDir);
783     entries.emplace_back(kPreloadIcons);
784   }
785
786   if (kTestUserId == kGlobalUserUid) {
787     entries.emplace_back(kSkelDir);
788     entries.emplace_back(kGlobalManifestDir);
789     ci::UserList list = ci::GetUserList();
790     for (auto l : list) {
791       bf::path apps = std::get<2>(l) / "apps_rw";
792       entries.emplace_back(apps);
793     }
794   } else {
795     tzplatform_set_user(kTestUserId);
796     bf::path approot = tzplatform_getenv(TZ_USER_APPROOT);
797     tzplatform_reset_user();
798     entries.emplace_back(approot);
799   }
800
801   bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
802   entries.emplace_back(apps_rw);
803
804   return entries;
805 }
806
807 void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) {
808   if(bf::exists(dir)) {
809     for (auto& dir_entry : boost::make_iterator_range(
810         bf::directory_iterator(dir), bf::directory_iterator())) {
811       if (dir_entry.path().string().find("smoke") != std::string::npos &&
812           bf::is_directory(dir_entry)) {
813         std::string package = dir_entry.path().filename().string();
814         std::regex pkg_regex("smoke[a-zA-Z]{3,}[1-9]{2,}");
815         if (std::regex_match(package, pkg_regex)) {
816           if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
817               is_preload, RequestResult::NORMAL) !=
818               ci::AppInstaller::Result::OK) {
819             LOG(ERROR) << "Cannot uninstall smoke test app: "
820                 << dir_entry.path().filename().string();
821           }
822         }
823       }
824     }
825   }
826 }
827
828 void UninstallAllSmokeApps(ci::RequestMode request_mode) {
829   if (getuid() == 0 && request_mode == ci::RequestMode::GLOBAL) {
830     bf::path root_path = kPreloadApps;
831     UninstallAllAppsInDirectory(root_path, true);
832   }
833   bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
834   UninstallAllAppsInDirectory(apps_rw, false);
835 }
836
837 }  // namespace
838
839 namespace common_installer {
840
841 class SmokeEnvironment : public testing::Environment {
842  public:
843   explicit SmokeEnvironment(ci::RequestMode mode) {\
844     request_mode_ = mode;
845   }
846   void SetUp() override {
847     if (request_mode_ == ci::RequestMode::USER)
848       ASSERT_TRUE(AddTestUser(kNormalUserName));
849     else {
850       kTestUserId = kGlobalUserUid;
851       kTestGroupId = kGlobalUserGid;
852       kTestUserIdStr = std::to_string(kTestUserId);
853     }
854     backups_ = SetupBackupDirectories();
855     for (auto& path : backups_)
856       BackupPath(path);
857   }
858   void TearDown() override {
859     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
860                 (request_mode_ == ci::RequestMode::USER &&
861                 kGlobalUserUid != kTestUserId));
862     UninstallAllSmokeApps(request_mode_);
863     for (auto& path : backups_)
864       RestorePath(path);
865     if (request_mode_ == ci::RequestMode::USER)
866       ASSERT_TRUE(DeleteTestUser(kNormalUserName));
867   }
868
869  private:
870   ci::RequestMode request_mode_;
871   std::vector<bf::path> backups_;
872 };
873
874 class SmokeTest : public testing::Test {
875 };
876
877 class PreloadSmokeTest : public testing::Test {
878   void SetUp() override {
879     ASSERT_EQ(kGlobalUserUid, kTestUserId);
880   }
881 };
882
883 TEST_F(SmokeTest, InstallationMode) {
884   bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
885   std::string pkgid = "smokewgt03";
886   std::string appid = "smokewgt03.InstallationMode";
887   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
888   ValidatePackage(pkgid, {appid});
889 }
890
891 TEST_F(SmokeTest, UpdateMode) {
892   bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
893   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
894   std::string pkgid = "smokewgt04";
895   std::string appid = "smokewgt04.UpdateMode";
896   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
897   AddDataFiles(pkgid, kTestUserId);
898   ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
899   ValidatePackage(pkgid, {appid});
900
901   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
902   ValidateDataFiles(pkgid, kTestUserId);
903 }
904
905 TEST_F(SmokeTest, DeinstallationMode) {
906   bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
907   std::string pkgid = "smokewgt05";
908   std::string appid = "smokewgt05.DeinstallationMode";
909   ASSERT_EQ(Install(path, PackageType::WGT),
910             ci::AppInstaller::Result::OK);
911   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
912             ci::AppInstaller::Result::OK);
913   CheckPackageNonExistance(pkgid, {appid});
914 }
915
916 TEST_F(SmokeTest, RDSMode) {
917   bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
918   std::string pkgid = "smokewgt11";
919   std::string appid = "smokewgt11.RDSMode";
920   bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
921   bf::path sdk_expected_directory =
922       bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
923   bs::error_code error;
924   bf::create_directories(sdk_expected_directory.parent_path(), error);
925   ASSERT_FALSE(error);
926   ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
927   ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
928             ci::AppInstaller::Result::OK);
929   ValidatePackage(pkgid, {appid});
930
931   // Check delta modifications
932   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
933       "res" / "wgt" / "DELETED"));
934   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
935       "res" / "wgt" / "ADDED"));
936   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n"));
937 }
938
939 TEST_F(SmokeTest, EnablePkg) {
940   bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
941   std::string pkgid = "smokewgt22";
942   ASSERT_EQ(Install(path, PackageType::WGT),
943             ci::AppInstaller::Result::OK);
944   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
945             ci::AppInstaller::Result::OK);
946   ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
947             ci::AppInstaller::Result::OK);
948
949   ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
950       ci::GetRequestMode(kTestUserId),
951       kTestUserId));
952 }
953
954 TEST_F(SmokeTest, DisablePkg) {
955   bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
956   std::string pkgid = "smokewgt21";
957   std::string appid = "smokewgt21.DisablePkg";
958   ASSERT_EQ(Install(path, PackageType::WGT),
959             ci::AppInstaller::Result::OK);
960   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
961             ci::AppInstaller::Result::OK);
962   ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
963   ValidatePackage(pkgid, {appid});
964 }
965
966 TEST_F(SmokeTest, DeltaMode) {
967   bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
968   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
969   std::string pkgid = "smokewgt17";
970   std::string appid = "smokewgt17.DeltaMode";
971   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
972             ci::AppInstaller::Result::OK);
973   ValidatePackage(pkgid, {appid});
974
975   // Check delta modifications
976   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
977       "res" / "wgt" / "DELETED"));
978   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
979       "res" / "wgt" / "ADDED"));
980   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
981       "res" / "wgt" / "css" / "style.css"));
982   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
983       "res" / "wgt" / "images" / "tizen_32.png"));
984   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
985       "res" / "wgt" / "js" / "main.js"));
986   ASSERT_TRUE(ValidateFileContentInPackage(
987       pkgid, "res/wgt/MODIFIED", "version 2\n"));
988 }
989
990 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
991   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
992   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
993   backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
994   ASSERT_NE(backend_crash.Wait(), 0);
995
996   std::string pkgid = "smokewgt09";
997   std::string appid = "smokewgt09.RecoveryModeForInstallation";
998   bf::path recovery_file = FindRecoveryFile();
999   ASSERT_FALSE(recovery_file.empty());
1000   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1001       ci::AppInstaller::Result::OK);
1002   CheckPackageNonExistance(pkgid, {appid});
1003 }
1004
1005 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
1006   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
1007   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
1008   RemoveAllRecoveryFiles();
1009   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
1010   std::string pkgid = "smokewgt10";
1011   std::string appid = "smokewgt10.RecoveryModeForUpdate";
1012   AddDataFiles(pkgid, kTestUserId);
1013   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1014   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
1015   ASSERT_NE(backend_crash.Wait(), 0);
1016
1017   bf::path recovery_file = FindRecoveryFile();
1018   ASSERT_FALSE(recovery_file.empty());
1019   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1020             ci::AppInstaller::Result::OK);
1021   ValidatePackage(pkgid, {appid});
1022
1023   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1024   ValidateDataFiles(pkgid, kTestUserId);
1025 }
1026
1027 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
1028   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
1029   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
1030   RemoveAllRecoveryFiles();
1031   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
1032   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1033   backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
1034   ASSERT_NE(backend_crash.Wait(), 0);
1035
1036   std::string pkgid = "smokewgt30";
1037   std::string appid = "smokewgt30.RecoveryModeForDelta";
1038   bf::path recovery_file = FindRecoveryFile();
1039   ASSERT_FALSE(recovery_file.empty());
1040   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1041             ci::AppInstaller::Result::OK);
1042   ValidatePackage(pkgid, {appid});
1043
1044   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1045 }
1046
1047 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
1048   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
1049   RemoveAllRecoveryFiles();
1050   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1051   backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
1052   ASSERT_NE(backend_crash.Wait(), 0);
1053
1054   std::string pkgid = "smokewgt31";
1055   std::string appid = "smokewgt31.RecoveryModeForMountInstall";
1056   bf::path recovery_file = FindRecoveryFile();
1057   ASSERT_FALSE(recovery_file.empty());
1058   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1059             ci::AppInstaller::Result::OK);
1060   CheckPackageNonExistance(pkgid, {appid});
1061 }
1062
1063 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
1064   bf::path path_old =
1065       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
1066   bf::path path_new =
1067       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
1068   std::string pkgid = "smokewgt32";
1069   std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
1070   RemoveAllRecoveryFiles();
1071   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1072             ci::AppInstaller::Result::OK);
1073   AddDataFiles(pkgid, kTestUserId);
1074   Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1075   backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
1076   ASSERT_NE(backend_crash.Wait(), 0);
1077
1078   // Filesystem may be mounted after crash
1079   ScopedTzipInterface poweroff_unmount_interface(pkgid);
1080   poweroff_unmount_interface.Release();
1081
1082   bf::path recovery_file = FindRecoveryFile();
1083   ASSERT_FALSE(recovery_file.empty());
1084   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1085             ci::AppInstaller::Result::OK);
1086
1087   ScopedTzipInterface interface(pkgid);
1088   ValidatePackage(pkgid, {appid});
1089   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1090   ValidateDataFiles(pkgid, kTestUserId);
1091 }
1092
1093 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
1094   // pkgid: smokewgt08
1095   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
1096   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1097 }
1098
1099 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
1100   // pkgid: smokewgt12
1101   bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt";  // NOLINT
1102   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
1103 }
1104
1105 TEST_F(SmokeTest, InstallationMode_Rollback) {
1106   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
1107   std::string pkgid = "smokewgt06";
1108   std::string appid = "smokewgt06.InstallationModeRollback";
1109   ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
1110             ci::AppInstaller::Result::ERROR);
1111   CheckPackageNonExistance(pkgid, {appid});
1112 }
1113
1114 TEST_F(SmokeTest, UpdateMode_Rollback) {
1115   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
1116   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
1117   std::string pkgid = "smokewgt07";
1118   std::string appid = "smokewgt07.UpdateModeRollback";
1119   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
1120   AddDataFiles(pkgid, kTestUserId);
1121   ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
1122                     ci::AppInstaller::Result::ERROR);
1123   ValidatePackage(pkgid, {appid});
1124
1125   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1126   ValidateDataFiles(pkgid, kTestUserId);
1127 }
1128
1129 TEST_F(SmokeTest, DeltaMode_Rollback) {
1130   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
1131   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
1132   std::string pkgid = "smokewgt01";
1133   std::string appid = "smokewgt01.DeltaMode";
1134   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1135   AddDataFiles(pkgid, kTestUserId);
1136   ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
1137             ci::AppInstaller::Result::ERROR);
1138
1139   ValidatePackage(pkgid, {appid});
1140   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
1141                                            "version 1\n"));
1142   ValidateDataFiles(pkgid, kTestUserId);
1143   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
1144                          "res/wgt/DELETED"));
1145   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
1146                           "res/wgt/ADDED"));
1147 }
1148
1149 TEST_F(SmokeTest, InstallationMode_Hybrid) {
1150   bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
1151   std::string pkgid = "smokehyb01";
1152   // Excutable for native app doesn't create symlink
1153   std::string appid1 = "smokehyb01.Web";
1154   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
1155   ValidatePackage(pkgid, {appid1});
1156 }
1157
1158 TEST_F(SmokeTest, UpdateMode_Hybrid) {
1159   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
1160   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
1161   std::string pkgid = "smokehyb02";
1162   std::string appid1 = "smokehyb02.Web";
1163   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
1164             ci::AppInstaller::Result::OK);
1165 //  AddDataFiles(pkgid, kTestUserId);
1166   ASSERT_EQ(Install(path_new, PackageType::HYBRID),
1167             ci::AppInstaller::Result::OK);
1168   ValidatePackage(pkgid, {appid1});
1169
1170   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1171   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
1172 //  ValidateDataFiles(pkgid, kTestUserId);
1173 }
1174
1175 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
1176   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
1177   std::string pkgid = "smokehyb03";
1178   std::string appid1 = "smokehyb03.Web";
1179   ASSERT_EQ(Install(path, PackageType::HYBRID),
1180             ci::AppInstaller::Result::OK);
1181   ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
1182             ci::AppInstaller::Result::OK);
1183   CheckPackageNonExistance(pkgid, {appid1});
1184 }
1185
1186 TEST_F(SmokeTest, DeltaMode_Hybrid) {
1187   bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
1188   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
1189   std::string pkgid = "smokehyb04";
1190   std::string appid1 = "smokehyb04.Web";
1191   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
1192             ci::AppInstaller::Result::OK);
1193   ValidatePackage(pkgid, {appid1});
1194
1195   // Check delta modifications
1196   bf::path root_path = ci::GetRootAppPath(false,
1197       kTestUserId);
1198   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
1199   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
1200   ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
1201   ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
1202   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css"));  // NOLINT
1203   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png"));  // NOLINT
1204   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
1205   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n"));  // NOLINT
1206   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n"));  // NOLINT
1207 }
1208
1209 TEST_F(SmokeTest, MountInstallationMode_Hybrid) {
1210   bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
1211   std::string pkgid = "smokehyb05";
1212   std::string appid1 = "smokehyb05.web";
1213   ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
1214             ci::AppInstaller::Result::OK);
1215   ScopedTzipInterface interface(pkgid);
1216   ValidatePackage(pkgid, {appid1});
1217 }
1218
1219 TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
1220   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
1221   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
1222   std::string pkgid = "smokehyb06";
1223   std::string appid1 = "smokehyb06.web";
1224   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
1225             ci::AppInstaller::Result::OK);
1226   AddDataFiles(pkgid, kTestUserId);
1227   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID),
1228             ci::AppInstaller::Result::OK);
1229   ScopedTzipInterface interface(pkgid);
1230   ValidatePackage(pkgid, {appid1});
1231
1232   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1233   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n"));
1234   ValidateDataFiles(pkgid, kTestUserId);
1235 }
1236
1237 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
1238   bf::path path = kSmokePackagesDirectory /
1239       "InstallationMode_Rollback_Hybrid.wgt";
1240   std::string pkgid = "smokehyb07";
1241   std::string appid1 = "smokehyb07.web";
1242   ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
1243             ci::AppInstaller::Result::ERROR);
1244   CheckPackageNonExistance(pkgid, {appid1});
1245 }
1246
1247 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
1248   bf::path path_old = kSmokePackagesDirectory /
1249       "UpdateMode_Rollback_Hybrid.wgt";
1250   bf::path path_new = kSmokePackagesDirectory /
1251       "UpdateMode_Rollback_Hybrid_2.wgt";
1252   std::string pkgid = "smokehyb08";
1253   std::string appid1 = "smokehyb08.web";
1254   ASSERT_EQ(Install(path_old, PackageType::HYBRID),
1255             ci::AppInstaller::Result::OK);
1256   AddDataFiles(pkgid, kTestUserId);
1257   ASSERT_EQ(Install(path_new, PackageType::HYBRID,
1258       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1259   ValidatePackage(pkgid, {appid1});
1260
1261   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1262   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
1263   ValidateDataFiles(pkgid, kTestUserId);
1264 }
1265
1266 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
1267   bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
1268   bf::path delta_package = kSmokePackagesDirectory /
1269       "DeltaMode_Rollback_Hybrid.delta";
1270   std::string pkgid = "smokehyb11";
1271   std::string appid1 = "smokehyb11.web";
1272   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
1273   AddDataFiles(pkgid, kTestUserId);
1274   ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
1275             ci::AppInstaller::Result::ERROR);
1276
1277   ValidatePackage(pkgid, {appid1});
1278   // Check delta modifications
1279   bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
1280   ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
1281   ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
1282   ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
1283   ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
1284   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
1285                                            "version 1\n"));
1286   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
1287                                            "version 1\n"));
1288   ValidateDataFiles(pkgid, kTestUserId);
1289 }
1290
1291 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
1292   bf::path path = kSmokePackagesDirectory /
1293       "MountInstallationMode_Rollback_Hybrid.wgt";
1294   std::string pkgid = "smokehyb09";
1295   std::string appid1 = "smokehyb09.web";
1296   ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
1297       ci::AppInstaller::Result::ERROR);
1298   ScopedTzipInterface interface(pkgid);
1299   CheckPackageNonExistance(pkgid, {appid1});
1300 }
1301
1302 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
1303   bf::path path_old = kSmokePackagesDirectory /
1304       "MountUpdateMode_Rollback_Hybrid.wgt";
1305   bf::path path_new = kSmokePackagesDirectory /
1306       "MountUpdateMode_Rollback_Hybrid_2.wgt";
1307   std::string pkgid = "smokehyb10";
1308   std::string appid1 = "smokehyb10.web";
1309   ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
1310             ci::AppInstaller::Result::OK);
1311   AddDataFiles(pkgid, kTestUserId);
1312   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID,
1313       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1314   ScopedTzipInterface interface(pkgid);
1315   ValidatePackage(pkgid, {appid1});
1316
1317   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1318   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
1319   ValidateDataFiles(pkgid, kTestUserId);
1320 }
1321
1322 TEST_F(SmokeTest, MountInstallationMode) {
1323   bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
1324   std::string pkgid = "smokewgt28";
1325   std::string appid = "smokewgt28.InstallationMode";
1326   ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1327   ScopedTzipInterface interface(pkgid);
1328   ValidatePackage(pkgid, {appid});
1329 }
1330
1331 TEST_F(SmokeTest, MountUpdateMode) {
1332   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
1333   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
1334   std::string pkgid = "smokewgt29";
1335   std::string appid = "smokewgt29.UpdateMode";
1336   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1337             ci::AppInstaller::Result::OK);
1338   AddDataFiles(pkgid, kTestUserId);
1339   ASSERT_EQ(MountInstall(path_new, PackageType::WGT),
1340             ci::AppInstaller::Result::OK);
1341   ScopedTzipInterface interface(pkgid);
1342   ValidatePackage(pkgid, {appid});
1343
1344   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1345   ValidateDataFiles(pkgid, kTestUserId);
1346 }
1347
1348 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
1349   bf::path path =
1350       kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
1351   std::string pkgid = "smokewgt33";
1352   std::string appid = "smokewgt33.web";
1353   ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
1354             ci::AppInstaller::Result::ERROR);
1355   ScopedTzipInterface interface(pkgid);
1356   CheckPackageNonExistance(pkgid, {appid});
1357 }
1358
1359 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
1360   bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
1361   bf::path path_new =
1362       kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
1363   std::string pkgid = "smokewgt34";
1364   std::string appid = "smokewgt34.web";
1365   ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1366             ci::AppInstaller::Result::OK);
1367   AddDataFiles(pkgid, kTestUserId);
1368   ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
1369       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1370   ScopedTzipInterface interface(pkgid);
1371   ValidatePackage(pkgid, {appid});
1372
1373   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1374   ValidateDataFiles(pkgid, kTestUserId);
1375 }
1376
1377 TEST_F(SmokeTest, UserDefinedPlugins) {
1378   bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
1379   std::string pkgid = "smokewgt02";
1380   std::string appid = "smokewgt02.SimpleEcho";
1381   std::string call_privilege = "http://tizen.org/privilege/call";
1382   std::string location_privilege = "http://tizen.org/privilege/location";
1383   std::string power_privilege = "http://tizen.org/privilege/power";
1384
1385   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1386   ValidatePackage(pkgid, {appid});
1387   std::vector<std::string> res;
1388   ASSERT_TRUE(ci::QueryPrivilegesForPkgId(pkgid, kTestUserId, &res));
1389   ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
1390   ASSERT_TRUE(std::find(res.begin(), res.end(), location_privilege)
1391           != res.end());
1392   ASSERT_TRUE(std::find(res.begin(), res.end(), power_privilege) != res.end());
1393 }
1394
1395 TEST_F(SmokeTest, InstallExternalMode) {
1396   ASSERT_TRUE(CheckAvailableExternalPath());
1397   bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
1398   std::string pkgid = "smokewgt35";
1399   std::string appid = "smokewgt35.web";
1400   ASSERT_EQ(InstallExternal(path, PackageType::WGT),
1401       ci::AppInstaller::Result::OK);
1402   ValidateExternalPackage(pkgid, {appid});
1403 }
1404
1405 TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
1406   ASSERT_TRUE(CheckAvailableExternalPath());
1407   bf::path path =
1408       kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
1409   std::string pkgid = "smokewgt36";
1410   std::string appid = "smokewgt36.web";
1411   bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
1412   ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path,
1413       PackageType::WGT), ci::AppInstaller::Result::OK);
1414   ValidateExternalPackage(pkgid, {appid});
1415 }
1416
1417 TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
1418   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1419   bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
1420   std::string pkgid = "smokewgt37";
1421   std::string appid = "smokewgt37.InstallationModePreload";
1422   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
1423             ci::AppInstaller::Result::OK);
1424   ValidatePackage(pkgid, {appid}, true);
1425 }
1426
1427 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
1428   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1429   bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
1430   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
1431   std::string pkgid = "smokewgt38";
1432   std::string appid = "smokewgt38.UpdateModePreload";
1433   ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
1434             ci::AppInstaller::Result::OK);
1435   AddDataFiles(pkgid, kTestUserId);
1436   ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
1437             ci::AppInstaller::Result::OK);
1438   ValidatePackage(pkgid, {appid}, true);
1439
1440   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
1441                                            true));
1442   ValidateDataFiles(pkgid, kTestUserId);
1443 }
1444
1445 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
1446   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1447   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
1448   std::string pkgid = "smokewgt39";
1449   std::string appid = "smokewgt39.DeinstallationModePreload";
1450   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
1451             ci::AppInstaller::Result::OK);
1452   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
1453             ci::AppInstaller::Result::OK);
1454   CheckPackageReadonlyNonExistance(pkgid, {appid});
1455 }
1456
1457 TEST_F(SmokeTest, SharedRes24) {
1458   bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
1459   std::string pkgid = "smokeSh2xx";
1460   std::string appid = "smokeSh2xx.SharedRes24";
1461   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1462   ValidatePackage(pkgid, {appid});
1463   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
1464   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
1465   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT"));  // NOLINT
1466 }
1467
1468 TEST_F(SmokeTest, SharedRes30) {
1469   bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
1470   std::string pkgid = "smokeSh3xx";
1471   std::string appid = "smokeSh3xx.SharedRes30";
1472   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1473   ValidatePackage(pkgid, {appid});
1474   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
1475   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
1476   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
1477 }
1478
1479 TEST_F(SmokeTest, SharedRes30Delta) {
1480   bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
1481   bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
1482   std::string pkgid = "smokeSh3De";
1483   std::string appid = "smokeSh3De.SharedRes30Delta";
1484   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
1485             ci::AppInstaller::Result::OK);
1486   ValidatePackage(pkgid, {appid});
1487   // Check delta modifications
1488   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
1489   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
1490   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
1491   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
1492   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
1493 }
1494
1495 TEST_F(SmokeTest, SharedRes30Hybrid) {
1496   bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
1497   std::string pkgid = "smokeSh3Hy";
1498   std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
1499   std::string appid2 = "sharedres30hybridserivce";
1500   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
1501   ValidatePackage(pkgid, {appid1, appid2});
1502   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
1503   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
1504   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
1505   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK"));  // NOLINT
1506   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK"));  // NOLINT
1507 }
1508
1509 TEST_F(SmokeTest, SharedRes30HybridDelta) {
1510   bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
1511   bf::path delta_package = kSmokePackagesDirectory / "SharedRes30HybridDelta.delta";
1512   std::string pkgid = "smokeSh3HD";
1513   std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
1514   std::string appid2 = "sharedres30hybriddeltaserivce";
1515   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
1516             ci::AppInstaller::Result::OK);
1517   ValidatePackage(pkgid, {appid1, appid2});
1518   // Check delta modifications
1519   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
1520   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
1521   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
1522   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
1523   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK-2"));  // NOLINT
1524   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
1525   ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1"));  // NOLINT
1526 }
1527
1528 }  // namespace common_installer
1529
1530 int main(int argc,  char** argv) {
1531   ci::RequestMode request_mode = ParseRequestMode(argc, argv);
1532   if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
1533     std::cout << "Skip tests for preload request" << std::endl;
1534     ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
1535   }
1536   testing::InitGoogleTest(&argc, argv);
1537   testing::Environment *env = testing::AddGlobalTestEnvironment(
1538       new common_installer::SmokeEnvironment(request_mode));
1539   return RUN_ALL_TESTS();
1540 }