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