1 /*
2  * Copyright (c) 2024 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 SYSTEM_ABILITY_MOCK_H
17 #define SYSTEM_ABILITY_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include <memory>
21 #include <refbase.h>
22 #include "hilog/log.h"
23 #include "iremote_object.h"
24 #include "iservice_registry.h"
25 
26 #ifdef REGISTER_SYSTEM_ABILITY_BY_ID
27 #undef REGISTER_SYSTEM_ABILITY_BY_ID
28 #endif
29 #define REGISTER_SYSTEM_ABILITY_BY_ID(a, b, c)
30 
31 #define DECLARE_SYSTEM_ABILITY(className)                                                                              \
32 public:                                                                                                                \
33     virtual std::string GetClassName()                                                                                 \
34     {                                                                                                                  \
35         return #className;                                                                                             \
36     }
37 namespace OHOS {
38 class SystemAbility;
39 class ISystemAbilityManagerMock;
40 class SystemAbilityMock {
41 public:
42     SystemAbilityMock() = default;
43     ~SystemAbilityMock() = default;
44 
45     MOCK_METHOD(void, SystemAbilityCtor, (const int32_t serviceId, bool runOnCreate));
46     MOCK_METHOD(void, SystemAbilityCtor, (bool runOnCreate));
47     MOCK_METHOD(void, SystemAbilityDtor, ());
48     MOCK_METHOD(bool, Publish, (SystemAbility * systemAbility));
49     MOCK_METHOD(bool, AddSystemAbilityListener, (int32_t systemAbilityId));
50 };
51 
52 // SystemAbility: foundation/systemabilitymgr/safwk/interfaces/innerkits/safwk/system_ability.h
53 class SystemAbility {
54 public:
55     static void RegisterMock(std::shared_ptr<SystemAbilityMock> &mock);
56 
57 protected:
58     explicit SystemAbility(bool runOnCreate = false);
59     SystemAbility(const int32_t serviceId, bool runOnCreate = false);
60     virtual ~SystemAbility();
61     virtual bool Publish(SystemAbility *systemAbility);
62     virtual void OnDump();
63     virtual void OnStart();
64     virtual void OnStop();
65     virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId);
66     bool AddSystemAbilityListener(int32_t systemAbilityId);
67 };
68 } // namespace OHOS
69 #endif // SYSTEM_ABILITY_MOCK_H
70