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_DEVICE_MANAGER_SERVICE_IMPL_MOCK_H 16 #define OHOS_DEVICE_MANAGER_SERVICE_IMPL_MOCK_H 17 18 #include <string> 19 #include <gmock/gmock.h> 20 21 #include "device_manager_service_impl.h" 22 23 namespace OHOS { 24 namespace DistributedHardware { 25 class DmDeviceManagerServiceImpl { 26 public: 27 virtual ~DmDeviceManagerServiceImpl() = default; 28 public: 29 virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0; 30 virtual int32_t GetBindLevel(const std::string &pkgName, const std::string &localUdid, 31 const std::string &udid, uint64_t &tokenId) = 0; 32 virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) = 0; 33 virtual std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t userId, const std::string &accountId) = 0; 34 virtual std::map<std::string, int32_t> GetDeviceIdAndBindLevel(int32_t userId) = 0; 35 virtual std::multimap<std::string, int32_t> GetDeviceIdAndUserId(int32_t localUserId) = 0; 36 virtual std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceIdList(std::string pkgname) = 0; 37 virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &udid, int32_t bindLevel) = 0; 38 virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &udid, 39 int32_t bindLevel, const std::string &extra) = 0; 40 virtual bool CheckSharePeerSrc(const std::string &peerUdid, const std::string &localUdid) = 0; 41 virtual void HandleCredentialDeleted(const char *credId, const char *credInfo, const std::string &localUdid, 42 std::string &remoteUdid, bool &isSendBroadCast) = 0; 43 virtual void HandleShareUnbindBroadCast(const std::string &credId, const int32_t &userId, 44 const std::string &localUdid) = 0; 45 virtual int32_t CheckDeviceInfoPermission(const std::string &localUdid, const std::string &peerDeviceId) = 0; 46 virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId) = 0; 47 virtual void HandleAppUnBindEvent(int32_t remoteUserId, const std::string &remoteUdid, 48 int32_t tokenId, int32_t peerTokenId) = 0; 49 virtual bool CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid, 50 const DmAccessCallee &callee, const std::string &sinkUdid) = 0; 51 virtual bool CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid, 52 const DmAccessCallee &callee, const std::string &sinkUdid) = 0; 53 public: 54 static inline std::shared_ptr<DmDeviceManagerServiceImpl> dmDeviceManagerServiceImpl = nullptr; 55 }; 56 57 class DeviceManagerServiceImplMock : public DmDeviceManagerServiceImpl { 58 public: 59 MOCK_METHOD(int32_t, StopAuthenticateDevice, (const std::string &)); 60 MOCK_METHOD(int32_t, GetBindLevel, (const std::string &, const std::string &, const std::string &, uint64_t &)); 61 MOCK_METHOD(int32_t, UnBindDevice, (const std::string &, const std::string &, int32_t)); 62 MOCK_METHOD((std::multimap<std::string, int32_t>), GetDeviceIdAndUserId, (int32_t, const std::string &)); 63 MOCK_METHOD((std::multimap<std::string, int32_t>), GetDeviceIdAndUserId, (int32_t)); 64 MOCK_METHOD((std::map<std::string, int32_t>), GetDeviceIdAndBindLevel, (int32_t)); 65 MOCK_METHOD((std::unordered_map<std::string, DmAuthForm>), GetAppTrustDeviceIdList, (std::string)); 66 MOCK_METHOD(int32_t, UnAuthenticateDevice, (const std::string &, const std::string &, int32_t)); 67 MOCK_METHOD(int32_t, UnBindDevice, (const std::string &, const std::string &, int32_t, const std::string &)); 68 MOCK_METHOD(bool, CheckSharePeerSrc, (const std::string &peerUdid, const std::string &localUdid)); 69 MOCK_METHOD(void, HandleCredentialDeleted, (const char *, const char *, const std::string &, 70 std::string &, bool &)); 71 MOCK_METHOD(void, HandleShareUnbindBroadCast, (const std::string &, const int32_t &, const std::string &)); 72 MOCK_METHOD(int32_t, CheckDeviceInfoPermission, (const std::string &, const std::string &)); 73 MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, int32_t tokenId)); 74 MOCK_METHOD(void, HandleAppUnBindEvent, (int32_t remoteUserId, const std::string &remoteUdid, 75 int32_t tokenId, int32_t peerTokenId)); 76 MOCK_METHOD(bool, CheckAccessControl, (const DmAccessCaller &caller, const std::string &srcUdid, 77 const DmAccessCallee &callee, const std::string &sinkUdid)); 78 MOCK_METHOD(bool, CheckIsSameAccount, (const DmAccessCaller &caller, const std::string &srcUdid, 79 const DmAccessCallee &callee, const std::string &sinkUdid)); 80 }; 81 } 82 } 83 #endif 84