#include <pkgmgrinfo_basic.h>
+#include <filesystem>
#include <gtest/gtest.h>
#include <iostream>
#include <memory>
class UnifiedInstallerFactoryTest : public TestFixture {
public:
- UnifiedInstallerFactoryTest() : TestFixture(std::make_unique<Mocks>()) {}
+ UnifiedInstallerFactoryTest() : TestFixture(std::make_unique<Mocks>()) {
+ char buffer[PATH_MAX];
+ ssize_t len = readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
+ EXPECT_NE(len, -1);
+ if (len != -1) {
+ buffer[len] = '\0';
+ std::filesystem::path p(buffer);
+ executable_dir_ = p.parent_path().string();
+ } else {
+ executable_dir_ = "";
+ }
+ }
virtual ~UnifiedInstallerFactoryTest() {}
virtual void SetUp() {}
virtual void TestDown() {}
+
+ const std::string& ExecutableDir() {
+ return executable_dir_;
+ }
+
+ private:
+ std::string executable_dir_;
};
class TestPkgmgrInstaller : public common_installer::PkgmgrInstallerInterface {
}
TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromFilename) {
- std::vector<std::string> arguments =
- {"unified-backend", "-b", "test_samples/tpk-recovery-123456",
- "test_samples/wgt-recovery-123456"};
+ std::vector<std::string> arguments = {
+ "unified-backend", "-b",
+ ExecutableDir() + "/test_samples/tpk-recovery-123456",
+ ExecutableDir() + "/test_samples/wgt-recovery-123456"
+ };
std::vector<char*> argv;
for (const auto& arg : arguments)
argv.push_back(const_cast<char*>(
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/tpk-recovery-123456"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/tpk-recovery-123456"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
Return(PMINFO_R_OK)));
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/wgt-recovery-123456"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/wgt-recovery-123456"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
}
TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromXml) {
- std::vector<std::string> arguments =
- {"unified-backend", "-y", "test_samples/test-resource-pkg"};
+ std::vector<std::string> arguments = {
+ "unified-backend", "-y",
+ ExecutableDir() + "/test_samples/test-resource-pkg"
+ };
std::vector<char*> argv;
for (const auto& arg : arguments)
argv.push_back(const_cast<char*>(
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/test-resource-pkg"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/test-resource-pkg"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
getUserManifestPath(_, _)).
- WillRepeatedly(DoAll(Return(".")));
+ WillRepeatedly(DoAll(Return("")));
TestPkgmgrInstaller installer;
EXPECT_CALL(GetMock<GumMock>(),
}
TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_WrongRecoveryFile) {
- std::vector<std::string> arguments =
- {"unified-backend", "-b", "test_samples/kkk-recovery-123456",
- "test_samples/tgt-recovery-123456"};
+ std::vector<std::string> arguments = {
+ "unified-backend", "-b",
+ ExecutableDir() + "/test_samples/kkk-recovery-123456",
+ ExecutableDir() + "/test_samples/tgt-recovery-123456"
+ };
std::vector<char*> argv;
for (const auto& arg : arguments)
argv.push_back(const_cast<char*>(
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/kkk-recovery-123456"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/kkk-recovery-123456"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
Return(PMINFO_R_OK)));
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/tgt-recovery-123456"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/tgt-recovery-123456"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),
}
TEST_F(UnifiedInstallerFactoryTest, CreateInstaller_GetPkgTypeFromPkgFile) {
- std::vector<std::string> arguments =
- {"unified-backend", "-i", "test_samples/test-tpk-pkg.tpk",
- "test_samples/test-wgt-pkg.wgt"};
+ std::vector<std::string> arguments = {
+ "unified-backend", "-i",
+ ExecutableDir() + "/test_samples/test-tpk-pkg.tpk",
+ ExecutableDir() + "/test_samples/test-wgt-pkg.wgt"
+ };
std::vector<char*> argv;
for (const auto& arg : arguments)
argv.push_back(const_cast<char*>(
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/test-tpk-pkg.tpk"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/test-tpk-pkg.tpk"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle1)),
Return(PMINFO_R_OK)));
EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
pkgmgrinfo_pkginfo_get_usr_all_pkginfo(
- StrEq("test_samples/test-wgt-pkg.wgt"), _, _)).
+ StrEq(ExecutableDir() + "/test_samples/test-wgt-pkg.wgt"), _, _)).
WillOnce(DoAll(
SetArgPointee<2>(
reinterpret_cast<pkgmgrinfo_pkginfo_h>(handle2)),