• 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 
16 #ifndef MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
17 #define MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
18 
19 #include "gmock/gmock.h"
20 #include "semaphore_ex.h"
21 #include "app_mgr_service_inner.h"
22 #include "param.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class MockAppMgrServiceInner : public AppMgrServiceInner {
27 public:
MockAppMgrServiceInner()28     MockAppMgrServiceInner() : lock_(0)
29     {}
~MockAppMgrServiceInner()30     virtual ~MockAppMgrServiceInner()
31     {}
32 
33     MOCK_METHOD4(LoadAbility, void(std::shared_ptr<AbilityInfo> abilityInfo, std::shared_ptr<ApplicationInfo> appInfo,
34             std::shared_ptr<AAFwk::Want> want, std::shared_ptr<AbilityRuntime::LoadParam> loadParam));
35     MOCK_METHOD2(AttachApplication, void(const pid_t pid, const sptr<IAppScheduler>& app));
36     MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId));
37     MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId));
38     MOCK_METHOD1(ApplicationTerminated, void(const int32_t recordId));
39     MOCK_METHOD2(UpdateAbilityState, void(const sptr<IRemoteObject>& token, const AbilityState state));
40     MOCK_METHOD2(TerminateAbility, void(const sptr<IRemoteObject>& token, bool clearMissionFlag));
41     MOCK_METHOD2(UpdateApplicationInfoInstalled, int(const std::string&, const int uid));
42     MOCK_METHOD2(KillApplication, int32_t(const std::string& bundleName, const bool clearPageStack));
43     MOCK_METHOD3(KillApplicationByUid, int(const std::string&, const int uid, const std::string&));
44     MOCK_METHOD1(AbilityTerminated, void(const sptr<IRemoteObject>& token));
45     MOCK_METHOD5(ClearUpApplicationData,
46         int32_t(const std::string&, const int32_t, const pid_t, int32_t appCloneIndex, int32_t userId));
47     MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&));
48     MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector<RunningProcessInfo>&));
49     MOCK_METHOD1(GetAllRunningInstanceKeysBySelf, int32_t(std::vector<std::string> &instanceKeys));
50     MOCK_METHOD3(GetAllRunningInstanceKeysByBundleName, int32_t(const std::string &bundleName,
51         std::vector<std::string> &instanceKeys, int32_t userId));
52     MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector<RenderProcessInfo>&));
53     MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector<ChildProcessInfo>&));
54     MOCK_METHOD1(RegisterAppStateCallback, void(const sptr<IAppStateCallback>& callback));
55     MOCK_METHOD0(StopAllProcess, void());
56     MOCK_CONST_METHOD0(QueryAppSpawnConnectionState, SpawnConnectionState());
57     MOCK_CONST_METHOD2(AddAppDeathRecipient, void(const pid_t pid, const sptr<AppDeathRecipient>& appDeathRecipient));
58     MOCK_METHOD1(KillProcessByAbilityToken, void(const sptr<IRemoteObject>& token));
59     MOCK_METHOD1(KillProcessesByUserId, void(int32_t userId));
60     MOCK_METHOD5(AbilityBehaviorAnalysis,
61         void(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& preToken, const int32_t visibility,
62             const int32_t perceptibility, const int32_t connectionState));
63     MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId));
64     MOCK_METHOD0(GetConfiguration, std::shared_ptr<Configuration>());
65     MOCK_METHOD2(IsSharedBundleRunning, bool(const std::string &bundleName, uint32_t versionCode));
66     MOCK_METHOD3(GetBundleNameByPid, int32_t(const int pid, std::string &bundleName, int32_t &uid));
67     MOCK_METHOD3(StartChildProcess, int32_t(const pid_t hostPid, pid_t &childPid, const ChildProcessRequest &request));
68     MOCK_METHOD1(GetChildProcessInfoForSelf, int32_t(ChildProcessInfo &info));
69     MOCK_METHOD4(PreloadApplication, int32_t(const std::string&, int32_t, AppExecFwk::PreloadMode, int32_t));
70     MOCK_METHOD4(StartNativeChildProcess, int32_t(const pid_t hostPid, const std::string &libName,
71         int32_t childProcessCount, const sptr<IRemoteObject> &callback));
StartSpecifiedAbility(const AAFwk::Want &,const AppExecFwk::AbilityInfo &,int32_t)72     void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t)
73     {}
74 
Post()75     void Post()
76     {
77         if (currentCount_ > 1) {
78             currentCount_--;
79         } else {
80             lock_.Post();
81             currentCount_ = count_;
82         }
83     }
84     // for mock function return int32_t
Post4Int()85     int32_t Post4Int()
86     {
87         if (currentCount_ > 1) {
88             currentCount_--;
89         } else {
90             lock_.Post();
91             currentCount_ = count_;
92         }
93         return 0;
94     }
95 
Wait()96     void Wait()
97     {
98         lock_.Wait();
99     }
100 
SetWaitCount(const int32_t waitCount)101     void SetWaitCount(const int32_t waitCount)
102     {
103         count_ = waitCount;
104         currentCount_ = waitCount;
105     }
106 
OpenAppSpawnConnection()107     int32_t OpenAppSpawnConnection() override
108     {
109         return 0;
110     }
111 
112 private:
113     Semaphore lock_;
114     int32_t count_ = 1;
115     int32_t currentCount_ = 1;
116 };
117 }  // namespace AppExecFwk
118 }  // namespace OHOS
119 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
120