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_CLIENT_H 18 #define UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_CLIENT_H 19 20 #include <gmock/gmock.h> 21 #include <memory> 22 #include <map> 23 #define protected public 24 #define private public 25 #include "system_ability.h" 26 #include "dataobs_mgr_service.h" 27 #include "semaphore_ex.h" 28 #include "mock_dataobs_mgr_service.h" 29 #include "dataobs_mgr_client.h" 30 #include "mock_dataobs_mgr_service.h" 31 32 namespace OHOS { 33 namespace AAFwk { 34 class MockDataObsMgrClient : public DataObsMgrClient { 35 public: 36 static std::shared_ptr<DataObsMgrClient> GetInstance(); 37 ErrCode Connect(); 38 }; 39 GetInstance()40std::shared_ptr<DataObsMgrClient> MockDataObsMgrClient::GetInstance() 41 { 42 if (instance_ == nullptr) { 43 std::shared_ptr<DataObsMgrClient> client {new (std::nothrow) MockDataObsMgrClient()}; 44 if (client != nullptr) { 45 ((MockDataObsMgrClient *)client.get())->Connect(); 46 } 47 instance_ = client; 48 } 49 return instance_; 50 } 51 Connect()52ErrCode MockDataObsMgrClient::Connect() 53 { 54 if (remoteObject_ == nullptr) { 55 sptr<IRemoteObject> mockDataObsMgrService(new (std::nothrow) MockDataObsMgrService()); 56 if (mockDataObsMgrService != nullptr) { 57 ((MockDataObsMgrService *)mockDataObsMgrService.GetRefPtr())->OnStart(); 58 } 59 60 remoteObject_ = mockDataObsMgrService; 61 } 62 return ERR_OK; 63 } 64 } // namespace AAFwk 65 } // namespace OHOS 66 #endif // UNITTEST_OHOS_ABILITY_RUNTIME_MOCK_DATAOBS_MGR_CLIENT_H 67