• 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     }
PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)90     void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath,
91         const std::string& hapPath,  bool isEsMode, const std::string& srcEntrance) override
92     {
93         return;
94     }
PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)95     void PreloadModule(const std::string& moduleName, const std::string& srcPath,
96         const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override
97     {
98         return;
99     }
100     bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
101     {
102         return true;
103     }
Initialize(const Options & options)104     bool Initialize(const Options& options)
105     {
106         return true;
107     }
Deinitialize()108     void Deinitialize() {}
109     napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
110     {
111         return nullptr;
112     }
LoadJsModule(const std::string & path,const std::string & hapPath)113     napi_value LoadJsModule(const std::string& path, const std::string& hapPath)
114     {
115         return nullptr;
116     }
117     bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
118     {
119         return true;
120     }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)121     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override
122     {
123         return;
124     }
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)125     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override
126     {
127         return;
128     }
129 
StartProfiler(const DebugOption debugOption)130     void StartProfiler(const DebugOption debugOption) override
131     {
132         return;
133     }
134 
DoCleanWorkAfterStageCleaned()135     void DoCleanWorkAfterStageCleaned() override {}
136     void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) override {}
ForceFullGC(uint32_t tid)137     void ForceFullGC(uint32_t tid) override {}
138 public:
139     Language language;
140 };
141 
142 class MockRuntimeJS : public Runtime {
143 public:
144     const int DEFAULT_LANGUAGE = 0;
145     MockRuntimeJS() = default;
146     ~MockRuntimeJS() = default;
147 
GetLanguage()148     Language GetLanguage() const override
149     {
150         return static_cast<Runtime::Language>(DEFAULT_LANGUAGE);
151     }
152 
StartDebugMode(const DebugOption debugOption)153     void StartDebugMode(const DebugOption debugOption) override
154     {
155         return;
156     }
157 
FinishPreload()158     void FinishPreload() override {}
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)159     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override
160     {
161         return true;
162     }
NotifyHotReloadPage()163     bool NotifyHotReloadPage() override
164     {
165         return true;
166     }
SuspendVM(uint32_t tid)167     bool SuspendVM(uint32_t tid) override
168     {
169         return true;
170     }
ResumeVM(uint32_t tid)171     void ResumeVM(uint32_t tid) override {}
UnLoadRepairPatch(const std::string & patchFile)172     bool UnLoadRepairPatch(const std::string& patchFile) override
173     {
174         return true;
175     }
DumpHeapSnapshot(bool isPrivate)176     void DumpHeapSnapshot(bool isPrivate) override
177     {
178         return;
179     }
DumpCpuProfile()180     void DumpCpuProfile() override
181     {
182         return;
183     }
DestroyHeapProfiler()184     void DestroyHeapProfiler() override
185     {
186         return;
187     }
ForceFullGC()188     void ForceFullGC() override
189     {
190         return;
191     }
AllowCrossThreadExecution()192     void AllowCrossThreadExecution() override
193     {
194         return;
195     }
GetHeapPrepare()196     void GetHeapPrepare() override
197     {
198         return;
199     }
NotifyApplicationState(bool isBackground)200     void NotifyApplicationState(bool isBackground) override
201     {
202         return;
203     }
PreloadSystemModule(const std::string & moduleName)204     void PreloadSystemModule(const std::string& moduleName) override
205     {
206         return;
207     }
PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)208     void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath,
209         const std::string& hapPath,  bool isEsMode, const std::string& srcEntrance) override
210     {
211         return;
212     }
PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)213     void PreloadModule(const std::string& moduleName, const std::string& srcPath,
214         const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override
215     {
216         return;
217     }
218     bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
219     {
220         return true;
221     }
Initialize(const Options & options)222     bool Initialize(const Options& options)
223     {
224         return true;
225     }
Deinitialize()226     void Deinitialize() {}
227     napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
228     {
229         return nullptr;
230     }
LoadJsModule(const std::string & path,const std::string & hapPath)231     napi_value LoadJsModule(const std::string& path, const std::string& hapPath)
232     {
233         return nullptr;
234     }
235     bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
236     {
237         return true;
238     }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)239     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override
240     {
241         return;
242     }
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)243     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override
244     {
245         return;
246     }
247 
StartProfiler(const DebugOption debugOption)248     void StartProfiler(const DebugOption debugOption) override
249     {
250         return;
251     }
252 
DoCleanWorkAfterStageCleaned()253     void DoCleanWorkAfterStageCleaned() override {}
254     void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) override {}
ForceFullGC(uint32_t tid)255     void ForceFullGC(uint32_t tid) override {}
256 public:
257     Language language;
258 };
259 } // namespace AbilityRuntime
260 } // namespace OHOS
261 #endif // MOCK_RUNTIME_H
262