namespace {
+const uid_t kTestUserId = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+const std::string kTestUserIdStr =
+ std::to_string(kTestUserId);
+
const bf::path kSmokePackagesDirectory =
"/usr/share/wgt-backend-ut/test_samples/smoke/";
public:
explicit ScopedTzipInterface(const std::string& pkgid)
: pkg_path_(bf::path(ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER))) / pkgid),
+ kTestUserId)) / pkgid),
interface_(ci::GetMountLocation(pkg_path_)) {
interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
}
void RemoveAllRecoveryFiles() {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
if (!bf::exists(root_path))
return;
for (auto& dir_entry : boost::make_iterator_range(
bf::path FindRecoveryFile() {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
for (auto& dir_entry : boost::make_iterator_range(
bf::directory_iterator(root_path), bf::directory_iterator())) {
if (bf::is_regular_file(dir_entry)) {
const std::string& relative,
const std::string& expected) {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bf::path file_path = root_path / pkgid / relative;
if (!bf::exists(file_path)) {
LOG(ERROR) << file_path << " doesn't exist";
void ValidatePackageFS(const std::string& pkgid,
const std::vector<std::string>& appids) {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bf::path package_path = root_path / pkgid;
bf::path data_path = package_path / "data";
bf::path shared_path = package_path / "shared";
bf::path manifest_path =
bf::path(getUserManifestPath(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+ kTestUserId, false)) / (pkgid + ".xml");
ASSERT_TRUE(bf::exists(manifest_path));
for (auto& appid : appids) {
void PackageCheckCleanup(const std::string& pkgid,
const std::vector<std::string>&) {
bf::path root_path = ci::GetRootAppPath(
- false, tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ false, kTestUserId);
bf::path package_path = root_path / pkgid;
ASSERT_FALSE(bf::exists(package_path));
bf::path manifest_path =
bf::path(getUserManifestPath(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+ kTestUserId, false)) / (pkgid + ".xml");
ASSERT_FALSE(bf::exists(manifest_path));
// backups should not exist
void ValidatePackage(const std::string& pkgid,
const std::vector<std::string>& appids) {
ASSERT_TRUE(ci::QueryIsPackageInstalled(
- pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ pkgid, ci::GetRequestMode(kTestUserId),
+ kTestUserId));
ValidatePackageFS(pkgid, appids);
}
void CheckPackageNonExistance(const std::string& pkgid,
const std::vector<std::string>& appids) {
ASSERT_FALSE(ci::QueryIsPackageInstalled(
- pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ pkgid, ci::GetRequestMode(kTestUserId),
+ kTestUserId));
PackageCheckCleanup(pkgid, appids);
}
ci::AppInstaller::Result Install(const bf::path& path,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-i", path.c_str()};
+ const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result MountInstall(const bf::path& path,
PackageType type, RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-w", path.c_str()};
+ const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result Uninstall(const std::string& pkgid,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-d", pkgid.c_str()};
+ const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
LOG(ERROR) << "Failed to install application. Cannot perform RDS";
return ci::AppInstaller::Result::UNKNOWN;
}
- const char* argv[] = {"", "-r", delta_dir.c_str()};
+ const char* argv[] = {"", "-r", delta_dir.c_str(), "-u",
+ kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result Clear(const std::string& pkgid,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-c", pkgid.c_str()};
+ const char* argv[] = {"", "-c", pkgid.c_str(), "-u", kTestUserIdStr.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()};
+ const char* argv[] = {"", "-A", pkgid.c_str(), "-u", kTestUserIdStr.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()};
+ const char* argv[] = {"", "-D", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
ci::AppInstaller::Result Recover(const bf::path& recovery_file,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-b", recovery_file.c_str()};
+ const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
+ kTestUserIdStr.c_str()};
TestPkgmgrInstaller pkgmgr_installer;
std::unique_ptr<ci::AppQueryInterface> query_interface =
CreateQueryInterface();
explicit SmokeEnvironment(const bf::path& home) : home_(home) {
}
void SetUp() override {
- bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
bs::error_code error;
}
}
void TearDown() override {
- bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
bs::error_code error;
// Check delta modifications
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
ci::AppInstaller::Result::OK);
ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
- ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ ci::GetRequestMode(kTestUserId),
+ kTestUserId));
}
TEST_F(SmokeTest, DisablePkg) {
ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
ci::AppInstaller::Result::OK);
ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid,
- ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ ci::GetRequestMode(kTestUserId),
+ kTestUserId));
ValidatePackageFS(pkgid, {appid});
}
ASSERT_EQ(Install(path, PackageType::WGT),
ci::AppInstaller::Result::OK);
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bs::error_code error;
bf::create_directory(root_path / pkgid / "data" / "dir", error);
ASSERT_FALSE(error);
// Check delta modifications
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
- backend_crash.Run("-i", path.string());
+ backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
std::string pkgid = "smokeapp09";
bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
RemoveAllRecoveryFiles();
- Subprocess backend_test("/usr/bin/wgt-backend");
- backend_test.Run("-i", path_old.string());
- ASSERT_EQ(backend_test.Wait(), 0);
+ ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
- backend_crash.Run("-i", path_new.string());
+ backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
std::string pkgid = "smokeapp10";
// Check delta modifications
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- const char* directory = getenv("HOME");
- if (!directory) {
- LOG(ERROR) << "Cannot get $HOME value";
- return 1;
- }
+ bf::path directory =
+ bf::path("/home") / tzplatform_getenv(TZ_SYS_DEFAULT_USER);
testing::AddGlobalTestEnvironment(
new common_installer::SmokeEnvironment(directory));
return RUN_ALL_TESTS();