1 /* 2 * Copyright (c) 2021 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_SYSTEM_ABILITY_H 17 #define MOCK_OHOS_ABILITY_RUNTIME_SYSTEM_ABILITY_H 18 19 #include "hilog/log.h" 20 #include "iremote_object.h" 21 22 namespace OHOS { 23 #define REGISTER_SYSTEM_ABILITY_BY_ID(a, b, c) 24 #define REGISTER_SYSTEM_ABILITY(abilityClassName, abilityId, runOnCreate) 25 #define DECLEAR_SYSTEM_ABILITY(className) 26 27 static constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0xD001100, "MockSystemAbility"}; 28 29 class SystemAbility { 30 public: MakeAndRegisterAbility(SystemAbility *)31 static bool MakeAndRegisterAbility(SystemAbility *) 32 { 33 return true; 34 } 35 36 bool AddSystemAbilityListener(int32_t systemAbilityId); 37 38 protected: OnStart()39 virtual void OnStart() 40 { 41 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility OnStart called"); 42 } 43 OnStop()44 virtual void OnStop() 45 { 46 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility OnStop called"); 47 } 48 OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)49 virtual void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) 50 { 51 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility OnAddSystemAbility called"); 52 } 53 OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)54 virtual void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) 55 { 56 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility OnRemoveSystemAbility called"); 57 } 58 Publish(sptr<IRemoteObject> systemAbility)59 bool Publish(sptr<IRemoteObject> systemAbility) 60 { 61 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility Publish called"); 62 systemAbility.ForceSetRefPtr(nullptr); 63 // For test just mock to return true 64 return true; 65 } 66 67 SystemAbility(bool runOnCreate = false) 68 { 69 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility default Creator called %d", runOnCreate); 70 } 71 72 SystemAbility(const int32_t serviceId, bool runOnCreate = false) 73 { 74 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility Creator called %d", runOnCreate); 75 } 76 ~SystemAbility()77 virtual ~SystemAbility() 78 { 79 HiviewDFX::HiLog::Debug(LABEL, "Mock SystemAbility Destructor called"); 80 } 81 }; 82 } // namespace OHOS 83 #endif // MOCK_OHOS_ABILITY_RUNTIME_SYSTEM_ABILITY_H 84