#include <boost/filesystem/path.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/system/error_code.hpp>
-#include <common/backup_paths.h>
+#include <common/paths.h>
#include <common/pkgmgr_interface.h>
-#include <common/pkgmgr_registration.h>
+#include <common/pkgmgr_query.h>
#include <common/request.h>
#include <common/step/configuration/step_fail.h>
+#include <common/tzip_interface.h>
#include <common/utils/subprocess.h>
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
const char kApplicationDirBackup[] = ".applications.bck";
const char KUserAppsDir[] = "apps_rw";
const char KUserAppsDirBackup[] = "apps_rw.bck";
+const char kUserDataBaseDir[] = "/opt/dbspace/user";
enum class RequestResult {
NORMAL,
FAIL
};
+class ScopedTzipInterface {
+ public:
+ explicit ScopedTzipInterface(const std::string& pkgid)
+ : pkg_path_(bf::path(ci::GetRootAppPath(false)) / pkgid),
+ interface_(ci::GetMountLocation(pkg_path_)) {
+ interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
+ }
+
+ ~ScopedTzipInterface() {
+ interface_.UnmountZip();
+ }
+
+ private:
+ bf::path pkg_path_;
+ ci::TzipInterface interface_;
+};
+
class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
public:
bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
HYBRID
};
+bool TouchFile(const bf::path& path) {
+ FILE* f = fopen(path.c_str(), "w+");
+ if (!f)
+ return false;
+ fclose(f);
+ return true;
+}
+
void RemoveAllRecoveryFiles() {
bf::path root_path = ci::GetRootAppPath(false);
if (!bf::exists(root_path))
for (auto& appid : appids) {
bf::path binary_path = package_path / "bin" / appid;
ASSERT_TRUE(bf::exists(binary_path));
- bf::path icon_path = bf::path(getIconPath(getuid(), false)) / (appid + ".png");
- ASSERT_TRUE(bf::exists(icon_path));
- bf::path icon_backup = ci::GetBackupPathForIconFile(icon_path);
- ASSERT_FALSE(bf::exists(icon_backup));
}
bf::path widget_root_path = package_path / "res" / "wgt";
}
void PackageCheckCleanup(const std::string& pkgid,
- const std::vector<std::string>& appids) {
+ const std::vector<std::string>&) {
bf::path root_path = ci::GetRootAppPath(false);
bf::path package_path = root_path / pkgid;
ASSERT_FALSE(bf::exists(package_path));
bf::path(getUserManifestPath(getuid(), false)) / (pkgid + ".xml");
ASSERT_FALSE(bf::exists(manifest_path));
- for (auto& appid : appids) {
- bf::path icon_path = bf::path(getIconPath(getuid(), false)) / (appid + ".png");
- ASSERT_FALSE(bf::exists(icon_path));
- bf::path icon_backup = ci::GetBackupPathForIconFile(icon_path);
- ASSERT_FALSE(bf::exists(icon_backup));
- }
-
// backups should not exist
bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
void ValidatePackage(const std::string& pkgid,
const std::vector<std::string>& appids) {
- ASSERT_TRUE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode()));
+ ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
ValidatePackageFS(pkgid, appids);
}
void CheckPackageNonExistance(const std::string& pkgid,
const std::vector<std::string>& appids) {
- ASSERT_FALSE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode()));
+ ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
PackageCheckCleanup(pkgid, appids);
}
}
return installer->Run();
}
-
-ci::AppInstaller::Result Install(const bf::path& path,
- PackageType type,
- RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-i", path.c_str()};
+ci::AppInstaller::Result CallBackend(int argc,
+ const char* argv[],
+ PackageType type,
+ RequestResult mode = RequestResult::NORMAL
+ ) {
TestPkgmgrInstaller pkgmgr_installer;
std::unique_ptr<ci::AppQueryInterface> query_interface =
CreateQueryInterface();
auto pkgmgr =
- ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
+ ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
&pkgmgr_installer, query_interface.get());
if (!pkgmgr) {
LOG(ERROR) << "Failed to initialize pkgmgr interface";
return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
}
+ci::AppInstaller::Result Install(const bf::path& path,
+ PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-i", path.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
ci::AppInstaller::Result Update(const bf::path& path_old,
const bf::path& path_new,
PackageType type,
return Install(path_new, type, mode);
}
+ci::AppInstaller::Result MountInstall(const bf::path& path,
+ PackageType type, RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-w", path.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
+ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
+ const bf::path& path_new, PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ if (MountInstall(path_old, type) != ci::AppInstaller::Result::OK) {
+ LOG(ERROR) << "Failed to mount-install application. Cannot mount-update";
+ return ci::AppInstaller::Result::UNKNOWN;
+ }
+ return MountInstall(path_new, type, mode);
+}
+
ci::AppInstaller::Result Uninstall(const std::string& pkgid,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
const char* argv[] = {"", "-d", pkgid.c_str()};
- TestPkgmgrInstaller pkgmgr_installer;
- std::unique_ptr<ci::AppQueryInterface> query_interface =
- CreateQueryInterface();
- auto pkgmgr =
- ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
- &pkgmgr_installer, query_interface.get());
- if (!pkgmgr) {
- LOG(ERROR) << "Failed to initialize pkgmgr interface";
- return ci::AppInstaller::Result::UNKNOWN;
- }
- return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result Reinstall(const bf::path& path,
return ci::AppInstaller::Result::UNKNOWN;
}
const char* argv[] = {"", "-r", delta_dir.c_str()};
- TestPkgmgrInstaller pkgmgr_installer;
- std::unique_ptr<ci::AppQueryInterface> query_interface =
- CreateQueryInterface();
- auto pkgmgr =
- ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
- &pkgmgr_installer, query_interface.get());
- if (!pkgmgr) {
- LOG(ERROR) << "Failed to initialize pkgmgr interface";
- return ci::AppInstaller::Result::UNKNOWN;
- }
- return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result DeltaInstall(const bf::path& path,
const bf::path& delta_package, PackageType type) {
if (Install(path, type) != ci::AppInstaller::Result::OK) {
- LOG(ERROR) << "Failed to install application. Cannot perform RDS";
+ LOG(ERROR) << "Failed to install application. Cannot perform delta update";
return ci::AppInstaller::Result::UNKNOWN;
}
return Install(delta_package, type);
}
+ci::AppInstaller::Result Clear(const std::string& pkgid,
+ PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-c", pkgid.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
+ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
+ PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-A", pkgid.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
+ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
+ PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-D", pkgid.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
ci::AppInstaller::Result Recover(const bf::path& recovery_file,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
explicit SmokeEnvironment(const bf::path& home) : home_(home) {
}
void SetUp() override {
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
+
bs::error_code error;
bf::remove_all(home_ / kApplicationDirBackup, error);
bf::remove_all(home_ / KUserAppsDirBackup, error);
+ bf::remove_all(UserDBDirBackup, error);
if (bf::exists(home_ / KUserAppsDir)) {
bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
if (error)
<< (home_ / kApplicationDirBackup) << " should not exist.";
assert(!error);
}
+ if (bf::exists(UserDBDir)) {
+ bf::rename(UserDBDir, UserDBDirBackup, error);
+ if (error)
+ LOG(ERROR) << "Failed to setup test environment. Does some previous"
+ << " test crashed? Directory: "
+ << UserDBDirBackup << " should not exist.";
+ assert(!error);
+ }
}
void TearDown() override {
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
+
bs::error_code error;
bf::remove_all(home_ / kApplicationDir, error);
bf::remove_all(home_ / KUserAppsDir, error);
+ bf::remove_all(UserDBDir, error);
if (bf::exists(home_ / KUserAppsDirBackup))
bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error);
if (bf::exists(home_ / kApplicationDirBackup))
bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error);
+ if (bf::exists(UserDBDirBackup))
+ bf::rename(UserDBDirBackup, UserDBDir, error);
}
private:
ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
}
+TEST_F(SmokeTest, EnablePkg) {
+ bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
+ std::string pkgid = "smokeapp22";
+ ASSERT_EQ(Install(path, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+
+ ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+}
+
+TEST_F(SmokeTest, DisablePkg) {
+ bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
+ std::string pkgid = "smokeapp21";
+ std::string appid = "smokeapp21.DisablePkg";
+ ASSERT_EQ(Install(path, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode()));
+ ValidatePackageFS(pkgid, {appid});
+}
+
+TEST_F(SmokeTest, ClearMode) {
+ bf::path path = kSmokePackagesDirectory / "ClearMode.wgt";
+ std::string pkgid = "smokeapp20";
+ std::string appid = "smokeapp20.ClearMode";
+ ASSERT_EQ(Install(path, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ bf::path root_path = ci::GetRootAppPath(false);
+ bs::error_code error;
+ bf::create_directory(root_path / pkgid / "data" / "dir", error);
+ ASSERT_FALSE(error);
+ ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file"));
+ ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file"));
+ ASSERT_EQ(Clear(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid});
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file"));
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file"));
+}
+
TEST_F(SmokeTest, DeltaMode) {
bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n");
}
+TEST_F(SmokeTest, MountInstallationMode) {
+ bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
+ std::string pkgid = "smokeapp28";
+ std::string appid = "smokeapp28.InstallationMode";
+ ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+ ScopedTzipInterface interface(pkgid);
+ ValidatePackage(pkgid, {appid});
+}
+
+TEST_F(SmokeTest, MountUpdateMode) {
+ bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
+ bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
+ std::string pkgid = "smokeapp29";
+ std::string appid = "smokeapp29.UpdateMode";
+ ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ScopedTzipInterface interface(pkgid);
+ ValidatePackage(pkgid, {appid});
+
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
+}
+
} // namespace common_installer
int main(int argc, char** argv) {