1 /*
2 * Copyright (c) 2022-2023 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_net_builder_deps_mock.h"
21 #include "lnn_net_builder.c"
22 #include "lnn_net_builder_init.c"
23 #include "lnn_net_builder_process.c"
24 #include "lnn_net_builder.h"
25 #include "softbus_adapter_bt_common.h"
26 #include "softbus_common.h"
27 #include "softbus_errcode.h"
28
29 namespace OHOS {
30 using namespace testing::ext;
31 constexpr int32_t LOCAL_WEIGHT = 10;
32 constexpr char NODE_UDID[] = "123456ABCDEF";
33 constexpr char NODE_NETWORK_ID[] = "235689BNHFCF";
34 constexpr char NODE1_NETWORK_ID[] = "345678BNHFCF";
35 constexpr int64_t AUTH_META_ID = 1;
36 constexpr char INVALID_UDID[] =
37 "ASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJK\
38 LPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJ\
39 KLPASDFGHJKLPASDFGHJKLPASDFGHJKLPASDFGHJKLP";
40 constexpr int64_t AUTH_ID = 10;
41 constexpr int64_t AUTH_ID_ADD = 11;
42 constexpr char NODE1_BR_MAC[] = "12345TTU";
43 constexpr char NODE2_BR_MAC[] = "56789TTU";
44 constexpr char ACCOUNT_HASH[] = "5FEC";
45 constexpr uint32_t REQUEST_ID = 1;
46 constexpr uint32_t REQUEST_ID_ADD = 2;
47 constexpr uint16_t FSM_ID = 1;
48 constexpr uint16_t FSM_ID_ADD = 2;
49 constexpr char NODE1_IP[] = "10.146.181.134";
50 constexpr char NODE2_IP[] = "10.147.182.135";
51 constexpr int32_t CONN_COUNT = 10;
52 constexpr int32_t CURRENT_COUNT = 11;
53 constexpr uint32_t CONN_FLAG1 = 128;
54 constexpr uint32_t CONN_FLAG2 = 255;
55 constexpr uint32_t CONN_FLAG3 = 1;
56 constexpr uint32_t MSG_ERR_LEN0 = 0;
57 constexpr uint32_t MSG_ERR_LEN1 = 1;
58 constexpr uint8_t SELECT_MASTER_MSG[] = "{\"MasterWeight\":\"500\", \"MasterUdid\":\"123456\"}";
59 constexpr uint8_t EMPTY_ACCOUNT[] = "5FEC";
60
61 using namespace testing;
62 class LNNNetBuilderMockTest : public testing::Test {
63 public:
64 static void SetUpTestCase();
65 static void TearDownTestCase();
66 void SetUp();
67 void TearDown();
68 };
69
SetUpTestCase()70 void LNNNetBuilderMockTest::SetUpTestCase() {}
71
TearDownTestCase()72 void LNNNetBuilderMockTest::TearDownTestCase() {}
73
SetUp()74 void LNNNetBuilderMockTest::SetUp() {}
75
TearDown()76 void LNNNetBuilderMockTest::TearDown() {}
77
ClearNetBuilderFsmList()78 static void ClearNetBuilderFsmList()
79 {
80 NetBuilder *netBuilder = LnnGetNetBuilder();
81 if (netBuilder == nullptr) {
82 return;
83 }
84 LnnConnectionFsm *item = NULL;
85 LnnConnectionFsm *next = NULL;
86 LIST_FOR_EACH_ENTRY_SAFE(item, next, &netBuilder->fsmList, LnnConnectionFsm, node) {
87 ListDelete(&item->node);
88 --netBuilder->connCount;
89 }
90 }
91
92 /*
93 * @tc.name: LNN_INIT_NET_BUILDER_TEST_001
94 * @tc.desc: lnn init netbuilder test
95 * @tc.type: FUNC
96 * @tc.require:
97 */
98 HWTEST_F(LNNNetBuilderMockTest, LNN_INIT_NET_BUILDER_TEST_001, TestSize.Level1)
99 {
100 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
101 EXPECT_CALL(NetBuilderMock, LnnInitSyncInfoManager())
102 .WillOnce(Return(SOFTBUS_ERR))
103 .WillRepeatedly(Return(SOFTBUS_OK));
104 EXPECT_CALL(NetBuilderMock, LnnInitTopoManager()).WillRepeatedly(Return(SOFTBUS_OK));
105 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
106 EXPECT_CALL(NetBuilderMock, RegAuthVerifyListener(_))
107 .WillOnce(Return(SOFTBUS_ERR))
108 .WillRepeatedly(Return(SOFTBUS_OK));
109 EXPECT_CALL(NetBuilderMock, LnnRegSyncInfoHandler(_, _))
110 .WillOnce(Return(SOFTBUS_ERR))
111 .WillRepeatedly(Return(SOFTBUS_OK));
112 EXPECT_CALL(NetBuilderMock, LnnGenLocalNetworkId(_, _))
113 .WillOnce(Return(SOFTBUS_ERR))
114 .WillRepeatedly(Return(SOFTBUS_OK));
115 EXPECT_CALL(NetBuilderMock, LnnGenLocalUuid(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
116 EXPECT_CALL(NetBuilderMock, LnnGenLocalIrk(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
117 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
118 EXPECT_CALL(NetBuilderMock, SoftBusGetBtState()).WillRepeatedly(Return(BLE_ENABLE));
119 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
120 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
121 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
122 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_ERR);
123 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_LOOPER_ERR);
124 }
125
126 /*
127 * @tc.name: CONFIG_LOCAL_LEDGER_TEST_001
128 * @tc.desc: config local ledger test
129 * @tc.type: FUNC
130 * @tc.require:
131 */
132 HWTEST_F(LNNNetBuilderMockTest, CONFIG_LOCAL_LEDGER_TEST_001, TestSize.Level1)
133 {
134 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
135 EXPECT_CALL(NetBuilderMock, LnnGenLocalNetworkId(_, _))
136 .WillOnce(Return(SOFTBUS_ERR))
137 .WillRepeatedly(Return(SOFTBUS_OK));
138 EXPECT_CALL(NetBuilderMock, LnnGenLocalUuid(_, _))
139 .WillOnce(Return(SOFTBUS_ERR))
140 .WillRepeatedly(Return(SOFTBUS_OK));
141 EXPECT_CALL(NetBuilderMock, LnnGenLocalIrk(_, _))
142 .WillOnce(Return(SOFTBUS_ERR))
143 .WillRepeatedly(Return(SOFTBUS_OK));
144 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
145 EXPECT_TRUE(ConifgLocalLedger() != SOFTBUS_OK);
146 EXPECT_TRUE(ConifgLocalLedger() != SOFTBUS_OK);
147 EXPECT_TRUE(ConifgLocalLedger() == SOFTBUS_OK);
148 }
149
150 /*
151 * @tc.name: LNN_INIT_NET_BUILDER_DELAY_TEST_001
152 * @tc.desc: lnn init netbuilder delay test
153 * @tc.type: FUNC
154 * @tc.require:
155 */
156 HWTEST_F(LNNNetBuilderMockTest, LNN_INIT_NET_BUILDER_DELAY_TEST_001, TestSize.Level1)
157 {
158 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
159 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
160 EXPECT_CALL(NetBuilderMock, LnnGetLocalWeight()).WillRepeatedly(Return(LOCAL_WEIGHT));
161 EXPECT_CALL(NetBuilderMock, LnnSetLocalNumInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
162 EXPECT_CALL(NetBuilderMock, LnnInitFastOffline())
163 .WillOnce(Return(SOFTBUS_ERR))
164 .WillRepeatedly(Return(SOFTBUS_OK));
165 EXPECT_TRUE(LnnInitNetBuilderDelay() == SOFTBUS_ERR);
166 EXPECT_TRUE(LnnInitNetBuilderDelay() == SOFTBUS_OK);
167 EXPECT_TRUE(LnnInitNetBuilderDelay() == SOFTBUS_OK);
168 }
169
170 /*
171 * @tc.name: PROCESS_LEAVE_BY_ADDR_TYPE_TEST_002
172 * @tc.desc: ProcessLeaveByAddrType test
173 * @tc.type: FUNC
174 * @tc.require:
175 */
176 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_BY_ADDR_TYPE_TEST_002, TestSize.Level1)
177 {
178 ClearNetBuilderFsmList();
179 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
180 EXPECT_TRUE(connFsm != nullptr);
181 ListInit(&connFsm->node);
182 (void)strcpy_s(connFsm->connInfo.addr.info.ip.ip, IP_STR_MAX_LEN, NODE1_IP);
183 connFsm->connInfo.addr.type = CONNECTION_ADDR_WLAN;
184 connFsm->connInfo.authHandle.authId = AUTH_ID_ADD;
185 connFsm->isDead = false;
186 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
187 ++LnnGetNetBuilder()->connCount;
188 LnnConnectionFsm *connFsm1 = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
189 EXPECT_TRUE(connFsm1 != nullptr);
190 connFsm1->connInfo.addr.type = CONNECTION_ADDR_BR;
191 connFsm1->isDead = true;
192 ListInit(&connFsm1->node);
193 ListAdd(&g_netBuilder.fsmList, &connFsm1->node);
194 ++LnnGetNetBuilder()->connCount;
195 bool addrType[CONNECTION_ADDR_MAX] = {
196 [CONNECTION_ADDR_BR] = false,
197 [CONNECTION_ADDR_WLAN] = true,
198 [CONNECTION_ADDR_BLE] = false,
199 };
200 bool *para = reinterpret_cast<bool *>(SoftBusMalloc(sizeof(bool) * CONNECTION_ADDR_MAX));
201 EXPECT_TRUE(para != nullptr);
202 EXPECT_EQ(EOK, memcpy_s(para, sizeof(bool) * CONNECTION_ADDR_MAX, addrType, sizeof(bool) * CONNECTION_ADDR_MAX));
203 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
204 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_ERR));
205 EXPECT_CALL(NetBuilderMock, LnnNotifyAllTypeOffline(_)).WillRepeatedly(Return());
206 int32_t ret = ProcessLeaveByAddrType(reinterpret_cast<const void *>(para));
207 EXPECT_EQ(ret, SOFTBUS_OK);
208 bool *para1 = reinterpret_cast<bool *>(SoftBusMalloc(sizeof(bool) * CONNECTION_ADDR_MAX));
209 EXPECT_TRUE(para1 != nullptr);
210 EXPECT_EQ(EOK, memcpy_s(para1, sizeof(bool) * CONNECTION_ADDR_MAX, addrType, sizeof(bool) * CONNECTION_ADDR_MAX));
211 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
212 ret = ProcessLeaveByAddrType(reinterpret_cast<const void *>(para1));
213 EXPECT_EQ(ret, SOFTBUS_OK);
214 EXPECT_CALL(NetBuilderMock, LnnDestroyConnectionFsm).WillRepeatedly(Return());
215 EXPECT_CALL(NetBuilderMock, LnnStopConnectionFsm).WillOnce(Return(SOFTBUS_ERR));
216 CleanConnectionFsm(nullptr);
217 CleanConnectionFsm(connFsm);
218 StopConnectionFsm(connFsm);
219 EXPECT_CALL(NetBuilderMock, LnnStopConnectionFsm).WillRepeatedly(Return(SOFTBUS_OK));
220 StopConnectionFsm(connFsm1);
221 ret = FindRequestIdByAddr(nullptr, nullptr);
222 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
223 ClearNetBuilderFsmList();
224 }
225
226 /*
227 * @tc.name: LNN_UPDATE_NODE_ADDR_TEST_001
228 * @tc.desc: lnn update node addr test
229 * @tc.type: FUNC
230 * @tc.require:
231 */
232 HWTEST_F(LNNNetBuilderMockTest, LNN_UPDATE_NODE_ADDR_TEST_001, TestSize.Level1)
233 {
234 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
235 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _))
236 .WillOnce(Return(SOFTBUS_ERR))
237 .WillRepeatedly(Return(SOFTBUS_OK));
238 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _))
239 .WillOnce(Return(SOFTBUS_ERR))
240 .WillRepeatedly(Return(SOFTBUS_OK));
241 EXPECT_CALL(NetBuilderMock, LnnGetAllOnlineNodeInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
242 EXPECT_CALL(NetBuilderMock, LnnNotifyNodeAddressChanged(_, _, _)).WillRepeatedly(Return());
243 EXPECT_TRUE(LnnUpdateNodeAddr(nullptr) == SOFTBUS_INVALID_PARAM);
244 EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) != SOFTBUS_OK);
245 EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) != SOFTBUS_OK);
246 EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) == SOFTBUS_OK);
247 EXPECT_TRUE(LnnUpdateNodeAddr(NODE_NETWORK_ID) == SOFTBUS_OK);
248 }
249
250 /*
251 * @tc.name: NODE_INFO_SYNC_TEST_001
252 * @tc.desc: node info sync test
253 * @tc.type: FUNC
254 * @tc.require:
255 */
256 HWTEST_F(LNNNetBuilderMockTest, NODE_INFO_SYNC_TEST_001, TestSize.Level1)
257 {
258 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
259 EXPECT_CALL(NetBuilderMock, LnnInitP2p())
260 .WillOnce(Return(SOFTBUS_ERR))
261 .WillRepeatedly(Return(SOFTBUS_OK));
262 EXPECT_CALL(NetBuilderMock, LnnInitNetworkInfo())
263 .WillOnce(Return(SOFTBUS_ERR))
264 .WillRepeatedly(Return(SOFTBUS_OK));
265 EXPECT_CALL(NetBuilderMock, LnnInitDevicename())
266 .WillOnce(Return(SOFTBUS_ERR))
267 .WillRepeatedly(Return(SOFTBUS_OK));
268 EXPECT_CALL(NetBuilderMock, LnnInitOffline())
269 .WillOnce(Return(SOFTBUS_ERR))
270 .WillRepeatedly(Return(SOFTBUS_OK));
271 EXPECT_TRUE(InitNodeInfoSync() == SOFTBUS_ERR);
272 EXPECT_TRUE(InitNodeInfoSync() == SOFTBUS_ERR);
273 EXPECT_TRUE(InitNodeInfoSync() == SOFTBUS_ERR);
274 EXPECT_TRUE(InitNodeInfoSync() == SOFTBUS_ERR);
275 EXPECT_TRUE(InitNodeInfoSync() == SOFTBUS_OK);
276 }
277
278 /*
279 * @tc.name: ON_DEVICE_NOT_TRUSTED_TEST_001
280 * @tc.desc: on device not trusted test
281 * @tc.type: FUNC
282 * @tc.require:
283 */
284 HWTEST_F(LNNNetBuilderMockTest, ON_DEVICE_NOT_TRUSTED_TEST_001, TestSize.Level1)
285 {
286 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
287 SoftBusLooper loop;
288 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById(_, _))
289 .WillOnce(Return(false))
290 .WillRepeatedly(Return(true));
291 EXPECT_CALL(NetBuilderMock, AuthGetLatestAuthSeqList(_, _, _))
292 .WillOnce(Return(SOFTBUS_ERR))
293 .WillRepeatedly(Return(SOFTBUS_OK));
294 EXPECT_CALL(NetBuilderMock, LnnSendNotTrustedInfo(_, _, _))
295 .WillOnce(Return(SOFTBUS_ERR))
296 .WillRepeatedly(Return(SOFTBUS_OK));
297 EXPECT_CALL(NetBuilderMock, GetLooper(_)).WillRepeatedly(Return(&loop));
298 EXPECT_CALL(NetBuilderMock, LnnAsyncCallbackDelayHelper(_, _, _, _))
299 .WillOnce(Return(SOFTBUS_ERR))
300 .WillRepeatedly(Return(SOFTBUS_OK));
301 OnDeviceNotTrusted(nullptr);
302 OnDeviceNotTrusted(INVALID_UDID);
303 OnDeviceNotTrusted(NODE_UDID);
304 OnDeviceNotTrusted(NODE_UDID);
305 OnDeviceNotTrusted(NODE_UDID);
306 OnDeviceNotTrusted(NODE_UDID);
307 OnDeviceNotTrusted(NODE_UDID);
308 }
309
310 /*
311 * @tc.name: ON_DEVICE_VERIFY_PASS_TEST_001
312 * @tc.desc: on device verify pass test
313 * @tc.type: FUNC
314 * @tc.require:
315 */
316 HWTEST_F(LNNNetBuilderMockTest, ON_DEVICE_VERIFY_PASS_TEST_001, TestSize.Level1)
317 {
318 NodeInfo info;
319 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
320 EXPECT_CALL(NetBuilderMock, AuthGetConnInfo(_, _))
321 .WillOnce(Return(SOFTBUS_ERR))
322 .WillRepeatedly(Return(SOFTBUS_OK));
323 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _)).WillRepeatedly(Return(SOFTBUS_ERR));
324 EXPECT_CALL(NetBuilderMock, LnnConvertAuthConnInfoToAddr(_, _, _))
325 .WillOnce(Return(false))
326 .WillRepeatedly(Return(true));
327 AuthHandle authHandle = { .authId = AUTH_META_ID, .type = AUTH_LINK_TYPE_WIFI };
328 OnDeviceVerifyPass(authHandle, &info);
329 OnDeviceVerifyPass(authHandle, &info);
330 OnDeviceVerifyPass(authHandle, nullptr);
331 }
332
333 /*
334 * @tc.name: GET_CURRENT_CONNECT_TYPE_TEST_001
335 * @tc.desc: get current connect type test
336 * @tc.type: FUNC
337 * @tc.require:
338 */
339 HWTEST_F(LNNNetBuilderMockTest, GET_CURRENT_CONNECT_TYPE_TEST_001, TestSize.Level1)
340 {
341 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
342 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _))
343 .WillOnce(Return(SOFTBUS_ERR))
344 .WillRepeatedly(Return(SOFTBUS_OK));
345 EXPECT_CALL(NetBuilderMock, LnnGetAddrTypeByIfName(_, _))
346 .WillOnce(Return(SOFTBUS_ERR))
347 .WillRepeatedly(Return(SOFTBUS_OK));
348 EXPECT_TRUE(GetCurrentConnectType() == CONNECTION_ADDR_MAX);
349 EXPECT_TRUE(GetCurrentConnectType() == CONNECTION_ADDR_MAX);
350 EXPECT_TRUE(GetCurrentConnectType() == CONNECTION_ADDR_MAX);
351 }
352
353 /*
354 * @tc.name: PROCESS_LEAVE_SPECIFIC_TEST_001
355 * @tc.desc: process leave specific test
356 * @tc.type: FUNC
357 * @tc.require:
358 */
359 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_SPECIFIC_TEST_001, TestSize.Level1)
360 {
361 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
362 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
363 EXPECT_TRUE(ProcessLeaveSpecific(nullptr) == SOFTBUS_INVALID_PARAM);
364 }
365
366 /*
367 * @tc.name: PROCESS_LEAVE_BY_ADDR_TYPE_TEST_001
368 * @tc.desc: process leave by addr type test
369 * @tc.type: FUNC
370 * @tc.require:
371 */
372 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_BY_ADDR_TYPE_TEST_001, TestSize.Level1)
373 {
374 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
375 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
376 EXPECT_CALL(NetBuilderMock, LnnNotifyAllTypeOffline(_)).WillRepeatedly(Return());
377 EXPECT_TRUE(ProcessLeaveByAddrType(nullptr) == SOFTBUS_INVALID_PARAM);
378 }
379
380 /*
381 * @tc.name: PROCESS_ELETE_TEST_001
382 * @tc.desc: process elect test
383 * @tc.type: FUNC
384 * @tc.require:
385 */
386 HWTEST_F(LNNNetBuilderMockTest, PROCESS_ELETE_TEST_001, TestSize.Level1)
387 {
388 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ElectMsgPara)));
389 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
390 SoftBusLooper loop;
391 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
392 EXPECT_CALL(NetBuilderMock, RegAuthVerifyListener(_)).WillRepeatedly(Return(SOFTBUS_OK));
393 EXPECT_CALL(NetBuilderMock, LnnRegSyncInfoHandler(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
394 EXPECT_CALL(NetBuilderMock, LnnGenLocalNetworkId(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
395 EXPECT_CALL(NetBuilderMock, LnnGenLocalUuid(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
396 EXPECT_CALL(NetBuilderMock, LnnGenLocalIrk(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
397 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
398 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
399 EXPECT_CALL(NetBuilderMock, LnnUnregSyncInfoHandler(_, _)).WillRepeatedly(Return(SOFTBUS_OK));
400 EXPECT_CALL(NetBuilderMock, GetLooper(_)).WillRepeatedly(Return(&loop));
401 EXPECT_CALL(NetBuilderMock, SoftBusGetBtState()).WillRepeatedly(Return(BLE_ENABLE));
402 EXPECT_TRUE(ProcessMasterElect(nullptr) == SOFTBUS_INVALID_PARAM);
403 EXPECT_TRUE(LnnInitBusCenterEvent() == SOFTBUS_OK);
404 EXPECT_TRUE(LnnInitNetBuilder() == SOFTBUS_OK);
405 EXPECT_TRUE(ProcessMasterElect(para) == SOFTBUS_ERR);
406 LnnDeinitNetBuilder();
407 LnnDeinitBusCenterEvent();
408 }
409
410 /*
411 * @tc.name: PROCESS_NODE_STATE_CHANGED_TEST_001
412 * @tc.desc: process node state changed test
413 * @tc.type: FUNC
414 * @tc.require:
415 */
416 HWTEST_F(LNNNetBuilderMockTest, PROCESS_NODE_STATE_CHANGED_TEST_001, TestSize.Level1)
417 {
418 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
419 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
420 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
421 EXPECT_TRUE(ProcessNodeStateChanged(nullptr) == SOFTBUS_INVALID_PARAM);
422 EXPECT_TRUE(ProcessNodeStateChanged(para) == SOFTBUS_ERR);
423 }
424
425 /*
426 * @tc.name: PROCESS_NODE_STATE_CHANGED_TEST_002
427 * @tc.desc: process node state changed test
428 * @tc.type: FUNC
429 * @tc.require:
430 */
431 HWTEST_F(LNNNetBuilderMockTest, PROCESS_NODE_STATE_CHANGED_TEST_002, TestSize.Level1)
432 {
433 void *para = nullptr;
434 para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
435 EXPECT_TRUE(para != nullptr);
436 void *para1 = nullptr;
437 para1 = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
438 EXPECT_TRUE(para1 != nullptr);
439 void *para2 = nullptr;
440 para2 = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
441 EXPECT_TRUE(para2 != nullptr);
442 LnnConnectionFsm *connFsm = nullptr;
443 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
444 EXPECT_TRUE(connFsm != nullptr);
445 ListInit(&connFsm->node);
446 connFsm->connInfo.version = SOFTBUS_NEW_V1;
447 connFsm->isDead = false;
448 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
449 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
450 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
451 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(true));
452 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById)
453 .WillOnce(Return(true))
454 .WillRepeatedly(Return(false));
455 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo)
456 .WillOnce(Return(SOFTBUS_OK))
457 .WillRepeatedly(Return(SOFTBUS_ERR));
458 EXPECT_TRUE(ProcessNodeStateChanged(para) == SOFTBUS_OK);
459 EXPECT_TRUE(ProcessNodeStateChanged(para1) != SOFTBUS_OK);
460 EXPECT_TRUE(ProcessNodeStateChanged(para2) != SOFTBUS_OK);
461 ListDelete(&connFsm->node);
462 SoftBusFree(connFsm);
463 }
464
465 /*
466 * @tc.name: PROCESS_NODE_STATE_CHANGED_TEST_003
467 * @tc.desc: process node state changed test
468 * @tc.type: FUNC
469 * @tc.require:
470 */
471 HWTEST_F(LNNNetBuilderMockTest, PROCESS_NODE_STATE_CHANGED_TEST_003, TestSize.Level1)
472 {
473 void *para = nullptr;
474 para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
475 EXPECT_TRUE(para != nullptr);
476 void *para1 = nullptr;
477 para1 = reinterpret_cast<void *>(SoftBusMalloc(sizeof(ConnectionAddr)));
478 EXPECT_TRUE(para1 != nullptr);
479 LnnConnectionFsm *connFsm = nullptr;
480 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
481 EXPECT_TRUE(connFsm != nullptr);
482 ListInit(&connFsm->node);
483 connFsm->connInfo.version = SOFTBUS_OLD_V2;
484 connFsm->isDead = false;
485 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
486 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
487 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
488 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(true));
489 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo)
490 .WillOnce(Return(SOFTBUS_ERR))
491 .WillRepeatedly(Return(SOFTBUS_OK));
492 EXPECT_CALL(NetBuilderMock, LnnConvertDLidToUdid).WillOnce(Return(NODE_UDID));
493 EXPECT_TRUE(ProcessNodeStateChanged(para) == SOFTBUS_OK);
494 EXPECT_TRUE(ProcessNodeStateChanged(para1) == SOFTBUS_OK);
495 ListDelete(&connFsm->node);
496 SoftBusFree(connFsm);
497 }
498
499 /*
500 * @tc.name: TRY_ELECT_NODE_OFFLINE_TEST_001
501 * @tc.desc: try elect node offline test
502 * @tc.type: FUNC
503 * @tc.require:
504 */
505 HWTEST_F(LNNNetBuilderMockTest, TRY_ELECT_NODE_OFFLINE_TEST_001, TestSize.Level1)
506 {
507 LnnConnectionFsm connFsm;
508 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
509 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _))
510 .WillOnce(Return(SOFTBUS_ERR))
511 .WillRepeatedly(Return(SOFTBUS_OK));
512 EXPECT_TRUE(TryElectMasterNodeOffline(&connFsm) != SOFTBUS_OK);
513 EXPECT_TRUE(TryElectMasterNodeOffline(&connFsm) == SOFTBUS_OK);
514 }
515
516 /*
517 * @tc.name: TRY_ELECT_NODE_ONLINE_TEST_001
518 * @tc.desc: try elect node online test
519 * @tc.type: FUNC
520 * @tc.require:
521 */
522 HWTEST_F(LNNNetBuilderMockTest, TRY_ELECT_NODE_ONLINE_TEST_001, TestSize.Level1)
523 {
524 LnnConnectionFsm connFsm;
525 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
526 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _))
527 .WillOnce(Return(SOFTBUS_ERR))
528 .WillRepeatedly(Return(SOFTBUS_OK));
529 EXPECT_CALL(NetBuilderMock, LnnGetLocalNumInfo(_, _))
530 .WillOnce(Return(SOFTBUS_ERR))
531 .WillRepeatedly(Return(SOFTBUS_OK));
532 EXPECT_CALL(NetBuilderMock, LnnGetRemoteStrInfo(_, _, _, _))
533 .WillOnce(Return(SOFTBUS_ERR))
534 .WillRepeatedly(Return(SOFTBUS_OK));
535 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNumInfo(_, _, _))
536 .WillOnce(Return(SOFTBUS_ERR))
537 .WillRepeatedly(Return(SOFTBUS_OK));
538 EXPECT_CALL(NetBuilderMock, LnnCompareNodeWeight(_, _, _, _)).WillRepeatedly(Return(0));
539 EXPECT_TRUE(TryElectMasterNodeOnline(&connFsm) != SOFTBUS_OK);
540 EXPECT_TRUE(TryElectMasterNodeOnline(&connFsm) != SOFTBUS_OK);
541 EXPECT_TRUE(TryElectMasterNodeOnline(&connFsm) != SOFTBUS_OK);
542 EXPECT_TRUE(TryElectMasterNodeOnline(&connFsm) != SOFTBUS_OK);
543 EXPECT_TRUE(TryElectMasterNodeOnline(&connFsm) == SOFTBUS_OK);
544 }
545
546 /*
547 * @tc.name: PROCESS_LEAVE_INVALID_CONN_TEST_001
548 * @tc.desc: process leave invalid conn test
549 * @tc.type: FUNC
550 * @tc.require:
551 */
552 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_INVALID_CONN_TEST_001, TestSize.Level1)
553 {
554 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(LeaveInvalidConnMsgPara)));
555 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
556 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
557 EXPECT_TRUE(ProcessLeaveInvalidConn(nullptr) == SOFTBUS_INVALID_PARAM);
558 EXPECT_TRUE(ProcessLeaveInvalidConn(para) == SOFTBUS_OK);
559 }
560
561 /*
562 * @tc.name: IS_INVALID_CONNECTION_FSM_TEST_001
563 * @tc.desc: is invalid connection fsm test
564 * @tc.type: FUNC
565 * @tc.require:
566 */
567 HWTEST_F(LNNNetBuilderMockTest, IS_INVALID_CONNECTION_FSM_TEST_001, TestSize.Level1)
568 {
569 LnnConnectionFsm connFsm;
570 (void)memset_s(&connFsm, sizeof(LnnConnectionFsm), 0, sizeof(LnnConnectionFsm));
571 (void)strncpy_s(connFsm.connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
572 LeaveInvalidConnMsgPara msgPara;
573 (void)memset_s(&msgPara, sizeof(LeaveInvalidConnMsgPara), 0, sizeof(LeaveInvalidConnMsgPara));
574 (void)strncpy_s(msgPara.oldNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE1_NETWORK_ID));
575 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
576 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
577 EXPECT_TRUE(IsInvalidConnectionFsm(&connFsm, &msgPara) == false);
578 (void)memset_s(&msgPara, sizeof(LeaveInvalidConnMsgPara), 0, sizeof(LeaveInvalidConnMsgPara));
579 (void)strncpy_s(msgPara.oldNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID, strlen(NODE_NETWORK_ID));
580 connFsm.isDead = true;
581 EXPECT_TRUE(IsInvalidConnectionFsm(&connFsm, &msgPara) == false);
582 connFsm.isDead = false;
583 msgPara.addrType = CONNECTION_ADDR_WLAN;
584 connFsm.connInfo.addr.type = CONNECTION_ADDR_BR;
585 EXPECT_TRUE(IsInvalidConnectionFsm(&connFsm, &msgPara) == false);
586 msgPara.addrType = CONNECTION_ADDR_MAX;
587 connFsm.connInfo.flag = 0;
588 EXPECT_TRUE(IsInvalidConnectionFsm(&connFsm, &msgPara) == false);
589 connFsm.connInfo.flag = 1;
590 EXPECT_TRUE(IsInvalidConnectionFsm(&connFsm, &msgPara) == false);
591 }
592
593 /*
594 * @tc.name: PROCESS_SYNC_OFFLINE_FINISH_TEST_001
595 * @tc.desc: process sync offline finish test
596 * @tc.type: FUNC
597 * @tc.require:
598 */
599 HWTEST_F(LNNNetBuilderMockTest, PROCESS_SYNC_OFFLINE_FINISH_TEST_001, TestSize.Level1)
600 {
601 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
602 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
603 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
604 EXPECT_TRUE(ProcessSyncOfflineFinish(nullptr) == SOFTBUS_INVALID_PARAM);
605 EXPECT_TRUE(ProcessSyncOfflineFinish(para) == SOFTBUS_OK);
606 }
607
608 /*
609 * @tc.name: PROCESS_LEAVE_LNN_REQUEST_TEST_001
610 * @tc.desc: process leave lnn request test
611 * @tc.type: FUNC
612 * @tc.require:
613 */
614 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_001, TestSize.Level1)
615 {
616 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
617 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
618 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_ERR));
619 EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
620 EXPECT_TRUE(ProcessLeaveLNNRequest(nullptr) == SOFTBUS_INVALID_PARAM);
621 EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
622 }
623
624 /*
625 * @tc.name: PROCESS_DEVICE_NOT_TRUSTED_TEST_001
626 * @tc.desc: process device not trusted test
627 * @tc.type: FUNC
628 * @tc.require:
629 */
630 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_NOT_TRUSTED_TEST_001, TestSize.Level1)
631 {
632 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
633 EXPECT_CALL(NetBuilderMock, LnnGetNetworkIdByUdid(_, _, _)).WillOnce(Return(SOFTBUS_ERR));
634 const char *peerUdid = NODE_UDID;
635 LnnDeleteLinkFinderInfo(peerUdid);
636 EXPECT_CALL(NetBuilderMock, LnnGetNetworkIdByUdid(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
637 LnnDeleteLinkFinderInfo(peerUdid);
638 EXPECT_TRUE(ProcessDeviceNotTrusted(nullptr) == SOFTBUS_INVALID_PARAM);
639 }
640
641 /*
642 * @tc.name: PROCESS_DEVICE_DISCONNECT_TEST_001
643 * @tc.desc: process device disconnect test
644 * @tc.type: FUNC
645 * @tc.require:
646 */
647 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_DISCONNECT_TEST_001, TestSize.Level1)
648 {
649 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(int64_t)));
650 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
651 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
652 EXPECT_TRUE(ProcessDeviceDisconnect(nullptr) == SOFTBUS_INVALID_PARAM);
653 EXPECT_TRUE(ProcessDeviceDisconnect(para) != SOFTBUS_OK);
654 }
655
656 /*
657 * @tc.name: PROCESS_DEVICE_VERIFY_PASS_TEST_001
658 * @tc.desc: process device verify pass test
659 * @tc.type: FUNC
660 * @tc.require:
661 */
662 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_001, TestSize.Level1)
663 {
664 DeviceVerifyPassMsgPara *msgPara =
665 reinterpret_cast<DeviceVerifyPassMsgPara *>(SoftBusMalloc(sizeof(DeviceVerifyPassMsgPara)));
666 msgPara->nodeInfo = NULL;
667 void *para = reinterpret_cast<void *>(msgPara);
668 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
669 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
670 EXPECT_TRUE(ProcessDeviceVerifyPass(nullptr) == SOFTBUS_INVALID_PARAM);
671 EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_INVALID_PARAM);
672 }
673
674 /*
675 * @tc.name: PROCESS_VERIFY_RESULT_TEST_001
676 * @tc.desc: process verify result test
677 * @tc.type: FUNC
678 * @tc.require:
679 */
680 HWTEST_F(LNNNetBuilderMockTest, PROCESS_VERIFY_RESULT_TEST_001, TestSize.Level1)
681 {
682 VerifyResultMsgPara *msgPara1 = reinterpret_cast<VerifyResultMsgPara *>(SoftBusMalloc(sizeof(VerifyResultMsgPara)));
683 msgPara1->nodeInfo = NULL;
684 void *para1 = reinterpret_cast<void *>(msgPara1);
685 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
686 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
687 EXPECT_TRUE(ProcessVerifyResult(nullptr) == SOFTBUS_INVALID_PARAM);
688 EXPECT_TRUE(ProcessVerifyResult(para1) != SOFTBUS_OK);
689 VerifyResultMsgPara *msgPara2 = reinterpret_cast<VerifyResultMsgPara *>(SoftBusMalloc(sizeof(VerifyResultMsgPara)));
690 msgPara2->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
691 void *para2 = reinterpret_cast<void *>(msgPara2);
692 EXPECT_TRUE(ProcessVerifyResult(para2) != SOFTBUS_OK);
693 }
694
695 /*
696 * @tc.name: PROCESS_CLEAN_CONNECTION_FSM_TEST_001
697 * @tc.desc: process clean connection fsm test
698 * @tc.type: FUNC
699 * @tc.require:
700 */
701 HWTEST_F(LNNNetBuilderMockTest, PROCESS_CLEAN_CONNECTION_FSM_TEST_001, TestSize.Level1)
702 {
703 void *para = reinterpret_cast<void *>(SoftBusMalloc(sizeof(uint16_t)));
704 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
705 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
706 EXPECT_TRUE(ProcessCleanConnectionFsm(nullptr) == SOFTBUS_INVALID_PARAM);
707 EXPECT_TRUE(ProcessCleanConnectionFsm(para) == SOFTBUS_ERR);
708 }
709
710 /*
711 * @tc.name: IS_NODE_ONLINE_TEST_001
712 * @tc.desc: is node online test
713 * @tc.type: FUNC
714 * @tc.require:
715 */
716 HWTEST_F(LNNNetBuilderMockTest, IS_NODE_ONLINE_TEST_001, TestSize.Level1)
717 {
718 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
719 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById(_, _))
720 .WillOnce(Return(false))
721 .WillRepeatedly(Return(true));
722 bool ret = IsNodeOnline(NODE_NETWORK_ID);
723 EXPECT_TRUE(ret == false);
724 ret = IsNodeOnline(NODE_NETWORK_ID);
725 EXPECT_TRUE(ret == true);
726 ret = IsNodeOnline(NODE_NETWORK_ID);
727 EXPECT_TRUE(ret == true);
728 }
729
730 /*
731 * @tc.name: UPDATE_LOCAL_NODE_TEST_001
732 * @tc.desc: update local node test
733 * @tc.type: FUNC
734 * @tc.require:
735 */
736 HWTEST_F(LNNNetBuilderMockTest, UPDATE_LOCAL_NODE_TEST_001, TestSize.Level1)
737 {
738 bool isCurrentNode = false;
739
740 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
741 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillOnce(Return(SOFTBUS_ERR));
742 UpdateLocalMasterNode(isCurrentNode, NODE_UDID, LOCAL_WEIGHT);
743
744 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillOnce(Return(SOFTBUS_OK));
745 EXPECT_CALL(NetBuilderMock, LnnSetLocalNumInfo(_, _)).WillOnce(Return(SOFTBUS_ERR));
746 EXPECT_CALL(NetBuilderMock, LnnNotifyMasterNodeChanged(_, _, _)).WillOnce(Return());
747 UpdateLocalMasterNode(isCurrentNode, NODE_UDID, LOCAL_WEIGHT);
748
749 EXPECT_CALL(NetBuilderMock, LnnSetLocalStrInfo(_, _)).WillOnce(Return(SOFTBUS_OK));
750 EXPECT_CALL(NetBuilderMock, LnnSetLocalNumInfo(_, _)).WillOnce(Return(SOFTBUS_OK));
751 EXPECT_CALL(NetBuilderMock, LnnNotifyMasterNodeChanged(_, _, _)).WillOnce(Return());
752 UpdateLocalMasterNode(isCurrentNode, NODE_UDID, LOCAL_WEIGHT);
753 }
754
755 /*
756 * @tc.name: DUP_NODE_INFO_TEST_001
757 * @tc.desc: dup node info test
758 * @tc.type: FUNC
759 * @tc.require:
760 */
761 HWTEST_F(LNNNetBuilderMockTest, DUP_NODE_INFO_TEST_001, TestSize.Level1)
762 {
763 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
764 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_ERR));
765 NetBuilderConfigInit();
766 NodeInfo info;
767 NodeInfo *ret = nullptr;
768 ret = DupNodeInfo(&info);
769 EXPECT_TRUE(ret != nullptr);
770 if (ret != nullptr) {
771 SoftBusFree(ret);
772 }
773 CleanConnectionFsm(nullptr);
774 EXPECT_TRUE(CreateNetworkIdMsgPara(nullptr) == nullptr);
775 EXPECT_TRUE(CreateConnectionAddrMsgPara(nullptr) == nullptr);
776 }
777
778 /*
779 * @tc.name: FIND_CONNECTION_FSM_TEST_001
780 * @tc.desc: net builder config init test
781 * @tc.type: FUNC
782 * @tc.require:
783 */
784 HWTEST_F(LNNNetBuilderMockTest, FIND_CONNECTION_FSM_TEST_001, TestSize.Level1)
785 {
786 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
787 ListInit(&connFsm->node);
788 (void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
789 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
790 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
791 connFsm->connInfo.requestId = REQUEST_ID;
792 connFsm->connInfo.authHandle.authId = AUTH_ID;
793 connFsm->connInfo.authHandle.type = AUTH_LINK_TYPE_BR;
794 connFsm->id = FSM_ID;
795 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
796 MetaJoinRequestNode *requestNode =
797 reinterpret_cast<MetaJoinRequestNode *>(SoftBusMalloc(sizeof(MetaJoinRequestNode)));
798 ListInit(&requestNode->node);
799 (void)strcpy_s(requestNode->addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
800 requestNode->requestId = REQUEST_ID;
801
802 ConnectionAddr addr;
803 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
804 (void)memset_s(&addr, sizeof(ConnectionAddr), 0, sizeof(ConnectionAddr));
805 (void)strcpy_s(addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
806 addr.type = CONNECTION_ADDR_BR;
807 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillOnce(Return(true));
808 EXPECT_TRUE(FindConnectionFsmByAddr(&addr, false) != nullptr);
809 addr.type = CONNECTION_ADDR_BLE;
810 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillOnce(Return(false));
811 EXPECT_TRUE(FindConnectionFsmByAddr(&addr, false) == nullptr);
812
813 EXPECT_TRUE(FindConnectionFsmByRequestId(REQUEST_ID) != nullptr);
814
815 EXPECT_TRUE(FindConnectionFsmByRequestId(REQUEST_ID_ADD) == nullptr);
816 AuthHandle authHandle = { .authId = AUTH_ID, .type = AUTH_LINK_TYPE_BR };
817 AuthHandle authHandle2 = { .authId = AUTH_ID_ADD, .type = AUTH_LINK_TYPE_WIFI };
818 EXPECT_TRUE(FindConnectionFsmByAuthHandle(&authHandle) != nullptr);
819 EXPECT_TRUE(FindConnectionFsmByAuthHandle(&authHandle2) == nullptr);
820 EXPECT_TRUE(FindConnectionFsmByNetworkId(NODE_NETWORK_ID) != nullptr);
821 EXPECT_TRUE(FindConnectionFsmByNetworkId(NODE1_NETWORK_ID) == nullptr);
822 EXPECT_TRUE(FindConnectionFsmByConnFsmId(FSM_ID) != nullptr);
823 EXPECT_TRUE(FindConnectionFsmByConnFsmId(FSM_ID_ADD) == nullptr);
824
825 ListDelete(&connFsm->node);
826 ListDelete(&requestNode->node);
827 SoftBusFree(connFsm);
828 SoftBusFree(requestNode);
829 }
830
831 /*
832 * @tc.name: SEND_ELECT_MESSAGE_TO_ALL_TEST_001
833 * @tc.desc: send elect message to all test
834 * @tc.type: FUNC
835 * @tc.require:
836 */
837 HWTEST_F(LNNNetBuilderMockTest, SEND_ELECT_MESSAGE_TO_ALL_TEST_001, TestSize.Level1)
838 {
839 ClearNetBuilderFsmList();
840 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
841 ListInit(&connFsm->node);
842 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
843 connFsm->isDead = false;
844 connFsm->connInfo.flag = CONN_FLAG1;
845 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
846 g_netBuilder.maxConcurrentCount = 0;
847 EXPECT_EQ(false, NeedPendingJoinRequest());
848 g_netBuilder.maxConcurrentCount = 1;
849 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
850 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
851 SendElectMessageToAll(NODE1_NETWORK_ID);
852 SendElectMessageToAll(NODE1_NETWORK_ID);
853 EXPECT_TRUE(NeedPendingJoinRequest() == false);
854 LnnConnectionFsm *connFsm1 = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
855 ListInit(&connFsm1->node);
856 (void)strcpy_s(connFsm1->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE1_NETWORK_ID);
857 connFsm1->isDead = true;
858 connFsm1->connInfo.flag = CONN_FLAG3;
859 ListAdd(&g_netBuilder.fsmList, &connFsm1->node);
860 EXPECT_TRUE(NeedPendingJoinRequest() == false);
861 ClearNetBuilderFsmList();
862 }
863
864 /*
865 * @tc.name: SEND_ELECT_MESSAGE_TO_ALL_TEST_002
866 * @tc.desc: send elect message to all test
867 * @tc.type: FUNC
868 * @tc.require:
869 */
870 HWTEST_F(LNNNetBuilderMockTest, SEND_ELECT_MESSAGE_TO_ALL_TEST_002, TestSize.Level1)
871 {
872 LnnConnectionFsm *connFsm = nullptr;
873 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
874 EXPECT_TRUE(connFsm != nullptr);
875 ListInit(&connFsm->node);
876 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
877 connFsm->isDead = false;
878 connFsm->connInfo.flag = CONN_FLAG1;
879 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
880 g_netBuilder.maxConcurrentCount = 1;
881 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
882 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
883 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNodeInfoById)
884 .WillOnce(Return(SOFTBUS_ERR))
885 .WillRepeatedly(Return(SOFTBUS_OK));
886 EXPECT_CALL(NetBuilderMock, LnnHasDiscoveryType).WillRepeatedly(Return(true));
887 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo)
888 .WillOnce(Return(SOFTBUS_ERR))
889 .WillRepeatedly(Return(SOFTBUS_OK));
890 EXPECT_CALL(NetBuilderMock, LnnGetLocalNumInfo)
891 .WillOnce(Return(SOFTBUS_ERR))
892 .WillRepeatedly(Return(SOFTBUS_OK));
893 EXPECT_CALL(NetBuilderMock, AddStringToJsonObject).WillOnce(Return(true)).WillRepeatedly(Return(false));
894 EXPECT_CALL(NetBuilderMock, AddNumberToJsonObject).WillOnce(Return(true)).WillRepeatedly(Return(false));
895 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById).WillRepeatedly(Return(true));
896 SendElectMessageToAll(NODE1_NETWORK_ID);
897 SendElectMessageToAll(NODE1_NETWORK_ID);
898 SendElectMessageToAll(NODE1_NETWORK_ID);
899 SendElectMessageToAll(NODE1_NETWORK_ID);
900 SendElectMessageToAll(NODE1_NETWORK_ID);
901 SendElectMessageToAll(NODE1_NETWORK_ID);
902 SendElectMessageToAll(NODE1_NETWORK_ID);
903 EXPECT_TRUE(NeedPendingJoinRequest() == false);
904 ListDelete(&connFsm->node);
905 SoftBusFree(connFsm);
906 }
907
908 /*
909 * @tc.name: INITIATE_NEW_NETWORK_ONLINE_TEST_001
910 * @tc.desc: initiate new network online test
911 * @tc.type: FUNC
912 * @tc.require:
913 */
914 HWTEST_F(LNNNetBuilderMockTest, INITIATE_NEW_NETWORK_ONLINE_TEST_001, TestSize.Level1)
915 {
916 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
917 ListInit(&connFsm->node);
918 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
919 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
920 connFsm->isDead = false;
921 connFsm->connInfo.flag = CONN_FLAG2;
922 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
923
924 InitiateNewNetworkOnline(CONNECTION_ADDR_MAX, NODE1_NETWORK_ID);
925 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
926 EXPECT_CALL(NetBuilderMock, LnnSendNewNetworkOnlineToConnFsm(_)).WillOnce(Return(SOFTBUS_OK));
927 InitiateNewNetworkOnline(CONNECTION_ADDR_MAX, NODE_NETWORK_ID);
928
929 EXPECT_CALL(NetBuilderMock, LnnSendNewNetworkOnlineToConnFsm(_)).WillOnce(Return(SOFTBUS_OK));
930 InitiateNewNetworkOnline(CONNECTION_ADDR_BR, NODE_NETWORK_ID);
931 InitiateNewNetworkOnline(CONNECTION_ADDR_BLE, NODE_NETWORK_ID);
932 ListDelete(&connFsm->node);
933 SoftBusFree(connFsm);
934 }
935
936 /*
937 * @tc.name: TRY_DISCONNECT_ALL_CONNECTION_TEST_001
938 * @tc.desc: tyr disconnect all connection test
939 * @tc.type: FUNC
940 * @tc.require:
941 */
942 HWTEST_F(LNNNetBuilderMockTest, TRY_DISCONNECT_ALL_CONNECTION_TEST_001, TestSize.Level1)
943 {
944 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
945 ListInit(&connFsm->node);
946 (void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
947 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
948 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
949
950 LnnConnectionFsm fsmTest;
951 (void)memset_s(&fsmTest, sizeof(LnnConnectionFsm), 0, sizeof(LnnConnectionFsm));
952 fsmTest.connInfo.flag = 1;
953 TryDisconnectAllConnection(&fsmTest);
954
955 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
956 EXPECT_CALL(NetBuilderMock, LnnConvertAddrToOption(_, _)).WillOnce(Return(false));
957 fsmTest.connInfo.flag = CONN_FLAG1;
958 fsmTest.connInfo.addr.type = CONNECTION_ADDR_BLE;
959 TryDisconnectAllConnection(&fsmTest);
960
961 EXPECT_CALL(NetBuilderMock, LnnConvertAddrToOption(_, _)).WillOnce(Return(true));
962 TryDisconnectAllConnection(&fsmTest);
963
964 fsmTest.connInfo.addr.type = CONNECTION_ADDR_BR;
965 (void)strcpy_s(fsmTest.connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
966 TryDisconnectAllConnection(&fsmTest);
967
968 (void)strcpy_s(fsmTest.connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE2_BR_MAC);
969 TryDisconnectAllConnection(&fsmTest);
970 ListDelete(&connFsm->node);
971 SoftBusFree(connFsm);
972 }
973
974 /*
975 * @tc.name: TRY_DISCONNECT_ALL_CONNECTION_TEST_003
976 * @tc.desc: tyr disconnect all connection test
977 * @tc.type: FUNC
978 * @tc.require:
979 */
980 HWTEST_F(LNNNetBuilderMockTest, TRY_DISCONNECT_ALL_CONNECTION_TEST_002, TestSize.Level1)
981 {
982 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
983 ListInit(&connFsm->node);
984 (void)strcpy_s(connFsm->connInfo.addr.info.ip.ip, IP_STR_MAX_LEN, NODE1_IP);
985 connFsm->connInfo.addr.type = CONNECTION_ADDR_WLAN;
986 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
987
988 LnnConnectionFsm fsmTest;
989 (void)memset_s(&fsmTest, sizeof(LnnConnectionFsm), 0, sizeof(LnnConnectionFsm));
990 fsmTest.connInfo.flag = CONN_FLAG1;
991 fsmTest.connInfo.addr.type = CONNECTION_ADDR_WLAN;
992 (void)strcpy_s(fsmTest.connInfo.addr.info.ip.ip, IP_STR_MAX_LEN, NODE2_IP);
993
994 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
995 EXPECT_CALL(NetBuilderMock, LnnConvertAddrToOption(_, _)).WillOnce(Return(false));
996 TryDisconnectAllConnection(&fsmTest);
997 TryNotifyAllTypeOffline(&fsmTest);
998
999 (void)strcpy_s(fsmTest.connInfo.addr.info.ip.ip, IP_STR_MAX_LEN, NODE1_IP);
1000 TryDisconnectAllConnection(&fsmTest);
1001 TryNotifyAllTypeOffline(&fsmTest);
1002
1003 ListDelete(&connFsm->node);
1004 SoftBusFree(connFsm);
1005 }
1006
1007 /*
1008 * @tc.name: PROCESS_VERIFY_RESULT_TEST_002
1009 * @tc.desc: process verify result test
1010 * @tc.type: FUNC
1011 * @tc.require:
1012 */
1013 HWTEST_F(LNNNetBuilderMockTest, PROCESS_VERIFY_RESULT_TEST_002, TestSize.Level1)
1014 {
1015 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1016 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1017 VerifyResultMsgPara *msgPara = reinterpret_cast<VerifyResultMsgPara *>(SoftBusMalloc(sizeof(VerifyResultMsgPara)));
1018 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1019 msgPara->requestId = REQUEST_ID;
1020 void *para = reinterpret_cast<void *>(msgPara);
1021
1022 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1023 ListInit(&connFsm->node);
1024 connFsm->connInfo.requestId = REQUEST_ID;
1025 connFsm->isDead = true;
1026 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1027 EXPECT_TRUE(ProcessVerifyResult(para) != SOFTBUS_OK);
1028 ListDelete(&connFsm->node);
1029 SoftBusFree(connFsm);
1030 }
1031
1032 /*
1033 * @tc.name: PROCESS_VERIFY_RESULT_TEST_003
1034 * @tc.desc: process verify result test
1035 * @tc.type: FUNC
1036 * @tc.require:
1037 */
1038 HWTEST_F(LNNNetBuilderMockTest, PROCESS_VERIFY_RESULT_TEST_003, TestSize.Level1)
1039 {
1040 VerifyResultMsgPara *msgPara = reinterpret_cast<VerifyResultMsgPara *>(SoftBusMalloc(sizeof(VerifyResultMsgPara)));
1041 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1042 msgPara->requestId = REQUEST_ID;
1043 msgPara->retCode = SOFTBUS_ERR;
1044 void *para = reinterpret_cast<void *>(msgPara);
1045
1046 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1047 ListInit(&connFsm->node);
1048 connFsm->connInfo.requestId = REQUEST_ID;
1049 connFsm->isDead = false;
1050 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1051
1052 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1053 EXPECT_CALL(NetBuilderMock, LnnSendAuthResultMsgToConnFsm(_, _)).WillOnce(Return(SOFTBUS_ERR));
1054 EXPECT_TRUE(ProcessVerifyResult(para) == SOFTBUS_ERR);
1055 ListDelete(&connFsm->node);
1056 SoftBusFree(connFsm);
1057 }
1058
1059 /*
1060 * @tc.name: PROCESS_VERIFY_RESULT_TEST_004
1061 * @tc.desc: process verify result test
1062 * @tc.type: FUNC
1063 * @tc.require:
1064 */
1065 HWTEST_F(LNNNetBuilderMockTest, PROCESS_VERIFY_RESULT_TEST_004, TestSize.Level1)
1066 {
1067 VerifyResultMsgPara *msgPara = reinterpret_cast<VerifyResultMsgPara *>(SoftBusMalloc(sizeof(VerifyResultMsgPara)));
1068 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1069 msgPara->requestId = REQUEST_ID;
1070 msgPara->retCode = SOFTBUS_ERR;
1071 void *para = reinterpret_cast<void *>(msgPara);
1072 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1073 ListInit(&connFsm->node);
1074 connFsm->connInfo.requestId = REQUEST_ID;
1075 connFsm->isDead = false;
1076 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1077 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1078 EXPECT_CALL(NetBuilderMock, LnnSendAuthResultMsgToConnFsm(_, _)).WillOnce(Return(SOFTBUS_OK));
1079 EXPECT_TRUE(ProcessVerifyResult(para) == SOFTBUS_OK);
1080 ListDelete(&connFsm->node);
1081 SoftBusFree(connFsm);
1082 }
1083
1084 /*
1085 * @tc.name: PROCESS_DEVICE_VERIFY_PASS_TEST_002
1086 * @tc.desc: process device verify pass test
1087 * @tc.type: FUNC
1088 * @tc.require:
1089 */
1090 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_002, TestSize.Level1)
1091 {
1092 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1093 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1094 DeviceVerifyPassMsgPara *msgPara =
1095 reinterpret_cast<DeviceVerifyPassMsgPara *>(SoftBusMalloc(sizeof(DeviceVerifyPassMsgPara)));
1096 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1097 (void)strcpy_s(msgPara->nodeInfo->networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1098 msgPara->authHandle.authId = AUTH_ID;
1099
1100 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1101 ListInit(&connFsm->node);
1102 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1103 connFsm->connInfo.authHandle.authId = AUTH_ID_ADD;
1104 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1105 g_netBuilder.connCount = CURRENT_COUNT;
1106 g_netBuilder.maxConnCount = CONN_COUNT;
1107 void *para = reinterpret_cast<void *>(msgPara);
1108 EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
1109 ListDelete(&connFsm->node);
1110 SoftBusFree(connFsm);
1111 }
1112
1113 /*
1114 * @tc.name: PROCESS_DEVICE_VERIFY_PASS_TEST_003
1115 * @tc.desc: process device verify pass test
1116 * @tc.type: FUNC
1117 * @tc.require:
1118 */
1119 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_003, TestSize.Level1)
1120 {
1121 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1122 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1123 DeviceVerifyPassMsgPara *msgPara =
1124 reinterpret_cast<DeviceVerifyPassMsgPara *>(SoftBusMalloc(sizeof(DeviceVerifyPassMsgPara)));
1125 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1126 (void)strcpy_s(msgPara->nodeInfo->networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1127 msgPara->authHandle.authId = AUTH_ID;
1128
1129 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1130 ListInit(&connFsm->node);
1131 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1132 connFsm->connInfo.authHandle.authId = AUTH_ID;
1133 connFsm->isDead = true;
1134 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1135 g_netBuilder.connCount = CURRENT_COUNT;
1136 g_netBuilder.maxConnCount = CONN_COUNT;
1137 void *para = reinterpret_cast<void *>(msgPara);
1138 EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
1139 ListDelete(&connFsm->node);
1140 SoftBusFree(connFsm);
1141 }
1142
1143 /*
1144 * @tc.name: PROCESS_DEVICE_VERIFY_PASS_TEST_004
1145 * @tc.desc: process device verify pass test
1146 * @tc.type: FUNC
1147 * @tc.require:
1148 */
1149 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_VERIFY_PASS_TEST_004, TestSize.Level1)
1150 {
1151 DeviceVerifyPassMsgPara *msgPara =
1152 reinterpret_cast<DeviceVerifyPassMsgPara *>(SoftBusMalloc(sizeof(DeviceVerifyPassMsgPara)));
1153 msgPara->nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1154 (void)strcpy_s(msgPara->nodeInfo->networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1155 msgPara->authHandle.authId = AUTH_ID;
1156
1157 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1158 ListInit(&connFsm->node);
1159 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1160 connFsm->connInfo.authHandle.authId = AUTH_ID;
1161 connFsm->isDead = false;
1162 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1163
1164 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1165 void *para = reinterpret_cast<void *>(msgPara);
1166 EXPECT_TRUE(ProcessDeviceVerifyPass(para) == SOFTBUS_ERR);
1167 ListDelete(&connFsm->node);
1168 SoftBusFree(connFsm);
1169 }
1170
1171 /*
1172 * @tc.name: PROCESS_DEVICE_NOT_TRUSTED_TEST_002
1173 * @tc.desc: process device not trusted test
1174 * @tc.type: FUNC
1175 * @tc.require:
1176 */
1177 HWTEST_F(LNNNetBuilderMockTest, PROCESS_DEVICE_NOT_TRUSTED_TEST_002, TestSize.Level1)
1178 {
1179 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1180 void *msgPara = reinterpret_cast<void *>(SoftBusMalloc(sizeof(char) * UDID_BUF_LEN));
1181 EXPECT_CALL(NetBuilderMock, LnnGetNetworkIdByUdid(_, _, _)).WillRepeatedly(Return(SOFTBUS_ERR));
1182 EXPECT_CALL(NetBuilderMock, LnnGetDeviceUdid(_)).WillRepeatedly(Return(nullptr));
1183
1184 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1185 ListInit(&connFsm->node);
1186 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1187 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1188
1189 void *para = reinterpret_cast<void *>(msgPara);
1190 EXPECT_TRUE(ProcessDeviceNotTrusted(para) == SOFTBUS_OK);
1191 ListDelete(&connFsm->node);
1192 SoftBusFree(connFsm);
1193 }
1194
1195 /*
1196 * @tc.name: PROCESS_LEAVE_LNN_REQUEST_TEST_002
1197 * @tc.desc: process leave lnn request test
1198 * @tc.type: FUNC
1199 * @tc.require:
1200 */
1201 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_002, TestSize.Level1)
1202 {
1203 char *msgPara = reinterpret_cast<char *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
1204 (void)strcpy_s(msgPara, NETWORK_ID_BUF_LEN, NODE1_NETWORK_ID);
1205
1206 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1207 ListInit(&connFsm->node);
1208 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1209 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1210
1211 void *para = reinterpret_cast<void *>(msgPara);
1212 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1213 EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
1214 EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
1215 ListDelete(&connFsm->node);
1216 SoftBusFree(connFsm);
1217 }
1218
1219 /*
1220 * @tc.name: PROCESS_LEAVE_LNN_REQUEST_TEST_003
1221 * @tc.desc: process leave lnn request test
1222 * @tc.type: FUNC
1223 * @tc.require:
1224 */
1225 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_003, TestSize.Level1)
1226 {
1227 char *msgPara = reinterpret_cast<char *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
1228 (void)strcpy_s(msgPara, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1229
1230 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1231 ListInit(&connFsm->node);
1232 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1233 connFsm->isDead = true;
1234 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1235
1236 void *para = reinterpret_cast<void *>(msgPara);
1237 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1238 EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
1239 EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_ERR);
1240 ListDelete(&connFsm->node);
1241 SoftBusFree(connFsm);
1242 }
1243
1244 /*
1245 * @tc.name: PROCESS_LEAVE_LNN_REQUEST_TEST_004
1246 * @tc.desc: process leave lnn request test
1247 * @tc.type: FUNC
1248 * @tc.require:
1249 */
1250 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_LNN_REQUEST_TEST_004, TestSize.Level1)
1251 {
1252 char *msgPara = reinterpret_cast<char *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
1253 (void)strcpy_s(msgPara, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1254
1255 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1256 ListInit(&connFsm->node);
1257 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1258 connFsm->isDead = false;
1259 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1260
1261 void *para = reinterpret_cast<void *>(msgPara);
1262 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1263 EXPECT_CALL(NetBuilderMock, LnnNotifyLeaveResult(_, _)).WillRepeatedly(Return());
1264 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
1265 EXPECT_TRUE(ProcessLeaveLNNRequest(para) == SOFTBUS_OK);
1266 ListDelete(&connFsm->node);
1267 SoftBusFree(connFsm);
1268 }
1269
1270 /*
1271 * @tc.name: PROCESS_SYNC_OFFLINE_FINISH_TEST_002
1272 * @tc.desc: process sync offline finish test
1273 * @tc.type: FUNC
1274 * @tc.require:
1275 */
1276 HWTEST_F(LNNNetBuilderMockTest, PROCESS_SYNC_OFFLINE_FINISH_TEST_002, TestSize.Level1)
1277 {
1278 char *msgPara = reinterpret_cast<char *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
1279 (void)strcpy_s(msgPara, NETWORK_ID_BUF_LEN, NODE1_NETWORK_ID);
1280
1281 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1282 ListInit(&connFsm->node);
1283 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1284 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1285
1286 void *para = reinterpret_cast<void *>(msgPara);
1287 EXPECT_TRUE(ProcessSyncOfflineFinish(para) == SOFTBUS_OK);
1288 ListDelete(&connFsm->node);
1289 SoftBusFree(connFsm);
1290 }
1291
1292 /*
1293 * @tc.name: PROCESS_SYNC_OFFLINE_FINISH_TEST_003
1294 * @tc.desc: process sync offline finish test
1295 * @tc.type: FUNC
1296 * @tc.require:
1297 */
1298 HWTEST_F(LNNNetBuilderMockTest, PROCESS_SYNC_OFFLINE_FINISH_TEST_003, TestSize.Level1)
1299 {
1300 char *msgPara = reinterpret_cast<char *>(SoftBusMalloc(sizeof(char) * NETWORK_ID_BUF_LEN));
1301 (void)strcpy_s(msgPara, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1302
1303 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1304 ListInit(&connFsm->node);
1305 connFsm->isDead = true;
1306 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1307 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1308
1309 void *para = reinterpret_cast<void *>(msgPara);
1310 EXPECT_TRUE(ProcessSyncOfflineFinish(para) == SOFTBUS_OK);
1311 ListDelete(&connFsm->node);
1312 SoftBusFree(connFsm);
1313 }
1314
1315 /*
1316 * @tc.name: PROCESS_LEAVE_SPECIFIC_TEST_002
1317 * @tc.desc: process leave specific test
1318 * @tc.type: FUNC
1319 * @tc.require:
1320 */
1321 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_SPECIFIC_TEST_002, TestSize.Level1)
1322 {
1323 SpecificLeaveMsgPara *msgPara =
1324 reinterpret_cast<SpecificLeaveMsgPara *>(SoftBusMalloc(sizeof(SpecificLeaveMsgPara)));
1325 (void)strcpy_s(msgPara->networkId, NETWORK_ID_BUF_LEN, NODE1_NETWORK_ID);
1326 msgPara->addrType = CONNECTION_ADDR_BLE;
1327
1328 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1329 ListInit(&connFsm->node);
1330 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1331 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
1332 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1333
1334 void *para = reinterpret_cast<void *>(msgPara);
1335 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1336 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1337 EXPECT_TRUE(ProcessLeaveSpecific(para) == SOFTBUS_OK);
1338 ListDelete(&connFsm->node);
1339 SoftBusFree(connFsm);
1340 }
1341
1342 /*
1343 * @tc.name: PROCESS_LEAVE_SPECIFIC_TEST_003
1344 * @tc.desc: process leave specific test
1345 * @tc.type: FUNC
1346 * @tc.require:
1347 */
1348 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_SPECIFIC_TEST_003, TestSize.Level1)
1349 {
1350 SpecificLeaveMsgPara *msgPara =
1351 reinterpret_cast<SpecificLeaveMsgPara *>(SoftBusMalloc(sizeof(SpecificLeaveMsgPara)));
1352 (void)strcpy_s(msgPara->networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1353 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1354 ListInit(&connFsm->node);
1355 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1356 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1357
1358 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1359 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
1360 void *para = reinterpret_cast<void *>(msgPara);
1361 EXPECT_TRUE(ProcessLeaveSpecific(para) == SOFTBUS_OK);
1362 ListDelete(&connFsm->node);
1363 SoftBusFree(connFsm);
1364 }
1365
1366 /*
1367 * @tc.name: ON_LNN_PROCESS_NOT_TRUSTED_MSG_DELAY_TEST_001
1368 * @tc.desc: on lnn prodecc not trusted msg delay test
1369 * @tc.type: FUNC
1370 * @tc.require:
1371 */
1372 HWTEST_F(LNNNetBuilderMockTest, ON_LNN_PROCESS_NOT_TRUSTED_MSG_DELAY_TEST_001, TestSize.Level1)
1373 {
1374 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1375 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1376 OnLnnProcessNotTrustedMsgDelay(nullptr);
1377 void *para1 = reinterpret_cast<void *>(SoftBusMalloc(sizeof(NotTrustedDelayInfo)));
1378 EXPECT_CALL(NetBuilderMock, AuthGetLatestAuthSeqList(_, _, _)).WillRepeatedly(Return(SOFTBUS_ERR));
1379 OnLnnProcessNotTrustedMsgDelay(para1);
1380
1381 void *para2 = reinterpret_cast<void *>(SoftBusMalloc(sizeof(NotTrustedDelayInfo)));
1382 EXPECT_CALL(NetBuilderMock, AuthGetLatestAuthSeqList(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1383 EXPECT_CALL(NetBuilderMock, LnnConvertDlId(_, _, _, _, _)).WillRepeatedly(Return(SOFTBUS_ERR));
1384 OnLnnProcessNotTrustedMsgDelay(para2);
1385 }
1386
1387 /*
1388 * @tc.name: PROCESS_ELETE_TEST_002
1389 * @tc.desc: process elect test
1390 * @tc.type: FUNC
1391 * @tc.require:
1392 */
1393 HWTEST_F(LNNNetBuilderMockTest, PROCESS_ELETE_TEST_002, TestSize.Level1)
1394 {
1395 ElectMsgPara *msgPara = reinterpret_cast<ElectMsgPara *>(SoftBusMalloc(sizeof(ElectMsgPara)));
1396 (void)strcpy_s(msgPara->networkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1397
1398 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1399 ListInit(&connFsm->node);
1400 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1401 connFsm->isDead = false;
1402 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1403 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1404
1405 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1406 void *para = reinterpret_cast<void *>(msgPara);
1407
1408 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById(_, _)).WillRepeatedly(Return(true));
1409 EXPECT_CALL(NetBuilderMock, LnnGetLocalStrInfo(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1410
1411 EXPECT_TRUE(ProcessMasterElect(para) == SOFTBUS_OK);
1412 ListDelete(&connFsm->node);
1413 SoftBusFree(connFsm);
1414 }
1415
1416 /*
1417 * @tc.name: TRY_SEND_JOIN_LNN_REQUEST_TEST_001
1418 * @tc.desc: try send join lnn request test
1419 * @tc.type: FUNC
1420 * @tc.require:
1421 */
1422 HWTEST_F(LNNNetBuilderMockTest, TRY_SEND_JOIN_LNN_REQUEST_TEST_001, TestSize.Level1)
1423 {
1424 JoinLnnMsgPara *para = nullptr;
1425 para = reinterpret_cast<JoinLnnMsgPara *>(SoftBusMalloc(sizeof(JoinLnnMsgPara)));
1426 EXPECT_TRUE(para != nullptr);
1427 LnnConnectionFsm *connFsm = nullptr;
1428 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1429 EXPECT_TRUE(connFsm != nullptr);
1430 ListInit(&connFsm->node);
1431 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1432 connFsm->isDead = false;
1433 connFsm->connInfo.flag = CONN_FLAG3;
1434 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1435 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1436
1437 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1438 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(false));
1439 para->isNeedConnect = false;
1440 (void)strcpy_s(para->pkgName, PKG_NAME_SIZE_MAX, "pkgName");
1441 EXPECT_TRUE(TrySendJoinLNNRequest(nullptr, true, false) == SOFTBUS_INVALID_PARAM);
1442 EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_ERR);
1443
1444 DfxRecordLnnAuthStart(nullptr, para, 0);
1445 ListDelete(&connFsm->node);
1446 SoftBusFree(connFsm);
1447 }
1448
1449 /*
1450 * @tc.name: TRY_SEND_JOIN_LNN_REQUEST_TEST_002
1451 * @tc.desc: try send join lnn request test
1452 * @tc.type: FUNC
1453 * @tc.require:
1454 */
1455 HWTEST_F(LNNNetBuilderMockTest, TRY_SEND_JOIN_LNN_REQUEST_TEST_002, TestSize.Level1)
1456 {
1457 JoinLnnMsgPara *para = nullptr;
1458 para = reinterpret_cast<JoinLnnMsgPara *>(SoftBusMalloc(sizeof(JoinLnnMsgPara)));
1459 EXPECT_TRUE(para != nullptr);
1460 LnnConnectionFsm *connFsm = nullptr;
1461 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1462 EXPECT_TRUE(connFsm != nullptr);
1463 ListInit(&connFsm->node);
1464 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1465 connFsm->isDead = false;
1466 connFsm->connInfo.flag = CONN_FLAG3;
1467 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1468 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1469
1470 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1471 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(false));
1472 para->isNeedConnect = true;
1473 (void)strcpy_s(para->pkgName, PKG_NAME_SIZE_MAX, "pkgName");
1474 EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_OK);
1475
1476 ListDelete(&connFsm->node);
1477 SoftBusFree(connFsm);
1478 }
1479
1480 /*
1481 * @tc.name: TRY_SEND_JOIN_LNN_REQUEST_TEST_003
1482 * @tc.desc: try send join lnn request test
1483 * @tc.type: FUNC
1484 * @tc.require:
1485 */
1486 HWTEST_F(LNNNetBuilderMockTest, TRY_SEND_JOIN_LNN_REQUEST_TEST_003, TestSize.Level1)
1487 {
1488 JoinLnnMsgPara *para = nullptr;
1489 para = reinterpret_cast<JoinLnnMsgPara *>(SoftBusMalloc(sizeof(JoinLnnMsgPara)));
1490 EXPECT_TRUE(para != nullptr);
1491 LnnConnectionFsm *connFsm = nullptr;
1492 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1493 EXPECT_TRUE(connFsm != nullptr);
1494 ListInit(&connFsm->node);
1495 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1496 connFsm->isDead = false;
1497 connFsm->connInfo.flag = CONN_FLAG3;
1498 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1499 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1500
1501 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1502 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(true));
1503 para->isNeedConnect = true;
1504 (void)strcpy_s(para->pkgName, PKG_NAME_SIZE_MAX, "pkgName");
1505 EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_OK);
1506
1507 ListDelete(&connFsm->node);
1508 SoftBusFree(connFsm);
1509 }
1510
1511 /*
1512 * @tc.name: TRY_SEND_JOIN_LNN_REQUEST_TEST_004
1513 * @tc.desc: try send join lnn request test
1514 * @tc.type: FUNC
1515 * @tc.require:
1516 */
1517 HWTEST_F(LNNNetBuilderMockTest, TRY_SEND_JOIN_LNN_REQUEST_TEST_004, TestSize.Level1)
1518 {
1519 JoinLnnMsgPara *para = nullptr;
1520 para = reinterpret_cast<JoinLnnMsgPara *>(SoftBusMalloc(sizeof(JoinLnnMsgPara)));
1521 EXPECT_TRUE(para != nullptr);
1522 LnnConnectionFsm *connFsm = nullptr;
1523 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1524 EXPECT_TRUE(connFsm != nullptr);
1525 ListInit(&connFsm->node);
1526 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1527 connFsm->isDead = false;
1528 connFsm->connInfo.flag = CONN_FLAG2;
1529 (void)strcpy_s(connFsm->connInfo.peerNetworkId, NETWORK_ID_BUF_LEN, NODE_NETWORK_ID);
1530 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1531
1532 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1533 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _)).WillRepeatedly(Return(true));
1534 para->isNeedConnect = true;
1535 (void)strcpy_s(para->pkgName, PKG_NAME_SIZE_MAX, "pkgName");
1536 EXPECT_TRUE(TrySendJoinLNNRequest(para, true, false) == SOFTBUS_OK);
1537
1538 ListDelete(&connFsm->node);
1539 SoftBusFree(connFsm);
1540 }
1541
1542 /*
1543 * @tc.name: LNN_PROCESS_COMPLETE_NOT_TRUSTED_MSG_TEST_001
1544 * @tc.desc: lnn process complete not trusted msg test
1545 * @tc.type: FUNC
1546 * @tc.require:
1547 */
1548 HWTEST_F(LNNNetBuilderMockTest, LNN_PROCESS_COMPLETE_NOT_TRUSTED_MSG_TEST_001, TestSize.Level1)
1549 {
1550 char jsonStr[] = "{\"1\":10}";
1551 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1552 EXPECT_CALL(NetBuilderMock, LnnGetOnlineStateById).WillOnce(Return(false)).WillRepeatedly(Return(true));
1553 EXPECT_CALL(NetBuilderMock, AuthGetLatestAuthSeqList)
1554 .WillOnce(Return(SOFTBUS_ERR))
1555 .WillRepeatedly(Return(SOFTBUS_OK));
1556 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, nullptr, nullptr, 0);
1557 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_WIFI_DIRECT, NODE_NETWORK_ID, nullptr, MSG_ERR_LEN0);
1558 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, NODE_NETWORK_ID, nullptr, MSG_ERR_LEN0);
1559 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, NODE_NETWORK_ID,
1560 reinterpret_cast<uint8_t *>(jsonStr), MSG_ERR_LEN0);
1561 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, NODE_NETWORK_ID,
1562 reinterpret_cast<uint8_t *>(jsonStr), MSG_ERR_LEN0);
1563 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, NODE_NETWORK_ID,
1564 reinterpret_cast<uint8_t *>(jsonStr), strlen(jsonStr) + 1);
1565 LnnProcessCompleteNotTrustedMsg(LNN_INFO_TYPE_NOT_TRUSTED, NODE_NETWORK_ID,
1566 reinterpret_cast<uint8_t *>(jsonStr), strlen(jsonStr) + 1);
1567 }
1568
1569 /*
1570 * @tc.name: ON_RE_AUTH_VERIFY_PASSED_TEST_001
1571 * @tc.desc: on re auth verify passed test
1572 * @tc.type: FUNC
1573 * @tc.require:
1574 */
1575 HWTEST_F(LNNNetBuilderMockTest, ON_RE_AUTH_VERIFY_PASSED_TEST_001, TestSize.Level1)
1576 {
1577 NodeInfo info;
1578 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1579 EXPECT_CALL(NetBuilderMock, GetAuthRequest)
1580 .WillOnce(Return(SOFTBUS_ERR))
1581 .WillRepeatedly(Return(SOFTBUS_OK));
1582 EXPECT_CALL(NetBuilderMock, LnnConvertAuthConnInfoToAddr)
1583 .WillOnce(Return(false))
1584 .WillRepeatedly(Return(true));
1585 AuthHandle authHandle = { .authId = AUTH_ID, .type = AUTH_LINK_TYPE_WIFI };
1586 OnReAuthVerifyPassed(REQUEST_ID, authHandle, nullptr);
1587 OnReAuthVerifyPassed(REQUEST_ID, authHandle, &info);
1588 OnReAuthVerifyPassed(REQUEST_ID, authHandle, &info);
1589 OnReAuthVerifyPassed(REQUEST_ID, authHandle, &info);
1590 }
1591
1592 /*
1593 * @tc.name: ON_RE_AUTH_VERIFY_PASSED_TEST_002
1594 * @tc.desc: on re auth verify passed test
1595 * @tc.type: FUNC
1596 * @tc.require:
1597 */
1598 HWTEST_F(LNNNetBuilderMockTest, ON_RE_AUTH_VERIFY_PASSED_TEST_002, TestSize.Level1)
1599 {
1600 LnnConnectionFsm *connFsm = nullptr;
1601 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1602 EXPECT_TRUE(connFsm != nullptr);
1603 ListInit(&connFsm->node);
1604 connFsm->connInfo.version = SOFTBUS_NEW_V1;
1605 connFsm->isDead = false;
1606 connFsm->connInfo.flag = CONN_FLAG2;
1607 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1608 NodeInfo info;
1609 (void)strcpy_s(info.deviceInfo.deviceUdid, UDID_BUF_LEN, NODE_UDID);
1610
1611 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1612 EXPECT_CALL(NetBuilderMock, GetAuthRequest).WillRepeatedly(Return(SOFTBUS_OK));
1613 EXPECT_CALL(NetBuilderMock, LnnConvertAuthConnInfoToAddr).WillRepeatedly(Return(true));
1614 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _))
1615 .WillOnce(Return(false))
1616 .WillRepeatedly(Return(true));
1617 AuthHandle authHandle = { .authId = AUTH_ID, .type = AUTH_LINK_TYPE_WIFI };
1618 OnReAuthVerifyPassed(REQUEST_ID, authHandle, &info);
1619 OnReAuthVerifyPassed(REQUEST_ID, authHandle, &info);
1620
1621 ListDelete(&connFsm->node);
1622 SoftBusFree(connFsm);
1623 }
1624
1625 /*
1626 * @tc.name: FIND_NODE_INFO_BY_RQUESTID_TEST_001
1627 * @tc.desc: find node info by rquestid test
1628 * @tc.type: FUNC
1629 * @tc.require:
1630 */
1631 HWTEST_F(LNNNetBuilderMockTest, FIND_NODE_INFO_BY_RQUESTID_TEST_001, TestSize.Level1)
1632 {
1633 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1634 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr(_, _, _))
1635 .WillOnce(Return(false))
1636 .WillRepeatedly(Return(true));
1637 LnnConnectionFsm *connFsm = nullptr;
1638 connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1639 EXPECT_TRUE(connFsm != nullptr);
1640 ListInit(&connFsm->node);
1641 connFsm->connInfo.requestId = REQUEST_ID;
1642 connFsm->isDead = false;
1643 connFsm->connInfo.nodeInfo = reinterpret_cast<NodeInfo *>(SoftBusMalloc(sizeof(NodeInfo)));
1644 EXPECT_TRUE(connFsm->connInfo.nodeInfo != nullptr);
1645 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1646
1647 ConnectionAddr addr;
1648 uint32_t requestId;
1649 int32_t ret = FindRequestIdByAddr(&addr, &requestId);
1650 EXPECT_TRUE(ret != SOFTBUS_OK);
1651 ret = FindRequestIdByAddr(&addr, &requestId);
1652 EXPECT_TRUE(ret == SOFTBUS_OK);
1653 NodeInfo *info = FindNodeInfoByRquestId(requestId);
1654 EXPECT_TRUE(info != nullptr);
1655
1656 ListDelete(&connFsm->node);
1657 SoftBusFree(connFsm->connInfo.nodeInfo);
1658 SoftBusFree(connFsm);
1659 }
1660
1661 /*
1662 * @tc.name: ON_RECEIVE_NODE_ADDR_CHANGED_MSG_TEST_001
1663 * @tc.desc: on receive node addr changed msg test
1664 * @tc.type: FUNC
1665 * @tc.require:
1666 */
1667 HWTEST_F(LNNNetBuilderMockTest, ON_RECEIVE_NODE_ADDR_CHANGED_MSG_TEST_001, TestSize.Level1)
1668 {
1669 char jsonStr1[] = "{\"NODE_CODE\":1111,\"NODE_ADDR\":\"127.0.0.1\",\"PROXY_PORT\":1000,\"SESSION_PORT\":1001}";
1670 char jsonStr2[] = "{\"NODE_ADDR\":\"127.0.0.1\",\"PROXY_PORT\":1000,\"SESSION_PORT\":1001}";
1671 char jsonStr3[] = "{\"NODE_CODE\":1111,\"PROXY_PORT\":1000,\"SESSION_PORT\":1001}";
1672 char jsonStr4[] = "{\"NODE_CODE\":1111,\"NODE_ADDR\":\"127.0.0.1\",\"SESSION_PORT\":1001}";
1673 char jsonStr5[] = "{\"NODE_CODE\":1111,\"NODE_ADDR\":\"127.0.0.1\",\"PROXY_PORT\":1000}";
1674 uint8_t jsonMsg6[] = {0};
1675 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1676 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK));
1677 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_DEVICE_NAME, NODE_NETWORK_ID,
1678 reinterpret_cast<uint8_t *>(jsonStr1), MSG_ERR_LEN0);
1679 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1680 reinterpret_cast<uint8_t *>(jsonStr1), MSG_ERR_LEN0);
1681 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID, jsonMsg6, MSG_ERR_LEN1);
1682 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1683 reinterpret_cast<uint8_t *>(jsonStr2), strlen(jsonStr2) + 1);
1684 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1685 reinterpret_cast<uint8_t *>(jsonStr3), strlen(jsonStr3) + 1);
1686 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1687 reinterpret_cast<uint8_t *>(jsonStr4), strlen(jsonStr4) + 1);
1688 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1689 reinterpret_cast<uint8_t *>(jsonStr5), strlen(jsonStr5) + 1);
1690 OnReceiveNodeAddrChangedMsg(LNN_INFO_TYPE_NODE_ADDR, NODE_NETWORK_ID,
1691 reinterpret_cast<uint8_t *>(jsonStr1), strlen(jsonStr1) + 1);
1692 }
1693
1694 /*
1695 * @tc.name: ACCOUNT_STATE_CHANGE_HANDLER_TEST_001
1696 * @tc.desc: account state change handler test
1697 * @tc.type: FUNC
1698 * @tc.require:
1699 */
1700 HWTEST_F(LNNNetBuilderMockTest, ACCOUNT_STATE_CHANGE_HANDLER_TEST_001, TestSize.Level1)
1701 {
1702 LnnEventBasicInfo info;
1703 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1704 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK));
1705 EXPECT_CALL(NetBuilderMock, LnnGetAllOnlineNodeInfo).WillOnce(Return(false)).WillRepeatedly(Return(true));
1706 AccountStateChangeHandler(nullptr);
1707 AccountStateChangeHandler(&info);
1708 info.event = LNN_EVENT_ACCOUNT_CHANGED;
1709 AccountStateChangeHandler(&info);
1710 UpdatePCInfoWithoutSoftbus();
1711 UpdatePCInfoWithoutSoftbus();
1712 UpdatePCInfoWithoutSoftbus();
1713 }
1714
1715 /*
1716 * @tc.name: TRY_INITIATE_NEW_NETWORK_ONLINE_TEST_001
1717 * @tc.desc: try initiate new network online test
1718 * @tc.type: FUNC
1719 * @tc.require:
1720 */
1721 HWTEST_F(LNNNetBuilderMockTest, TRY_INITIATE_NEW_NETWORK_ONLINE_TEST_001, TestSize.Level1)
1722 {
1723 LnnConnectionFsm *connFsm1 = nullptr;
1724 connFsm1 = reinterpret_cast<LnnConnectionFsm *>(SoftBusMalloc(sizeof(LnnConnectionFsm)));
1725 EXPECT_TRUE(connFsm1 != nullptr);
1726 connFsm1->connInfo.flag = CONN_FLAG1;
1727 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1728 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig).WillRepeatedly(Return(SOFTBUS_OK));
1729 TryInitiateNewNetworkOnline(connFsm1);
1730 SoftBusFree(connFsm1);
1731 }
1732
1733 /*
1734 * @tc.name: LNN_REQUEST_LEAVE_ALL_ONLINE_NODES_TEST_001
1735 * @tc.desc: lnn request leave all online nodes test
1736 * @tc.type: FUNC
1737 * @tc.require:
1738 */
1739 HWTEST_F(LNNNetBuilderMockTest, LNN_REQUEST_LEAVE_ALL_ONLINE_NODES_TEST_001, TestSize.Level1)
1740 {
1741 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1742 EXPECT_CALL(NetBuilderMock, SoftbusGetConfig(_, _, _)).WillRepeatedly(Return(SOFTBUS_OK));
1743 EXPECT_CALL(NetBuilderMock, LnnGetAllOnlineNodeInfo).WillOnce(Return(false)).WillRepeatedly(Return(true));
1744 LnnRequestLeaveAllOnlineNodes();
1745 LnnRequestLeaveAllOnlineNodes();
1746 }
1747
1748 /*
1749 * @tc.name: PROCESS_LEAVE_BY_AUTH_ID_TEST_001
1750 * @tc.desc: ProcessLeaveByAuthId test
1751 * @tc.type: FUNC
1752 * @tc.require:
1753 */
1754 HWTEST_F(LNNNetBuilderMockTest, PROCESS_LEAVE_BY_AUTH_ID_TEST_001, TestSize.Level1)
1755 {
1756 ClearNetBuilderFsmList();
1757 int32_t maxConnCount = CONN_COUNT;
1758 LnnGetNetBuilder()->connCount = 0;
1759 LnnGetNetBuilder()->maxConnCount = maxConnCount;
1760 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
1761 EXPECT_TRUE(connFsm != nullptr);
1762 ListInit(&connFsm->node);
1763 (void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
1764 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
1765 connFsm->connInfo.authHandle.authId = AUTH_ID;
1766 connFsm->isDead = false;
1767 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1768 ++LnnGetNetBuilder()->connCount;
1769 LnnConnectionFsm *connFsm1 = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
1770 EXPECT_TRUE(connFsm1 != nullptr);
1771 ListInit(&connFsm1->node);
1772 (void)strcpy_s(connFsm1->connInfo.addr.info.ip.ip, IP_STR_MAX_LEN, NODE2_IP);
1773 connFsm1->connInfo.addr.type = CONNECTION_ADDR_WLAN;
1774 connFsm1->connInfo.authHandle.authId = AUTH_ID_ADD;
1775 connFsm1->isDead = true;
1776 ListAdd(&g_netBuilder.fsmList, &connFsm1->node);
1777 ++LnnGetNetBuilder()->connCount;
1778 SoftBusMessage msg = { .what = MSG_TYPE_BUILD_MAX, };
1779 NetBuilderMessageHandler(nullptr);
1780 NetBuilderMessageHandler(&msg);
1781 int64_t *authId = reinterpret_cast<int64_t *>(SoftBusCalloc(sizeof(int64_t)));
1782 EXPECT_TRUE(authId != nullptr);
1783 *authId = AUTH_ID_ADD;
1784 const void *para = reinterpret_cast<const void *>(authId);
1785 EXPECT_EQ(ProcessLeaveByAuthId(nullptr), SOFTBUS_INVALID_PARAM);
1786 EXPECT_EQ(ProcessLeaveByAuthId(para), SOFTBUS_OK);
1787 int64_t *authId1 = reinterpret_cast<int64_t *>(SoftBusCalloc(sizeof(int64_t)));
1788 EXPECT_TRUE(authId1 != nullptr);
1789 *authId1 = AUTH_ID;
1790 const void *para1 = reinterpret_cast<const void *>(authId1);
1791 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1792 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_ERR));
1793 EXPECT_EQ(ProcessLeaveByAuthId(para1), SOFTBUS_ERR);
1794 int64_t *authId2 = reinterpret_cast<int64_t *>(SoftBusCalloc(sizeof(int64_t)));
1795 EXPECT_TRUE(authId2 != nullptr);
1796 *authId2 = AUTH_ID;
1797 const void *para2 = reinterpret_cast<const void *>(authId2);
1798 EXPECT_CALL(NetBuilderMock, LnnSendLeaveRequestToConnFsm(_)).WillRepeatedly(Return(SOFTBUS_OK));
1799 EXPECT_EQ(ProcessLeaveByAuthId(para2), SOFTBUS_OK);
1800 ClearNetBuilderFsmList();
1801 }
1802
1803 /*
1804 * @tc.name: CREATE_PASSIVE_CONNECTION_FSM_TEST_001
1805 * @tc.desc: CreatePassiveConnectionFsm test
1806 * @tc.type: FUNC
1807 * @tc.require:
1808 */
1809 HWTEST_F(LNNNetBuilderMockTest, CREATE_PASSIVE_CONNECTION_FSM_TEST_001, TestSize.Level1)
1810 {
1811 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1812 EXPECT_CALL(NetBuilderMock, LnnCreateConnectionFsm).WillOnce(Return(nullptr));
1813 ConnectionAddr addr;
1814 const char *pkgName = "testPkgName";
1815 LnnConnectionFsm *fsm = StartNewConnectionFsm(&addr, pkgName, false);
1816 EXPECT_TRUE(fsm == nullptr);
1817 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
1818 EXPECT_TRUE(connFsm != nullptr);
1819 ListInit(&connFsm->node);
1820 (void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE2_BR_MAC);
1821 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
1822 EXPECT_CALL(NetBuilderMock, LnnCreateConnectionFsm).WillRepeatedly(Return(connFsm));
1823 EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_ERR));
1824 EXPECT_CALL(NetBuilderMock, LnnDestroyConnectionFsm).WillRepeatedly(Return());
1825 fsm = StartNewConnectionFsm(&addr, pkgName, false);
1826 EXPECT_TRUE(fsm == nullptr);
1827 DeviceVerifyPassMsgPara msgPara;
1828 EXPECT_CALL(NetBuilderMock, LnnStartConnectionFsm).WillOnce(Return(SOFTBUS_ERR));
1829 int32_t ret = CreatePassiveConnectionFsm(&msgPara);
1830 EXPECT_EQ(ret, SOFTBUS_ERR);
1831 ClearNetBuilderFsmList();
1832 }
1833
1834 /*
1835 * @tc.name: IS_SAME_PENDING_REQUEST_TEST_001
1836 * @tc.desc: IsSamePendingRequest test
1837 * @tc.type: FUNC
1838 * @tc.require:
1839 */
1840 HWTEST_F(LNNNetBuilderMockTest, IS_SAME_PENDING_REQUEST_TEST_001, TestSize.Level1)
1841 {
1842 PendingJoinRequestNode *request =
1843 reinterpret_cast<PendingJoinRequestNode *>(SoftBusCalloc(sizeof(PendingJoinRequestNode)));
1844 EXPECT_TRUE(request != nullptr);
1845 ListInit(&request->node);
1846 request->needReportFailure = true;
1847 ListAdd(&g_netBuilder.pendingList, &request->node);
1848 PendingJoinRequestNode request1 = { .needReportFailure = true, };
1849 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1850 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr).WillRepeatedly(Return(false));
1851 bool ret = IsSamePendingRequest(&request1);
1852 EXPECT_EQ(ret, false);
1853 EXPECT_CALL(NetBuilderMock, LnnIsSameConnectionAddr).WillRepeatedly(Return(true));
1854 ret = IsSamePendingRequest(&request1);
1855 EXPECT_EQ(ret, true);
1856 request1.needReportFailure = false;
1857 EXPECT_EQ(ret, true);
1858 bool addrType[CONNECTION_ADDR_MAX] = {
1859 [CONNECTION_ADDR_BR] = false,
1860 };
1861 const bool *addr = reinterpret_cast<const bool *>(&addrType);
1862 RemovePendingRequestByAddrType(nullptr, CONNECTION_ADDR_MAX);
1863 RemovePendingRequestByAddrType(addr, CONNECTION_ADDR_MAX - 1);
1864 }
1865
1866 /*
1867 * @tc.name: IS_NEED_WIFI_REAUTH_TEST_001
1868 * @tc.desc: IsNeedWifiReauth test
1869 * @tc.type: FUNC
1870 * @tc.require:
1871 */
1872 HWTEST_F(LNNNetBuilderMockTest, IS_NEED_WIFI_REAUTH_TEST_001, TestSize.Level1)
1873 {
1874 const char *networkId = NODE_NETWORK_ID;
1875 const char *newAccountHash = "0000";
1876 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1877 EXPECT_CALL(NetBuilderMock, LnnIsDefaultOhosAccount).WillOnce(Return(false));
1878 bool ret = IsNeedWifiReauth(networkId, newAccountHash, MAX_ACCOUNT_HASH_LEN);
1879 EXPECT_EQ(ret, true);
1880 EXPECT_CALL(NetBuilderMock, LnnIsDefaultOhosAccount).WillOnce(Return(true));
1881 ret = IsNeedWifiReauth(networkId, newAccountHash, MAX_ACCOUNT_HASH_LEN);
1882 EXPECT_EQ(ret, false);
1883 NodeInfo info;
1884 (void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
1885 EXPECT_EQ(EOK, strcpy_s(info.accountHash, SHA_256_HASH_LEN, ACCOUNT_HASH));
1886 EXPECT_CALL(NetBuilderMock, LnnIsDefaultOhosAccount).WillRepeatedly(Return(false));
1887 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNodeInfoById).WillOnce(Return(SOFTBUS_ERR));
1888 ret = IsNeedWifiReauth(networkId, newAccountHash, MAX_ACCOUNT_HASH_LEN);
1889 EXPECT_EQ(ret, false);
1890 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNodeInfoById)
1891 .WillRepeatedly(DoAll(SetArgPointee<2>(info), Return(SOFTBUS_OK)));
1892 EXPECT_CALL(NetBuilderMock, SoftBusGenerateStrHash).WillOnce(Return(SOFTBUS_ERR));
1893 ret = IsNeedWifiReauth(networkId, newAccountHash, MAX_ACCOUNT_HASH_LEN);
1894 EXPECT_EQ(ret, false);
1895 char *newAccountHash1 = reinterpret_cast<char *>(const_cast<uint8_t *>(EMPTY_ACCOUNT));
1896 unsigned char *hash = reinterpret_cast<unsigned char *>(const_cast<uint8_t *>(EMPTY_ACCOUNT));
1897 EXPECT_CALL(NetBuilderMock, SoftBusGenerateStrHash)
1898 .WillOnce(DoAll(SetArgPointee<2>(*hash), Return(SOFTBUS_OK)));
1899 ret = IsNeedWifiReauth(networkId, newAccountHash1, MAX_ACCOUNT_HASH_LEN);
1900 EXPECT_EQ(ret, false);
1901 }
1902
1903 /*
1904 * @tc.name: DELETE_PC_NODE_INFO_TEST_001
1905 * @tc.desc: DeletePcNodeInfo test
1906 * @tc.type: FUNC
1907 * @tc.require:
1908 */
1909 HWTEST_F(LNNNetBuilderMockTest, DELETE_PC_NODE_INFO_TEST_001, TestSize.Level1)
1910 {
1911 LnnEventExtra lnnEventExtra;
1912 (void)memset_s(&lnnEventExtra, sizeof(LnnEventExtra), 0, sizeof(LnnEventExtra));
1913 ConnectionAddr addr = { .type = CONNECTION_ADDR_BLE, };
1914 BuildLnnEvent(nullptr, &addr);
1915 BuildLnnEvent(&lnnEventExtra, nullptr);
1916 BuildLnnEvent(&lnnEventExtra, &addr);
1917 const char *packageName = "";
1918 DfxRecordLnnServerjoinStart(nullptr, nullptr, true);
1919 DfxRecordLnnServerjoinStart(&addr, nullptr, true);
1920 AuthConnInfo connInfo;
1921 (void)memset_s(&connInfo, sizeof(AuthConnInfo), 0, sizeof(AuthConnInfo));
1922 JoinLnnMsgPara para;
1923 (void)memset_s(¶, sizeof(JoinLnnMsgPara), 0, sizeof(JoinLnnMsgPara));
1924 EXPECT_EQ(EOK, strcpy_s(para.pkgName, PKG_NAME_SIZE_MAX, packageName));
1925 DfxRecordLnnAuthStart(nullptr, ¶, REQUEST_ID);
1926 DfxRecordLnnAuthStart(&connInfo, nullptr, REQUEST_ID);
1927 DfxRecordLnnAuthStart(&connInfo, ¶, REQUEST_ID);
1928 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1929 NodeInfo info = { .accountId = AUTH_ID, };
1930 EXPECT_EQ(EOK, strcpy_s(info.uuid, UDID_BUF_LEN, NODE_UDID));
1931 EXPECT_EQ(EOK, strcpy_s(info.deviceInfo.deviceUdid, UDID_BUF_LEN, NODE_UDID));
1932 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNodeInfoById).WillOnce(Return(SOFTBUS_ERR));
1933 const char *peerUdid = NODE_UDID;
1934 bool ret = DeletePcNodeInfo(peerUdid);
1935 EXPECT_EQ(ret, false);
1936 EXPECT_CALL(NetBuilderMock, LnnGetRemoteNodeInfoById)
1937 .WillRepeatedly(DoAll(SetArgPointee<2>(info), Return(SOFTBUS_OK)));
1938 EXPECT_CALL(NetBuilderMock, LnnGetLocalNodeInfo).WillOnce(Return(NULL));
1939 ret = DeletePcNodeInfo(peerUdid);
1940 EXPECT_EQ(ret, false);
1941 NodeInfo localNodeInfo = { .accountId = AUTH_ID, };
1942 EXPECT_CALL(NetBuilderMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo));
1943 ret = DeletePcNodeInfo(peerUdid);
1944 EXPECT_EQ(ret, false);
1945 localNodeInfo.accountId = AUTH_ID_ADD;
1946 EXPECT_CALL(NetBuilderMock, LnnGetLocalNodeInfo).WillOnce(Return(&localNodeInfo));
1947 EXPECT_CALL(NetBuilderMock, DeleteFromProfile).WillOnce(Return());
1948 EXPECT_CALL(NetBuilderMock, LnnRemoveNode).WillOnce(Return());
1949 ret = DeletePcNodeInfo(peerUdid);
1950 EXPECT_EQ(ret, true);
1951 }
1952
1953 /*
1954 * @tc.name: LNN_NOTIFY_AUTH_HANDLE_LEAVE_LNN_TEST_001
1955 * @tc.desc: LnnNotifyAuthHandleLeaveLNN test
1956 * @tc.type: FUNC
1957 * @tc.require:
1958 */
1959 HWTEST_F(LNNNetBuilderMockTest, LNN_NOTIFY_AUTH_HANDLE_LEAVE_LNN_TEST_001, TestSize.Level1)
1960 {
1961 ClearNetBuilderFsmList();
1962 LnnConnectionFsm *connFsm = reinterpret_cast<LnnConnectionFsm *>(SoftBusCalloc(sizeof(LnnConnectionFsm)));
1963 EXPECT_TRUE(connFsm != nullptr);
1964 ListInit(&connFsm->node);
1965 (void)strcpy_s(connFsm->connInfo.addr.info.br.brMac, BT_MAC_LEN, NODE1_BR_MAC);
1966 connFsm->connInfo.addr.type = CONNECTION_ADDR_BR;
1967 connFsm->connInfo.authHandle.authId = AUTH_ID;
1968 connFsm->isDead = false;
1969 ListAdd(&g_netBuilder.fsmList, &connFsm->node);
1970 ++LnnGetNetBuilder()->connCount;
1971 g_netBuilder.isInit = false;
1972 AuthHandle authHandle = { .authId = AUTH_ID, .type = CONNECTION_ADDR_BR, };
1973 int32_t ret = LnnNotifyAuthHandleLeaveLNN(authHandle);
1974 EXPECT_EQ(ret, SOFTBUS_NO_INIT);
1975 const char *networkId = NODE_NETWORK_ID;
1976 uint8_t *msg = const_cast<uint8_t *>(SELECT_MASTER_MSG);
1977 uint32_t len = strlen(reinterpret_cast<const char *>(msg));
1978 OnReceiveMasterElectMsg(LNN_INFO_TYPE_NICK_NAME, networkId, msg, len);
1979 g_netBuilder.isInit = true;
1980 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
1981 EXPECT_CALL(NetBuilderMock, AuthHandleLeaveLNN).WillRepeatedly(Return());
1982 ret = LnnNotifyAuthHandleLeaveLNN(authHandle);
1983 EXPECT_EQ(ret, SOFTBUS_OK);
1984 authHandle.type = 0;
1985 NodeInfo info;
1986 (void)memset_s(&info, sizeof(NodeInfo), 0, sizeof(NodeInfo));
1987 OnVerifyPassed(REQUEST_ID, authHandle, &info);
1988 authHandle.type = AUTH_LINK_TYPE_MAX;
1989 OnVerifyPassed(REQUEST_ID, authHandle, &info);
1990 OnReceiveMasterElectMsg(LNN_INFO_TYPE_MASTER_ELECT, networkId, msg, len);
1991 }
1992
PostMessageFunc(const SoftBusLooper * looper,SoftBusMessage * msg)1993 static void PostMessageFunc(const SoftBusLooper *looper, SoftBusMessage *msg)
1994 {
1995 (void)looper;
1996 if (msg != nullptr) {
1997 SoftBusFree(msg);
1998 }
1999 }
2000
SetNetBuilderLooper()2001 static void SetNetBuilderLooper()
2002 {
2003 g_netBuilder.looper->PostMessage = PostMessageFunc;
2004 }
2005
2006 /*
2007 * @tc.name: LNN_NOTIFY_LEAVE_LNN_BY_AUTH_HANDLE_TEST_001
2008 * @tc.desc: LnnNotifyLeaveLnnByAuthHandle test
2009 * @tc.type: FUNC
2010 * @tc.require:
2011 */
2012 HWTEST_F(LNNNetBuilderMockTest, LNN_NOTIFY_LEAVE_LNN_BY_AUTH_HANDLE_TEST_001, TestSize.Level1)
2013 {
2014 SetNetBuilderLooper();
2015 AuthHandle authHandle;
2016 int32_t ret = LnnNotifyLeaveLnnByAuthHandle(&authHandle);
2017 EXPECT_EQ(ret, SOFTBUS_OK);
2018 ret = LnnNotifyEmptySessionKey(AUTH_ID);
2019 EXPECT_EQ(ret, SOFTBUS_OK);
2020 }
2021
2022 /*
2023 * @tc.name: LNN_BLE_REPORT_EXTRA_MAP_INIT_TEST_001
2024 * @tc.desc: LnnBleReportExtraMapInit test
2025 * @tc.type: FUNC
2026 * @tc.require:
2027 */
2028 HWTEST_F(LNNNetBuilderMockTest, LNN_BLE_REPORT_EXTRA_MAP_INIT_TEST_001, TestSize.Level1)
2029 {
2030 const char *udidHash = NODE_UDID;
2031 LnnBleReportExtra bleExtra = { .extra.result = SOFTBUS_OK, .status = BLE_REPORT_EVENT_INIT, };
2032 LnnBleReportExtra bleExtraDest;
2033 (void)memset_s(&bleExtraDest, sizeof(LnnBleReportExtra), 0, sizeof(LnnBleReportExtra));
2034 AddNodeToLnnBleReportExtraMap(udidHash, &bleExtra);
2035 DeleteNodeFromLnnBleReportExtraMap(udidHash);
2036 int32_t rc = GetNodeFromLnnBleReportExtraMap(udidHash, &bleExtraDest);
2037 EXPECT_EQ(rc, SOFTBUS_INVALID_PARAM);
2038 bool ret = IsExistLnnDfxNodeByUdidHash(udidHash, &bleExtra);
2039 EXPECT_EQ(ret, false);
2040 ret = LnnBleReportExtraMapInit();
2041 EXPECT_EQ(ret, true);
2042 AddNodeToLnnBleReportExtraMap(nullptr, &bleExtra);
2043 AddNodeToLnnBleReportExtraMap(udidHash, nullptr);
2044 AddNodeToLnnBleReportExtraMap(udidHash, &bleExtra);
2045 rc = GetNodeFromLnnBleReportExtraMap(nullptr, &bleExtraDest);
2046 EXPECT_EQ(rc, SOFTBUS_INVALID_PARAM);
2047 rc = GetNodeFromLnnBleReportExtraMap(udidHash, nullptr);
2048 EXPECT_EQ(rc, SOFTBUS_INVALID_PARAM);
2049 rc = GetNodeFromLnnBleReportExtraMap(udidHash, &bleExtraDest);
2050 EXPECT_EQ(rc, SOFTBUS_OK);
2051 const char *udidHash1 = NODE_NETWORK_ID;
2052 rc = GetNodeFromLnnBleReportExtraMap(udidHash1, &bleExtraDest);
2053 EXPECT_EQ(rc, SOFTBUS_NOT_FIND);
2054 }
2055
2056 /*
2057 * @tc.name: IS_EXIST_LNN_DFX_NODE_BY_UDID_HASH_TEST_001
2058 * @tc.desc: IsExistLnnDfxNodeByUdidHash test
2059 * @tc.type: FUNC
2060 * @tc.require:
2061 */
2062 HWTEST_F(LNNNetBuilderMockTest, IS_EXIST_LNN_DFX_NODE_BY_UDID_HASH_TEST_001, TestSize.Level1)
2063 {
2064 const char *udidHash = NODE_UDID;
2065 const char *udidHash1 = NODE_NETWORK_ID;
2066 LnnBleReportExtra bleExtra;
2067 (void)memset_s(&bleExtra, sizeof(LnnBleReportExtra), 0, sizeof(LnnBleReportExtra));
2068 bool ret = IsExistLnnDfxNodeByUdidHash(udidHash, &bleExtra);
2069 EXPECT_EQ(ret, true);
2070 ret = IsExistLnnDfxNodeByUdidHash(udidHash1, &bleExtra);
2071 EXPECT_EQ(ret, false);
2072 ret = IsExistLnnDfxNodeByUdidHash(nullptr, &bleExtra);
2073 EXPECT_EQ(ret, false);
2074 ret = IsExistLnnDfxNodeByUdidHash(udidHash, nullptr);
2075 EXPECT_EQ(ret, false);
2076 DeleteNodeFromLnnBleReportExtraMap(nullptr);
2077 DeleteNodeFromLnnBleReportExtraMap(udidHash1);
2078 DeleteNodeFromLnnBleReportExtraMap(udidHash);
2079 ClearLnnBleReportExtraMap();
2080 }
2081
2082 /*
2083 * @tc.name: GET_NODE_FROM_PC_RESTRICT_MAP_TEST_001
2084 * @tc.desc: GetNodeFromPcRestrictMap test
2085 * @tc.type: FUNC
2086 * @tc.require:
2087 */
2088 HWTEST_F(LNNNetBuilderMockTest, GET_NODE_FROM_PC_RESTRICT_MAP_TEST_001, TestSize.Level1)
2089 {
2090 const char *udidHash = NODE_UDID;
2091 const char *udidHash1 = NODE_NETWORK_ID;
2092 uint32_t count = 0;
2093 AddNodeToPcRestrictMap(udidHash);
2094 DeleteNodeFromPcRestrictMap(udidHash);
2095 int32_t ret = GetNodeFromPcRestrictMap(udidHash, &count);
2096 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2097 ret = UpdateNodeFromPcRestrictMap(udidHash);
2098 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2099 LnnBlePcRestrictMapInit();
2100 AddNodeToPcRestrictMap(udidHash);
2101 AddNodeToPcRestrictMap(nullptr);
2102 ret = GetNodeFromPcRestrictMap(udidHash, &count);
2103 EXPECT_EQ(ret, SOFTBUS_OK);
2104 ret = GetNodeFromPcRestrictMap(udidHash1, &count);
2105 EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
2106 ret = GetNodeFromPcRestrictMap(nullptr, &count);
2107 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2108 ret = GetNodeFromPcRestrictMap(udidHash, nullptr);
2109 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2110 ret = UpdateNodeFromPcRestrictMap(udidHash);
2111 EXPECT_EQ(ret, SOFTBUS_OK);
2112 ret = UpdateNodeFromPcRestrictMap(udidHash1);
2113 EXPECT_EQ(ret, SOFTBUS_NOT_FIND);
2114 ret = UpdateNodeFromPcRestrictMap(nullptr);
2115 EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
2116 DeleteNodeFromPcRestrictMap(nullptr);
2117 DeleteNodeFromPcRestrictMap(udidHash);
2118 DeleteNodeFromPcRestrictMap(udidHash1);
2119 ClearPcRestrictMap();
2120 }
2121
2122 /*
2123 * @tc.name: USER_SWITCHED_HANDLER_TEST_001
2124 * @tc.desc: UserSwitchedHandler test
2125 * @tc.type: FUNC
2126 * @tc.require:
2127 */
2128 HWTEST_F(LNNNetBuilderMockTest, USER_SWITCHED_HANDLER_TEST_001, TestSize.Level1)
2129 {
2130 LnnMonitorHbStateChangedEvent event = {
2131 .basic.event = LNN_EVENT_IP_ADDR_CHANGED,
2132 .status = SOFTBUS_USER_SWITCH_UNKNOWN,
2133 };
2134 const LnnEventBasicInfo *info = reinterpret_cast<const LnnEventBasicInfo *>(&event);
2135 UserSwitchedHandler(nullptr);
2136 UserSwitchedHandler(info);
2137 NiceMock<NetBuilderDepsInterfaceMock> NetBuilderMock;
2138 EXPECT_CALL(NetBuilderMock, LnnSetUnlockState).WillOnce(Return());
2139 event.basic.event = LNN_EVENT_USER_SWITCHED;
2140 const LnnEventBasicInfo *info1 = reinterpret_cast<const LnnEventBasicInfo *>(&event);
2141 UserSwitchedHandler(info1);
2142 event.status = SOFTBUS_USER_SWITCHED;
2143 const LnnEventBasicInfo *info2 = reinterpret_cast<const LnnEventBasicInfo *>(&event);
2144 UserSwitchedHandler(info2);
2145 AuthHandle authHandle = { .type = 0, .authId = AUTH_ID_ADD, };
2146 OnDeviceDisconnect(authHandle);
2147 authHandle.type = AUTH_LINK_TYPE_MAX;
2148 OnDeviceDisconnect(authHandle);
2149 bool ret = IsSupportMasterNodeElect(SOFTBUS_NEW_V1);
2150 EXPECT_EQ(ret, true);
2151 }
2152 } // namespace OHOS
2153