• 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(RegisterAppStateCallback, void(const sptr<IAppStateCallback> &callback));
51     MOCK_METHOD0(StopAllProcess, void());
52     MOCK_CONST_METHOD0(QueryAppSpawnConnectionState, SpawnConnectionState());
53     MOCK_CONST_METHOD2(AddAppDeathRecipient, void(const pid_t pid, const sptr<AppDeathRecipient> &appDeathRecipient));
54     MOCK_METHOD1(KillProcessByAbilityToken, void(const sptr<IRemoteObject> &token));
55     MOCK_METHOD1(KillProcessesByUserId, void(int32_t userId));
56     MOCK_METHOD5(AbilityBehaviorAnalysis,
57         void(const sptr<IRemoteObject> &token, const sptr<IRemoteObject> &preToken, const int32_t visibility,
58             const int32_t perceptibility, const int32_t connectionState));
59     MOCK_METHOD1(AddAbilityStageDone, void(const int32_t recordId));
60     MOCK_METHOD0(GetConfiguration, std::shared_ptr<Configuration>());
61 
Post()62     void Post()
63     {
64         if (currentCount_ > 1) {
65             currentCount_--;
66         } else {
67             lock_.Post();
68             currentCount_ = count_;
69         }
70     }
71     // for mock function return int32_t
Post4Int()72     int32_t Post4Int()
73     {
74         if (currentCount_ > 1) {
75             currentCount_--;
76         } else {
77             lock_.Post();
78             currentCount_ = count_;
79         }
80         return 0;
81     }
82 
Wait()83     void Wait()
84     {
85         lock_.Wait();
86     }
87 
SetWaitCount(const int waitCount)88     void SetWaitCount(const int waitCount)
89     {
90         count_ = waitCount;
91         currentCount_ = waitCount;
92     }
93 
OpenAppSpawnConnection()94     int32_t OpenAppSpawnConnection() override
95     {
96         return 0;
97     }
98 
99 private:
100     Semaphore lock_;
101     int32_t count_ = 1;
102     int32_t currentCount_ = 1;
103 };
104 }  // namespace AppExecFwk
105 }  // namespace OHOS
106 #endif  // MOCK_OHOS_ABILITY_RUNTIME_MOCK_APP_MGR_SERVICE_INNER_H
107