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 OnStart()72 void OnStart() {} OnStop()73 void OnStop() {} 74 75 private: 76 std::atomic_int onChangeCall_ = 0; 77 }; 78 } // namespace AAFwk 79 } // namespace OHOS 80 #endif // UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_SERVICE_H 81