--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include <common/utils/subprocess.h>
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-death-test.h>
+
+#include "unit_tests/smoke_utils.h"
+
+namespace ci = common_installer;
+
+namespace smoke_test {
+
+class SmokeEnvironment : public testing::Environment {
+ public:
+ explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) { }
+
+ void SetUp() override {
+ if (request_mode_ == ci::RequestMode::USER) {
+ ASSERT_TRUE(AddTestUser(&test_user));
+ }
+ backups_ = SetupBackupDirectories(test_user.uid);
+ for (auto& path : backups_)
+ ASSERT_TRUE(BackupPath(path));
+ }
+ void TearDown() override {
+ ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
+ (request_mode_ == ci::RequestMode::USER &&
+ kGlobalUserUid != test_user.uid));
+ BackendInterface::SmokeInstallerFactoryPtr factory(
+ new UnifiedSmokeInstallerFactory());
+ UnifiedBackendInterface backend(
+ std::move(factory), std::to_string(test_user.uid));
+ UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
+ for (auto& path : backups_)
+ ASSERT_TRUE(RestorePath(path));
+ if (request_mode_ == ci::RequestMode::USER) {
+ ASSERT_TRUE(DeleteTestUser());
+ }
+ }
+ User test_user;
+
+ private:
+ ci::RequestMode request_mode_;
+ std::vector<bf::path> backups_;
+};
+
+} // namespace smoke_test
+
+
+namespace {
+
+const char kSmokeTestHelperPath[] =
+ "/usr/bin/unified-installer-ut/smoke-test-helper";
+
+smoke_test::SmokeEnvironment *env = nullptr;
+void signalHandler(int signum) {
+ env->TearDown();
+ exit(signum);
+}
+
+} // namespace
+
+namespace smoke_test {
+
+const bf::path kUnifiedSmokePackagesDirectory =
+ "/usr/share/unified-installer-ut/test_samples/smoke/";
+
+class SmokeTest : public testing::Test {
+ public:
+ SmokeTest()
+ : backend(BackendInterface::SmokeInstallerFactoryPtr(
+ new UnifiedSmokeInstallerFactory()),
+ std::to_string(env->test_user.uid)),
+ params({PackageType::TPK, false}) {
+ params.test_user.uid = env->test_user.uid;
+ params.test_user.gid = env->test_user.gid;
+ }
+ protected:
+ UnifiedBackendInterface backend;
+ TestParameters params;
+};
+
+TEST_F(SmokeTest, Install_Single) {
+ bf::path path =
+ kUnifiedSmokePackagesDirectory / "Install_SingleTpk.tpk";
+ std::string pkgid = "smokeuni01";
+ std::string appid = "smokeuni01.InstallSingleTpk";
+ std::string exec = "smokeunified";
+
+ std::vector<bf::path> paths = { path };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+}
+
+TEST_F(SmokeTest, Install_Double) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_DoubleTpk.tpk";
+ std::string pkgid1 = "smokeuni02";
+ std::string appid1 = "smokeuni02.InstallDoubleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_DoubleWgt.wgt";
+ std::string pkgid2 = "smokeuni03";
+ std::string appid2 = "smokeuni03.InstallDoubleWgt";
+ std::string exec2 = "smokeuni03.InstallDoubleWgt";
+
+ std::vector<bf::path> paths = { path1, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+}
+
+TEST_F(SmokeTest, Install_Triple) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleTpk.tpk";
+ std::string pkgid1 = "smokeuni04";
+ std::string appid1 = "smokeuni04.InstallTripleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleWgt.wgt";
+ std::string pkgid2 = "smokeuni05";
+ std::string appid2 = "smokeuni05.InstallTripleWgt";
+ std::string exec2 = "smokeuni05.InstallTripleWgt";
+ bf::path path3 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleHybrid.wgt";
+ std::string pkgid3 = "smokeuni06";
+ std::string appid3 = "smokeuni06.InstallTripleHybrid";
+ std::string exec3 = "smokeuni06.InstallTripleHybrid";
+
+ std::vector<bf::path> paths = { path1, path2, path3 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
+}
+
+TEST_F(SmokeTest, Update_Single) {
+ bf::path path_old =
+ kUnifiedSmokePackagesDirectory / "Update_SingleTpk.tpk";
+ bf::path path_new =
+ kUnifiedSmokePackagesDirectory / "Update_SingleTpk_2.tpk";
+ std::string pkgid = "smokeuni07";
+ std::string appid = "smokeuni07.UpdateSingleTpk";
+ std::string exec = "smokeunified";
+
+ std::vector<bf::path> paths = { path_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid, "res/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, Update_Double) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleTpk_2.tpk";
+ std::string pkgid1 = "smokeuni08";
+ std::string appid1 = "smokeuni08.UpdateDoubleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleWgt_2.wgt";
+ std::string pkgid2 = "smokeuni09";
+ std::string appid2 = "smokeuni09.UpdateDoubleWgt";
+ std::string exec2 = "smokeuni09.UpdateDoubleWgt";
+
+ std::vector<bf::path> paths = { path1_old, path2_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, Update_Triple) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleTpk_2.tpk";
+ std::string pkgid1 = "smokeuni10";
+ std::string appid1 = "smokeuni10.UpdateTripleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleWgt_2.wgt";
+ std::string pkgid2 = "smokeuni11";
+ std::string appid2 = "smokeuni11.UpdateTripleWgt";
+ std::string exec2 = "smokeuni11.UpdateTripleWgt";
+ bf::path path3_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleHybrid.wgt";
+ bf::path path3_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleHybrid_2.wgt";
+ std::string pkgid3 = "smokeuni12";
+ std::string appid3 = "smokeuni12.UpdateTripleHybrid";
+ std::string exec3 = "smokeuni12.UpdateTripleHybrid";
+
+ std::vector<bf::path> paths = { path1_old, path2_old, path3_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new, path3_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid3, "res/wgt/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, InstallAndUpdate) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk_2.tpk";
+ std::string pkgid1 = "smokeuni13";
+ std::string appid1 = "smokeuni13.InstallAndUpdateModeTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Wgt.wgt";
+ std::string pkgid2 = "smokeuni14";
+ std::string appid2 = "smokeuni14.InstallAndUpdateWgt";
+ std::string exec2 = "smokeuni14.InstallAndUpdateWgt";
+
+ // install tpk version 1
+ std::vector<bf::path> paths = { path1_old };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ // update tpk version 2, install wgt version 1
+ paths = { path1_new, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+}
+
+class RollbackSmokeTest : public testing::Test {
+ public:
+ RollbackSmokeTest()
+ : backend(BackendInterface::SmokeInstallerFactoryPtr(
+ new UnifiedSmokeInstallerFactory()),
+ std::to_string(env->test_user.uid),
+ RequestResult::FAIL),
+ params({PackageType::TPK, false}) {
+ params.test_user.uid = env->test_user.uid;
+ params.test_user.gid = env->test_user.gid;
+ }
+ protected:
+ UnifiedBackendInterface backend;
+ TestParameters params;
+};
+
+TEST_F(RollbackSmokeTest, Install_Rollback) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_RollbackTpk.tpk";
+ std::string pkgid1 = "smokeuni15";
+ std::string appid1 = "smokeuni15.InstallRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_RollbackWgt.wgt";
+ std::string pkgid2 = "smokeuni16";
+ std::string appid2 = "smokeuni16.InstallRollbackWgt";
+ std::string exec2 = "smokeuni16.InstallRollbackWgt";
+
+ std::vector<bf::path> paths = { path1, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+};
+
+TEST_F(RollbackSmokeTest, Update_Rollback) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackTpk_2.tpk";
+ std::string pkgid1 = "smokeuni17";
+ std::string appid1 = "smokeuni17.UpdateRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackWgt_2.wgt";
+ std::string pkgid2 = "smokeuni18";
+ std::string appid2 = "smokeuni18.UpdateRollbackWgt";
+ std::string exec2 = "smokeuni18.UpdateRollbackWgt";
+
+ std::vector<bf::path> paths = { path1_old, path2_old };
+ ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+};
+
+TEST_F(RollbackSmokeTest, InstallAndUpdate_Rollback) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackTpk.tpk";
+ std::string pkgid1 = "smokeuni19";
+ std::string appid1 = "smokeuni19.InstallAndUpdateRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt_2.wgt";
+ std::string pkgid2 = "smokeuni20";
+ std::string appid2 = "smokeuni20.InstallAndUpdateRollbackWgt";
+ std::string exec2 = "smokeuni20.InstallAndUpdateRollbackWgt";
+
+ std::vector<bf::path> paths = { path2_old };
+ ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ // pkgid1: install, pkgid2: update
+ paths = { path1, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+};
+
+TEST_F(SmokeTest, Recovery_Install) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Recovery_InstallTpk.tpk";
+ std::string pkgid1 = "smokeuni21";
+ std::string appid1 = "smokeuni21.Recovery_InstallTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Recovery_InstallWgt.wgt";
+ std::string pkgid2 = "smokeuni22";
+ std::string appid2 = "smokeuni22.Recovery_InstallWgt";
+ std::string exec2 = "smokeuni22.Recovery_InstallWgt";
+
+ std::vector<std::string> paths = { path1.string(), path2.string() };
+ ci::Subprocess backend_crash(kSmokeTestHelperPath);
+ std::string test_uid_str = std::to_string(params.test_user.uid);
+ std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
+ argv.insert(argv.end(), paths.begin(), paths.end());
+ backend_crash.Run(argv);
+ ASSERT_NE(backend_crash.Wait(), 0);
+
+ bf::path recovery_file =
+ FindRecoveryFile("/tpk-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+
+ recovery_file =
+ FindRecoveryFile("/wgt-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ recovery_info.reset();
+ recovery_info = GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+ ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+};
+
+TEST_F(SmokeTest, Recovery_Update) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk.tpk";
+ std::string pkgid1 = "smokeuni23";
+ std::string appid1 = "smokeuni23.Recovery_UpdateTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt.wgt";
+ std::string pkgid2 = "smokeuni24";
+ std::string appid2 = "smokeuni24.Recovery_UpdateWgt";
+ std::string exec2 = "smokeuni24.Recovery_UpdateWgt";
+
+ std::vector<bf::path> paths_old = { path1_old, path2_old };
+ ASSERT_EQ(backend.Install(paths_old), ci::AppInstaller::Result::OK);
+
+ std::vector<std::string> paths = { path1_new.string(), path2_new.string() };
+ ci::Subprocess backend_crash(kSmokeTestHelperPath);
+ std::string test_uid_str = std::to_string(params.test_user.uid);
+ std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
+ argv.insert(argv.end(), paths.begin(), paths.end());
+ backend_crash.Run(argv);
+ ASSERT_NE(backend_crash.Wait(), 0);
+
+ bf::path recovery_file =
+ FindRecoveryFile("/tpk-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
+
+ recovery_file =
+ FindRecoveryFile("/wgt-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ recovery_info.reset();
+ recovery_info = GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+};
+
+} // namespace smoke_test
+
+int main(int argc, char** argv) {
+ try {
+ ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
+ if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
+ std::cout << "Skip tests for preload request" << std::endl;
+ ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
+ }
+ testing::InitGoogleTest(&argc, argv);
+ ::env = static_cast<smoke_test::SmokeEnvironment*>(
+ testing::AddGlobalTestEnvironment(
+ new smoke_test::SmokeEnvironment(request_mode)));
+ signal(SIGINT, ::signalHandler);
+ signal(SIGSEGV, ::signalHandler);
+ return RUN_ALL_TESTS();
+ } catch (...) {
+ std::cout << "Exception occurred during testing" << std::endl;
+ return -1;
+ }
+}
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include "unit_tests/smoke_utils.h"
+
+#include <unit_tests/common/smoke_utils.h>
+#include <unit_tests/tpk_smoke_utils.h>
+#include <unit_tests/wgt_smoke_utils.h>
+#include <unzip.h>
+
+#include <map>
+#include <string>
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+std::map<const char*, const char*> kTypeMap = {
+ {"res/wgt/config.xml", "wgt"},
+ {"config.xml", "wgt"},
+ {"tizen-manifest.xml", "tpk"},
+};
+
+std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
+ ci::PkgQueryInterface query(pkgid, uid);
+ return query.Type();
+}
+
+std::string GetPkgTypeFromPath(const std::string& path) {
+ std::string type;
+ unzFile uf = unzOpen(path.c_str());
+ if (!uf) {
+ LOG(ERROR) << "Failed to open zip file: " << path;
+ return type;
+ }
+ for (auto it : kTypeMap) {
+ if (unzLocateFile(uf, it.first, 0) == UNZ_OK) {
+ LOG(DEBUG) << "Found: " << it.first;
+ type = it.second;
+ break;
+ }
+ }
+ if (type.empty())
+ LOG(ERROR) << "Cannot get pkg type";
+ unzClose(uf);
+ return type;
+}
+
+std::string GetPkgTypeFromRecoveryFile(const std::string& path) {
+ bf::path recovery_file = path;
+ if (recovery_file.filename().string().find("tpk") == 0)
+ return "tpk";
+ else if (recovery_file.filename().string().find("wgt") == 0)
+ return "wgt";
+ return {};
+}
+
+std::string GetPkgType(const std::string& pkginfo, uid_t uid) {
+ std::string type = GetPkgTypeFromPkgid(pkginfo, uid);
+ if (type.empty())
+ type = GetPkgTypeFromPath(pkginfo);
+ // recovery file
+ if (type.empty())
+ type = GetPkgTypeFromRecoveryFile(pkginfo);
+ return type;
+}
+
+} // namespace
+
+namespace smoke_test {
+
+UnifiedSmokeInstallerFactory::AppInstallerPtr
+UnifiedSmokeInstallerFactory::CreateInstaller(
+ int idx, ci::PkgMgrPtr pkgmgr) const {
+ std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
+ if (type.empty())
+ return {};
+
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+ installer.reset(new tpk::TpkInstaller(pkgmgr));
+ } else {
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+ if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
+ pkgmgr->GetUid())) {
+ LOG(INFO) << "Hybrid package detected";
+ installer.reset(new hybrid::HybridInstaller(pkgmgr));
+ } else {
+ installer.reset(new wgt::WgtInstaller(pkgmgr));
+ }
+ }
+
+ installer->SetIndex(idx);
+
+ return installer;
+}
+
+UnifiedSmokeInstallerFactory::AppInstallerPtr
+UnifiedSmokeInstallerFactory::CreateFailExpectedInstaller(
+ int idx, ci::PkgMgrPtr pkgmgr, int fail_at) const {
+ std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
+ if (type.empty())
+ return {};
+
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+ installer.reset(new smoke_test::FailExpectedTpkInstaller(pkgmgr, fail_at));
+ } else {
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+ if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
+ pkgmgr->GetUid())) {
+ LOG(INFO) << "Hybrid package detected";
+ installer.reset(
+ new smoke_test::FailExpectedHybridInstaller(pkgmgr, fail_at));
+ } else {
+ installer.reset(
+ new smoke_test::FailExpectedWgtInstaller(pkgmgr, fail_at));
+ }
+ }
+
+ installer->SetIndex(idx);
+
+ return installer;
+}
+
+UnifiedBackendInterface::AppQueryInterfacePtr
+UnifiedBackendInterface::CreateQueryInterface() const {
+ // this is not used
+ return {};
+}
+
+UnifiedBackendInterface::AppInstallerPtr
+UnifiedBackendInterface::CreateInstaller(ci::PkgMgrPtr pkgmgr) const {
+ return factory_->CreateInstaller(0, pkgmgr);
+}
+
+UnifiedBackendInterface::AppInstallerPtr
+UnifiedBackendInterface::CreateFailExpectedInstaller(
+ ci::PkgMgrPtr pkgmgr, int fail_at) const {
+ return factory_->CreateFailExpectedInstaller(0, pkgmgr, fail_at);;
+}
+
+} // smoke_test