• 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 "hilog_wrapper.h"
21 #include "semaphore_ex.h"
22 #include "app_mgr_service_inner.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_METHOD5(LoadAbility,
34         void(const sptr<IRemoteObject>& token, const sptr<IRemoteObject>& preToken,
35             const std::shared_ptr<AbilityInfo>& abilityInfo, const std::shared_ptr<ApplicationInfo>& appInfo,
36             const std::shared_ptr<AAFwk::Want>& want));
37     MOCK_METHOD2(AttachApplication, void(const pid_t pid, const sptr<IAppScheduler>& app));
38     MOCK_METHOD1(ApplicationForegrounded, void(const int32_t recordId));
39     MOCK_METHOD1(ApplicationBackgrounded, void(const int32_t recordId));
40     MOCK_METHOD1(ApplicationTerminated, void(const int32_t recordId));
41     MOCK_METHOD2(UpdateAbilityState, void(const sptr<IRemoteObject>& token, const AbilityState state));
42     MOCK_METHOD2(TerminateAbility, void(const sptr<IRemoteObject>& token, bool clearMissionFlag));
43     MOCK_METHOD2(UpdateApplicationInfoInstalled, int(const std::string&, const int uid));
44     MOCK_METHOD1(KillApplication, int32_t(const std::string& bundleName));
45     MOCK_METHOD2(KillApplicationByUid, int(const std::string&, const int uid));
46     MOCK_METHOD1(AbilityTerminated, void(const sptr<IRemoteObject>& token));
47     MOCK_METHOD3(ClearUpApplicationData, void(const std::string&, const int32_t, const pid_t));
48     MOCK_METHOD1(IsBackgroundRunningRestricted, int32_t(const std::string&));
49     MOCK_METHOD1(GetAllRunningProcesses, int32_t(std::vector<RunningProcessInfo>&));
50     MOCK_METHOD1(GetAllRenderProcesses, int32_t(std::vector<RenderProcessInfo>&));
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));
StartSpecifiedAbility(const AAFwk::Want & want,const AppExecFwk::AbilityInfo & abilityInfo)64     void StartSpecifiedAbility(const AAFwk::Want &want, const AppExecFwk::AbilityInfo &abilityInfo)
65     {}
66 
Post()67     void Post()
68     {
69         if (currentCount_ > 1) {
70             currentCount_--;
71         } else {
72             lock_.Post();
73             currentCount_ = count_;
74         }
75     }
76     // for mock function return int32_t
Post4Int()77     int32_t Post4Int()
78     {
79         if (currentCount_ > 1) {
80             currentCount_--;
81         } else {
82             lock_.Post();
83             currentCount_ = count_;
84         }
85         return 0;
86     }
87 
Wait()88     void Wait()
89     {
90         lock_.Wait();
91     }
92 
SetWaitCount(const int waitCount)93     void SetWaitCount(const int waitCount)
94     {
95         count_ = waitCount;
96         currentCount_ = waitCount;
97     }
98 
OpenAppSpawnConnection()99     int32_t OpenAppSpawnConnection() override
100     {
101         return 0;
102     }
103 
104 private:
105     Semaphore lock_;
106     int32_t count_ = 1;
107     int32_t currentCount_ = 1;
108 };
109 }  // namespace AppExecFwk
110 }  // namespace OHOS
111 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
112