1 2 /* 3 * Copyright (c) 2021 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H 18 #define UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H 19 20 #include <gmock/gmock.h> 21 #define protected public 22 #define private public 23 #include "dataobs_mgr_stub.h" 24 25 namespace OHOS { 26 namespace AAFwk { 27 class MockDataObsMgrService : public DataObsManagerStub { 28 public: 29 MockDataObsMgrService() = default; 30 virtual ~MockDataObsMgrService() = default; 31 RegisterObserver(const Uri & uri,sptr<IDataAbilityObserver> dataObserver)32 int RegisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override 33 { 34 onChangeCall_++; 35 return NO_ERROR; 36 } UnregisterObserver(const Uri & uri,sptr<IDataAbilityObserver> dataObserver)37 int UnregisterObserver(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override 38 { 39 onChangeCall_++; 40 return NO_ERROR; 41 } NotifyChange(const Uri & uri)42 int NotifyChange(const Uri &uri) override 43 { 44 onChangeCall_++; 45 return NO_ERROR; 46 } 47 RegisterObserverExt(const Uri & uri,sptr<IDataAbilityObserver> dataObserver,bool isDe)48 Status RegisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver, bool isDe) override 49 { 50 onChangeCall_++; 51 return SUCCESS; 52 } 53 UnregisterObserverExt(const Uri & uri,sptr<IDataAbilityObserver> dataObserver)54 Status UnregisterObserverExt(const Uri &uri, sptr<IDataAbilityObserver> dataObserver) override 55 { 56 onChangeCall_++; 57 return SUCCESS; 58 } 59 UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver)60 Status UnregisterObserverExt(sptr<IDataAbilityObserver> dataObserver) override 61 { 62 onChangeCall_++; 63 return SUCCESS; 64 } 65 NotifyChangeExt(const ChangeInfo & changeInfo)66 Status NotifyChangeExt(const ChangeInfo &changeInfo) override 67 { 68 onChangeCall_++; 69 return SUCCESS; 70 } 71 NotifyProcessObserver(const std::string & key,const sptr<IRemoteObject> & observer)72 Status NotifyProcessObserver(const std::string &key, const sptr<IRemoteObject> &observer) override 73 { 74 onChangeCall_++; 75 return SUCCESS; 76 } 77 OnStart()78 void OnStart() {} OnStop()79 void OnStop() {} 80 81 private: 82 std::atomic_int onChangeCall_ = 0; 83 }; 84 } // namespace AAFwk 85 } // namespace OHOS 86 #endif // UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H 87