• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "socket.h"
23 
24 #include "dslm_callback_info.h"
25 #include "messenger.h"
26 
27 namespace OHOS {
28 namespace Security {
29 namespace DslmUnitTest {
30 class DslmMsgInterface {
31 public:
DslmMsgInterface()32     DslmMsgInterface() {};
~DslmMsgInterface()33     virtual ~DslmMsgInterface() {};
34 
35     virtual bool IsMessengerReady(const Messenger *messenger) = 0;
36 
37     virtual uint64_t SendMsgTo(const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId,
38         const uint8_t *msg, uint32_t msgLen) = 0;
39 
40     virtual bool GetDeviceOnlineStatus(const Messenger *messenger, const DeviceIdentify *devId, int32_t *level) = 0;
41 
42     virtual bool GetSelfDeviceIdentify(const Messenger *messenger, DeviceIdentify *devId, int32_t *level) = 0;
43 
44     virtual void ForEachDeviceProcess(const Messenger *messenger, const DeviceProcessor processor, void *para) = 0;
45 
46     virtual int32_t Socket(SocketInfo info) = 0;
47 
48     virtual int32_t Listen(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener) = 0;
49 
50     virtual int32_t Bind(int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener) = 0;
51 
52     virtual int32_t SendBytes(int32_t socket, const void *data, uint32_t len) = 0;
53 
54     virtual void Shutdown(int32_t socket) = 0;
55 };
56 
57 class DslmMsgInterfaceMock : public DslmMsgInterface {
58 public:
59     DslmMsgInterfaceMock();
60     ~DslmMsgInterfaceMock() override;
61     MOCK_METHOD(bool, IsMessengerReady, (const Messenger *messenger), (override));
62     MOCK_METHOD(uint64_t, SendMsgTo, (const Messenger *messenger, uint64_t transNo, const DeviceIdentify *devId,
63                                 const uint8_t *msg, uint32_t msgLen), (override));
64     MOCK_METHOD(bool, GetDeviceOnlineStatus,
65         (const Messenger *messenger, const DeviceIdentify *devId, int32_t *level), (override));
66     MOCK_METHOD(bool, GetSelfDeviceIdentify, (const Messenger *messenger, DeviceIdentify *devId, int32_t *level),
67         (override));
68     MOCK_METHOD(void, ForEachDeviceProcess, (const Messenger *messenger, const DeviceProcessor processor, void *para),
69         (override));
70     MOCK_METHOD(int32_t, Socket, (SocketInfo info), (override));
71     MOCK_METHOD(int32_t, Listen,
72         (int32_t socket, const QosTV qos[], uint32_t qosCount, const ISocketListener *listener), (override));
73     MOCK_METHOD(int32_t, Bind, (int32_t socket, const QosTV qos[], uint32_t qosCount,
74         const ISocketListener *listener), (override));
75     MOCK_METHOD(int32_t, SendBytes, (int32_t socket, const void *data, uint32_t len), (override));
76     MOCK_METHOD(void, Shutdown, (int32_t socket), (override));
77     void MakeMsgLoopback() const;
78     void MakeSelfDeviceId(const DeviceIdentify *devId) const;
79     void MakeDeviceOnline(const DeviceIdentify *devId) const;
80     void MakeDeviceOffline(const DeviceIdentify *devId) const;
81     void MakeMsgReceivedFrom(const DeviceIdentify *devId, const uint8_t *msg, uint32_t msgLen) const;
82 };
83 } // namespace DslmUnitTest
84 } // namespace Security
85 } // namespace OHOS
86 
87 #endif // DSLM_MSG_INTERFACE_MOCK_H
88