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 DSOFTBUS_LNN_SOCKET_MOCK_H
17 #define DSOFTBUS_LNN_SOCKET_MOCK_H
18 
19 #include "softbus_socket.h"
20 #include "auth_tcp_connection.h"
21 #include <gmock/gmock.h>
22 
23 namespace OHOS {
24 class LnnSocketInterface {
25 public:
LnnSocketInterface()26     LnnSocketInterface() {};
~LnnSocketInterface()27     virtual ~LnnSocketInterface() {};
28     virtual const SocketInterface* GetSocketInterface(ProtocolType protocolType) = 0;
29     virtual int32_t RegistSocketProtocol(const SocketInterface* interface) = 0;
30     virtual int32_t ConnOpenClientSocket(const ConnectOption *option, const char *bindAddr, bool isNonBlock) = 0;
31     virtual ssize_t ConnSendSocketData(int32_t fd, const char *buf, size_t len, int32_t timeout) = 0;
32     virtual void ConnShutdownSocket(int32_t fd) = 0;
33     virtual int32_t ConnSetTcpKeepalive(
34         int32_t fd, int32_t seconds, int32_t keepAliveIntvl, int32_t keepAliveCount) = 0;
35     virtual int32_t ConnSetTcpUserTimeOut(int32_t fd, uint32_t millSec) = 0;
36     virtual int32_t ConnToggleNonBlockMode(int32_t fd, bool isNonBlock) = 0;
37     virtual int32_t ConnGetSocketError(int32_t fd) = 0;
38     virtual int32_t ConnGetLocalSocketPort(int32_t fd) = 0;
39     virtual int32_t ConnGetPeerSocketAddr(int32_t fd, SocketAddr *socketAddr) = 0;
40 };
41 
42 class LnnSocketInterfaceMock : public LnnSocketInterface {
43 public:
44     LnnSocketInterfaceMock();
45     ~LnnSocketInterfaceMock() override;
46 
47     MOCK_METHOD1(GetSocketInterface, const SocketInterface*(ProtocolType));
48     MOCK_METHOD1(RegistSocketProtocol, int32_t (const SocketInterface*));
49     MOCK_METHOD3(ConnOpenClientSocket, int32_t (const ConnectOption *, const char *, bool));
50     MOCK_METHOD4(ConnSendSocketData, ssize_t (int32_t, const char *, size_t, int32_t));
51     MOCK_METHOD1(ConnShutdownSocket, void (int32_t));
52     MOCK_METHOD4(ConnSetTcpKeepalive, int32_t (int32_t, int32_t, int32_t, int32_t));
53     MOCK_METHOD2(ConnSetTcpUserTimeOut, int32_t (int32_t, uint32_t));
54     MOCK_METHOD2(ConnToggleNonBlockMode, int32_t (int32_t, bool));
55     MOCK_METHOD1(ConnGetSocketError, int32_t (int32_t));
56     MOCK_METHOD1(ConnGetLocalSocketPort, int32_t (int32_t));
57     MOCK_METHOD2(ConnGetPeerSocketAddr, int32_t (int32_t, SocketAddr *));
58 };
59 } // namespace OHOS
60 #endif // DSOFTBUS_LNN_SOCKET_MOCK_H