1 /* 2 * Copyright (c) 2021-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 #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, void()); 28 MOCK_METHOD0(ScheduleBackgroundApplication, void()); 29 MOCK_METHOD0(ScheduleTerminateApplication, void()); 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_METHOD3(ScheduleLaunchAbility, void(const AbilityInfo&, const sptr<IRemoteObject>&, 36 const std::shared_ptr<AAFwk::Want>&)); 37 MOCK_METHOD1(ScheduleCleanAbility, void(const sptr<IRemoteObject>&)); 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_METHOD1(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&)); 43 MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want& want, const std::string& moduleName)); 44 MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string& bundleName, 45 const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 46 MOCK_METHOD2(ScheduleNotifyHotReloadPage, int32_t(const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 47 MOCK_METHOD3(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string& bundleName, 48 const sptr<IQuickFixCallback>& callback, const int32_t recordId)); 49 MOCK_METHOD1(ScheduleNotifyAppFault, int32_t(const FaultData &faultData)); 50 Post()51 void Post() 52 { 53 lock_.Post(); 54 } 55 Wait()56 void Wait() 57 { 58 lock_.Wait(); 59 } 60 ShrinkMemory(const int level)61 void ShrinkMemory(const int level) 62 { 63 shrinkLevel_ = level; 64 lock_.Post(); 65 } 66 GetShrinkLevel()67 int GetShrinkLevel() const 68 { 69 return shrinkLevel_; 70 } 71 LaunchApplication(const AppLaunchData & launchData,const Configuration & config)72 void LaunchApplication(const AppLaunchData& launchData, const Configuration& config) 73 { 74 launchData_ = launchData; 75 lock_.Post(); 76 } 77 CompareAppLaunchData(const AppLaunchData & launchData)78 bool CompareAppLaunchData(const AppLaunchData& launchData) const 79 { 80 if (launchData_.GetApplicationInfo().name != launchData.GetApplicationInfo().name) { 81 return false; 82 } 83 if (launchData_.GetProfile().GetName() != launchData.GetProfile().GetName()) { 84 return false; 85 } 86 if (launchData_.GetProcessInfo().GetProcessName() != launchData.GetProcessInfo().GetProcessName()) { 87 return false; 88 } 89 return true; 90 } 91 LaunchAbility(const AbilityInfo & info,const sptr<IRemoteObject> &)92 void LaunchAbility(const AbilityInfo& info, const sptr<IRemoteObject>&) 93 { 94 abilityInfo_ = info; 95 lock_.Post(); 96 } 97 CompareAbilityInfo(const AbilityInfo & info)98 bool CompareAbilityInfo(const AbilityInfo& info) const 99 { 100 return (info.name == abilityInfo_.name); 101 } 102 ProfileChanged(const Profile & profile)103 void ProfileChanged(const Profile& profile) 104 { 105 profile_ = profile; 106 lock_.Post(); 107 } 108 CompareProfile(const Profile & profile)109 bool CompareProfile(const Profile& profile) const 110 { 111 return (profile.GetName() == profile_.GetName()); 112 } 113 114 private: 115 Semaphore lock_; 116 volatile int shrinkLevel_ = 0; 117 AppLaunchData launchData_; 118 AbilityInfo abilityInfo_; 119 Profile profile_; 120 }; 121 } // namespace AppExecFwk 122 } // namespace OHOS 123 #endif // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APPLICATION_H 124