• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 
22 namespace OHOS {
23 namespace AppExecFwk {
24 class MockApplication : public AppSchedulerHost {
25 public:
26     MOCK_METHOD0(ScheduleForegroundApplication, void());
27     MOCK_METHOD0(ScheduleBackgroundApplication, void());
28     MOCK_METHOD0(ScheduleTerminateApplication, void());
29     MOCK_METHOD1(ScheduleShrinkMemory, void(const int));
30     MOCK_METHOD0(ScheduleLowMemory, void());
31     MOCK_METHOD1(ScheduleMemoryLevel, void(int32_t level));
32     MOCK_METHOD2(ScheduleLaunchApplication, void(const AppLaunchData &, const Configuration &config));
33     MOCK_METHOD3(ScheduleLaunchAbility, void(const AbilityInfo &, const sptr<IRemoteObject> &,
34         const std::shared_ptr<AAFwk::Want> &));
35     MOCK_METHOD1(ScheduleCleanAbility, void(const sptr<IRemoteObject> &));
36     MOCK_METHOD1(ScheduleProfileChanged, void(const Profile &));
37     MOCK_METHOD1(ScheduleConfigurationUpdated, void(const Configuration &));
38     MOCK_METHOD0(ScheduleProcessSecurityExit, void());
39     MOCK_METHOD1(ScheduleAbilityStage, void(const HapModuleInfo &));
40     MOCK_METHOD1(ScheduleUpdateApplicationInfoInstalled, void(const ApplicationInfo&));
41     MOCK_METHOD2(ScheduleAcceptWant, void(const AAFwk::Want &want, const std::string &moduleName));
42     MOCK_METHOD3(ScheduleNotifyLoadRepairPatch, int32_t(const std::string &bundleName,
43         const sptr<IQuickFixCallback> &callback, const int32_t recordId));
44     MOCK_METHOD2(ScheduleNotifyHotReloadPage, int32_t(const sptr<IQuickFixCallback> &callback, const int32_t recordId));
45     MOCK_METHOD3(ScheduleNotifyUnLoadRepairPatch, int32_t(const std::string &bundleName,
46         const sptr<IQuickFixCallback> &callback, const int32_t recordId));
47 
Post()48     void Post()
49     {
50         lock_.Post();
51     }
52 
Wait()53     void Wait()
54     {
55         lock_.Wait();
56     }
57 
ShrinkMemory(const int level)58     void ShrinkMemory(const int level)
59     {
60         shrinkLevel_ = level;
61         lock_.Post();
62     }
63 
GetShrinkLevel()64     int GetShrinkLevel() const
65     {
66         return shrinkLevel_;
67     }
68 
LaunchApplication(const AppLaunchData & launchData,const Configuration & config)69     void LaunchApplication(const AppLaunchData &launchData, const Configuration &config)
70     {
71         launchData_ = launchData;
72         lock_.Post();
73     }
74 
CompareAppLaunchData(const AppLaunchData & launchData)75     bool CompareAppLaunchData(const AppLaunchData &launchData) const
76     {
77         if (launchData_.GetApplicationInfo().name != launchData.GetApplicationInfo().name) {
78             return false;
79         }
80         if (launchData_.GetProfile().GetName() != launchData.GetProfile().GetName()) {
81             return false;
82         }
83         if (launchData_.GetProcessInfo().GetProcessName() != launchData.GetProcessInfo().GetProcessName()) {
84             return false;
85         }
86         return true;
87     }
88 
LaunchAbility(const AbilityInfo & info,const sptr<IRemoteObject> &)89     void LaunchAbility(const AbilityInfo &info, const sptr<IRemoteObject> &)
90     {
91         abilityInfo_ = info;
92         lock_.Post();
93     }
94 
CompareAbilityInfo(const AbilityInfo & info)95     bool CompareAbilityInfo(const AbilityInfo &info) const
96     {
97         return (info.name == abilityInfo_.name);
98     }
99 
ProfileChanged(const Profile & profile)100     void ProfileChanged(const Profile &profile)
101     {
102         profile_ = profile;
103         lock_.Post();
104     }
105 
CompareProfile(const Profile & profile)106     bool CompareProfile(const Profile &profile) const
107     {
108         return (profile.GetName() == profile_.GetName());
109     }
110 
111 private:
112     Semaphore lock_;
113     volatile int shrinkLevel_ = 0;
114     AppLaunchData launchData_;
115     AbilityInfo abilityInfo_;
116     Profile profile_;
117 };
118 }  // namespace AppExecFwk
119 }  // namespace OHOS
120 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APPLICATION_H
121