1 /* 2 * Copyright (c) 2021 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 16 #ifndef DSLM_MSG_INTERFACE_MOCK_H 17 #define DSLM_MSG_INTERFACE_MOCK_H 18 19 #include <gmock/gmock.h> 20 #include <mutex> 21 22 #include "messenger.h" 23 24 #include "dslm_callback_info.h" 25 26 namespace OHOS { 27 namespace Security { 28 namespace DslmUnitTest { 29 class DslmMsgInterface { 30 public: DslmMsgInterface()31 DslmMsgInterface() {}; ~DslmMsgInterface()32 virtual ~DslmMsgInterface() {}; 33 34 virtual bool IsMessengerReady(const Messenger *messenger) = 0; 35 36 virtual uint64_t SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, 37 const uint8_t *msg, uint32_t msgLen) = 0; 38 39 virtual bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType) = 0; 40 41 virtual bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType) = 0; 42 43 virtual void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para) = 0; 44 }; 45 46 class DslmMsgInterfaceMock : public DslmMsgInterface { 47 public: 48 DslmMsgInterfaceMock(); 49 ~DslmMsgInterfaceMock() override; 50 MOCK_METHOD1(IsMessengerReady, bool(const Messenger *messenger)); 51 MOCK_METHOD5(SendMsgTo, uint64_t(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId, 52 const uint8_t *msg, uint32_t msgLen)); 53 MOCK_METHOD3(GetDeviceOnlineStatus, 54 bool(const Messenger *messenger, const DeviceIdentify *devId, uint32_t *devType)); 55 MOCK_METHOD3(GetSelfDeviceIdentify, bool(const Messenger *messenger, DeviceIdentify *devId, uint32_t *devType)); 56 MOCK_METHOD3(ForEachDeviceProcess, void(const Messenger *messenger, const DeviceProcessor processor, void *para)); 57 void MakeMsgLoopback() const; 58 void MakeSelfDeviceId(const DeviceIdentify *devId) const; 59 void MakeDeviceOnline(const DeviceIdentify *devId) const; 60 void MakeDeviceOffline(const DeviceIdentify *devId) const; 61 void MakeMsgReceivedFrom(const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen) const; 62 }; 63 } // namespace DslmUnitTest 64 } // namespace Security 65 } // namespace OHOS 66 67 #endif // DSLM_MSG_INTERFACE_MOCK_H 68