ASSERT_EQ(i , 1);
}
+BackendInterface::CommandResult BackendInterface::RunInstallersWithPkgmgr(
+ ci::PkgMgrPtr pkgmgr) const {
+ std::list<AppInstallerPtr> installers;
+ for (int i = 0; i < pkgmgr->GetRequestInfoCount(); i++) {
+ AppInstallerPtr installer;
+ if (mode_ == RequestResult::FAIL && i == pkgmgr->GetRequestInfoCount() - 1)
+ installer = factory_->CreateFailExpectedInstaller(i, pkgmgr);
+ else
+ installer = factory_->CreateInstaller(i, pkgmgr);
+ if (!installer)
+ LOG(ERROR) << "Failed to create installer";
+ else
+ installers.emplace_back(std::move(installer));
+ }
+
+ // FIXME: I think we should not implement this logic here...
+ CommandResult result = CommandResult::OK;
+ std::list<AppInstallerPtr>::iterator it(installers.begin());
+ for (; it != installers.end(); ++it) {
+ result = (*it)->Process();
+ if (result != CommandResult::OK)
+ break;
+ }
+ if (it != installers.end() && result == CommandResult::ERROR) {
+ do {
+ CommandResult ret = (*it)->Undo();
+ if (ret != CommandResult::OK && ret != CommandResult::ERROR)
+ result = CommandResult::UNDO_ERROR;
+ } while (it-- != installers.begin());
+ } else {
+ --it;
+ do {
+ if ((*it)->Clean() != CommandResult::OK)
+ result = CommandResult::CLEANUP_ERROR;
+ } while (it-- != installers.begin());
+ }
+ return result;
+}
+
+BackendInterface::CommandResult BackendInterface::CallBackendWithRunner(
+ int argc, const char* argv[]) const {
+ TestPkgmgrInstaller pkgmgr_installer;
+ auto pkgmgr = ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
+ &pkgmgr_installer);
+ if (!pkgmgr) {
+ LOG(ERROR) << "Failed to initialize pkgmgr interface";
+ return BackendInterface::CommandResult::UNKNOWN;
+ }
+ return RunInstallersWithPkgmgr(pkgmgr);
+}
+
+BackendInterface::CommandResult BackendInterface::Install(
+ const std::vector<bf::path>& paths) const {
+ std::vector<const char*> argv;
+ argv.emplace_back("");
+ argv.emplace_back("-i");
+ for (const auto& p : paths)
+ argv.emplace_back(p.string().c_str());
+ return CallBackendWithRunner(argv.size(), argv.data());
+}
+
+BackendInterface::CommandResult BackendInterface::InstallSuccess(
+ const std::vector<bf::path>& paths) const {
+ RequestResult tmp_mode = mode_;
+ RequestResult &original_mode = const_cast<RequestResult&>(mode_);
+ original_mode = RequestResult::NORMAL;
+ if (Install(paths) != BackendInterface::CommandResult::OK) {
+ LOG(ERROR) << "Failed to install application. Cannot update";
+ return BackendInterface::CommandResult::UNKNOWN;
+ }
+ original_mode = tmp_mode;
+ return BackendInterface::CommandResult::OK;
+}
+
BackendInterface::CommandResult BackendInterface::RunInstallerWithPkgrmgr(
ci::PkgMgrPtr pkgmgr) const {
std::unique_ptr<ci::AppInstaller> installer;
bool TouchFile(const boost::filesystem::path& path);
+class SmokeInstallerFactory {
+ public:
+ using AppInstallerPtr = std::unique_ptr<common_installer::AppInstaller>;
+ virtual AppInstallerPtr CreateInstaller(
+ int idx, common_installer::PkgMgrPtr pkgmgr) const = 0;
+ virtual AppInstallerPtr CreateFailExpectedInstaller(
+ int idx, common_installer::PkgMgrPtr pkgmgr, int fail_at = -1) const = 0;
+};
+
class BackendInterface {
public:
using CommandResult = common_installer::AppInstaller::Result;
+ using SmokeInstallerFactoryPtr = std::unique_ptr<SmokeInstallerFactory>;
explicit BackendInterface(std::string uid,
RequestResult mode = RequestResult::NORMAL)
: uid_str_(uid), mode_(mode) {}
+ explicit BackendInterface(SmokeInstallerFactoryPtr factory,
+ std::string uid,
+ RequestResult mode = RequestResult::NORMAL)
+ : factory_(std::move(factory)), uid_str_(uid), mode_(mode) {}
virtual ~BackendInterface() {}
void TestRollbackAfterEachStep(int argc, const char* argv[],
void CrashAfterEachStep(std::vector<std::string>* args,
std::function<bool(int iter)> validator,
PackageType type) const;
+ CommandResult Install(const std::vector<bf::path>& paths) const;
+ CommandResult InstallSuccess(const std::vector<bf::path>& paths) const;
CommandResult Install(const boost::filesystem::path& path) const;
CommandResult InstallPreload(const boost::filesystem::path& path) const;
CommandResult InstallWithStorage(const boost::filesystem::path& path,
protected:
CommandResult CallBackend(int argc, const char* argv[]) const;
+ CommandResult CallBackendWithRunner(int argc, const char* argv[]) const;
using AppQueryInterfacePtr =
std::unique_ptr<common_installer::AppQueryInterface>;
using AppInstallerPtr = std::unique_ptr<common_installer::AppInstaller>;
+ SmokeInstallerFactoryPtr factory_;
std::string uid_str_;
RequestResult mode_;
common_installer::PkgMgrPtr pkgmgr) const = 0;
virtual AppInstallerPtr CreateFailExpectedInstaller(
common_installer::PkgMgrPtr pkgmgr, int fail_at = -1) const = 0;
+ CommandResult RunInstallersWithPkgmgr(
+ common_installer::PkgMgrPtr pkgmgr) const;
};
class SmokeTestHelperRunner {