• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "UTTest_softbus_connector.h"
16 
17 #include <securec.h>
18 #include <unistd.h>
19 #include <cstdlib>
20 #include <string>
21 #include <thread>
22 
23 #include "dm_anonymous.h"
24 #include "dm_constants.h"
25 #include "dm_device_info.h"
26 #include "dm_log.h"
27 #include "ipc_notify_auth_result_req.h"
28 #include "ipc_notify_device_state_req.h"
29 #include "ipc_notify_device_found_req.h"
30 #include "ipc_notify_discover_result_req.h"
31 #include "ipc_notify_publish_result_req.h"
32 #include "ipc_notify_verify_auth_result_req.h"
33 #include "parameter.h"
34 #include "system_ability_definition.h"
35 
36 namespace OHOS {
37 namespace DistributedHardware {
SetUp()38 void SoftbusConnectorTest::SetUp()
39 {
40 }
TearDown()41 void SoftbusConnectorTest::TearDown()
42 {
43 }
SetUpTestCase()44 void SoftbusConnectorTest::SetUpTestCase()
45 {
46 }
TearDownTestCase()47 void SoftbusConnectorTest::TearDownTestCase()
48 {
49 }
50 
51 namespace {
52 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
53 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
54 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
55 std::shared_ptr<DmDeviceStateManager> deviceStateMgr =
56     std::make_shared<DmDeviceStateManager>(softbusConnector, listener, hiChainConnector);
57 std::shared_ptr<DmDiscoveryManager> discoveryMgr =
58     std::make_shared<DmDiscoveryManager>(softbusConnector, listener, hiChainConnector);
59 std::shared_ptr<DmPublishManager> publishMgr = std::make_shared<DmPublishManager>(softbusConnector, listener);
60 /**
61  * @tc.name: DeviceOnLine_001
62  * @tc.desc: go to the corrort case and return DM_OK
63  * @tc.type: FUNC
64  * @tc.require: AR000GHSJK
65  */
66 HWTEST_F(SoftbusConnectorTest, DeviceOnLine_001, testing::ext::TestSize.Level0)
67 {
68     std::string pkgName = "123";
69     DmDeviceInfo info;
70     strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
71     int32_t ret = deviceStateMgr->RegisterSoftbusStateCallback();
72     DeviceOnLine(info);
73     EXPECT_EQ(ret, DM_OK);
74     SoftbusConnector::stateCallbackMap_.clear();
75 }
76 
77 /**
78  * @tc.name: DeviceOnLine_002
79  * @tc.desc: go to the corrort case and return DM_OK
80  * @tc.type: FUNC
81  * @tc.require: AR000GHSJK
82  */
83 HWTEST_F(SoftbusConnectorTest, DeviceOnLine_002, testing::ext::TestSize.Level0)
84 {
85     std::string pkgName = "123";
86     DmDeviceInfo info;
87     strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
88     DeviceOnLine(info);
89     bool ret = false;
90     if (listener->ipcServerListener_.req_ != nullptr) {
91         ret = true;
92         listener->ipcServerListener_.req_ = nullptr;
93     }
94     EXPECT_EQ(ret, false);
95     SoftbusConnector::stateCallbackMap_.clear();
96 }
97 
98 /**
99  * @tc.name: DeviceOffLine_001
100  * @tc.desc: go to the corrort case and return false
101  * @tc.type: FUNC
102  * @tc.require: AR000GHSJK
103  */
104 HWTEST_F(SoftbusConnectorTest, DeviceOffLine_001, testing::ext::TestSize.Level0)
105 {
106     std::string pkgName = "123";
107     DmDeviceInfo info;
108     strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
109     deviceStateMgr->PostDeviceChanged(pkgName, info);
110     DeviceOffLine(info);
111     bool ret = false;
112     if (listener->ipcServerListener_.req_ != nullptr) {
113         ret = true;
114         listener->ipcServerListener_.req_ = nullptr;
115     }
116     EXPECT_EQ(ret, true);
117     SoftbusConnector::stateCallbackMap_.clear();
118 }
119 
120 /**
121  * @tc.name: DeviceOffLine_002
122  * @tc.desc: go to the corrort case and return false
123  * @tc.type: FUNC
124  * @tc.require: AR000GHSJK
125  */
126 HWTEST_F(SoftbusConnectorTest, DeviceOffLine_002, testing::ext::TestSize.Level0)
127 {
128     std::string pkgName = "123";
129     DmDeviceInfo info;
130     strcpy_s(info.deviceId, DM_MAX_DEVICE_ID_LEN, "123");
131     DeviceOffLine(info);
132     bool ret = false;
133     if (listener->ipcServerListener_.req_ != nullptr) {
134         ret = true;
135         listener->ipcServerListener_.req_ = nullptr;
136     }
137     EXPECT_EQ(ret, false);
138     SoftbusConnector::stateCallbackMap_.clear();
139 }
140 
141 /**
142  * @tc.name: SoftbusConnector_001
143  * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr
144  * @tc.type: FUNC
145  * @tc.require: AR000GHSJK
146  */
147 HWTEST_F(SoftbusConnectorTest, SoftbusConnector_001, testing::ext::TestSize.Level0)
148 {
149     std::shared_ptr<SoftbusConnector> m_SoftbusConnector = std::make_shared<SoftbusConnector>();
150     ASSERT_NE(m_SoftbusConnector, nullptr);
151 }
152 
153 /**
154  * @tc.name: SoftbusConnector_002
155  * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
156  * @tc.type: FUNC
157  * @tc.require: AR000GHSJK
158  */
159 HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Level0)
160 {
161     std::shared_ptr<SoftbusConnector> m_SoftbusConnector = std::make_shared<SoftbusConnector>();
162     m_SoftbusConnector.reset();
163     EXPECT_EQ(m_SoftbusConnector, nullptr);
164 }
165 
166 /**
167  * @tc.name: RegisterSoftbusDiscoveryCallback_001
168  * @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusDiscoveryCallback function to corrort, return DM_OK
169  * @tc.type: FUNC
170  * @tc.require: AR000GHSJK
171  */
172 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)
173 {
174     std::string pkgName = "com.ohos.helloworld";
175     int ret1 = softbusConnector->RegisterSoftbusDiscoveryCallback(
176         pkgName, std::shared_ptr<ISoftbusDiscoveryCallback>(discoveryMgr));
177     int ret = SoftbusConnector::discoveryCallbackMap_.count(pkgName);
178     EXPECT_EQ(ret1, DM_OK);
179     EXPECT_EQ(ret, 1);
180 }
181 
182 /**
183  * @tc.name: UnRegisterSoftbusDiscoveryCallback_001
184  * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusDiscoveryCallback function to corrort, return
185  * DM_OK
186  * @tc.type: FUNC
187  * @tc.require: AR000GHSJK
188  */
189 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)
190 {
191     std::string pkgName = "com.ohos.helloworld";
192     int ret = softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
193     int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName);
194     EXPECT_EQ(ret1, 0);
195     EXPECT_EQ(ret, DM_OK);
196 }
197 
198 /**
199  * @tc.name: RegisterSoftbusPublishCallback_001
200  * @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusPublishCallback function to corrort, return DM_OK
201  * @tc.type: FUNC
202  * @tc.require: I5N1K3
203  */
204 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)
205 {
206     std::string pkgName = "com.ohos.helloworld";
207     int ret1 = softbusConnector->RegisterSoftbusPublishCallback(
208         pkgName, std::shared_ptr<ISoftbusPublishCallback>(publishMgr));
209     int ret = SoftbusConnector::publishCallbackMap_.count(pkgName);
210     EXPECT_EQ(ret1, DM_OK);
211     EXPECT_EQ(ret, 1);
212 }
213 
214 /**
215  * @tc.name: UnRegisterSoftbusPublishCallback_001
216  * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusPublishyCallback function to corrort, return
217  * DM_OK
218  * @tc.type: FUNC
219  * @tc.require: I5N1K3
220  */
221 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)
222 {
223     std::string pkgName = "com.ohos.helloworld";
224     int ret = softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
225     int ret1 = SoftbusConnector::publishCallbackMap_.count(pkgName);
226     EXPECT_EQ(ret1, 0);
227     EXPECT_EQ(ret, DM_OK);
228 }
229 
230 /**
231  * @tc.name: RegisterSoftbusStateCallback_001
232  * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusStateCallback function to corrort, return DM_OK
233  * @tc.type: FUNC
234  * @tc.require: AR000GHSJK
235  */
236 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)
237 {
238     std::string pkgName = "com.ohos.helloworld";
239     int ret = softbusConnector->RegisterSoftbusStateCallback(
240         pkgName, std::shared_ptr<ISoftbusStateCallback>(deviceStateMgr));
241     int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName);
242     EXPECT_EQ(ret1, DM_OK);
243     EXPECT_EQ(ret, 0);
244     softbusConnector->UnRegisterSoftbusStateCallback(pkgName);
245 }
246 
247 /**
248  * @tc.name: UnRegisterSoftbusStateCallback_001
249  * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusStateCallback function to corrort, return DM_OK
250  * @tc.type: FUNC
251  * @tc.require: AR000GHSJK
252  */
253 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)
254 {
255     std::string pkgName = "com.ohos.helloworld";
256     int ret = softbusConnector->UnRegisterSoftbusStateCallback(pkgName);
257     int ret1 = SoftbusConnector::stateCallbackMap_.count(pkgName);
258     EXPECT_EQ(ret1, 0);
259     EXPECT_EQ(ret, DM_OK);
260 }
261 
262 /**
263  * @tc.name: StartDiscovery_001
264  * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
265  * @tc.type: FUNC
266  * @tc.require: AR000GHSJK
267  */
268 HWTEST_F(SoftbusConnectorTest, StartDiscovery_001, testing::ext::TestSize.Level0)
269 {
270     DmSubscribeInfo dmSubscribeInfo;
271     int ret = softbusConnector->StartDiscovery(dmSubscribeInfo);
272     EXPECT_EQ(ret, ERR_DM_DISCOVERY_FAILED);
273 }
274 
275 /**
276  * @tc.name: StartDiscovery_002
277  * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
278  * @tc.type: FUNC
279  * @tc.require: AR000GHSJK
280  */
281 HWTEST_F(SoftbusConnectorTest, StartDiscovery_002, testing::ext::TestSize.Level0)
282 {
283     uint16_t subscribeId = 0;
284     int ret = softbusConnector->StartDiscovery(subscribeId);
285     EXPECT_EQ(ret, ERR_DM_DISCOVERY_FAILED);
286 }
287 
288 /**
289  * @tc.name: StopDiscovery_001
290  * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
291  * @tc.type: FUNC
292  * @tc.require: AR000GHSJK
293  */
294 HWTEST_F(SoftbusConnectorTest, StopDiscovery_001, testing::ext::TestSize.Level0)
295 {
296     uint16_t subscribeId = static_cast<uint16_t>(123456);
297     int ret = softbusConnector->StopDiscovery(subscribeId);
298     EXPECT_NE(ret, 0);
299 }
300 
301 /**
302  * @tc.name: PublishDiscovery_001
303  * @tc.desc: get PublishDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
304  * @tc.type: FUNC
305  * @tc.require: I5N1K3
306  */
307 HWTEST_F(SoftbusConnectorTest, PublishDiscovery_001, testing::ext::TestSize.Level0)
308 {
309     DmPublishInfo dmPublishInfo;
310     int ret = softbusConnector->PublishDiscovery(dmPublishInfo);
311     EXPECT_EQ(ret, ERR_DM_PUBLISH_FAILED);
312 }
313 
314 /**
315  * @tc.name: UnPublishDiscovery_001
316  * @tc.desc: get UnPublishDiscovery to wrong branch and return ERR_DM_PUBLISH_FAILED
317  * @tc.type: FUNC
318  * @tc.require: I5N1K3
319  */
320 HWTEST_F(SoftbusConnectorTest, UnPublishDiscovery_001, testing::ext::TestSize.Level0)
321 {
322     int32_t publishId = 123456;
323     int ret = softbusConnector->UnPublishDiscovery(publishId);
324     EXPECT_NE(ret, 0);
325 }
326 
327 /**
328  * @tc.name: GetUdidByNetworkId_001
329  * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
330  * @tc.type: FUNC
331  * @tc.require: AR000GHSJK
332  */
333 HWTEST_F(SoftbusConnectorTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0)
334 {
335     const char *networkId = "123456";
336     std::string udid;
337     int ret = softbusConnector->GetUdidByNetworkId(networkId, udid);
338     EXPECT_NE(ret, 0);
339 }
340 
341 /**
342  * @tc.name: GetUuidByNetworkId_001
343  * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
344  * @tc.type: FUNC
345  * @tc.require: AR000GHSJK
346  */
347 HWTEST_F(SoftbusConnectorTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0)
348 {
349     const char *networkId = "123456";
350     std::string udid;
351     int ret = softbusConnector->GetUdidByNetworkId(networkId, udid);
352     EXPECT_NE(ret, 0);
353 }
354 
355 /**
356  * @tc.name: GetSoftbusSession_001
357  * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
358  * @tc.type: FUNC
359  * @tc.require: AR000GHSJK
360  */
361 HWTEST_F(SoftbusConnectorTest, GetSoftbusSession_001, testing::ext::TestSize.Level0)
362 {
363     std::shared_ptr<SoftbusSession> softSession = softbusConnector->GetSoftbusSession();
364     EXPECT_NE(softSession, nullptr);
365 }
366 
367 /**
368  * @tc.name: GetSoftbusSession_001
369  * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
370  * @tc.type: FUNC
371  * @tc.require: AR000GHSJK
372  */
373 HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_001, testing::ext::TestSize.Level0)
374 {
375     std::string deviceId = "12345678";
376     SoftbusConnector::discoveryDeviceInfoMap_[deviceId];
377     bool ret = softbusConnector->HaveDeviceInMap(deviceId);
378     EXPECT_EQ(ret, true);
379     SoftbusConnector::discoveryDeviceInfoMap_.clear();
380 }
381 
382 /**
383  * @tc.name: GetSoftbusSession_001
384  * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
385  * @tc.type: FUNC
386  * @tc.require: AR000GHSJK
387  */
388 HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_002, testing::ext::TestSize.Level0)
389 {
390     std::string deviceId = "12345678";
391     bool ret = softbusConnector->HaveDeviceInMap(deviceId);
392     EXPECT_EQ(ret, false);
393     SoftbusConnector::discoveryDeviceInfoMap_.clear();
394 }
395 
396 /**
397  * @tc.name: GetConnectionIpAddress_001
398  * @tc.desc: set deviceId null, and return ERR_DM_FAILED
399  * @tc.type: FUNC
400  * @tc.require: AR000GHSJK
401  */
402 HWTEST_F(SoftbusConnectorTest, GetConnectionIpAddress_001, testing::ext::TestSize.Level0)
403 {
404     std::string deviceId;
405     std::string ipAddress = "123456";
406     int ret = softbusConnector->GetConnectionIpAddress(deviceId, ipAddress);
407     EXPECT_EQ(ret, ERR_DM_FAILED);
408 }
409 
410 /**
411  * @tc.name: GetConnectionIpAddress_002
412  * @tc.desc: set some corrort para, and return ERR_DM_FAILED
413  * @tc.type: FUNC
414  * @tc.require: AR000GHSJK
415  */
416 HWTEST_F(SoftbusConnectorTest, GetConnectionIpAddress_002, testing::ext::TestSize.Level0)
417 {
418     std::string deviceId = "213456";
419     std::string ipAddress = "123456";
420     int ret = softbusConnector->GetConnectionIpAddress(deviceId, ipAddress);
421     EXPECT_EQ(ret, ERR_DM_FAILED);
422 }
423 
424 /**
425  * @tc.name: GetConnectionIpAddress_003
426  * @tc.desc: set deviceInfo.addrNum = -1;go to second branch and return ERR_DM_FAILED
427  * @tc.type: FUNC
428  * @tc.require: AR000GHSJK
429  */
430 HWTEST_F(SoftbusConnectorTest, GetConnectionIpAddress_003, testing::ext::TestSize.Level0)
431 {
432     DeviceInfo deviceInfo;
433     deviceInfo.addrNum = -1;
434     std::string ipAddress;
435     std::string deviceId = "3338848";
436     int ret = softbusConnector->GetConnectionIpAddress(deviceId, ipAddress);
437     EXPECT_EQ(ret, ERR_DM_FAILED);
438 }
439 
440 /**
441  * @tc.name: GetConnectionIpAddress_004
442  * @tc.desc: set deviceInfo.addrNum = 1;go to second branch and return ERR_DM_FAILED
443  * @tc.type: FUNC
444  * @tc.require: AR000GHSJK
445  */
446 HWTEST_F(SoftbusConnectorTest, GetConnectionIpAddress_004, testing::ext::TestSize.Level0)
447 {
448     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
449     constexpr char ETH_IP[] = "0.0.0.0";
450     deviceInfo->addrNum = 1;
451     deviceInfo->addr[0].type = CONNECTION_ADDR_WLAN;
452     (void)strncpy_s(deviceInfo->addr[0].info.ip.ip, IP_STR_MAX_LEN, ETH_IP, strlen(ETH_IP));
453     std::string ipAddress;
454     std::string deviceId = "3338848";
455     SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
456     int ret = softbusConnector->GetConnectionIpAddress(deviceId, ipAddress);
457     EXPECT_EQ(ret, DM_OK);
458     SoftbusConnector::discoveryDeviceInfoMap_.clear();
459 }
460 
461 /**
462  * @tc.name: GetConnectAddrByType_001
463  * @tc.desc: set deviceInfo'pointer null, go to first branch, and return nullptr
464  * @tc.require: AR000GHSJK
465  */
466 HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_001, testing::ext::TestSize.Level0)
467 {
468     ConnectionAddrType type;
469     type = CONNECTION_ADDR_MAX;
470     ConnectionAddr *p = nullptr;
471     ConnectionAddr *ret = softbusConnector->GetConnectAddrByType(nullptr, type);
472     EXPECT_EQ(p, ret);
473 }
474 
475 /**
476  * @tc.name: GetConnectAddrByType_002
477  * @tc.desc:set deviceInfo to some corrort para, and return nullptr
478  * @tc.type: FUNC
479  * @tc.require: AR000GHSJK
480  */
481 HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_002, testing::ext::TestSize.Level0)
482 {
483     DeviceInfo deviceInfo;
484     deviceInfo.addrNum = 1;
485     ConnectionAddrType type;
486     type = CONNECTION_ADDR_BR;
487     ConnectionAddr *p = nullptr;
488     ConnectionAddr *ret = softbusConnector->GetConnectAddrByType(&deviceInfo, type);
489     EXPECT_EQ(ret, p);
490 }
491 
492 /**
493  * @tc.name: GetConnectAddr_001
494  * @tc.desc: set deviceId to null, and return nullptr
495  * @tc.type: FUNC
496  * @tc.require: AR000GHSJK
497  */
498 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_001, testing::ext::TestSize.Level0)
499 {
500     std::string deviceId;
501     std::string connectAddr;
502     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
503     EXPECT_EQ(ret, nullptr);
504 }
505 
506 /**
507  * @tc.name: GetConnectAddr_002
508  * @tc.desc:set deviceId nit null set deviceInfo.addrNum = -1; and return nullptr
509  * @tc.type: FUNC
510  * @tc.require: AR000GHSJK
511  */
512 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_002, testing::ext::TestSize.Level0)
513 {
514     std::string deviceId = "123345";
515     std::string connectAddr;
516     DeviceInfo deviceInfo;
517     deviceInfo.addrNum = -1;
518     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
519     EXPECT_EQ(ret, nullptr);
520 }
521 
522 /**
523  * @tc.name: GetConnectAddr_003
524  * @tc.desc:set deviceInfo.addrNum = 1
525  * @tc.type: FUNC
526  * @tc.require: AR000GHSJK
527  */
528 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_003, testing::ext::TestSize.Level0)
529 {
530     std::string deviceId = "123345";
531     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
532     std::string connectAddr;
533     constexpr char ETH_IP[] = "0.0.0.0";
534     deviceInfo->addrNum = 1;
535     deviceInfo->addr[0].type = CONNECTION_ADDR_ETH;
536     (void)strncpy_s(deviceInfo->addr[0].info.ip.ip, IP_STR_MAX_LEN, ETH_IP, strlen(ETH_IP));
537     deviceInfo->addr[0].info.ip.port = 0;
538     SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
539     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
540     EXPECT_NE(ret, nullptr);
541     SoftbusConnector::discoveryDeviceInfoMap_.clear();
542 }
543 
544 /**
545  * @tc.name: GetConnectAddr_004
546  * @tc.desc:set deviceInfo.addrNum = 1
547  * @tc.type: FUNC
548  * @tc.require: AR000GHSJK
549  */
550 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_004, testing::ext::TestSize.Level0)
551 {
552     std::string deviceId = "123345";
553     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
554     std::string connectAddr;
555     constexpr char WLAN_IP[] = "1.1.1.1";
556     deviceInfo->addrNum = 1;
557     deviceInfo->addr[0].type = CONNECTION_ADDR_WLAN;
558     (void)strncpy_s(deviceInfo->addr[0].info.ip.ip, IP_STR_MAX_LEN, WLAN_IP, strlen(WLAN_IP));
559     deviceInfo->addr[0].info.ip.port = 0;
560     SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
561     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
562     EXPECT_NE(ret, nullptr);
563     SoftbusConnector::discoveryDeviceInfoMap_.clear();
564 }
565 
566 /**
567  * @tc.name: GetConnectAddr_005
568  * @tc.desc:get brMac addr
569  * @tc.type: FUNC
570  * @tc.require: AR000GHSJK
571  */
572 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_005, testing::ext::TestSize.Level0)
573 {
574     std::string deviceId = "123345";
575     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
576     std::string connectAddr;
577     deviceInfo->addrNum = 1;
578     constexpr char BR_MAC[] = "2:2:2:2";
579     deviceInfo->addr[0].type = CONNECTION_ADDR_BR;
580     (void)strncpy_s(deviceInfo->addr[0].info.br.brMac, IP_STR_MAX_LEN, BR_MAC, strlen(BR_MAC));
581     SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
582     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
583     EXPECT_NE(ret, nullptr);
584     SoftbusConnector::discoveryDeviceInfoMap_.clear();
585 }
586 
587 /**
588  * @tc.name: GetConnectAddr_006
589  * @tc.desc:get bleMac addr
590  * @tc.type: FUNC
591  * @tc.require: AR000GHSJK
592  */
593 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_006, testing::ext::TestSize.Level0)
594 {
595     std::string deviceId = "123345";
596     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
597     std::string connectAddr;
598     constexpr char BLE_MAC[] = "3:3:3:3";
599     deviceInfo->addrNum = 1;
600     deviceInfo->addr[0].type = CONNECTION_ADDR_BLE;
601     (void)strncpy_s(deviceInfo->addr[0].info.ble.bleMac, IP_STR_MAX_LEN, BLE_MAC, strlen(BLE_MAC));
602     SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
603     ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
604     EXPECT_NE(ret, nullptr);
605     SoftbusConnector::discoveryDeviceInfoMap_.clear();
606 }
607 
608 /**
609  * @tc.name: ConvertNodeBasicInfoToDmDevice_001
610  * @tc.desc: go to the correct case and return DM_OK
611  * @tc.type: FUNC
612  * @tc.require: AR000GHSJK
613  */
614 HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_001, testing::ext::TestSize.Level0)
615 {
616     DeviceInfo deviceInfo = {
617         .devId = "123456",
618         .devType = (DeviceType)1,
619         .devName = "11111"
620     };
621     DmDeviceInfo dm;
622     DmDeviceInfo dm_1 = {
623         .deviceId = "123456",
624         .deviceName = "11111",
625         .deviceTypeId = 1
626     };
627     softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dm);
628     bool ret = false;
629     if (strcmp(dm.deviceId, dm_1.deviceId) == 0) {
630         ret = true;
631     }
632     EXPECT_EQ(ret, true);
633 }
634 
635 /**
636  * @tc.name: OnSoftbusDeviceFound_001
637  * @tc.desc: go to the correct case and return DM_OK
638  * @tc.type: FUNC
639  * @tc.require: AR000GHSJK
640  */
641 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_001, testing::ext::TestSize.Level0)
642 {
643     DeviceInfo *device = nullptr;
644     softbusConnector->OnSoftbusDeviceFound(device);
645     bool ret = false;
646     if (listener->ipcServerListener_.req_ != nullptr) {
647         listener->ipcServerListener_.req_ = nullptr;
648         ret = true;
649     }
650     EXPECT_EQ(ret, false);
651 }
652 
653 /**
654  * @tc.name: OnSoftbusDeviceFound_002
655  * @tc.desc: go to the correct case and return DM_OK
656  * @tc.type: FUNC
657  * @tc.require: AR000GHSJK
658  */
659 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_002, testing::ext::TestSize.Level0)
660 {
661     DeviceInfo device = {
662         .devId = "123456",
663         .devType = (DeviceType)1,
664         .devName = "11111"
665     };
666     softbusConnector->OnSoftbusDeviceFound(&device);
667     bool ret = false;
668     if (listener->ipcServerListener_.req_ != nullptr) {
669         listener->ipcServerListener_.req_ = nullptr;
670         ret = true;
671     }
672     EXPECT_EQ(ret, false);
673 }
674 
675 /**
676  * @tc.name: OnSoftbusDiscoveryResult_001
677  * @tc.desc: go to the correct case and return DM_OK
678  * @tc.type: FUNC
679  * @tc.require: AR000GHSJK
680  */
681 HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_001, testing::ext::TestSize.Level0)
682 {
683     int32_t subscribeId= 123456;
684     RefreshResult result = (RefreshResult)1;
685     std::string pkgName = "com.ohos.helloworld";
686     softbusConnector->RegisterSoftbusDiscoveryCallback(
687         pkgName, std::shared_ptr<ISoftbusDiscoveryCallback>(discoveryMgr));
688     softbusConnector->OnSoftbusDiscoveryResult(subscribeId, result);
689     bool ret = false;
690     if (listener->ipcServerListener_.req_ != nullptr) {
691         listener->ipcServerListener_.req_ = nullptr;
692         ret = true;
693     }
694     EXPECT_EQ(ret, true);
695     softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
696 }
697 
698 /**
699  * @tc.name: OnSoftbusDiscoveryResult_001
700  * @tc.desc: go to the correct case and return DM_OK
701  * @tc.type: FUNC
702  * @tc.require: AR000GHSJK
703  */
704 HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_002, testing::ext::TestSize.Level0)
705 {
706     int32_t subscribeId= 123456;
707     RefreshResult result = (RefreshResult)0;
708     std::string pkgName = "com.ohos.helloworld";
709     softbusConnector->RegisterSoftbusDiscoveryCallback(
710         pkgName, std::shared_ptr<ISoftbusDiscoveryCallback>(discoveryMgr));
711     softbusConnector->OnSoftbusDiscoveryResult(subscribeId, result);
712     bool ret = false;
713     if (listener->ipcServerListener_.req_ != nullptr) {
714         listener->ipcServerListener_.req_ = nullptr;
715         ret = true;
716     }
717     EXPECT_EQ(ret, true);
718     softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
719 }
720 
721 /**
722  * @tc.name: OnSoftbusPublishResult_001
723  * @tc.desc: go to the correct case and return DM_OK
724  * @tc.type: FUNC
725  * @tc.require: I5N1K3
726  */
727 HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_001, testing::ext::TestSize.Level0)
728 {
729     int32_t publishId = 123456;
730     PublishResult failReason = (PublishResult)1;
731     std::string pkgName = "com.ohos.helloworld";
732     softbusConnector->RegisterSoftbusPublishCallback(
733         pkgName, std::shared_ptr<ISoftbusPublishCallback>(publishMgr));
734     softbusConnector->OnSoftbusPublishResult(publishId, failReason);
735     bool ret = false;
736     if (listener->ipcServerListener_.req_ != nullptr) {
737         listener->ipcServerListener_.req_ = nullptr;
738         ret = true;
739     }
740     EXPECT_EQ(ret, true);
741     softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
742 }
743 
744 /**
745  * @tc.name: OnSoftbusPublishResult_004
746  * @tc.desc: go to the correct case and return DM_OK
747  * @tc.type: FUNC
748  * @tc.require: I5N1K3
749  */
750 HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_002, testing::ext::TestSize.Level0)
751 {
752     int32_t publishId= 123456;
753     std::string pkgName = "com.ohos.helloworld";
754     PublishResult failReason = (PublishResult)0;
755     softbusConnector->RegisterSoftbusPublishCallback(
756         pkgName, std::shared_ptr<ISoftbusPublishCallback>(publishMgr));
757     softbusConnector->OnSoftbusPublishResult(publishId, failReason);
758     bool ret = false;
759     if (listener->ipcServerListener_.req_ != nullptr) {
760         listener->ipcServerListener_.req_ = nullptr;
761         ret = true;
762     }
763     EXPECT_EQ(ret, true);
764     softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
765 }
766 
767 /**
768  * @tc.name: JoinLnn_001
769  * @tc.desc: set deviceId null
770  * @tc.type: FUNC
771  */
772 HWTEST_F(SoftbusConnectorTest, JoinLnn_001, testing::ext::TestSize.Level0)
773 {
774     std::string deviceId;
775     softbusConnector->JoinLnn(deviceId);
776     EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
777 }
778 
779 /**
780  * @tc.name: ConvertDeviceInfoToDmDevice_002
781  * @tc.desc: set deviceInfo not null
782  * @tc.type: FUNC
783  */
784 HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_002, testing::ext::TestSize.Level0)
785 {
786     DeviceInfo deviceInfo = {
787         .devId = "123456",
788         .devType = (DeviceType)1,
789         .devName = "11111"
790     };
791     DmDeviceBasicInfo dmDeviceBasicInfo;
792     softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dmDeviceBasicInfo);
793     EXPECT_EQ(dmDeviceBasicInfo.deviceTypeId, deviceInfo.devType);
794 }
795 
796 /**
797  * @tc.name: OnSoftbusDeviceDiscovery_001
798  * @tc.desc: set device null
799  * @tc.type: FUNC
800  */
801 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_001, testing::ext::TestSize.Level0)
802 {
803     DeviceInfo *device = nullptr;
804     softbusConnector->OnSoftbusDeviceDiscovery(device);
805     EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
806 }
807 
808 /**
809  * @tc.name: OnSoftbusDeviceDiscovery_002
810  * @tc.desc: set device not null
811  * @tc.type: FUNC
812  */
813 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_002, testing::ext::TestSize.Level0)
814 {
815     DeviceInfo device = {
816         .devId = "123456",
817         .devType = (DeviceType)1,
818         .devName = "11111"
819     };
820     softbusConnector->OnSoftbusDeviceDiscovery(&device);
821     EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
822 }
823 
824 /**
825  * @tc.name: GetDeviceUdidByUdidHash_001
826  * @tc.desc: set udidHash null
827  * @tc.type: FUNC
828  */
829 HWTEST_F(SoftbusConnectorTest, GetDeviceUdidByUdidHash_001, testing::ext::TestSize.Level0)
830 {
831     std::string udidHash;
832     std::string str = softbusConnector->GetDeviceUdidByUdidHash(udidHash);
833     EXPECT_EQ(str.empty(), true);
834 }
835 } // namespace
836 } // namespace DistributedHardware
837 } // namespace OHOS-