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 
16 #ifndef TRANS_TCP_DIRECT_P2P_TEST_MOCK_H
17 #define TRANS_TCP_DIRECT_P2P_TEST_MOCK_H
18 
19 #include <gmock/gmock.h>
20 #include "cJSON.h"
21 #include "auth_interface.h"
22 #include "softbus_base_listener.h"
23 #include "softbus_conn_interface.h"
24 #include "softbus_proxychannel_pipeline.h"
25 #include "trans_tcp_direct_sessionconn.h"
26 
27 namespace OHOS {
28 class TransTcpDirectP2pInterface {
29 public:
TransTcpDirectP2pInterface()30     TransTcpDirectP2pInterface() {};
~TransTcpDirectP2pInterface()31     virtual ~TransTcpDirectP2pInterface() {};
32     virtual int32_t TransTdcStartSessionListener(ListenerModule module, const LocalListenerInfo *info) = 0;
33     virtual SoftBusList *CreateSoftBusList() = 0;
34     virtual int32_t StopBaseListener(ListenerModule module) = 0;
35     virtual bool IsHmlIpAddr(const char *ip) = 0;
36     virtual int32_t RegAuthTransListener(int32_t module, const AuthTransListener *listener) = 0;
37     virtual int32_t TransProxyPipelineRegisterListener(TransProxyPipelineMsgType type,
38         const ITransProxyPipelineListener *listener) = 0;
39     virtual int32_t AuthPostTransData(AuthHandle authHandle, const AuthTransData *dataInfo) = 0;
40     virtual char *VerifyP2pPack(const char *myIp, int32_t myPort, const char *peerIp) = 0;
41     virtual int32_t NotifyChannelOpenFailed(int32_t channelId, int32_t errCode) = 0;
42     virtual int32_t AuthGetHmlConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta) = 0;
43     virtual int32_t AuthGetP2pConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta) = 0;
44     virtual int32_t AuthGetPreferConnInfo(const char *uuid, AuthConnInfo *connInfo, bool isMeta) = 0;
45     virtual int32_t AuthOpenConn(const AuthConnInfo *info, uint32_t requestId,
46         const AuthConnCallback *callback, bool isMeta) = 0;
47     virtual char *VerifyP2pPackError(int32_t code, int32_t errCode, const char *errDesc) = 0;
48     virtual int32_t TransProxyPipelineSendMessage(int32_t channelId, const uint8_t *data,
49         uint32_t dataLen, TransProxyPipelineMsgType type) = 0;
50     virtual int32_t ConnOpenClientSocket(const ConnectOption *option, const char *bindAddr, bool isNonBlock) = 0;
51     virtual int32_t AddTrigger(ListenerModule module, int32_t fd, TriggerType trigger) = 0;
52     virtual int32_t TransSrvAddDataBufNode(int32_t channelId, int32_t fd) = 0;
53     virtual cJSON *cJSON_ParseWithLength(const char *value, size_t buffer_length) = 0;
54     virtual int32_t TransProxyPipelineGetChannelIdByNetworkId(const char *networkId) = 0;
55     virtual uint32_t AuthGenRequestId() = 0;
56     virtual int32_t TransProxyReuseByChannelId(int32_t channelId) = 0;
57     virtual int32_t TransProxyPipelineCloseChannelDelay(int32_t channelId) = 0;
58     virtual SessionConn *CreateNewSessinConn(ListenerModule module, bool isServerSid) = 0;
59 };
60 
61 class TransTcpDirectP2pInterfaceMock : public TransTcpDirectP2pInterface {
62 public:
63     TransTcpDirectP2pInterfaceMock();
64     ~TransTcpDirectP2pInterfaceMock() override;
65     MOCK_METHOD2(TransTdcStartSessionListener, int32_t (ListenerModule module, const LocalListenerInfo *info));
66     MOCK_METHOD0(CreateSoftBusList, SoftBusList *());
67     MOCK_METHOD1(StopBaseListener, int32_t (ListenerModule module));
68     MOCK_METHOD1(IsHmlIpAddr, bool (const char *ip));
69     MOCK_METHOD2(RegAuthTransListener, int32_t (int32_t module, const AuthTransListener *listener));
70     MOCK_METHOD2(TransProxyPipelineRegisterListener, int32_t (TransProxyPipelineMsgType type,
71         const ITransProxyPipelineListener *listener));
72     MOCK_METHOD2(AuthPostTransData, int32_t (AuthHandle authHandle, const AuthTransData *dataInfo));
73     MOCK_METHOD3(VerifyP2pPack, char *(const char *myIp, int32_t myPort, const char *peerIp));
74     MOCK_METHOD2(NotifyChannelOpenFailed, int32_t (int32_t channelId, int32_t errCode));
75     MOCK_METHOD3(AuthGetHmlConnInfo, int32_t (const char *uuid, AuthConnInfo *connInfo, bool isMeta));
76     MOCK_METHOD3(AuthGetP2pConnInfo, int32_t (const char *uuid, AuthConnInfo *connInfo, bool isMeta));
77     MOCK_METHOD3(AuthGetPreferConnInfo, int32_t (const char *uuid, AuthConnInfo *connInfo, bool isMeta));
78     MOCK_METHOD4(AuthOpenConn, int32_t (const AuthConnInfo *info, uint32_t requestId,
79         const AuthConnCallback *callback, bool isMeta));
80     MOCK_METHOD3(VerifyP2pPackError, char *(int32_t code, int32_t errCode, const char *errDesc));
81     MOCK_METHOD4(TransProxyPipelineSendMessage, int32_t (int32_t channelId, const uint8_t *data,
82         uint32_t dataLen, TransProxyPipelineMsgType type));
83     MOCK_METHOD3(ConnOpenClientSocket, int32_t (const ConnectOption *option, const char *bindAddr, bool isNonBlock));
84     MOCK_METHOD3(AddTrigger, int32_t (ListenerModule module, int32_t fd, TriggerType trigger));
85     MOCK_METHOD2(TransSrvAddDataBufNode, int32_t (int32_t channelId, int32_t fd));
86     MOCK_METHOD2(cJSON_ParseWithLength, cJSON *(const char *value, size_t buffer_length));
87     MOCK_METHOD1(TransProxyPipelineGetChannelIdByNetworkId, int32_t (const char *networkId));
88     MOCK_METHOD0(AuthGenRequestId, uint32_t ());
89     MOCK_METHOD1(TransProxyReuseByChannelId, int32_t (int32_t channelId));
90     MOCK_METHOD1(TransProxyPipelineCloseChannelDelay, int32_t (int32_t channelId));
91     MOCK_METHOD2(CreateNewSessinConn, SessionConn *(ListenerModule module, bool isServerSid));
92 };
93 } // namespace OHOS
94 #endif // TRANS_TCP_DIRECT_P2P_TEST_MOCK_H
95