1 /* 2 * Copyright (C) 2024 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 #ifndef OHOS_DFS_SERVICE_DEVICE_MANAGER_MOCK_H 16 #define OHOS_DFS_SERVICE_DEVICE_MANAGER_MOCK_H 17 18 #include <memory> 19 #include <string> 20 #include <gmock/gmock.h> 21 22 #include "device_manager.h" 23 #include "softbus_bus_center.h" 24 25 namespace OHOS::Storage::DistributedFile { 26 using namespace OHOS::DistributedHardware; 27 class DfsDeviceManagerImpl { 28 public: 29 virtual ~DfsDeviceManagerImpl() = default; 30 public: 31 virtual int32_t InitDeviceManager(const std::string &pkgName, 32 std::shared_ptr<DmInitCallback> dmInitCallback) = 0; 33 virtual int32_t UnInitDeviceManager(const std::string &pkgName) = 0; 34 virtual int32_t GetTrustedDeviceList(const std::string &pkgName, 35 const std::string &extra, std::vector<DmDeviceInfo> &deviceList) = 0; 36 virtual int32_t RegisterDevStateCallback(const std::string &pkgName, 37 const std::string &extra, std::shared_ptr<DeviceStateCallback> callback) = 0; 38 virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName) = 0; 39 virtual int32_t GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) = 0; 40 virtual bool CheckSrcAccessControl(const DmAccessCaller &caller,const DmAccessCallee &callee) = 0; 41 virtual bool CheckSinkAccessControl(const DmAccessCaller &caller,const DmAccessCallee &callee) = 0; 42 virtual bool CheckSrcIsSameAccount(const DmAccessCaller &caller,const DmAccessCallee &callee) = 0; 43 virtual bool CheckSinkIsSameAccount(const DmAccessCaller &caller,const DmAccessCallee &callee) = 0; 44 #ifdef NORMAL_MOCK 45 virtual int32_t GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId, 46 int32_t &netWorkType) = 0; 47 #endif 48 public: 49 virtual int32_t GetLocalNodeDeviceInfo(const char *pkgName, NodeBasicInfo *info) = 0; 50 public: 51 static inline std::shared_ptr<DfsDeviceManagerImpl> dfsDeviceManagerImpl = nullptr; 52 }; 53 54 class DeviceManagerImplMock : public DfsDeviceManagerImpl { 55 public: 56 MOCK_METHOD2(InitDeviceManager, int32_t(const std::string &pkgName, 57 std::shared_ptr<DmInitCallback> dmInitCallback)); 58 MOCK_METHOD1(UnInitDeviceManager, int32_t(const std::string &pkgName)); 59 MOCK_METHOD3(GetTrustedDeviceList, int32_t(const std::string &pkgName, 60 const std::string &extra, std::vector<DmDeviceInfo> &deviceList)); 61 MOCK_METHOD3(RegisterDevStateCallback, int32_t(const std::string &pkgName, 62 const std::string &extra, std::shared_ptr<DeviceStateCallback> callback)); 63 MOCK_METHOD1(UnRegisterDevStateCallback, int32_t(const std::string &pkgName)); 64 MOCK_METHOD2(GetLocalNodeDeviceInfo, int32_t(const char *pkgName, NodeBasicInfo *info)); 65 MOCK_METHOD2(GetLocalDeviceInfo, int32_t(const std::string &pkgName, DmDeviceInfo &info)); 66 MOCK_METHOD2(CheckSrcAccessControl, bool(const DmAccessCaller &caller,const DmAccessCallee &callee)); 67 MOCK_METHOD2(CheckSinkAccessControl, bool(const DmAccessCaller &caller,const DmAccessCallee &callee)); 68 MOCK_METHOD2(CheckSrcIsSameAccount, bool(const DmAccessCaller &caller,const DmAccessCallee &callee)); 69 MOCK_METHOD2(CheckSinkIsSameAccount, bool(const DmAccessCaller &caller,const DmAccessCallee &callee)); 70 #ifdef NORMAL_MOCK 71 MOCK_METHOD3(GetNetworkTypeByNetworkId, int32_t(const std::string &pkgName, const std::string &netWorkId, 72 int32_t &netWorkType)); 73 #endif 74 }; 75 } 76 #endif