• 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_METHOD1(KillApplication, int32_t(const std::string& bundleName));
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(GetAllRenderProcesses, int32_t(std::vector<RenderProcessInfo>&));
50     MOCK_METHOD1(GetAllChildrenProcesses, int(std::vector<ChildProcessInfo>&));
51     MOCK_METHOD1(RegisterAppStateCallback, void(const sptr<IAppStateCallback>& callback));
52     MOCK_METHOD0(StopAllProcess, void());
53     MOCK_CONST_METHOD0(QueryAppSpawnConnectionState, SpawnConnectionState());
54     MOCK_CONST_METHOD2(AddAppDeathRecipient, void(const pid_t pid, const sptr<AppDeathRecipient>& appDeathRecipient));
55     MOCK_METHOD1(KillProcessByAbilityToken, void(const sptr<IRemoteObject>& token));
56     MOCK_METHOD1(KillProcessesByUserId, void(int32_t userId));
57     MOCK_METHOD5(AbilityBehaviorAnalysis,
58         void(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& preToken, const int32_t visibility,
59             const int32_t perceptibility, const int32_t connectionState));
60     MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId));
61     MOCK_METHOD0(GetConfiguration, std::shared_ptr<Configuration>());
62     MOCK_METHOD2(IsSharedBundleRunning, bool(const std::string &bundleName, uint32_t versionCode));
63     MOCK_METHOD3(GetBundleNameByPid, int32_t(const int pid, std::string &bundleName, int32_t &uid));
64     MOCK_METHOD3(StartChildProcess, int32_t(const pid_t hostPid, pid_t &childPid, const ChildProcessRequest &request));
65     MOCK_METHOD1(GetChildProcessInfoForSelf, int32_t(ChildProcessInfo &info));
66     MOCK_METHOD4(PreloadApplication, int32_t(const std::string&, int32_t, AppExecFwk::PreloadMode, int32_t));
67     MOCK_METHOD4(StartNativeChildProcess, int32_t(const pid_t hostPid, const std::string &libName,
68         int32_t childProcessCount, const sptr<IRemoteObject> &callback));
StartSpecifiedAbility(const AAFwk::Want &,const AppExecFwk::AbilityInfo &,int32_t)69     void StartSpecifiedAbility(const AAFwk::Want&, const AppExecFwk::AbilityInfo&, int32_t)
70     {}
71 
Post()72     void Post()
73     {
74         if (currentCount_ > 1) {
75             currentCount_--;
76         } else {
77             lock_.Post();
78             currentCount_ = count_;
79         }
80     }
81     // for mock function return int32_t
Post4Int()82     int32_t Post4Int()
83     {
84         if (currentCount_ > 1) {
85             currentCount_--;
86         } else {
87             lock_.Post();
88             currentCount_ = count_;
89         }
90         return 0;
91     }
92 
Wait()93     void Wait()
94     {
95         lock_.Wait();
96     }
97 
SetWaitCount(const int32_t waitCount)98     void SetWaitCount(const int32_t waitCount)
99     {
100         count_ = waitCount;
101         currentCount_ = waitCount;
102     }
103 
OpenAppSpawnConnection()104     int32_t OpenAppSpawnConnection() override
105     {
106         return 0;
107     }
108 
109 private:
110     Semaphore lock_;
111     int32_t count_ = 1;
112     int32_t currentCount_ = 1;
113 };
114 }  // namespace AppExecFwk
115 }  // namespace OHOS
116 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
117