Fix WgtArchiveInfo
[platform/core/appfw/wgt-backend.git] / src / unit_tests / wgt_smoke_utils.h
1 // Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef UNIT_TESTS_WGT_SMOKE_UTILS_H_
6 #define UNIT_TESTS_WGT_SMOKE_UTILS_H_
7
8 #include <common/app_installer.h>
9 #include <common/pkgmgr_interface.h>
10 #include <common/step/configuration/step_fail.h>
11 #include <unit_tests/common/smoke_utils.h>
12
13 #include <memory>
14 #include <string>
15 #include <vector>
16
17 #include "hybrid/hybrid_installer.h"
18 #include "wgt/wgt_installer.h"
19 #include "wgt/utils/wgt_app_query_interface.h"
20
21 namespace smoke_test {
22
23 bool ValidatePackage(const std::string& pkgid,
24     const std::vector<std::string>& appids,
25     const TestParameters& params);
26
27 bool ValidateExternalPackage(const std::string& pkgid,
28     const std::vector<std::string>& appids,
29     const TestParameters& params);
30
31 bool ValidateExtendedPackage(const std::string& pkgid,
32     const std::vector<std::string>& appids,
33     const TestParameters& params);
34
35 extern const bf::path kSmokePackagesDirectory;
36
37 class WgtBackendInterface: public BackendInterface {
38  public:
39   using BackendInterface::BackendInterface;
40
41 // private:
42   AppQueryInterfacePtr CreateQueryInterface() const override;
43   AppInstallerPtr CreateInstaller(
44       common_installer::PkgMgrPtr pkgmgr) const override;
45   AppInstallerPtr CreateFailExpectedInstaller(
46       common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
47 };
48
49 class HybridBackendInterface: public BackendInterface {
50  public:
51   using BackendInterface::BackendInterface;
52
53   AppQueryInterfacePtr CreateQueryInterface() const override;
54   AppInstallerPtr CreateInstaller(
55       common_installer::PkgMgrPtr pkgmgr) const override;
56   AppInstallerPtr CreateFailExpectedInstaller(
57       common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
58 };
59
60 #ifdef OVERRIDE_STEPS_BLOCK
61 #undef OVERRIDE_STEPS_BLOCK
62 #endif
63 #define OVERRIDE_STEPS_BLOCK(TYPE, STEPS)                                      \
64   void STEPS() override {                                                      \
65     TYPE::STEPS();                                                             \
66     if (fail_at_ > -1)                                                         \
67       AddStepAtIndex<common_installer::configuration::StepFail>(fail_at_);     \
68     else                                                                       \
69       AddStep<common_installer::configuration::StepFail>();                    \
70   }                                                                            \
71
72 class FailExpectedWgtInstaller : public wgt::WgtInstaller {
73  public:
74   explicit FailExpectedWgtInstaller(
75       common_installer::PkgMgrPtr pkgmgr, int fail_at)
76       : wgt::WgtInstaller(pkgmgr), fail_at_(fail_at) { }
77
78  private:
79   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, InstallSteps)
80   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UpdateSteps)
81   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UninstallSteps)
82   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReinstallSteps)
83   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DeltaSteps)
84   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MoveSteps)
85   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverySteps)
86   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountInstallSteps)
87   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountUpdateSteps)
88   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectInstallSteps)
89   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectUpdateSteps)
90   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialInstallSteps)
91   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialUpdateSteps)
92   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, PartialUninstallSteps)
93   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateInstallSteps)
94   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateUninstallSteps)
95   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DisablePkgSteps)
96   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, EnablePkgSteps)
97   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MigrateExtImgSteps)
98   OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverDBSteps)
99
100   int fail_at_;
101 };
102
103 class FailExpectedHybridInstaller : public hybrid::HybridInstaller {
104  public:
105   explicit FailExpectedHybridInstaller(
106       common_installer::PkgMgrPtr pkgmgr, int fail_at)
107       : hybrid::HybridInstaller(pkgmgr), fail_at_(fail_at) { }
108
109  private:
110   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, InstallSteps)
111   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UpdateSteps)
112   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UninstallSteps)
113   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReinstallSteps)
114   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DeltaSteps)
115   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MoveSteps)
116   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverySteps)
117   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountInstallSteps)
118   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountUpdateSteps)
119   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectInstallSteps)
120   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectUpdateSteps)
121   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialInstallSteps)
122   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialUpdateSteps)
123   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, PartialUninstallSteps)
124   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateInstallSteps)
125   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateUninstallSteps)
126   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DisablePkgSteps)
127   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, EnablePkgSteps)
128   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MigrateExtImgSteps)
129   OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverDBSteps)
130
131   int fail_at_;
132 };
133
134 #ifdef OVERRIDE_STEPS_BLOCK
135 #undef OVERRIDE_STEPS_BLOCK
136 #endif
137 #define OVERRIDE_STEPS_BLOCK(STEPS)                                            \
138   void STEPS() override {                                                      \
139     wgt::WgtInstaller::STEPS();                                                \
140     if (crash_at_ > -1)                                                        \
141       AddStepAtIndex<StepCrash>(crash_at_, type_);                             \
142     else if (step_name_.size())                                                \
143       AddStepAfter<StepCrash>(step_name_, type_);                              \
144     else                                                                       \
145       AddStep<StepCrash>(type_);                                               \
146   }                                                                            \
147
148 class CrashWgtInstaller : public wgt::WgtInstaller {
149  public:
150   explicit CrashWgtInstaller(common_installer::PkgMgrPtr pkgmgr, int crash_at,
151       std::string step_name, CrashStepType type) :
152           wgt::WgtInstaller(pkgmgr), crash_at_(crash_at),
153           step_name_(step_name), type_(type) { }
154
155  private:
156   OVERRIDE_STEPS_BLOCK(InstallSteps)
157   OVERRIDE_STEPS_BLOCK(UpdateSteps)
158   OVERRIDE_STEPS_BLOCK(UninstallSteps)
159   OVERRIDE_STEPS_BLOCK(ReinstallSteps)
160   OVERRIDE_STEPS_BLOCK(DeltaSteps)
161   OVERRIDE_STEPS_BLOCK(MoveSteps)
162   OVERRIDE_STEPS_BLOCK(RecoverySteps)
163   OVERRIDE_STEPS_BLOCK(MountInstallSteps)
164   OVERRIDE_STEPS_BLOCK(MountUpdateSteps)
165   OVERRIDE_STEPS_BLOCK(ManifestDirectInstallSteps)
166   OVERRIDE_STEPS_BLOCK(ManifestDirectUpdateSteps)
167   OVERRIDE_STEPS_BLOCK(ManifestPartialInstallSteps)
168   OVERRIDE_STEPS_BLOCK(ManifestPartialUpdateSteps)
169   OVERRIDE_STEPS_BLOCK(PartialUninstallSteps)
170   OVERRIDE_STEPS_BLOCK(ReadonlyUpdateInstallSteps)
171   OVERRIDE_STEPS_BLOCK(ReadonlyUpdateUninstallSteps)
172   OVERRIDE_STEPS_BLOCK(DisablePkgSteps)
173   OVERRIDE_STEPS_BLOCK(EnablePkgSteps)
174   OVERRIDE_STEPS_BLOCK(MigrateExtImgSteps)
175   OVERRIDE_STEPS_BLOCK(RecoverDBSteps)
176
177   int crash_at_;
178   std::string step_name_;
179   CrashStepType type_;
180 };
181
182 }  // namespace smoke_test
183
184
185 #endif  // UNIT_TESTS_WGT_SMOKE_UTILS_H_