• 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 #include <gtest/gtest.h>
17 #include <securec.h>
18 
19 #include "lnn_ip_network_impl_mock.h"
20 #include "lnn_log.h"
21 #include "softbus_adapter_mem.h"
22 #include "softbus_error_code.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 void *g_ipNetworkImplInterface;
LnnIpNetworkImplInterfaceMock()29 LnnIpNetworkImplInterfaceMock::LnnIpNetworkImplInterfaceMock()
30 {
31     g_ipNetworkImplInterface = reinterpret_cast<void *>(this);
32 }
33 
~LnnIpNetworkImplInterfaceMock()34 LnnIpNetworkImplInterfaceMock::~LnnIpNetworkImplInterfaceMock()
35 {
36     g_ipNetworkImplInterface = nullptr;
37 }
38 
GetLnnIpNetworkImplInterface()39 static LnnIpNetworkImplInterface *GetLnnIpNetworkImplInterface()
40 {
41     return reinterpret_cast<LnnIpNetworkImplInterface *>(g_ipNetworkImplInterface);
42 }
43 
ActionOfGetNetworkIpByIfName(const char * ifName,char * ip,char * netmask,uint32_t len)44 int32_t LnnIpNetworkImplInterfaceMock::ActionOfGetNetworkIpByIfName(
45     const char *ifName, char *ip, char *netmask, uint32_t len)
46 {
47     if (ifName == nullptr || netmask == nullptr || len == 0) {
48         LNN_LOGI(LNN_TEST, "invalid para");
49         return SOFTBUS_INVALID_PARAM;
50     }
51     if (memcpy_s(ip, strlen("127.0.0.2") + 1, "127.0.0.2", strlen("127.0.0.2") + 1) != EOK) {
52         LNN_LOGI(LNN_TEST, "memcpy networkId fail");
53         return SOFTBUS_MEM_ERR;
54     }
55     return SOFTBUS_OK;
56 }
57 
58 extern "C" {
LnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)59 int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
60 {
61     return GetLnnIpNetworkImplInterface()->LnnRegisterEventHandler(event, handler);
62 }
63 
LnnRegistPhysicalSubnet(LnnPhysicalSubnet * manager)64 int32_t LnnRegistPhysicalSubnet(LnnPhysicalSubnet *manager)
65 {
66     return GetLnnIpNetworkImplInterface()->LnnRegistPhysicalSubnet(manager);
67 }
68 
DiscLinkStatusChanged(LinkStatus status,ExchangeMedium medium)69 void DiscLinkStatusChanged(LinkStatus status, ExchangeMedium medium)
70 {
71     return GetLnnIpNetworkImplInterface()->DiscLinkStatusChanged(status, medium);
72 }
73 
LnnVisitPhysicalSubnet(LnnVisitPhysicalSubnetCallback callback,void * data)74 bool LnnVisitPhysicalSubnet(LnnVisitPhysicalSubnetCallback callback, void *data)
75 {
76     return GetLnnIpNetworkImplInterface()->LnnVisitPhysicalSubnet(callback, data);
77 }
78 
LnnStopPublish(void)79 void LnnStopPublish(void)
80 {
81     return GetLnnIpNetworkImplInterface()->LnnStopPublish();
82 }
83 
LnnStopDiscovery(void)84 void LnnStopDiscovery(void)
85 {
86     return GetLnnIpNetworkImplInterface()->LnnStopDiscovery();
87 }
88 
LnnIpAddrChangeEventHandler(void)89 void LnnIpAddrChangeEventHandler(void)
90 {
91     return GetLnnIpNetworkImplInterface()->LnnIpAddrChangeEventHandler();
92 }
93 
AuthStopListening(AuthLinkType type)94 void AuthStopListening(AuthLinkType type)
95 {
96     return GetLnnIpNetworkImplInterface()->AuthStopListening(type);
97 }
98 
TransTdcStopSessionListener(ListenerModule module)99 int32_t TransTdcStopSessionListener(ListenerModule module)
100 {
101     return GetLnnIpNetworkImplInterface()->TransTdcStopSessionListener(module);
102 }
103 
ConnStopLocalListening(const LocalListenerInfo * info)104 int32_t ConnStopLocalListening(const LocalListenerInfo *info)
105 {
106     return GetLnnIpNetworkImplInterface()->ConnStopLocalListening(info);
107 }
108 
LnnGetAddrTypeByIfName(const char * ifName,ConnectionAddrType * type)109 int32_t LnnGetAddrTypeByIfName(const char *ifName, ConnectionAddrType *type)
110 {
111     return GetLnnIpNetworkImplInterface()->LnnGetAddrTypeByIfName(ifName, type);
112 }
113 
LnnStartPublish(void)114 int32_t LnnStartPublish(void)
115 {
116     return GetLnnIpNetworkImplInterface()->LnnStartPublish();
117 }
118 
LnnIsAutoNetWorkingEnabled(void)119 bool LnnIsAutoNetWorkingEnabled(void)
120 {
121     return GetLnnIpNetworkImplInterface()->LnnIsAutoNetWorkingEnabled();
122 }
123 
LnnStartDiscovery(void)124 int32_t LnnStartDiscovery(void)
125 {
126     return GetLnnIpNetworkImplInterface()->LnnStartDiscovery();
127 }
128 
AuthStartListening(AuthLinkType type,const char * ip,int32_t port)129 int32_t AuthStartListening(AuthLinkType type, const char *ip, int32_t port)
130 {
131     return GetLnnIpNetworkImplInterface()->AuthStartListening(type, ip, port);
132 }
133 
TransTdcStartSessionListener(ListenerModule module,const LocalListenerInfo * info)134 int32_t TransTdcStartSessionListener(ListenerModule module, const LocalListenerInfo *info)
135 {
136     return GetLnnIpNetworkImplInterface()->TransTdcStartSessionListener(module, info);
137 }
138 
ConnStartLocalListening(const LocalListenerInfo * info)139 int32_t ConnStartLocalListening(const LocalListenerInfo *info)
140 {
141     return GetLnnIpNetworkImplInterface()->ConnStartLocalListening(info);
142 }
143 
LnnIsLinkReady(const char * iface)144 bool LnnIsLinkReady(const char *iface)
145 {
146     return GetLnnIpNetworkImplInterface()->LnnIsLinkReady(iface);
147 }
148 
LnnNotifyPhysicalSubnetStatusChanged(const char * ifName,ProtocolType protocolType,void * status)149 void LnnNotifyPhysicalSubnetStatusChanged(const char *ifName, ProtocolType protocolType, void *status)
150 {
151     return GetLnnIpNetworkImplInterface()->LnnNotifyPhysicalSubnetStatusChanged(ifName, protocolType, status);
152 }
153 
LnnVisitNetif(VisitNetifCallback callback,void * data)154 bool LnnVisitNetif(VisitNetifCallback callback, void *data)
155 {
156     return GetLnnIpNetworkImplInterface()->LnnVisitNetif(callback, data);
157 }
158 
LnnRequestLeaveByAddrType(const bool * type,uint32_t typeLen)159 int32_t LnnRequestLeaveByAddrType(const bool *type, uint32_t typeLen)
160 {
161     return GetLnnIpNetworkImplInterface()->LnnRequestLeaveByAddrType(type, typeLen);
162 }
163 
GetNetworkIpByIfName(const char * ifName,char * ip,char * netmask,uint32_t len)164 int32_t GetNetworkIpByIfName(const char *ifName, char *ip, char *netmask, uint32_t len)
165 {
166     return GetLnnIpNetworkImplInterface()->GetNetworkIpByIfName(ifName, ip, netmask, len);
167 }
168 
lnnRegistProtocol(LnnProtocolManager * protocolMgr)169 int32_t lnnRegistProtocol(LnnProtocolManager *protocolMgr)
170 {
171     return GetLnnIpNetworkImplInterface()->LnnRegistProtocol(protocolMgr);
172 }
173 
LnnGetWlanIpv4Addr(char * ip,uint32_t size)174 int32_t LnnGetWlanIpv4Addr(char *ip, uint32_t size)
175 {
176     return GetLnnIpNetworkImplInterface()->GetWlanIpv4Addr(ip, size);
177 }
178 
ConnCoapStartServerListen(void)179 int32_t ConnCoapStartServerListen(void)
180 {
181     return GetLnnIpNetworkImplInterface()->ConnCoapStartServerListen();
182 }
183 
ConnCoapStopServerListen(void)184 void ConnCoapStopServerListen(void)
185 {
186     return GetLnnIpNetworkImplInterface()->ConnCoapStopServerListen();
187 }
188 }
189 } // namespace OHOS
190