• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef MOCK_RUNTIME_H
17 #define MOCK_RUNTIME_H
18 
19 #include <gmock/gmock.h>
20 #include "js_runtime.h"
21 
22 namespace OHOS {
23 namespace AbilityRuntime {
24 class MockRuntime : public Runtime {
25 public:
26     const int DEFAULT_LANGUAGE = 100;
27     MockRuntime() = default;
28     ~MockRuntime() = default;
29 
GetLanguage()30     Language GetLanguage() const override
31     {
32         return static_cast<Runtime::Language>(DEFAULT_LANGUAGE);
33     }
34 
StartDebugMode(const DebugOption debugOption)35     void StartDebugMode(const DebugOption debugOption) override
36     {
37         return;
38     }
39 
FinishPreload()40     void FinishPreload() override {}
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)41     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override
42     {
43         return true;
44     }
NotifyHotReloadPage()45     bool NotifyHotReloadPage() override
46     {
47         return true;
48     }
SuspendVM(uint32_t tid)49     bool SuspendVM(uint32_t tid) override
50     {
51         return true;
52     }
ResumeVM(uint32_t tid)53     void ResumeVM(uint32_t tid) override {}
UnLoadRepairPatch(const std::string & patchFile)54     bool UnLoadRepairPatch(const std::string& patchFile) override
55     {
56         return true;
57     }
DumpHeapSnapshot(bool isPrivate)58     void DumpHeapSnapshot(bool isPrivate) override
59     {
60         return;
61     }
DumpCpuProfile()62     void DumpCpuProfile() override
63     {
64         return;
65     }
DestroyHeapProfiler()66     void DestroyHeapProfiler() override
67     {
68         return;
69     }
ForceFullGC()70     void ForceFullGC() override
71     {
72         return;
73     }
AllowCrossThreadExecution()74     void AllowCrossThreadExecution() override
75     {
76         return;
77     }
GetHeapPrepare()78     void GetHeapPrepare() override
79     {
80         return;
81     }
NotifyApplicationState(bool isBackground)82     void NotifyApplicationState(bool isBackground) override
83     {
84         return;
85     }
PreloadSystemModule(const std::string & moduleName)86     void PreloadSystemModule(const std::string& moduleName) override
87     {
88         return;
89     }
90     bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
91     {
92         return true;
93     }
Initialize(const Options & options)94     bool Initialize(const Options& options)
95     {
96         return true;
97     }
Deinitialize()98     void Deinitialize() {}
99     napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
100     {
101         return nullptr;
102     }
LoadJsModule(const std::string & path,const std::string & hapPath)103     napi_value LoadJsModule(const std::string& path, const std::string& hapPath)
104     {
105         return nullptr;
106     }
107     bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
108     {
109         return true;
110     }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)111     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override
112     {
113         return;
114     }
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)115     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override
116     {
117         return;
118     }
119 
StartProfiler(const DebugOption debugOption)120     void StartProfiler(const DebugOption debugOption) override
121     {
122         return;
123     }
124 
DoCleanWorkAfterStageCleaned()125     void DoCleanWorkAfterStageCleaned() override {}
DumpHeapSnapshot(uint32_t tid,bool isFullGC)126     void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}
ForceFullGC(uint32_t tid)127     void ForceFullGC(uint32_t tid) override {}
UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)128     void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}
129 public:
130     Language language;
131 };
132 
133 class MockRuntimeJS : public Runtime {
134 public:
135     const int DEFAULT_LANGUAGE = 0;
136     MockRuntimeJS() = default;
137     ~MockRuntimeJS() = default;
138 
GetLanguage()139     Language GetLanguage() const override
140     {
141         return static_cast<Runtime::Language>(DEFAULT_LANGUAGE);
142     }
143 
StartDebugMode(const DebugOption debugOption)144     void StartDebugMode(const DebugOption debugOption) override
145     {
146         return;
147     }
148 
FinishPreload()149     void FinishPreload() override {}
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)150     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override
151     {
152         return true;
153     }
NotifyHotReloadPage()154     bool NotifyHotReloadPage() override
155     {
156         return true;
157     }
SuspendVM(uint32_t tid)158     bool SuspendVM(uint32_t tid) override
159     {
160         return true;
161     }
ResumeVM(uint32_t tid)162     void ResumeVM(uint32_t tid) override {}
UnLoadRepairPatch(const std::string & patchFile)163     bool UnLoadRepairPatch(const std::string& patchFile) override
164     {
165         return true;
166     }
DumpHeapSnapshot(bool isPrivate)167     void DumpHeapSnapshot(bool isPrivate) override
168     {
169         return;
170     }
DumpCpuProfile()171     void DumpCpuProfile() override
172     {
173         return;
174     }
DestroyHeapProfiler()175     void DestroyHeapProfiler() override
176     {
177         return;
178     }
ForceFullGC()179     void ForceFullGC() override
180     {
181         return;
182     }
AllowCrossThreadExecution()183     void AllowCrossThreadExecution() override
184     {
185         return;
186     }
GetHeapPrepare()187     void GetHeapPrepare() override
188     {
189         return;
190     }
NotifyApplicationState(bool isBackground)191     void NotifyApplicationState(bool isBackground) override
192     {
193         return;
194     }
PreloadSystemModule(const std::string & moduleName)195     void PreloadSystemModule(const std::string& moduleName) override
196     {
197         return;
198     }
199     bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
200     {
201         return true;
202     }
Initialize(const Options & options)203     bool Initialize(const Options& options)
204     {
205         return true;
206     }
Deinitialize()207     void Deinitialize() {}
208     napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
209     {
210         return nullptr;
211     }
LoadJsModule(const std::string & path,const std::string & hapPath)212     napi_value LoadJsModule(const std::string& path, const std::string& hapPath)
213     {
214         return nullptr;
215     }
216     bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
217     {
218         return true;
219     }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)220     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override
221     {
222         return;
223     }
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)224     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override
225     {
226         return;
227     }
228 
StartProfiler(const DebugOption debugOption)229     void StartProfiler(const DebugOption debugOption) override
230     {
231         return;
232     }
233 
DoCleanWorkAfterStageCleaned()234     void DoCleanWorkAfterStageCleaned() override {}
DumpHeapSnapshot(uint32_t tid,bool isFullGC)235     void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}
ForceFullGC(uint32_t tid)236     void ForceFullGC(uint32_t tid) override {}
UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)237     void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}
238 public:
239     Language language;
240 };
241 } // namespace AbilityRuntime
242 } // namespace OHOS
243 #endif // MOCK_RUNTIME_H
244