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