• 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 <gtest/gtest.h>
20 
21 #include "js_runtime.h"
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 class MockRuntime : public Runtime {
26 public:
27     const int DEFAULT_LANGUAGE = 100;
28     MockRuntime() = default;
29     ~MockRuntime() = default;
30 
GetLanguage()31     Language GetLanguage() const override
32     {
33         return static_cast<Runtime::Language>(DEFAULT_LANGUAGE);
34     }
35 
StartDebugMode(const DebugOption debugOption)36     void StartDebugMode(const DebugOption debugOption) override {}
37 
FinishPreload()38     void FinishPreload() override {}
LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)39     bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override
40     {
41         return true;
42     }
NotifyHotReloadPage()43     bool NotifyHotReloadPage() override
44     {
45         return true;
46     }
SuspendVM(uint32_t tid)47     bool SuspendVM(uint32_t tid) override
48     {
49         return true;
50     }
ResumeVM(uint32_t tid)51     void ResumeVM(uint32_t tid) override {}
UnLoadRepairPatch(const std::string & patchFile)52     bool UnLoadRepairPatch(const std::string& patchFile) override
53     {
54         return true;
55     }
DumpHeapSnapshot(bool isPrivate)56     void DumpHeapSnapshot(bool isPrivate) override
57     {
58         return;
59     }
DumpCpuProfile()60     void DumpCpuProfile() override
61     {
62         return;
63     }
DestroyHeapProfiler()64     void DestroyHeapProfiler() override
65     {
66         return;
67     }
ForceFullGC()68     void ForceFullGC() override
69     {
70         return;
71     }
AllowCrossThreadExecution()72     void AllowCrossThreadExecution() override
73     {
74         return;
75     }
GetHeapPrepare()76     void GetHeapPrepare() override
77     {
78         return;
79     }
NotifyApplicationState(bool isBackground)80     void NotifyApplicationState(bool isBackground) override
81     {
82         return;
83     }
PreloadSystemModule(const std::string & moduleName)84     void PreloadSystemModule(const std::string& moduleName) override
85     {
86         return;
87     }
88     bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
89     {
90         return true;
91     }
Initialize(const Options & options)92     bool Initialize(const Options& options)
93     {
94         return true;
95     }
Deinitialize()96     void Deinitialize() {}
97     napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false)
98     {
99         return nullptr;
100     }
LoadJsModule(const std::string & path,const std::string & hapPath)101     napi_value LoadJsModule(const std::string& path, const std::string& hapPath)
102     {
103         return nullptr;
104     }
105     bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false)
106     {
107         return true;
108     }
RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)109     void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override
110     {
111         return;
112     }
SetDeviceDisconnectCallback(const std::function<bool ()> & cb)113     void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override
114     {
115         return;
116     }
117 
StartProfiler(const DebugOption debugOption)118     void StartProfiler(const DebugOption debugOption) override {}
119 
DumpHeapSnapshot(uint32_t tid,bool isFullGC)120     void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {}
ForceFullGC(uint32_t tid)121     void ForceFullGC(uint32_t tid) override {}
UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)122     void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {}
123 public:
124     Language language;
125 };
126 } // namespace AbilityRuntime
127 } // namespace OHOS
128 #endif // MOCK_RUNTIME_H
129