Fix smoke-test functions for rollback cases 00/218100/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 19 Nov 2019 09:35:50 +0000 (18:35 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 6 Dec 2019 08:11:58 +0000 (17:11 +0900)
The custom step cannot be added outside of installer, because steps are
initialized when Run() invoked.
(If some step added outside of installer, that step will be executed at
 first, ignoring original steps)
This patch defines a new virtual function creating overridden installer
object which is fail at the end of steps or specific stage.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-installers/+/218093

Change-Id: I99de606909e5a673d45545dd05095ee0f4111a51
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/unit_tests/smoke_utils.cc
src/unit_tests/smoke_utils.h

index 817cdbc..14965f9 100644 (file)
@@ -61,14 +61,26 @@ WgtBackendInterface::CreateInstaller(ci::PkgMgrPtr pkgmgr) const {
   return AppInstallerPtr(new wgt::WgtInstaller(pkgmgr));
 }
 
-WgtBackendInterface::AppQueryInterfacePtr
+WgtBackendInterface::AppInstallerPtr
+WgtBackendInterface::CreateFailExpectedInstaller(
+    ci::PkgMgrPtr pkgmgr, int fail_at) const {
+  return AppInstallerPtr(new FailExpectedWgtInstaller(pkgmgr, fail_at));
+}
+
+HybridBackendInterface::AppQueryInterfacePtr
 HybridBackendInterface::CreateQueryInterface() const {
   return AppQueryInterfacePtr(new wgt::WgtAppQueryInterface());
 }
 
-WgtBackendInterface::AppInstallerPtr
+HybridBackendInterface::AppInstallerPtr
 HybridBackendInterface::CreateInstaller(ci::PkgMgrPtr pkgmgr) const {
   return AppInstallerPtr(new hybrid::HybridInstaller(pkgmgr));
 }
 
+HybridBackendInterface::AppInstallerPtr
+HybridBackendInterface::CreateFailExpectedInstaller(
+    ci::PkgMgrPtr pkgmgr, int fail_at) const {
+  return AppInstallerPtr(new FailExpectedHybridInstaller(pkgmgr, fail_at));
+}
+
 }  // namespace smoke_test
index e6ecbae..7b22263 100644 (file)
@@ -5,14 +5,17 @@
 #ifndef UNIT_TESTS_SMOKE_UTILS_H_
 #define UNIT_TESTS_SMOKE_UTILS_H_
 
-#include <common/pkgmgr_interface.h>
 #include <common/app_installer.h>
+#include <common/pkgmgr_interface.h>
+#include <common/step/configuration/step_fail.h>
 #include <unit_tests/common/smoke_utils.h>
 
 #include <memory>
 #include <string>
 #include <vector>
 
+#include "hybrid/hybrid_installer.h"
+#include "wgt/wgt_installer.h"
 #include "wgt/wgt_app_query_interface.h"
 
 namespace smoke_test {
@@ -39,6 +42,8 @@ class WgtBackendInterface: public BackendInterface {
   AppQueryInterfacePtr CreateQueryInterface() const override;
   AppInstallerPtr CreateInstaller(
       common_installer::PkgMgrPtr pkgmgr) const override;
+  AppInstallerPtr CreateFailExpectedInstaller(
+      common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
 };
 
 class HybridBackendInterface: public BackendInterface {
@@ -49,6 +54,79 @@ class HybridBackendInterface: public BackendInterface {
   AppQueryInterfacePtr CreateQueryInterface() const override;
   AppInstallerPtr CreateInstaller(
       common_installer::PkgMgrPtr pkgmgr) const override;
+  AppInstallerPtr CreateFailExpectedInstaller(
+      common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
+};
+
+#define OVERRIDE_STEPS_BLOCK(TYPE, STEPS)                                      \
+  void STEPS() override {                                                      \
+    TYPE::STEPS();                                                             \
+    if (fail_at_ > -1)                                                         \
+      AddStepAtIndex<common_installer::configuration::StepFail>(fail_at_);     \
+    else                                                                       \
+      AddStep<common_installer::configuration::StepFail>();                    \
+  }                                                                            \
+
+class FailExpectedWgtInstaller : public wgt::WgtInstaller {
+ public:
+  explicit FailExpectedWgtInstaller(
+      common_installer::PkgMgrPtr pkgmgr, int fail_at)
+      : wgt::WgtInstaller(pkgmgr), fail_at_(fail_at) { }
+
+ private:
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, InstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DeltaSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MoveSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverySteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverDBSteps)
+
+  int fail_at_;
+};
+
+class FailExpectedHybridInstaller : public hybrid::HybridInstaller {
+ public:
+  explicit FailExpectedHybridInstaller(
+      common_installer::PkgMgrPtr pkgmgr, int fail_at)
+      : hybrid::HybridInstaller(pkgmgr), fail_at_(fail_at) { }
+
+ private:
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, InstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DeltaSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MoveSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverySteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverDBSteps)
+
+  int fail_at_;
 };
 
 }  // namespace smoke_test