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, uint8_t relation, bool isJoin)
91 {
92 return GetServiceInterface()->LnnNotifyLnnRelationChanged(udid, type, relation, isJoin);
93 }
94
LnnNotifyMasterNodeChanged(bool isMaster,const char * masterNodeUdid,int32_t weight)95 void LnnNotifyMasterNodeChanged(bool isMaster, const char *masterNodeUdid, int32_t weight)
96 {
97 return GetServiceInterface()->LnnNotifyMasterNodeChanged(isMaster, masterNodeUdid, weight);
98 }
99
LnnUnregisterEventHandler(LnnEventType event,LnnEventHandler handler)100 void LnnUnregisterEventHandler(LnnEventType event, LnnEventHandler handler)
101 {
102 return GetServiceInterface()->LnnUnregisterEventHandler(event, handler);
103 }
104
LnnOfflineTimingByHeartbeat(const char * networkId,ConnectionAddrType addrType)105 int32_t LnnOfflineTimingByHeartbeat(const char *networkId, ConnectionAddrType addrType)
106 {
107 return GetServiceInterface()->LnnOfflineTimingByHeartbeat(networkId, addrType);
108 }
109
AuthGenRequestId(void)110 uint32_t AuthGenRequestId(void)
111 {
112 return GetServiceInterface()->AuthGenRequestId();
113 }
114
AuthHandleLeaveLNN(AuthHandle authHandle)115 void AuthHandleLeaveLNN(AuthHandle authHandle)
116 {
117 return GetServiceInterface()->AuthHandleLeaveLNN(authHandle);
118 }
119
AuthGetDeviceUuid(int64_t authId,char * uuid,uint16_t size)120 int32_t AuthGetDeviceUuid(int64_t authId, char *uuid, uint16_t size)
121 {
122 return GetServiceInterface()->AuthGetDeviceUuid(authId, uuid, size);
123 }
124
SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf * configList,uint32_t * num)125 int32_t SoftBusGetWifiDeviceConfig(SoftBusWifiDevConf *configList, uint32_t *num)
126 {
127 return GetServiceInterface()->SoftBusGetWifiDeviceConfig(configList, num);
128 }
129
SoftBusConnectToDevice(const SoftBusWifiDevConf * wifiConfig)130 int32_t SoftBusConnectToDevice(const SoftBusWifiDevConf *wifiConfig)
131 {
132 return GetServiceInterface()->SoftBusConnectToDevice(wifiConfig);
133 }
134
SoftBusDisconnectDevice(void)135 int32_t SoftBusDisconnectDevice(void)
136 {
137 return GetServiceInterface()->SoftBusDisconnectDevice();
138 }
139
LnnDiscTypeToConnAddrType(DiscoveryType type)140 ConnectionAddrType LnnDiscTypeToConnAddrType(DiscoveryType type)
141 {
142 return GetServiceInterface()->LnnDiscTypeToConnAddrType(type);
143 }
144
UpdateProfile(const NodeInfo * info)145 void UpdateProfile(const NodeInfo *info)
146 {
147 return GetServiceInterface()->UpdateProfile(info);
148 }
149
IsFeatureSupport(uint64_t feature,FeatureCapability capaBit)150 bool IsFeatureSupport(uint64_t feature, FeatureCapability capaBit)
151 {
152 return GetServiceInterface()->IsFeatureSupport(feature, capaBit);
153 }
154
LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType,LnnHeartbeatStrategyType strategy,bool isRelay)155 int32_t LnnStartHbByTypeAndStrategy(LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategy, bool isRelay)
156 {
157 return GetServiceInterface()->LnnStartHbByTypeAndStrategy(hbType, strategy, isRelay);
158 }
159
SoftBusIsWifiTripleMode(void)160 bool SoftBusIsWifiTripleMode(void)
161 {
162 return GetServiceInterface()->SoftBusIsWifiTripleMode();
163 }
164
SoftBusGetLinkBand(void)165 SoftBusBand SoftBusGetLinkBand(void)
166 {
167 return GetServiceInterface()->SoftBusGetLinkBand();
168 }
169
SoftBusGetWifiState(void)170 SoftBusWifiDetailState SoftBusGetWifiState(void)
171 {
172 return GetServiceInterface()->SoftBusGetWifiState();
173 }
174
SoftBusHasWifiDirectCapability(void)175 bool SoftBusHasWifiDirectCapability(void)
176 {
177 return GetServiceInterface()->SoftBusHasWifiDirectCapability();
178 }
179
SoftBusGetWifiInterfaceCoexistCap(void)180 char *SoftBusGetWifiInterfaceCoexistCap(void)
181 {
182 return GetServiceInterface()->SoftBusGetWifiInterfaceCoexistCap();
183 }
184
LnnAsyncCallbackHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para)185 int32_t LnnAsyncCallbackHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para)
186 {
187 return GetServiceInterface()->LnnAsyncCallbackHelper(looper, callback, para);
188 }
189
LnnAsyncCallbackDelayHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para,uint64_t delayMillis)190 int32_t LnnAsyncCallbackDelayHelper(
191 SoftBusLooper *looper, LnnAsyncCallbackFunc callback, void *para, uint64_t delayMillis)
192 {
193 return GetServiceInterface()->LnnAsyncCallbackDelayHelper(looper, callback, para, delayMillis);
194 }
195
SoftBusGenerateRandomArray(unsigned char * randStr,uint32_t len)196 int32_t SoftBusGenerateRandomArray(unsigned char *randStr, uint32_t len)
197 {
198 return GetServiceInterface()->SoftBusGenerateRandomArray(randStr, len);
199 }
200
LnnGetDeviceDisplayName(const char * nickName,const char * defaultName,char * deviceName,uint32_t len)201 int32_t LnnGetDeviceDisplayName(const char *nickName, const char *defaultName, char *deviceName, uint32_t len)
202 {
203 return GetServiceInterface()->LnnGetDeviceDisplayName(nickName, defaultName, deviceName, len);
204 }
205
LnnGetUnifiedDeviceName(char * unifiedName,uint32_t len)206 int32_t LnnGetUnifiedDeviceName(char *unifiedName, uint32_t len)
207 {
208 return GetServiceInterface()->LnnGetUnifiedDeviceName(unifiedName, len);
209 }
210
LnnGetUnifiedDefaultDeviceName(char * unifiedDefaultName,uint32_t len)211 int32_t LnnGetUnifiedDefaultDeviceName(char *unifiedDefaultName, uint32_t len)
212 {
213 return GetServiceInterface()->LnnGetUnifiedDefaultDeviceName(unifiedDefaultName, len);
214 }
215
GetCurrentAccount(int64_t * account)216 int32_t GetCurrentAccount(int64_t *account)
217 {
218 return GetServiceInterface()->GetCurrentAccount(account);
219 }
220
LnnSetLocalUnifiedName(const char * unifiedName)221 int32_t LnnSetLocalUnifiedName(const char *unifiedName)
222 {
223 return GetServiceInterface()->LnnSetLocalUnifiedName(unifiedName);
224 }
225
LnnNotifyLocalNetworkIdChanged(void)226 void LnnNotifyLocalNetworkIdChanged(void)
227 {
228 return GetServiceInterface()->LnnNotifyLocalNetworkIdChanged();
229 }
230
LnnGetSettingNickName(const char * defaultName,const char * unifiedName,char * nickName,uint32_t len)231 int32_t LnnGetSettingNickName(const char *defaultName, const char *unifiedName, char *nickName, uint32_t len)
232 {
233 return GetServiceInterface()->LnnGetSettingNickName(defaultName, unifiedName, nickName, len);
234 }
235
SoftbusGetConfig(ConfigType type,unsigned char * val,uint32_t len)236 int32_t SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len)
237 {
238 return GetServiceInterface()->SoftbusGetConfig(type, val, len);
239 }
240
LnnSubscribeAccountBootEvent(AccountEventHandle handle)241 int32_t LnnSubscribeAccountBootEvent(AccountEventHandle handle)
242 {
243 return GetServiceInterface()->LnnSubscribeAccountBootEvent(handle);
244 }
245
LnnNotifyOnlineNetType(const char * networkId,ConnectionAddrType addrType)246 void LnnNotifyOnlineNetType(const char *networkId, ConnectionAddrType addrType)
247 {
248 return GetServiceInterface()->LnnNotifyOnlineNetType(networkId, addrType);
249 }
250
LnnNotifyDeviceInfoChanged(SoftBusDeviceInfoState state)251 void LnnNotifyDeviceInfoChanged(SoftBusDeviceInfoState state)
252 {
253 return GetServiceInterface()->LnnNotifyDeviceInfoChanged(state);
254 }
255
ActionOfLnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)256 int32_t LnnServicetInterfaceMock::ActionOfLnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
257 {
258 if (event == LNN_EVENT_TYPE_MAX || handler == nullptr) {
259 return SOFTBUS_INVALID_PARAM;
260 }
261 g_lnnEventHandlers.emplace(event, handler);
262 return SOFTBUS_OK;
263 }
264 } // extern "C"
265 } // namespace OHOS