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 NET_WORK_MOCK_H
17 #define NET_WORK_MOCK_H
18 
19 
20 #include <gmock/gmock.h>
21 #include <linux/netlink.h>
22 #include <linux/rtnetlink.h>
23 #include <mutex>
24 #include <net/if.h>
25 #include <securec.h>
26 #include <stdint.h>
27 #include <sys/ioctl.h>
28 #include <unistd.h>
29 #include "gtest/gtest.h"
30 #include <arpa/inet.h>
31 
32 #include "bus_center_event.h"
33 #include "lnn_async_callback_utils.h"
34 #include "lnn_network_manager.h"
35 #include "message_handler.h"
36 #include "softbus_adapter_bt_common.h"
37 #include "softbus_adapter_socket.h"
38 #include "softbus_config_type.h"
39 
40 namespace OHOS {
41 class NetworkInterface {
42 public:
NetworkInterface()43     NetworkInterface() {};
~NetworkInterface()44     virtual ~NetworkInterface() {};
45 
46     virtual int32_t SoftBusSocketCreate(int32_t domain, int32_t type, int32_t protocol, int32_t *socketFd) = 0;
47     virtual int32_t SoftBusSocketSetOpt(
48         int32_t socketFd, int32_t level, int32_t optName, const void *optVal, int32_t optLen) = 0;
49     virtual int32_t SoftBusSocketClose(int32_t socketFd) = 0;
50     virtual int32_t SoftBusSocketBind(int32_t socketFd, SoftBusSockAddr *addr, int32_t addrLen) = 0;
51     virtual int32_t LnnGetNetIfTypeByName(const char *ifName, LnnNetIfType *type) = 0;
52     virtual void LnnNotifyAddressChangedEvent(const char *ifName) = 0;
53     virtual int32_t SoftBusSocketRecv(int32_t socketFd, void *buf, uint32_t len, int32_t flags) = 0;
54     virtual int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para) = 0;
55     virtual void LnnNotifyBtAclStateChangeEvent(const char *btMac, SoftBusBtAclState state) = 0;
56     virtual int32_t ConvertBtMacToStr(char *strMac, uint32_t strMacLen, const uint8_t *binMac, uint32_t binMacLen) = 0;
57     virtual int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener) = 0;
58     virtual int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len) = 0;
59     virtual void LnnNotifyBtStateChangeEvent(void *state) = 0;
60 };
61 class NetworkInterfaceMock : public NetworkInterface {
62 public:
63     NetworkInterfaceMock();
64     ~NetworkInterfaceMock() override;
65 
66     MOCK_METHOD4(SoftBusSocketCreate, int32_t(int32_t, int32_t, int32_t, int32_t *));
67     MOCK_METHOD5(SoftBusSocketSetOpt, int32_t(int32_t, int32_t, int32_t, const void *, int32_t));
68     MOCK_METHOD1(SoftBusSocketClose, int32_t(int32_t));
69     MOCK_METHOD3(SoftBusSocketBind, int32_t(int32_t, SoftBusSockAddr *, int32_t));
70     MOCK_METHOD2(LnnGetNetIfTypeByName, int32_t(const char *, LnnNetIfType *));
71     MOCK_METHOD1(LnnNotifyAddressChangedEvent, void(const char *));
72     MOCK_METHOD4(SoftBusSocketRecv, int32_t(int32_t, void *, uint32_t, int32_t));
73     MOCK_METHOD3(LnnAsyncCallbackHelper, int32_t(SoftBusLooper *, LnnAsyncCallbackFunc, void *));
74     MOCK_METHOD2(LnnNotifyBtAclStateChangeEvent, void(const char *, SoftBusBtAclState));
75     MOCK_METHOD4(ConvertBtMacToStr, int32_t(char *, uint32_t, const uint8_t *, uint32_t));
76     MOCK_METHOD1(SoftBusAddBtStateListener, int(const SoftBusBtStateListener *));
77     MOCK_METHOD3(SoftbusGetConfig, int(ConfigType, unsigned char *, uint32_t));
78     MOCK_METHOD1(LnnNotifyBtStateChangeEvent, void(void *));
79 };
80 } // namespace OHOS
81 #endif // NET_WORK_MOCK_H