1 /* 2 * Copyright (c) 2021-2024 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 #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_APPLICATION_H 16 #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APPLICATION_H 17 18 #include "gmock/gmock.h" 19 #include "semaphore_ex.h" 20 #include "app_scheduler_host.h" 21 #include "app_malloc_info.h" 22 23 namespace OHOS { 24 namespace AppExecFwk { 25 class MockApplication : public AppSchedulerHost { 26 public: 27 MOCK_METHOD0(ScheduleForegroundApplication, bool()); 28 MOCK_METHOD0(ScheduleBackgroundApplication, void()); 29 MOCK_METHOD1(ScheduleTerminateApplication, void(bool)); 30 MOCK_METHOD1(ScheduleShrinkMemory, void(const int)); 31 MOCK_METHOD0(ScheduleLowMemory, void()); 32 MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level)); 33 MOCK_METHOD2(ScheduleHeapMemory, void(const int32_t pid, OHOS::AppExecFwk::MallocInfo &mallocInfo)); 34 MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData&, const Configuration& config)); 35 MOCK_METHOD4(ScheduleLaunchAbility, void(const AbilityInfo&, const sptr<IRemoteObject>&, 36 const std::shared_ptr<AAFwk::Want>&, int32_t)); 37 MOCK_METHOD2(ScheduleCleanAbility, void(const sptr<IRemoteObject>&, bool)); 38 MOCK_METHOD1(ScheduleProfileChanged, void(const Profile&)); 39 MOCK_METHOD1(ScheduleConfigurationUpdated, void(const Configuration&)); 40 MOCK_METHOD0(ScheduleProcessSecurityExit, void()); 41 MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo&)); 42 MOCK_METHOD2(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&, const std::string&)); 43 MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); 44 MOCK_METHOD1(SchedulePrepareTerminate, void(const std::string &moduleName)); 45 MOCK_METHOD2(ScheduleNewProcessRequest, void(const AAFwk::Want& want, const std::string& moduleName)); 46 MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, 47 const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 48 MOCK_METHOD2(ScheduleNotifyHotReloadPage, int32_t(const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 49 MOCK_METHOD3(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string& bundleName, 50 const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 51 MOCK_METHOD1(ScheduleNotifyAppFault, int32_t(const FaultData &faultData)); 52 MOCK_METHOD1(AttachAppDebug, void(bool isDebugFromLocal)); 53 MOCK_METHOD0(DetachAppDebug, void()); 54 MOCK_METHOD2(SetAppWaitingDebug, int32_t(const std::string &bundleName, bool isPersist)); 55 MOCK_METHOD0(CancelAppWaitingDebug, int32_t()); 56 MOCK_METHOD1(GetWaitingDebugApp, int32_t(std::vector<std::string> &debugInfoList)); 57 MOCK_METHOD1(IsWaitingDebugApp, bool(const std::string &bundleName)); 58 MOCK_METHOD0(ClearNonPersistWaitingDebugFlag, void()); 59 MOCK_METHOD1(ScheduleDumpIpcStart, int32_t(std::string &result)); 60 MOCK_METHOD1(ScheduleDumpIpcStop, int32_t(std::string &result)); 61 MOCK_METHOD1(ScheduleDumpIpcStat, int32_t(std::string &result)); 62 MOCK_METHOD0(IsMemorySizeSufficent, bool()); 63 MOCK_METHOD1(ScheduleJsHeapMemory, void(OHOS::AppExecFwk::JsHeapDumpInfo &info)); 64 MOCK_METHOD1(ScheduleDumpFfrt, int32_t(std::string& result)); 65 MOCK_METHOD1(SetWatchdogBackgroundStatus, void(bool status)); 66 MOCK_METHOD0(ScheduleClearPageStack, void()); 67 MOCK_METHOD0(ScheduleCacheProcess, void()); 68 Post()69 void Post() 70 { 71 lock_.Post(); 72 } 73 Wait()74 void Wait() 75 { 76 lock_.Wait(); 77 } 78 ShrinkMemory(const int level)79 void ShrinkMemory(const int level) 80 { 81 shrinkLevel_ = level; 82 lock_.Post(); 83 } 84 GetShrinkLevel()85 int GetShrinkLevel() const 86 { 87 return shrinkLevel_; 88 } 89 LaunchApplication(const AppLaunchData & launchData,const Configuration & config)90 void LaunchApplication(const AppLaunchData& launchData, const Configuration& config) 91 { 92 launchData_ = launchData; 93 lock_.Post(); 94 } 95 CompareAppLaunchData(const AppLaunchData & launchData)96 bool CompareAppLaunchData(const AppLaunchData& launchData) const 97 { 98 if (launchData_.GetApplicationInfo().name != launchData.GetApplicationInfo().name) { 99 return false; 100 } 101 if (launchData_.GetProfile().GetName() != launchData.GetProfile().GetName()) { 102 return false; 103 } 104 if (launchData_.GetProcessInfo().GetProcessName() != launchData.GetProcessInfo().GetProcessName()) { 105 return false; 106 } 107 return true; 108 } 109 LaunchAbility(const AbilityInfo & info,const sptr<IRemoteObject> &)110 void LaunchAbility(const AbilityInfo& info, const sptr<IRemoteObject>&) 111 { 112 abilityInfo_ = info; 113 lock_.Post(); 114 } 115 CompareAbilityInfo(const AbilityInfo & info)116 bool CompareAbilityInfo(const AbilityInfo& info) const 117 { 118 return (info.name == abilityInfo_.name); 119 } 120 ProfileChanged(const Profile & profile)121 void ProfileChanged(const Profile& profile) 122 { 123 profile_ = profile; 124 lock_.Post(); 125 } 126 CompareProfile(const Profile & profile)127 bool CompareProfile(const Profile& profile) const 128 { 129 return (profile.GetName() == profile_.GetName()); 130 } 131 ScheduleChangeAppGcState(int32_t state)132 int32_t ScheduleChangeAppGcState(int32_t state) override 133 { 134 return 0; 135 } 136 137 private: 138 Semaphore lock_; 139 volatile int shrinkLevel_ = 0; 140 AppLaunchData launchData_; 141 AbilityInfo abilityInfo_; 142 Profile profile_; 143 }; 144 } // namespace AppExecFwk 145 } // namespace OHOS 146 #endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APPLICATION_H 147