• 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_log.h"
20 #include "lnn_service_mock.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_serviceInterface;
LnnServicetInterfaceMock()29 LnnServicetInterfaceMock::LnnServicetInterfaceMock()
30 {
31     g_serviceInterface = reinterpret_cast<void *>(this);
32 }
33 
~LnnServicetInterfaceMock()34 LnnServicetInterfaceMock::~LnnServicetInterfaceMock()
35 {
36     g_serviceInterface = nullptr;
37 }
38 
GetServiceInterface()39 static LnnServiceInterface *GetServiceInterface()
40 {
41     return reinterpret_cast<LnnServiceInterface *>(g_serviceInterface);
42 }
43 
44 extern "C" {
LnnInitBusCenterEvent(void)45 int32_t LnnInitBusCenterEvent(void)
46 {
47     return GetServiceInterface()->LnnInitBusCenterEvent();
48 }
49 
LnnDeinitBusCenterEvent(void)50 void LnnDeinitBusCenterEvent(void)
51 {
52     return GetServiceInterface()->LnnDeinitBusCenterEvent();
53 }
54 
LnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)55 int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
56 {
57     return GetServiceInterface()->LnnRegisterEventHandler(event, handler);
58 }
59 
LnnNotifyJoinResult(ConnectionAddr * addr,const char * networkId,int32_t retCode)60 void LnnNotifyJoinResult(ConnectionAddr *addr, const char *networkId, int32_t retCode)
61 {
62     return GetServiceInterface()->LnnNotifyJoinResult(addr, networkId, retCode);
63 }
64 
LnnNotifyLeaveResult(const char * networkId,int32_t retCode)65 void LnnNotifyLeaveResult(const char *networkId, int32_t retCode)
66 {
67     return GetServiceInterface()->LnnNotifyLeaveResult(networkId, retCode);
68 }
69 
LnnNotifyOnlineState(bool isOnline,NodeBasicInfo * info)70 void LnnNotifyOnlineState(bool isOnline, NodeBasicInfo *info)
71 {
72     return GetServiceInterface()->LnnNotifyOnlineState(isOnline, info);
73 }
74 
LnnNotifyBasicInfoChanged(NodeBasicInfo * info,NodeBasicInfoType type)75 void LnnNotifyBasicInfoChanged(NodeBasicInfo *info, NodeBasicInfoType type)
76 {
77     return GetServiceInterface()->LnnNotifyBasicInfoChanged(info, type);
78 }
79 
LnnNotifyWlanStateChangeEvent(void * state)80 void LnnNotifyWlanStateChangeEvent(void *state)
81 {
82     return GetServiceInterface()->LnnNotifyWlanStateChangeEvent(state);
83 }
84 
LnnNotifyBtStateChangeEvent(void * state)85 void LnnNotifyBtStateChangeEvent(void *state)
86 {
87     return GetServiceInterface()->LnnNotifyBtStateChangeEvent(state);
88 }
89 
LnnNotifyLnnRelationChanged(const char * udid,ConnectionAddrType type,uint8_t relation,bool isJoin)90 void LnnNotifyLnnRelationChanged(const char *udid, ConnectionAddrType type,
91     uint8_t relation, bool isJoin)
92 {
93     return GetServiceInterface()->LnnNotifyLnnRelationChanged(udid, type, relation, isJoin);
94 }
95 
LnnNotifyMasterNodeChanged(bool isMaster,const char * masterNodeUdid,int32_t weight)96 void LnnNotifyMasterNodeChanged(bool isMaster, const char* masterNodeUdid, int32_t weight)
97 {
98     return GetServiceInterface()->LnnNotifyMasterNodeChanged(isMaster, masterNodeUdid, weight);
99 }
100 
LnnInitGetDeviceName(LnnDeviceNameHandler handler)101 int32_t LnnInitGetDeviceName(LnnDeviceNameHandler handler)
102 {
103     return GetServiceInterface()->LnnInitGetDeviceName(handler);
104 }
105 
RegisterNameMonitor(void)106 void RegisterNameMonitor(void)
107 {
108     return GetServiceInterface()->RegisterNameMonitor();
109 }
110 
LnnUnregisterEventHandler(LnnEventType event,LnnEventHandler handler)111 void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler)
112 {
113     return GetServiceInterface()->LnnUnregisterEventHandler(event, handler);
114 }
115 
LnnOfflineTimingByHeartbeat(const char * networkId,ConnectionAddrType addrType)116 int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType)
117 {
118     return GetServiceInterface()->LnnOfflineTimingByHeartbeat(networkId, addrType);
119 }
120 
LnnGetSettingDeviceName(char * deviceName,uint32_t len)121 int32_t LnnGetSettingDeviceName(char *deviceName, uint32_t len)
122 {
123     return GetServiceInterface()->LnnGetSettingDeviceName(deviceName, len);
124 }
125 
AuthGenRequestId(void)126 uint32_t AuthGenRequestId(void)
127 {
128     return GetServiceInterface()->AuthGenRequestId();
129 }
130 
AuthHandleLeaveLNN(AuthHandle authHandle)131 void AuthHandleLeaveLNN(AuthHandle authHandle)
132 {
133     return GetServiceInterface()->AuthHandleLeaveLNN(authHandle);
134 }
135 
AuthGetDeviceUuid(int64_t authId,char * uuid,uint16_t size)136 int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
137 {
138     return GetServiceInterface()->AuthGetDeviceUuid(authId, uuid, size);
139 }
140 
SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf * configList,uint32_t * num)141 int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
142 {
143     return GetServiceInterface()->SoftBusGetWifiDeviceConfig(configList, num);
144 }
145 
SoftBusConnectToDevice(const SoftBusWifiDevConf * wifiConfig)146 int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
147 {
148     return GetServiceInterface()->SoftBusConnectToDevice(wifiConfig);
149 }
150 
SoftBusDisconnectDevice(void)151 int32_t SoftBusDisconnectDevice(void)
152 {
153     return GetServiceInterface()->SoftBusDisconnectDevice();
154 }
155 
LnnDiscTypeToConnAddrType(DiscoveryType type)156 ConnectionAddrType LnnDiscTypeToConnAddrType(DiscoveryType type)
157 {
158     return GetServiceInterface()->LnnDiscTypeToConnAddrType(type);
159 }
160 
UpdateProfile(const NodeInfo * info)161 void UpdateProfile(const NodeInfo *info)
162 {
163     return GetServiceInterface()->UpdateProfile(info);
164 }
165 
IsFeatureSupport(uint64_t feature,FeatureCapability capaBit)166 bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit)
167 {
168     return GetServiceInterface()->IsFeatureSupport(feature, capaBit);
169 }
170 
LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType,LnnHeartbeatStrategyType strategy,bool isRelay)171 int32_t LnnStartHbByTypeAndStrategy(
172     LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategy, bool isRelay)
173 {
174     return GetServiceInterface()->LnnStartHbByTypeAndStrategy(hbType, strategy, isRelay);
175 }
176 
SoftBusIsWifiTripleMode(void)177 bool SoftBusIsWifiTripleMode(void)
178 {
179     return GetServiceInterface()->SoftBusIsWifiTripleMode();
180 }
181 
SoftBusGetLinkBand(void)182 SoftBusBand SoftBusGetLinkBand(void)
183 {
184     return GetServiceInterface()->SoftBusGetLinkBand();
185 }
186 
SoftBusGetWifiState(void)187 SoftBusWifiDetailState SoftBusGetWifiState(void)
188 {
189     return GetServiceInterface()->SoftBusGetWifiState();
190 }
191 
SoftBusHasWifiDirectCapability(void)192 bool SoftBusHasWifiDirectCapability(void)
193 {
194     return GetServiceInterface()->SoftBusHasWifiDirectCapability();
195 }
196 
SoftBusGetWifiInterfaceCoexistCap(void)197 char* SoftBusGetWifiInterfaceCoexistCap(void)
198 {
199     return GetServiceInterface()->SoftBusGetWifiInterfaceCoexistCap();
200 }
201 
LnnAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)202 int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
203 {
204     return GetServiceInterface()->LnnAsyncCallbackHelper(looper, callback, para);
205 }
206 
LnnAsyncCallbackDelayHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para,uint64_t delayMillis)207 int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback,
208     void *para, uint64_t delayMillis)
209 {
210     return GetServiceInterface()->LnnAsyncCallbackDelayHelper(looper, callback, para, delayMillis);
211 }
212 
SoftBusGenerateRandomArray(unsigned char * randStr,uint32_t len)213 int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
214 {
215     return GetServiceInterface()->SoftBusGenerateRandomArray(randStr, len);
216 }
217 
LnnGetDeviceDisplayName(const char * nickName,const char * defaultName,char * deviceName,uint32_t len)218 int32_t LnnGetDeviceDisplayName(const char *nickName, const char *defaultName, char *deviceName, uint32_t len)
219 {
220     return GetServiceInterface()->LnnGetDeviceDisplayName(nickName, defaultName, deviceName, len);
221 }
222 
LnnGetUnifiedDeviceName(char * unifiedName,uint32_t len)223 int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len)
224 {
225     return GetServiceInterface()->LnnGetUnifiedDeviceName(unifiedName, len);
226 }
227 
LnnGetUnifiedDefaultDeviceName(char * unifiedDefaultName,uint32_t len)228 int32_t LnnGetUnifiedDefaultDeviceName(char *unifiedDefaultName, uint32_t len)
229 {
230     return GetServiceInterface()->LnnGetUnifiedDefaultDeviceName(unifiedDefaultName, len);
231 }
232 
GetCurrentAccount(int64_t * account)233 int32_t GetCurrentAccount(int64_t *account)
234 {
235     return GetServiceInterface()->GetCurrentAccount(account);
236 }
237 
LnnSetLocalUnifiedName(const char * unifiedName)238 int32_t LnnSetLocalUnifiedName(const char *unifiedName)
239 {
240     return GetServiceInterface()->LnnSetLocalUnifiedName(unifiedName);
241 }
242 
LnnNotifyLocalNetworkIdChanged(void)243 void LnnNotifyLocalNetworkIdChanged(void)
244 {
245     return GetServiceInterface()->LnnNotifyLocalNetworkIdChanged();
246 }
247 
LnnGetSettingNickName(const char * defaultName,const char * unifiedName,char * nickName,uint32_t len)248 int32_t LnnGetSettingNickName(const char *defaultName, const char *unifiedName, char *nickName, uint32_t len)
249 {
250     return GetServiceInterface()->LnnGetSettingNickName(defaultName, unifiedName, nickName, len);
251 }
252 
SoftbusGetConfig(ConfigType type,unsigned char * val,uint32_t len)253 int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len)
254 {
255     return GetServiceInterface()->SoftbusGetConfig(type, val, len);
256 }
257 
LnnSubscribeAccountBootEvent(AccountEventHandle handle)258 int32_t LnnSubscribeAccountBootEvent(AccountEventHandle handle)
259 {
260     return GetServiceInterface()->LnnSubscribeAccountBootEvent(handle);
261 }
262 
ActionOfLnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)263 int32_t LnnServicetInterfaceMock::ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
264 {
265     if (event == LNN_EVENT_TYPE_MAX || handler == NULL) {
266         return SOFTBUS_INVALID_PARAM;
267     }
268     g_lnnEventHandlers.emplace(event, handler);
269     return SOFTBUS_OK;
270 }
271 
ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)272 int32_t LnnServicetInterfaceMock::ActionOfLnnInitGetDeviceName(LnnDeviceNameHandler handler)
273 {
274     if (handler == NULL) {
275         return SOFTBUS_INVALID_PARAM;
276     }
277     g_deviceNameHandler = handler;
278     return SOFTBUS_OK;
279 }
280 
ActionOfLnnGetSettingDeviceName(char * deviceName,uint32_t len)281 int32_t LnnServicetInterfaceMock::ActionOfLnnGetSettingDeviceName(char *deviceName, uint32_t len)
282 {
283     if (deviceName == NULL) {
284         LNN_LOGW(LNN_TEST, "invalid para");
285         return SOFTBUS_ERR;
286     }
287     if (memcpy_s(deviceName, len, "abc", strlen("abc") + 1) != EOK) {
288         LNN_LOGE(LNN_TEST, "memcpy info fail");
289         return SOFTBUS_ERR;
290     }
291     return SOFTBUS_OK;
292 }
293 } // extern "C"
294 } // namespace OHOS