1 /* 2 * Copyright (c) 2025 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 "runtime.h" 20 21 namespace OHOS { 22 namespace AbilityRuntime { 23 using ExtensionApiCheckCallback = std::function<bool(const std::string &classNam, const std::string &fileName)>; 24 class MockRuntime : public Runtime { 25 public: MockRuntime()26 MockRuntime() {} ~MockRuntime()27 ~MockRuntime() {} 28 GetLanguage()29 Language GetLanguage() const override 30 { 31 return language_; 32 } 33 StartDebugMode(const DebugOption debugOption)34 void StartDebugMode(const DebugOption debugOption) override {} SetDebugOption(const DebugOption debugOption)35 void SetDebugOption(const DebugOption debugOption) override {} StartLocalDebugMode(bool isDebugFromLocal)36 void StartLocalDebugMode(bool isDebugFromLocal) override {} DumpHeapSnapshot(bool isPrivate)37 void DumpHeapSnapshot(bool isPrivate) override {} DumpCpuProfile()38 void DumpCpuProfile() override {} DestroyHeapProfiler()39 void DestroyHeapProfiler() override {} ForceFullGC()40 void ForceFullGC() override {} ForceFullGC(uint32_t tid)41 void ForceFullGC(uint32_t tid) override {} 42 void DumpHeapSnapshot(uint32_t tid, bool isFullGC, bool isBinary = false) override {} AllowCrossThreadExecution()43 void AllowCrossThreadExecution() override {} GetHeapPrepare()44 void GetHeapPrepare() override {} NotifyApplicationState(bool isBackground)45 void NotifyApplicationState(bool isBackground) override {} SuspendVM(uint32_t tid)46 bool SuspendVM(uint32_t tid) override { return false; } ResumeVM(uint32_t tid)47 void ResumeVM(uint32_t tid) override {} PreloadSystemModule(const std::string & moduleName)48 void PreloadSystemModule(const std::string& moduleName) override {} PreloadMainAbility(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,const std::string & srcEntrance)49 void PreloadMainAbility(const std::string& moduleName, const std::string& srcPath, 50 const std::string& hapPath, bool isEsMode, const std::string& srcEntrance) override {} PreloadModule(const std::string & moduleName,const std::string & srcPath,const std::string & hapPath,bool isEsMode,bool useCommonTrunk)51 void PreloadModule(const std::string& moduleName, const std::string& srcPath, 52 const std::string& hapPath, bool isEsMode, bool useCommonTrunk) override {} FinishPreload()53 void FinishPreload() override {} LoadRepairPatch(const std::string & patchFile,const std::string & baseFile)54 bool LoadRepairPatch(const std::string& patchFile, const std::string& baseFile) override { return false; } NotifyHotReloadPage()55 bool NotifyHotReloadPage() override { return false; } UnLoadRepairPatch(const std::string & patchFile)56 bool UnLoadRepairPatch(const std::string& patchFile) override { return false; } RegisterQuickFixQueryFunc(const std::map<std::string,std::string> & moduleAndPath)57 void RegisterQuickFixQueryFunc(const std::map<std::string, std::string>& moduleAndPath) override {} StartProfiler(const DebugOption debugOption)58 void StartProfiler(const DebugOption debugOption) override {} SetDeviceDisconnectCallback(const std::function<bool ()> & cb)59 void SetDeviceDisconnectCallback(const std::function<bool()> &cb) override {} SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate)60 void SetModuleLoadChecker(const std::shared_ptr<ModuleCheckerDelegate> moduleCheckerDelegate) const override 61 { 62 loadCheckerFlag_ = true; 63 } SetExtensionApiCheckCallback(const std::function<bool (const std::string & className,const std::string & fileName)> & cb)64 void SetExtensionApiCheckCallback( 65 const std::function<bool(const std::string &className, const std::string &fileName)> &cb) override 66 { 67 extensionApiCheckerFlag_ = true; 68 checkLibraryPermissionCallback_ = cb; 69 } SetLanguage(Language language)70 void SetLanguage(Language language) 71 { 72 language_ = language; 73 } GetExtensionApiCheckCallback()74 ExtensionApiCheckCallback GetExtensionApiCheckCallback() const 75 { 76 return checkLibraryPermissionCallback_; 77 } 78 private: 79 Runtime::Language language_ = Runtime::Language::ETS; 80 ExtensionApiCheckCallback checkLibraryPermissionCallback_ {nullptr}; 81 mutable bool loadCheckerFlag_ = false; 82 bool extensionApiCheckerFlag_ = false; 83 }; 84 } // namespace AbilityRuntime 85 } // namespace OHOS 86 #endif // MOCK_RUNTIME_H