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 } PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)88 void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath, 89 const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) override 90 { 91 return; 92 } PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)93 void PreloadModule(const std::string& moduleName, const std::string& srcPath, 94 const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override 95 { 96 return; 97 } 98 bool RunScript(const std::string& path, const std::string& hapPath, bool useCommonChunk = false) 99 { 100 return true; 101 } Initialize(const Options & options)102 bool Initialize(const Options& options) 103 { 104 return true; 105 } Deinitialize()106 void Deinitialize() {} 107 napi_value LoadJsBundle(const std::string& path, const std::string& hapPath, bool useCommonChunk = false) 108 { 109 return nullptr; 110 } LoadJsModule(const std::string & path,const std::string & hapPath)111 napi_value LoadJsModule(const std::string& path, const std::string& hapPath) 112 { 113 return nullptr; 114 } 115 bool LoadScript(const std::string& path, std::vector<uint8_t>* buffer = nullptr, bool isBundle = false) 116 { 117 return true; 118 } RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)119 void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override 120 { 121 return; 122 } SetDeviceDisconnectCallback(const std::function<bool ()> & cb)123 void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override 124 { 125 return; 126 } 127 StartProfiler(const DebugOption debugOption)128 void StartProfiler(const DebugOption debugOption) override {} 129 DumpHeapSnapshot(uint32_t tid,bool isFullGC)130 void DumpHeapSnapshot(uint32_t tid, bool isFullGC) override {} ForceFullGC(uint32_t tid)131 void ForceFullGC(uint32_t tid) override {} UpdatePkgContextInfoJson(std::string moduleName,std::string hapPath,std::string packageName)132 void UpdatePkgContextInfoJson(std::string moduleName, std::string hapPath, std::string packageName) override {} 133 public: 134 Language language; 135 }; 136 } // namespace AbilityRuntime 137 } // namespace OHOS 138 #endif // MOCK_RUNTIME_H 139