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.
5 #include <boost/filesystem/operations.hpp>
6 #include <boost/filesystem/path.hpp>
7 #include <boost/range/iterator_range.hpp>
8 #include <boost/system/error_code.hpp>
9 #include <common/paths.h>
10 #include <common/pkgmgr_interface.h>
11 #include <common/pkgmgr_query.h>
12 #include <common/request.h>
13 #include <common/step/configuration/step_fail.h>
14 #include <common/tzip_interface.h>
15 #include <common/utils/subprocess.h>
16 #include <gtest/gtest.h>
17 #include <gtest/gtest-death-test.h>
18 #include <pkgmgr-info.h>
21 #include <tzplatform_config.h>
28 #include "hybrid/hybrid_installer.h"
29 #include "wgt/wgt_app_query_interface.h"
30 #include "wgt/wgt_installer.h"
32 #define SIZEOFARRAY(ARR) \
33 sizeof(ARR) / sizeof(ARR[0]) \
35 namespace bf = boost::filesystem;
36 namespace bs = boost::system;
37 namespace ci = common_installer;
41 const bf::path kSmokePackagesDirectory =
42 "/usr/share/wgt-backend-ut/test_samples/smoke/";
44 const char kApplicationDir[] = ".applications";
45 const char kApplicationDirBackup[] = ".applications.bck";
46 const char KUserAppsDir[] = "apps_rw";
47 const char KUserAppsDirBackup[] = "apps_rw.bck";
48 const char kUserDataBaseDir[] = "/opt/dbspace/user";
50 enum class RequestResult {
55 class ScopedTzipInterface {
57 explicit ScopedTzipInterface(const std::string& pkgid)
58 : pkg_path_(bf::path(ci::GetRootAppPath(false)) / pkgid),
59 interface_(ci::GetMountLocation(pkg_path_)) {
60 interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
63 ~ScopedTzipInterface() {
64 interface_.UnmountZip();
69 ci::TzipInterface interface_;
72 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
74 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
75 ci::InstallationMode* mode) {
76 *installer = pkgmgr_installer_offline_new();
79 *mode = ci::InstallationMode::ONLINE;
83 bool ShouldCreateSignal() const {
88 enum class PackageType {
93 bool TouchFile(const bf::path& path) {
94 FILE* f = fopen(path.c_str(), "w+");
101 void RemoveAllRecoveryFiles() {
102 bf::path root_path = ci::GetRootAppPath(false);
103 if (!bf::exists(root_path))
105 for (auto& dir_entry : boost::make_iterator_range(
106 bf::directory_iterator(root_path), bf::directory_iterator())) {
107 if (bf::is_regular_file(dir_entry)) {
108 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
109 bs::error_code error;
110 bf::remove(dir_entry.path(), error);
116 bf::path FindRecoveryFile() {
117 bf::path root_path = ci::GetRootAppPath(false);
118 for (auto& dir_entry : boost::make_iterator_range(
119 bf::directory_iterator(root_path), bf::directory_iterator())) {
120 if (bf::is_regular_file(dir_entry)) {
121 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
122 return dir_entry.path();
129 bool ValidateFileContentInPackage(const std::string& pkgid,
130 const std::string& relative,
131 const std::string& expected) {
132 bf::path root_path = ci::GetRootAppPath(false);
133 bf::path file_path = root_path / pkgid / relative;
134 if (!bf::exists(file_path)) {
135 LOG(ERROR) << file_path << " doesn't exist";
138 FILE* handle = fopen(file_path.c_str(), "r");
140 LOG(ERROR) << file_path << " cannot be open";
144 std::array<char, 200> buffer;
145 while (fgets(buffer.data(), buffer.size(), handle)) {
146 content += buffer.data();
149 return content == expected;
152 void ValidatePackageFS(const std::string& pkgid,
153 const std::vector<std::string>& appids) {
154 bf::path root_path = ci::GetRootAppPath(false);
155 bf::path package_path = root_path / pkgid;
156 bf::path data_path = package_path / "data";
157 bf::path shared_path = package_path / "shared";
158 bf::path cache_path = package_path / "cache";
159 ASSERT_TRUE(bf::exists(root_path));
160 ASSERT_TRUE(bf::exists(package_path));
161 ASSERT_TRUE(bf::exists(data_path));
162 ASSERT_TRUE(bf::exists(shared_path));
163 ASSERT_TRUE(bf::exists(cache_path));
165 bf::path manifest_path =
166 bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
167 ASSERT_TRUE(bf::exists(manifest_path));
169 for (auto& appid : appids) {
170 bf::path binary_path = package_path / "bin" / appid;
171 ASSERT_TRUE(bf::exists(binary_path));
174 bf::path widget_root_path = package_path / "res" / "wgt";
175 bf::path config_path = widget_root_path / "config.xml";
176 ASSERT_TRUE(bf::exists(widget_root_path));
177 ASSERT_TRUE(bf::exists(config_path));
179 bf::path private_tmp_path = package_path / "tmp";
180 ASSERT_TRUE(bf::exists(private_tmp_path));
182 // backups should not exist
183 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
184 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
185 ASSERT_FALSE(bf::exists(package_backup));
186 ASSERT_FALSE(bf::exists(manifest_backup));
189 void PackageCheckCleanup(const std::string& pkgid,
190 const std::vector<std::string>&) {
191 bf::path root_path = ci::GetRootAppPath(false);
192 bf::path package_path = root_path / pkgid;
193 ASSERT_FALSE(bf::exists(package_path));
195 bf::path manifest_path =
196 bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
197 ASSERT_FALSE(bf::exists(manifest_path));
199 // backups should not exist
200 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
201 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
202 ASSERT_FALSE(bf::exists(package_backup));
203 ASSERT_FALSE(bf::exists(manifest_backup));
206 void ValidatePackage(const std::string& pkgid,
207 const std::vector<std::string>& appids) {
208 ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
209 ValidatePackageFS(pkgid, appids);
212 void CheckPackageNonExistance(const std::string& pkgid,
213 const std::vector<std::string>& appids) {
214 ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
215 PackageCheckCleanup(pkgid, appids);
218 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
219 std::unique_ptr<ci::AppQueryInterface> query_interface(
220 new wgt::WgtAppQueryInterface());
221 return query_interface;
224 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
227 case PackageType::WGT:
228 return std::unique_ptr<ci::AppInstaller>(new wgt::WgtInstaller(pkgmgr));
229 case PackageType::HYBRID:
230 return std::unique_ptr<ci::AppInstaller>(
231 new hybrid::HybridInstaller(pkgmgr));
233 LOG(ERROR) << "Unknown installer type";
238 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
240 RequestResult mode) {
241 std::unique_ptr<ci::AppInstaller> installer = CreateInstaller(pkgmgr, type);
243 case RequestResult::FAIL:
244 installer->AddStep<ci::configuration::StepFail>();
249 return installer->Run();
251 ci::AppInstaller::Result CallBackend(int argc,
254 RequestResult mode = RequestResult::NORMAL
256 TestPkgmgrInstaller pkgmgr_installer;
257 std::unique_ptr<ci::AppQueryInterface> query_interface =
258 CreateQueryInterface();
260 ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
261 &pkgmgr_installer, query_interface.get());
263 LOG(ERROR) << "Failed to initialize pkgmgr interface";
264 return ci::AppInstaller::Result::UNKNOWN;
266 return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
269 ci::AppInstaller::Result Install(const bf::path& path,
271 RequestResult mode = RequestResult::NORMAL) {
272 const char* argv[] = {"", "-i", path.c_str()};
273 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
276 ci::AppInstaller::Result Update(const bf::path& path_old,
277 const bf::path& path_new,
279 RequestResult mode = RequestResult::NORMAL) {
280 if (Install(path_old, type) != ci::AppInstaller::Result::OK) {
281 LOG(ERROR) << "Failed to install application. Cannot update";
282 return ci::AppInstaller::Result::UNKNOWN;
284 return Install(path_new, type, mode);
287 ci::AppInstaller::Result MountInstall(const bf::path& path,
288 PackageType type, RequestResult mode = RequestResult::NORMAL) {
289 const char* argv[] = {"", "-w", path.c_str()};
290 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
293 ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
294 const bf::path& path_new, PackageType type,
295 RequestResult mode = RequestResult::NORMAL) {
296 if (MountInstall(path_old, type) != ci::AppInstaller::Result::OK) {
297 LOG(ERROR) << "Failed to mount-install application. Cannot mount-update";
298 return ci::AppInstaller::Result::UNKNOWN;
300 return MountInstall(path_new, type, mode);
303 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
305 RequestResult mode = RequestResult::NORMAL) {
306 const char* argv[] = {"", "-d", pkgid.c_str()};
307 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
310 ci::AppInstaller::Result Reinstall(const bf::path& path,
311 const bf::path& delta_dir,
313 RequestResult mode = RequestResult::NORMAL) {
314 if (Install(path, type) != ci::AppInstaller::Result::OK) {
315 LOG(ERROR) << "Failed to install application. Cannot perform RDS";
316 return ci::AppInstaller::Result::UNKNOWN;
318 const char* argv[] = {"", "-r", delta_dir.c_str()};
319 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
322 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
323 const bf::path& delta_package, PackageType type) {
324 if (Install(path, type) != ci::AppInstaller::Result::OK) {
325 LOG(ERROR) << "Failed to install application. Cannot perform delta update";
326 return ci::AppInstaller::Result::UNKNOWN;
328 return Install(delta_package, type);
331 ci::AppInstaller::Result Clear(const std::string& pkgid,
333 RequestResult mode = RequestResult::NORMAL) {
334 const char* argv[] = {"", "-c", pkgid.c_str()};
335 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
338 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
340 RequestResult mode = RequestResult::NORMAL) {
341 const char* argv[] = {"", "-A", pkgid.c_str()};
342 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
345 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
347 RequestResult mode = RequestResult::NORMAL) {
348 const char* argv[] = {"", "-D", pkgid.c_str()};
349 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
352 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
354 RequestResult mode = RequestResult::NORMAL) {
355 const char* argv[] = {"", "-b", recovery_file.c_str()};
356 TestPkgmgrInstaller pkgmgr_installer;
357 std::unique_ptr<ci::AppQueryInterface> query_interface =
358 CreateQueryInterface();
360 ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
361 &pkgmgr_installer, query_interface.get());
363 LOG(ERROR) << "Failed to initialize pkgmgr interface";
364 return ci::AppInstaller::Result::UNKNOWN;
366 return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
371 namespace common_installer {
373 class SmokeEnvironment : public testing::Environment {
375 explicit SmokeEnvironment(const bf::path& home) : home_(home) {
377 void SetUp() override {
378 bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
379 bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
381 bs::error_code error;
382 bf::remove_all(home_ / kApplicationDirBackup, error);
383 bf::remove_all(home_ / KUserAppsDirBackup, error);
384 bf::remove_all(UserDBDirBackup, error);
385 if (bf::exists(home_ / KUserAppsDir)) {
386 bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
388 LOG(ERROR) << "Failed to setup test environment. Does some previous"
389 << " test crashed? Directory: "
390 << (home_ / KUserAppsDirBackup) << " should not exist.";
393 if (bf::exists(home_ / kApplicationDir)) {
394 bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error);
396 LOG(ERROR) << "Failed to setup test environment. Does some previous"
397 << " test crashed? Directory: "
398 << (home_ / kApplicationDirBackup) << " should not exist.";
401 if (bf::exists(UserDBDir)) {
402 bf::rename(UserDBDir, UserDBDirBackup, error);
404 LOG(ERROR) << "Failed to setup test environment. Does some previous"
405 << " test crashed? Directory: "
406 << UserDBDirBackup << " should not exist.";
410 void TearDown() override {
411 bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
412 bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
414 bs::error_code error;
415 bf::remove_all(home_ / kApplicationDir, error);
416 bf::remove_all(home_ / KUserAppsDir, error);
417 bf::remove_all(UserDBDir, error);
418 if (bf::exists(home_ / KUserAppsDirBackup))
419 bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error);
420 if (bf::exists(home_ / kApplicationDirBackup))
421 bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error);
422 if (bf::exists(UserDBDirBackup))
423 bf::rename(UserDBDirBackup, UserDBDir, error);
430 class SmokeTest : public testing::Test {
433 TEST_F(SmokeTest, InstallationMode) {
434 bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
435 std::string pkgid = "smokeapp03";
436 std::string appid = "smokeapp03.InstallationMode";
437 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
438 ValidatePackage(pkgid, {appid});
441 TEST_F(SmokeTest, UpdateMode) {
442 bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
443 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
444 std::string pkgid = "smokeapp04";
445 std::string appid = "smokeapp04.UpdateMode";
446 ASSERT_EQ(Update(path_old, path_new, PackageType::WGT),
447 ci::AppInstaller::Result::OK);
448 ValidatePackage(pkgid, {appid});
450 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
453 TEST_F(SmokeTest, DeinstallationMode) {
454 bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
455 std::string pkgid = "smokeapp05";
456 std::string appid = "smokeapp05.DeinstallationMode";
457 ASSERT_EQ(Install(path, PackageType::WGT),
458 ci::AppInstaller::Result::OK);
459 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
460 CheckPackageNonExistance(pkgid, {appid});
463 TEST_F(SmokeTest, RDSMode) {
464 bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
465 bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
466 std::string pkgid = "smokeapp11";
467 std::string appid = "smokeapp11.RDSMode";
468 ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT),
469 ci::AppInstaller::Result::OK);
470 ValidatePackage(pkgid, {appid});
472 // Check delta modifications
473 bf::path root_path = ci::GetRootAppPath(false);
474 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
475 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
476 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
479 TEST_F(SmokeTest, EnablePkg) {
480 bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
481 std::string pkgid = "smokeapp22";
482 ASSERT_EQ(Install(path, PackageType::WGT),
483 ci::AppInstaller::Result::OK);
484 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
485 ci::AppInstaller::Result::OK);
486 ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
487 ci::AppInstaller::Result::OK);
489 ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
492 TEST_F(SmokeTest, DisablePkg) {
493 bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
494 std::string pkgid = "smokeapp21";
495 std::string appid = "smokeapp21.DisablePkg";
496 ASSERT_EQ(Install(path, PackageType::WGT),
497 ci::AppInstaller::Result::OK);
498 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
499 ci::AppInstaller::Result::OK);
500 ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
501 ValidatePackageFS(pkgid, {appid});
504 TEST_F(SmokeTest, ClearMode) {
505 bf::path path = kSmokePackagesDirectory / "ClearMode.wgt";
506 std::string pkgid = "smokeapp20";
507 std::string appid = "smokeapp20.ClearMode";
508 ASSERT_EQ(Install(path, PackageType::WGT),
509 ci::AppInstaller::Result::OK);
510 bf::path root_path = ci::GetRootAppPath(false);
511 bs::error_code error;
512 bf::create_directory(root_path / pkgid / "data" / "dir", error);
514 ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file"));
515 ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file"));
516 ASSERT_EQ(Clear(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
517 ValidatePackage(pkgid, {appid});
518 ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file"));
519 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file"));
522 TEST_F(SmokeTest, DeltaMode) {
523 bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
524 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
525 std::string pkgid = "smokeapp17";
526 std::string appid = "smokeapp17.DeltaMode";
527 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
528 ci::AppInstaller::Result::OK);
529 ValidatePackage(pkgid, {appid});
531 // Check delta modifications
532 bf::path root_path = ci::GetRootAppPath(false);
533 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
534 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
535 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
536 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT
537 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
538 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
541 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
542 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
543 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
544 backend_crash.Run("-i", path.string());
545 ASSERT_NE(backend_crash.Wait(), 0);
547 std::string pkgid = "smokeapp09";
548 std::string appid = "smokeapp09.RecoveryModeForInstallation";
549 bf::path recovery_file = FindRecoveryFile();
550 ASSERT_FALSE(recovery_file.empty());
551 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
552 ci::AppInstaller::Result::OK);
553 CheckPackageNonExistance(pkgid, {appid});
556 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
557 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
558 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
559 RemoveAllRecoveryFiles();
560 Subprocess backend_test("/usr/bin/wgt-backend");
561 backend_test.Run("-i", path_old.string());
562 ASSERT_EQ(backend_test.Wait(), 0);
563 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
564 backend_crash.Run("-i", path_new.string());
565 ASSERT_NE(backend_crash.Wait(), 0);
567 std::string pkgid = "smokeapp10";
568 std::string appid = "smokeapp10.RecoveryModeForUpdate";
569 bf::path recovery_file = FindRecoveryFile();
570 ASSERT_FALSE(recovery_file.empty());
571 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
572 ci::AppInstaller::Result::OK);
573 ValidatePackage(pkgid, {appid});
575 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
578 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
579 bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt"; // NOLINT
580 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
583 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
584 bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt"; // NOLINT
585 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
588 TEST_F(SmokeTest, InstallationMode_Rollback) {
589 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
590 std::string pkgid = "smokeapp06";
591 std::string appid = "smokeapp06.InstallationModeRollback";
592 ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
593 ci::AppInstaller::Result::ERROR);
594 CheckPackageNonExistance(pkgid, {appid});
597 TEST_F(SmokeTest, UpdateMode_Rollback) {
598 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
599 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
600 std::string pkgid = "smokeapp07";
601 std::string appid = "smokeapp07.UpdateModeRollback";
602 ASSERT_EQ(Update(path_old, path_new, PackageType::WGT, RequestResult::FAIL),
603 ci::AppInstaller::Result::ERROR);
604 ValidatePackage(pkgid, {appid});
606 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
609 TEST_F(SmokeTest, InstallationMode_Hybrid) {
610 bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
611 std::string pkgid = "smokehyb01";
612 std::string appid1 = "smokehyb01.Web";
613 std::string appid2 = "smokehyb01.Native";
614 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
615 ValidatePackage(pkgid, {appid1, appid2});
618 TEST_F(SmokeTest, UpdateMode_Hybrid) {
619 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
620 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
621 std::string pkgid = "smokehyb02";
622 std::string appid1 = "smokehyb02.Web";
623 std::string appid2 = "smokehyb02.Native";
624 ASSERT_EQ(Update(path_old, path_new, PackageType::HYBRID),
625 ci::AppInstaller::Result::OK);
626 ValidatePackage(pkgid, {appid1, appid2});
628 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
629 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
632 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
633 bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
634 std::string pkgid = "smokehyb03";
635 std::string appid1 = "smokehyb03.Web";
636 std::string appid2 = "smokehyb03.Native";
637 ASSERT_EQ(Install(path, PackageType::HYBRID),
638 ci::AppInstaller::Result::OK);
639 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
640 CheckPackageNonExistance(pkgid, {appid1, appid2});
643 TEST_F(SmokeTest, DeltaMode_Hybrid) {
644 bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
645 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
646 std::string pkgid = "smokehyb04";
647 std::string appid1 = "smokehyb04.Web";
648 std::string appid2 = "smokehyb04.Native";
649 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
650 ci::AppInstaller::Result::OK);
651 ValidatePackage(pkgid, {appid1, appid2});
653 // Check delta modifications
654 bf::path root_path = ci::GetRootAppPath(false);
655 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
656 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
657 ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
658 ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
659 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
660 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT
661 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
662 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
663 ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n");
666 TEST_F(SmokeTest, MountInstallationMode) {
667 bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
668 std::string pkgid = "smokeapp28";
669 std::string appid = "smokeapp28.InstallationMode";
670 ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
671 ScopedTzipInterface interface(pkgid);
672 ValidatePackage(pkgid, {appid});
675 TEST_F(SmokeTest, MountUpdateMode) {
676 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
677 bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
678 std::string pkgid = "smokeapp29";
679 std::string appid = "smokeapp29.UpdateMode";
680 ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT),
681 ci::AppInstaller::Result::OK);
682 ScopedTzipInterface interface(pkgid);
683 ValidatePackage(pkgid, {appid});
685 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
688 } // namespace common_installer
690 int main(int argc, char** argv) {
691 testing::InitGoogleTest(&argc, argv);
692 const char* directory = getenv("HOME");
694 LOG(ERROR) << "Cannot get $HOME value";
697 testing::AddGlobalTestEnvironment(
698 new common_installer::SmokeEnvironment(directory));
699 return RUN_ALL_TESTS();