1 /*
2 * Copyright (c) 2022-2024 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 "parameter.h"
33 #include "system_ability_definition.h"
34 #include "softbus_error_code.h"
35
36 namespace OHOS {
37 namespace DistributedHardware {
38
39 class SoftbusStateCallbackTest : public ISoftbusStateCallback {
40 public:
SoftbusStateCallbackTest()41 SoftbusStateCallbackTest() {}
~SoftbusStateCallbackTest()42 virtual ~SoftbusStateCallbackTest() {}
OnDeviceOnline(std::string deviceId, int32_t authForm)43 void OnDeviceOnline(std::string deviceId, int32_t authForm) {}
OnDeviceOffline(std::string deviceId)44 void OnDeviceOffline(std::string deviceId) {}
45 void DeleteOffLineTimer(std::string udidHash) override {}
46 };
47
48 class SoftbusDiscoveryCallbackTest : public ISoftbusDiscoveryCallback {
49 public:
SoftbusDiscoveryCallbackTest()50 SoftbusDiscoveryCallbackTest() {}
~SoftbusDiscoveryCallbackTest()51 virtual ~SoftbusDiscoveryCallbackTest() {}
52 void OnDeviceFound(const std::string &pkgName, DmDeviceInfo &info, bool isOnline) override
53 {
54 (void)pkgName;
55 (void)info;
56 (void)isOnline;
57 }
58 void OnDeviceFound(const std::string &pkgName, DmDeviceBasicInfo &info, const int32_t range, bool isOnline) override
59 {
60 (void)pkgName;
61 (void)info;
62 (void)range;
63 (void)isOnline;
64 }
65 void OnDiscoverySuccess(const std::string &pkgName, int32_t subscribeId) override
66 {
67 (void)pkgName;
68 (void)subscribeId;
69 }
70 void OnDiscoveryFailed(const std::string &pkgName, int32_t subscribeId, int32_t failedReason) override
71 {
72 (void)pkgName;
73 (void)subscribeId;
74 (void)failedReason;
75 }
76 };
77
78 class SoftbusPublishCallbackTest : public ISoftbusPublishCallback {
79 public:
SoftbusPublishCallbackTest()80 SoftbusPublishCallbackTest() {}
~SoftbusPublishCallbackTest()81 virtual ~SoftbusPublishCallbackTest() {}
82 void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult) override
83 {
84 (void)pkgName;
85 (void)publishId;
86 (void)publishResult;
87 }
88 };
89
SetUp()90 void SoftbusConnectorTest::SetUp()
91 {
92 }
TearDown()93 void SoftbusConnectorTest::TearDown()
94 {
95 }
SetUpTestCase()96 void SoftbusConnectorTest::SetUpTestCase()
97 {
98 }
TearDownTestCase()99 void SoftbusConnectorTest::TearDownTestCase()
100 {
101 }
102
CheckReturnResult(int ret)103 bool SoftbusConnectorTest::CheckReturnResult(int ret)
104 {
105 return ret == SOFTBUS_IPC_ERR || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR;
106 }
107
108 namespace {
109 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
110
111 /**
112 * @tc.name: SoftbusConnector_001
113 * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr
114 * @tc.type: FUNC
115 * @tc.require: AR000GHSJK
116 */
HWTEST_F(SoftbusConnectorTest, SoftbusConnector_001, testing::ext::TestSize.Level0)117 HWTEST_F(SoftbusConnectorTest, SoftbusConnector_001, testing::ext::TestSize.Level0)
118 {
119 std::shared_ptr<SoftbusConnector> m_SoftbusConnector = std::make_shared<SoftbusConnector>();
120 ASSERT_NE(m_SoftbusConnector, nullptr);
121 }
122
123 /**
124 * @tc.name: SoftbusConnector_002
125 * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
126 * @tc.type: FUNC
127 * @tc.require: AR000GHSJK
128 */
HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Level0)129 HWTEST_F(SoftbusConnectorTest, SoftbusConnector_002, testing::ext::TestSize.Level0)
130 {
131 std::shared_ptr<SoftbusConnector> m_SoftbusConnector = std::make_shared<SoftbusConnector>();
132 m_SoftbusConnector.reset();
133 EXPECT_EQ(m_SoftbusConnector, nullptr);
134 }
135
136 /**
137 * @tc.name: RegisterSoftbusDiscoveryCallback_001
138 * @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusDiscoveryCallback function to corrort, return DM_OK
139 * @tc.type: FUNC
140 * @tc.require: AR000GHSJK
141 */
HWTEST_F(SoftbusConnectorTest, RegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)142 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)
143 {
144 std::string pkgName = "com.ohos.helloworld";
145 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
146 int ret1 = softbusConnector->RegisterSoftbusDiscoveryCallback(
147 pkgName, std::make_shared<SoftbusDiscoveryCallbackTest>());
148 int ret = SoftbusConnector::discoveryCallbackMap_.count(pkgName);
149 EXPECT_EQ(ret1, DM_OK);
150 EXPECT_EQ(ret, 1);
151 }
152
153 /**
154 * @tc.name: UnRegisterSoftbusDiscoveryCallback_001
155 * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusDiscoveryCallback function to corrort, return
156 * DM_OK
157 * @tc.type: FUNC
158 * @tc.require: AR000GHSJK
159 */
HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)160 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusDiscoveryCallback_001, testing::ext::TestSize.Level0)
161 {
162 std::string pkgName = "com.ohos.helloworld";
163 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
164 int ret = softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
165 int ret1 = SoftbusConnector::discoveryCallbackMap_.count(pkgName);
166 EXPECT_EQ(ret1, 0);
167 EXPECT_EQ(ret, DM_OK);
168 }
169
170 /**
171 * @tc.name: RegisterSoftbusPublishCallback_001
172 * @tc.desc: set pkgName = "com.ohos.helloworld";call RegisterSoftbusPublishCallback function to corrort, return DM_OK
173 * @tc.type: FUNC
174 * @tc.require: I5N1K3
175 */
HWTEST_F(SoftbusConnectorTest, RegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)176 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)
177 {
178 std::string pkgName = "com.ohos.helloworld";
179 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
180 int ret1 = softbusConnector->RegisterSoftbusPublishCallback(
181 pkgName, std::make_shared<SoftbusPublishCallbackTest>());
182 int ret = SoftbusConnector::publishCallbackMap_.count(pkgName);
183 EXPECT_EQ(ret1, DM_OK);
184 EXPECT_EQ(ret, 1);
185 }
186
187 /**
188 * @tc.name: UnRegisterSoftbusPublishCallback_001
189 * @tc.desc: set pkgName = "com.ohos.helloworld";call UnRegisterSoftbusPublishyCallback function to corrort, return
190 * DM_OK
191 * @tc.type: FUNC
192 * @tc.require: I5N1K3
193 */
HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)194 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusPublishCallback_001, testing::ext::TestSize.Level0)
195 {
196 std::string pkgName = "com.ohos.helloworld";
197 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
198 int ret = softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
199 int ret1 = SoftbusConnector::publishCallbackMap_.count(pkgName);
200 EXPECT_EQ(ret1, 0);
201 EXPECT_EQ(ret, DM_OK);
202 }
203
204 /**
205 * @tc.name: StartDiscovery_001
206 * @tc.desc: get StartDiscovery to wrong branch and return SOFTBUS_INVALID_PARAM
207 * @tc.type: FUNC
208 * @tc.require: AR000GHSJK
209 */
HWTEST_F(SoftbusConnectorTest, StartDiscovery_001, testing::ext::TestSize.Level0)210 HWTEST_F(SoftbusConnectorTest, StartDiscovery_001, testing::ext::TestSize.Level0)
211 {
212 DmSubscribeInfo dmSubscribeInfo;
213 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
214 int ret = softbusConnector->StartDiscovery(dmSubscribeInfo);
215 EXPECT_TRUE(CheckReturnResult(ret));
216 }
217 /**
218 * @tc.name: StartDiscovery_002
219 * @tc.desc: get StartDiscovery to wrong branch and return SOFTBUS_IPC_ERR
220 * @tc.type: FUNC
221 * @tc.require: AR000GHSJK
222 */
HWTEST_F(SoftbusConnectorTest, StartDiscovery_002, testing::ext::TestSize.Level0)223 HWTEST_F(SoftbusConnectorTest, StartDiscovery_002, testing::ext::TestSize.Level0)
224 {
225 uint16_t subscribeId = 0;
226 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
227 int ret = softbusConnector->StartDiscovery(subscribeId);
228 EXPECT_TRUE(CheckReturnResult(ret));
229 }
230
231 /**
232 * @tc.name: StopDiscovery_001
233 * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
234 * @tc.type: FUNC
235 * @tc.require: AR000GHSJK
236 */
HWTEST_F(SoftbusConnectorTest, StopDiscovery_001, testing::ext::TestSize.Level0)237 HWTEST_F(SoftbusConnectorTest, StopDiscovery_001, testing::ext::TestSize.Level0)
238 {
239 uint16_t subscribeId = static_cast<uint16_t>(123456);
240 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
241 int ret = softbusConnector->StopDiscovery(subscribeId);
242 EXPECT_NE(ret, 0);
243 }
244
245 /**
246 * @tc.name: PublishDiscovery_001
247 * @tc.desc: get PublishDiscovery to wrong branch and return SOFTBUS_INVALID_PARAM
248 * @tc.type: FUNC
249 * @tc.require: I5N1K3
250 */
HWTEST_F(SoftbusConnectorTest, PublishDiscovery_001, testing::ext::TestSize.Level0)251 HWTEST_F(SoftbusConnectorTest, PublishDiscovery_001, testing::ext::TestSize.Level0)
252 {
253 DmPublishInfo dmPublishInfo;
254 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
255 int ret = softbusConnector->PublishDiscovery(dmPublishInfo);
256 EXPECT_TRUE(CheckReturnResult(ret));
257 }
258
259 /**
260 * @tc.name: UnPublishDiscovery_001
261 * @tc.desc: get UnPublishDiscovery to wrong branch and return ERR_DM_PUBLISH_FAILED
262 * @tc.type: FUNC
263 * @tc.require: I5N1K3
264 */
HWTEST_F(SoftbusConnectorTest, UnPublishDiscovery_001, testing::ext::TestSize.Level0)265 HWTEST_F(SoftbusConnectorTest, UnPublishDiscovery_001, testing::ext::TestSize.Level0)
266 {
267 int32_t publishId = 123456;
268 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
269 int ret = softbusConnector->UnPublishDiscovery(publishId);
270 EXPECT_NE(ret, 0);
271 }
272
273 /**
274 * @tc.name: GetUdidByNetworkId_001
275 * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
276 * @tc.type: FUNC
277 * @tc.require: AR000GHSJK
278 */
HWTEST_F(SoftbusConnectorTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0)279 HWTEST_F(SoftbusConnectorTest, GetUdidByNetworkId_001, testing::ext::TestSize.Level0)
280 {
281 const char *networkId = "123456";
282 std::string udid;
283 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
284 int ret = softbusConnector->GetUdidByNetworkId(networkId, udid);
285 EXPECT_NE(ret, 0);
286 }
287
288 /**
289 * @tc.name: GetUuidByNetworkId_001
290 * @tc.desc: get StartDiscovery to wrong branch and return ERR_DM_DISCOVERY_FAILED
291 * @tc.type: FUNC
292 * @tc.require: AR000GHSJK
293 */
HWTEST_F(SoftbusConnectorTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0)294 HWTEST_F(SoftbusConnectorTest, GetUuidByNetworkId_001, testing::ext::TestSize.Level0)
295 {
296 const char *networkId = "123456";
297 std::string uuid;
298 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
299 int ret = softbusConnector->GetUuidByNetworkId(networkId, uuid);
300 EXPECT_NE(ret, 0);
301 }
302
303 /**
304 * @tc.name: GetSoftbusSession_001
305 * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
306 * @tc.type: FUNC
307 * @tc.require: AR000GHSJK
308 */
HWTEST_F(SoftbusConnectorTest, GetSoftbusSession_001, testing::ext::TestSize.Level0)309 HWTEST_F(SoftbusConnectorTest, GetSoftbusSession_001, testing::ext::TestSize.Level0)
310 {
311 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
312 std::shared_ptr<SoftbusSession> softSession = softbusConnector->GetSoftbusSession();
313 EXPECT_NE(softSession, nullptr);
314 }
315
316 /**
317 * @tc.name: GetSoftbusSession_001
318 * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
319 * @tc.type: FUNC
320 * @tc.require: AR000GHSJK
321 */
HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_001, testing::ext::TestSize.Level0)322 HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_001, testing::ext::TestSize.Level0)
323 {
324 std::string deviceId = "12345678";
325 SoftbusConnector::discoveryDeviceInfoMap_[deviceId];
326 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
327 bool ret = softbusConnector->HaveDeviceInMap(deviceId);
328 EXPECT_EQ(ret, true);
329 SoftbusConnector::discoveryDeviceInfoMap_.clear();
330 }
331
332 /**
333 * @tc.name: GetSoftbusSession_001
334 * @tc.desc: set SoftbusConnector to new a pointer, and the pointer nou equal nullptr, and delete it
335 * @tc.type: FUNC
336 * @tc.require: AR000GHSJK
337 */
HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_002, testing::ext::TestSize.Level0)338 HWTEST_F(SoftbusConnectorTest, HaveDeviceInMap_002, testing::ext::TestSize.Level0)
339 {
340 std::string deviceId = "12345678";
341 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
342 bool ret = softbusConnector->HaveDeviceInMap(deviceId);
343 EXPECT_EQ(ret, false);
344 SoftbusConnector::discoveryDeviceInfoMap_.clear();
345 }
346
347 /**
348 * @tc.name: GetConnectAddrByType_001
349 * @tc.desc: set deviceInfo'pointer null, go to first branch, and return nullptr
350 * @tc.require: AR000GHSJK
351 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_001, testing::ext::TestSize.Level0)352 HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_001, testing::ext::TestSize.Level0)
353 {
354 ConnectionAddrType type;
355 type = CONNECTION_ADDR_MAX;
356 ConnectionAddr *p = nullptr;
357 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
358 ConnectionAddr *ret = softbusConnector->GetConnectAddrByType(nullptr, type);
359 EXPECT_EQ(p, ret);
360 }
361
362 /**
363 * @tc.name: GetConnectAddrByType_002
364 * @tc.desc:set deviceInfo to some corrort para, and return nullptr
365 * @tc.type: FUNC
366 * @tc.require: AR000GHSJK
367 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_002, testing::ext::TestSize.Level0)368 HWTEST_F(SoftbusConnectorTest, GetConnectAddrByType_002, testing::ext::TestSize.Level0)
369 {
370 DeviceInfo deviceInfo;
371 deviceInfo.addrNum = 1;
372 ConnectionAddrType type;
373 type = CONNECTION_ADDR_BR;
374 ConnectionAddr *p = nullptr;
375 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
376 ConnectionAddr *ret = softbusConnector->GetConnectAddrByType(&deviceInfo, type);
377 EXPECT_EQ(ret, p);
378 }
379
380 /**
381 * @tc.name: GetConnectAddr_001
382 * @tc.desc: set deviceId to null, and return nullptr
383 * @tc.type: FUNC
384 * @tc.require: AR000GHSJK
385 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_001, testing::ext::TestSize.Level0)386 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_001, testing::ext::TestSize.Level0)
387 {
388 std::string deviceId;
389 std::string connectAddr;
390 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
391 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
392 EXPECT_EQ(ret, nullptr);
393 }
394
395 /**
396 * @tc.name: GetConnectAddr_002
397 * @tc.desc:set deviceId nit null set deviceInfo.addrNum = -1; and return nullptr
398 * @tc.type: FUNC
399 * @tc.require: AR000GHSJK
400 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_002, testing::ext::TestSize.Level0)401 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_002, testing::ext::TestSize.Level0)
402 {
403 std::string deviceId = "123345";
404 std::string connectAddr;
405 DeviceInfo deviceInfo;
406 deviceInfo.addrNum = -1;
407 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
408 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
409 EXPECT_EQ(ret, nullptr);
410 }
411
412 /**
413 * @tc.name: GetConnectAddr_003
414 * @tc.desc:set deviceInfo.addrNum = 1
415 * @tc.type: FUNC
416 * @tc.require: AR000GHSJK
417 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_003, testing::ext::TestSize.Level0)418 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_003, testing::ext::TestSize.Level0)
419 {
420 std::string deviceId = "123345";
421 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
422 std::string connectAddr;
423 constexpr char ethIp[] = "0.0.0.0";
424 deviceInfo->addrNum = 1;
425 deviceInfo->addr[0].type = CONNECTION_ADDR_ETH;
426 (void)strncpy_s(deviceInfo->addr[0].info.ip.ip, IP_STR_MAX_LEN, ethIp, strlen(ethIp));
427 deviceInfo->addr[0].info.ip.port = 0;
428 SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
429 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
430 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
431 EXPECT_NE(ret, nullptr);
432 SoftbusConnector::discoveryDeviceInfoMap_.clear();
433 }
434
435 /**
436 * @tc.name: GetConnectAddr_004
437 * @tc.desc:set deviceInfo.addrNum = 1
438 * @tc.type: FUNC
439 * @tc.require: AR000GHSJK
440 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_004, testing::ext::TestSize.Level0)441 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_004, testing::ext::TestSize.Level0)
442 {
443 std::string deviceId = "123345";
444 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
445 std::string connectAddr;
446 constexpr char wlanIp[] = "1.1.1.1";
447 deviceInfo->addrNum = 1;
448 deviceInfo->addr[0].type = CONNECTION_ADDR_WLAN;
449 (void)strncpy_s(deviceInfo->addr[0].info.ip.ip, IP_STR_MAX_LEN, wlanIp, strlen(wlanIp));
450 deviceInfo->addr[0].info.ip.port = 0;
451 SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
452 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
453 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
454 EXPECT_NE(ret, nullptr);
455 SoftbusConnector::discoveryDeviceInfoMap_.clear();
456 }
457
458 /**
459 * @tc.name: GetConnectAddr_005
460 * @tc.desc:get brMac addr
461 * @tc.type: FUNC
462 * @tc.require: AR000GHSJK
463 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_005, testing::ext::TestSize.Level0)464 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_005, testing::ext::TestSize.Level0)
465 {
466 std::string deviceId = "123345";
467 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
468 std::string connectAddr;
469 deviceInfo->addrNum = 1;
470 constexpr char brMac[] = "2:2:2:2";
471 deviceInfo->addr[0].type = CONNECTION_ADDR_BR;
472 (void)strncpy_s(deviceInfo->addr[0].info.br.brMac, IP_STR_MAX_LEN, brMac, strlen(brMac));
473 SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
474 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
475 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
476 EXPECT_NE(ret, nullptr);
477 SoftbusConnector::discoveryDeviceInfoMap_.clear();
478 }
479
480 /**
481 * @tc.name: GetConnectAddr_006
482 * @tc.desc:get bleMac addr
483 * @tc.type: FUNC
484 * @tc.require: AR000GHSJK
485 */
HWTEST_F(SoftbusConnectorTest, GetConnectAddr_006, testing::ext::TestSize.Level0)486 HWTEST_F(SoftbusConnectorTest, GetConnectAddr_006, testing::ext::TestSize.Level0)
487 {
488 std::string deviceId = "123345";
489 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
490 std::string connectAddr;
491 constexpr char bleMac[] = "3:3:3:3";
492 deviceInfo->addrNum = 1;
493 deviceInfo->addr[0].type = CONNECTION_ADDR_BLE;
494 (void)strncpy_s(deviceInfo->addr[0].info.ble.bleMac, IP_STR_MAX_LEN, bleMac, strlen(bleMac));
495 SoftbusConnector::discoveryDeviceInfoMap_[deviceId] = deviceInfo;
496 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
497 ConnectionAddr *ret = softbusConnector->GetConnectAddr(deviceId, connectAddr);
498 EXPECT_NE(ret, nullptr);
499 SoftbusConnector::discoveryDeviceInfoMap_.clear();
500 }
501
502 /**
503 * @tc.name: ConvertNodeBasicInfoToDmDevice_001
504 * @tc.desc: go to the correct case and return DM_OK
505 * @tc.type: FUNC
506 * @tc.require: AR000GHSJK
507 */
HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_001, testing::ext::TestSize.Level0)508 HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_001, testing::ext::TestSize.Level0)
509 {
510 DeviceInfo deviceInfo = {
511 .devId = "123456",
512 .devType = (DeviceType)1,
513 .devName = "11111"
514 };
515 DmDeviceInfo dm;
516 DmDeviceInfo dm_1 = {
517 .deviceId = "123456",
518 .deviceName = "11111",
519 .deviceTypeId = 1
520 };
521 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
522 softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dm);
523 bool ret = false;
524 if (strcmp(dm.deviceId, dm_1.deviceId) == 0) {
525 ret = true;
526 }
527 EXPECT_EQ(ret, true);
528 }
529
530 /**
531 * @tc.name: OnSoftbusDeviceFound_001
532 * @tc.desc: go to the correct case and return DM_OK
533 * @tc.type: FUNC
534 * @tc.require: AR000GHSJK
535 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_001, testing::ext::TestSize.Level0)536 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_001, testing::ext::TestSize.Level0)
537 {
538 DeviceInfo *device = nullptr;
539 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
540 softbusConnector->OnSoftbusDeviceFound(device);
541 bool ret = false;
542 if (listener->ipcServerListener_.req_ != nullptr) {
543 listener->ipcServerListener_.req_ = nullptr;
544 ret = true;
545 }
546 EXPECT_EQ(ret, false);
547 }
548
549 /**
550 * @tc.name: OnSoftbusDeviceFound_002
551 * @tc.desc: go to the correct case and return DM_OK
552 * @tc.type: FUNC
553 * @tc.require: AR000GHSJK
554 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_002, testing::ext::TestSize.Level0)555 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceFound_002, testing::ext::TestSize.Level0)
556 {
557 DeviceInfo device = {
558 .devId = "123456",
559 .devType = (DeviceType)1,
560 .devName = "com.ohos.helloworld"
561 };
562 std::string pkgName = "com.ohos.helloworld";
563 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
564 softbusConnector->RegisterSoftbusDiscoveryCallback(pkgName, std::make_shared<SoftbusDiscoveryCallbackTest>());
565 softbusConnector->OnSoftbusDeviceFound(&device);
566 bool ret = false;
567 if (listener->ipcServerListener_.req_ != nullptr) {
568 listener->ipcServerListener_.req_ = nullptr;
569 ret = true;
570 }
571 EXPECT_EQ(ret, false);
572 }
573
574 /**
575 * @tc.name: OnSoftbusDiscoveryResult_001
576 * @tc.desc: go to the correct case and return DM_OK
577 * @tc.type: FUNC
578 * @tc.require: AR000GHSJK
579 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_001, testing::ext::TestSize.Level0)580 HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_001, testing::ext::TestSize.Level0)
581 {
582 int32_t subscribeId = 123456;
583 RefreshResult result = (RefreshResult)1;
584 std::string pkgName = "com.ohos.helloworld";
585 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
586 softbusConnector->RegisterSoftbusDiscoveryCallback(
587 pkgName, std::make_shared<SoftbusDiscoveryCallbackTest>());
588 softbusConnector->OnSoftbusDiscoveryResult(subscribeId, result);
589 bool ret = false;
590 if (listener->ipcServerListener_.req_ != nullptr) {
591 listener->ipcServerListener_.req_ = nullptr;
592 ret = true;
593 }
594 EXPECT_EQ(ret, false);
595 softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
596 }
597
598 /**
599 * @tc.name: OnSoftbusDiscoveryResult_001
600 * @tc.desc: go to the correct case and return DM_OK
601 * @tc.type: FUNC
602 * @tc.require: AR000GHSJK
603 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_002, testing::ext::TestSize.Level0)604 HWTEST_F(SoftbusConnectorTest, OnSoftbusDiscoveryResult_002, testing::ext::TestSize.Level0)
605 {
606 int32_t subscribeId = 123456;
607 RefreshResult result = (RefreshResult)0;
608 std::string pkgName = "com.ohos.helloworld";
609 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
610 softbusConnector->RegisterSoftbusDiscoveryCallback(
611 pkgName, std::make_shared<SoftbusDiscoveryCallbackTest>());
612 softbusConnector->OnSoftbusDiscoveryResult(subscribeId, result);
613 bool ret = false;
614 if (listener->ipcServerListener_.req_ != nullptr) {
615 listener->ipcServerListener_.req_ = nullptr;
616 ret = true;
617 }
618 EXPECT_EQ(ret, false);
619 softbusConnector->UnRegisterSoftbusDiscoveryCallback(pkgName);
620 }
621
622 /**
623 * @tc.name: OnSoftbusPublishResult_001
624 * @tc.desc: go to the correct case and return DM_OK
625 * @tc.type: FUNC
626 * @tc.require: I5N1K3
627 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_001, testing::ext::TestSize.Level0)628 HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_001, testing::ext::TestSize.Level0)
629 {
630 int32_t publishId = 123456;
631 PublishResult failReason = (PublishResult)1;
632 std::string pkgName = "com.ohos.helloworld";
633 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
634 softbusConnector->RegisterSoftbusPublishCallback(
635 pkgName, std::make_shared<SoftbusPublishCallbackTest>());
636 softbusConnector->OnSoftbusPublishResult(publishId, failReason);
637 bool ret = false;
638 if (listener->ipcServerListener_.req_ != nullptr) {
639 listener->ipcServerListener_.req_ = nullptr;
640 ret = true;
641 }
642 EXPECT_EQ(ret, false);
643 softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
644 }
645
646 /**
647 * @tc.name: OnSoftbusPublishResult_004
648 * @tc.desc: go to the correct case and return DM_OK
649 * @tc.type: FUNC
650 * @tc.require: I5N1K3
651 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_002, testing::ext::TestSize.Level0)652 HWTEST_F(SoftbusConnectorTest, OnSoftbusPublishResult_002, testing::ext::TestSize.Level0)
653 {
654 int32_t publishId = 123456;
655 std::string pkgName = "com.ohos.helloworld";
656 PublishResult failReason = (PublishResult)0;
657 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
658 softbusConnector->RegisterSoftbusPublishCallback(
659 pkgName, std::make_shared<SoftbusPublishCallbackTest>());
660 softbusConnector->OnSoftbusPublishResult(publishId, failReason);
661 bool ret = false;
662 if (listener->ipcServerListener_.req_ != nullptr) {
663 listener->ipcServerListener_.req_ = nullptr;
664 ret = true;
665 }
666 EXPECT_EQ(ret, false);
667 softbusConnector->UnRegisterSoftbusPublishCallback(pkgName);
668 }
669
670 /**
671 * @tc.name: JoinLnn_001
672 * @tc.desc: set deviceId null
673 * @tc.type: FUNC
674 */
HWTEST_F(SoftbusConnectorTest, JoinLnn_001, testing::ext::TestSize.Level0)675 HWTEST_F(SoftbusConnectorTest, JoinLnn_001, testing::ext::TestSize.Level0)
676 {
677 std::string deviceId;
678 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
679 softbusConnector->JoinLnn(deviceId);
680 EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
681 }
682
683 /**
684 * @tc.name: ConvertDeviceInfoToDmDevice_002
685 * @tc.desc: set deviceInfo not null
686 * @tc.type: FUNC
687 */
HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_002, testing::ext::TestSize.Level0)688 HWTEST_F(SoftbusConnectorTest, ConvertDeviceInfoToDmDevice_002, testing::ext::TestSize.Level0)
689 {
690 DeviceInfo deviceInfo = {
691 .devId = "123456",
692 .devType = (DeviceType)1,
693 .devName = "11111"
694 };
695 DmDeviceBasicInfo dmDeviceBasicInfo;
696 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
697 softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dmDeviceBasicInfo);
698 EXPECT_EQ(dmDeviceBasicInfo.deviceTypeId, deviceInfo.devType);
699 }
700
701 /**
702 * @tc.name: OnSoftbusDeviceDiscovery_001
703 * @tc.desc: set device null
704 * @tc.type: FUNC
705 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_001, testing::ext::TestSize.Level0)706 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_001, testing::ext::TestSize.Level0)
707 {
708 DeviceInfo *device = nullptr;
709 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
710 softbusConnector->OnSoftbusDeviceDiscovery(device);
711 EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
712 }
713
714 /**
715 * @tc.name: OnSoftbusDeviceDiscovery_002
716 * @tc.desc: set device not null
717 * @tc.type: FUNC
718 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_002, testing::ext::TestSize.Level0)719 HWTEST_F(SoftbusConnectorTest, OnSoftbusDeviceDiscovery_002, testing::ext::TestSize.Level0)
720 {
721 DeviceInfo device = {
722 .devId = "123456",
723 .devType = (DeviceType)1,
724 .devName = "11111"
725 };
726 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
727 softbusConnector->OnSoftbusDeviceDiscovery(&device);
728 EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
729 }
730
731 /**
732 * @tc.name: GetDeviceUdidByUdidHash_001
733 * @tc.desc: set udidHash null
734 * @tc.type: FUNC
735 */
HWTEST_F(SoftbusConnectorTest, GetDeviceUdidByUdidHash_001, testing::ext::TestSize.Level0)736 HWTEST_F(SoftbusConnectorTest, GetDeviceUdidByUdidHash_001, testing::ext::TestSize.Level0)
737 {
738 std::string udidHash;
739 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
740 std::string str = softbusConnector->GetDeviceUdidByUdidHash(udidHash);
741 EXPECT_EQ(str.empty(), true);
742 }
743
744 /**
745 * @tc.name: RegisterSoftbusStateCallback_001
746 * @tc.desc: set callback null
747 * @tc.type: FUNC
748 */
HWTEST_F(SoftbusConnectorTest, RegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)749 HWTEST_F(SoftbusConnectorTest, RegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)
750 {
751 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
752 std::shared_ptr<ISoftbusStateCallback> callback = std::make_shared<SoftbusStateCallbackTest>();
753 int32_t ret = softbusConnector->RegisterSoftbusStateCallback(callback);
754 EXPECT_EQ(ret, DM_OK);
755 }
756
757 /**
758 * @tc.name: UnRegisterSoftbusStateCallback_001
759 * @tc.type: FUNC
760 */
HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)761 HWTEST_F(SoftbusConnectorTest, UnRegisterSoftbusStateCallback_001, testing::ext::TestSize.Level0)
762 {
763 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
764 int32_t ret = softbusConnector->UnRegisterSoftbusStateCallback();
765 EXPECT_EQ(ret, DM_OK);
766 }
767
768 /**
769 * @tc.name: OnSoftbusJoinLNNResult_001
770 * @tc.desc: set addr null
771 * @tc.desc: set networkId null
772 * @tc.desc: set result 0
773 * @tc.type: FUNC
774 */
HWTEST_F(SoftbusConnectorTest, OnSoftbusJoinLNNResult_001, testing::ext::TestSize.Level0)775 HWTEST_F(SoftbusConnectorTest, OnSoftbusJoinLNNResult_001, testing::ext::TestSize.Level0)
776 {
777 ConnectionAddr *addr = nullptr;
778 char *networkId = nullptr;
779 int32_t result = 0;
780 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
781 softbusConnector->OnSoftbusJoinLNNResult(addr, networkId, result);
782 EXPECT_EQ(SoftbusConnector::discoveryDeviceInfoMap_.empty(), false);
783 }
784
785 /**
786 * @tc.name: AddMemberToDiscoverMap_001
787 * @tc.type: FUNC
788 */
HWTEST_F(SoftbusConnectorTest, AddMemberToDiscoverMap_001, testing::ext::TestSize.Level0)789 HWTEST_F(SoftbusConnectorTest, AddMemberToDiscoverMap_001, testing::ext::TestSize.Level0)
790 {
791 std::string deviceId;
792 std::shared_ptr<DeviceInfo> deviceInfo = nullptr;
793 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
794 int32_t ret = softbusConnector->AddMemberToDiscoverMap(deviceId, deviceInfo);
795 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
796 }
797
798 /**
799 * @tc.name: AddMemberToDiscoverMap_002
800 * @tc.type: FUNC
801 */
HWTEST_F(SoftbusConnectorTest, AddMemberToDiscoverMap_002, testing::ext::TestSize.Level0)802 HWTEST_F(SoftbusConnectorTest, AddMemberToDiscoverMap_002, testing::ext::TestSize.Level0)
803 {
804 std::string deviceId = "deviceId";
805 std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
806 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
807 int32_t ret = softbusConnector->AddMemberToDiscoverMap(deviceId, deviceInfo);
808 EXPECT_EQ(ret, DM_OK);
809 }
810
811 /**
812 * @tc.name: SetPkgName_001
813 * @tc.type: FUNC
814 */
HWTEST_F(SoftbusConnectorTest, SetPkgName_001, testing::ext::TestSize.Level0)815 HWTEST_F(SoftbusConnectorTest, SetPkgName_001, testing::ext::TestSize.Level0)
816 {
817 std::string pkgName = "pkgName";
818 std::vector<std::string> pkgNameVec;
819 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
820 softbusConnector->SetPkgNameVec(pkgNameVec);
821 softbusConnector->SetPkgName(pkgName);
822 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), false);
823 }
824
825 /**
826 * @tc.name: GetDeviceUdidHashByUdid_001
827 * @tc.type: FUNC
828 */
HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_001, testing::ext::TestSize.Level0)829 HWTEST_F(SoftbusConnectorTest, GetDeviceUdidHashByUdid_001, testing::ext::TestSize.Level0)
830 {
831 std::string udid = "123456789";
832 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
833 std::string ret = softbusConnector->GetDeviceUdidHashByUdid(udid);
834 EXPECT_EQ(ret.empty(), false);
835 }
836
837 /**
838 * @tc.name: EraseUdidFromMap_001
839 * @tc.type: FUNC
840 */
HWTEST_F(SoftbusConnectorTest, EraseUdidFromMap_001, testing::ext::TestSize.Level0)841 HWTEST_F(SoftbusConnectorTest, EraseUdidFromMap_001, testing::ext::TestSize.Level0)
842 {
843 std::string udid = "123456789";
844 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
845 softbusConnector->EraseUdidFromMap(udid);
846 EXPECT_EQ(softbusConnector->deviceUdidMap_.empty(), false);
847 }
848
849 /**
850 * @tc.name: GetLocalDeviceName_001
851 * @tc.type: FUNC
852 */
HWTEST_F(SoftbusConnectorTest, GetLocalDeviceName_001, testing::ext::TestSize.Level0)853 HWTEST_F(SoftbusConnectorTest, GetLocalDeviceName_001, testing::ext::TestSize.Level0)
854 {
855 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
856 std::string ret = softbusConnector->GetLocalDeviceName();
857 EXPECT_EQ(ret.empty(), true);
858 }
859
860 /**
861 * @tc.name: GetNetworkIdByDeviceId_001
862 * @tc.type: FUNC
863 */
HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSize.Level0)864 HWTEST_F(SoftbusConnectorTest, GetNetworkIdByDeviceId_001, testing::ext::TestSize.Level0)
865 {
866 std::string deviceId = "deviceId";
867 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
868 std::string ret = softbusConnector->GetNetworkIdByDeviceId(deviceId);
869 EXPECT_EQ(ret.empty(), true);
870 }
871
872 /**
873 * @tc.name: SetPkgNameVec_001
874 * @tc.type: FUNC
875 */
HWTEST_F(SoftbusConnectorTest, SetPkgNameVec_001, testing::ext::TestSize.Level0)876 HWTEST_F(SoftbusConnectorTest, SetPkgNameVec_001, testing::ext::TestSize.Level0)
877 {
878 std::vector<std::string> pkgNameVec;
879 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
880 softbusConnector->SetPkgNameVec(pkgNameVec);
881 EXPECT_EQ(pkgNameVec.empty(), true);
882 }
883
884 /**
885 * @tc.name: GetPkgName_001
886 * @tc.type: FUNC
887 */
HWTEST_F(SoftbusConnectorTest, GetPkgName_001, testing::ext::TestSize.Level0)888 HWTEST_F(SoftbusConnectorTest, GetPkgName_001, testing::ext::TestSize.Level0)
889 {
890 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
891 auto ret = softbusConnector->GetPkgName();
892 EXPECT_EQ(ret.empty(), true);
893 }
894
895 /**
896 * @tc.name: ClearPkgName_001
897 * @tc.type: FUNC
898 */
HWTEST_F(SoftbusConnectorTest, ClearPkgName_001, testing::ext::TestSize.Level0)899 HWTEST_F(SoftbusConnectorTest, ClearPkgName_001, testing::ext::TestSize.Level0)
900 {
901 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
902 softbusConnector->ClearPkgName();
903 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), true);
904 }
905
906 /**
907 * @tc.name: HandleDeviceOnline_001
908 * @tc.type: FUNC
909 */
HWTEST_F(SoftbusConnectorTest, HandleDeviceOnline_001, testing::ext::TestSize.Level0)910 HWTEST_F(SoftbusConnectorTest, HandleDeviceOnline_001, testing::ext::TestSize.Level0)
911 {
912 std::string deviceId = "deviceId";
913 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
914 std::shared_ptr<ISoftbusStateCallback> callback = std::make_shared<SoftbusStateCallbackTest>();
915 softbusConnector->RegisterSoftbusStateCallback(callback);
916 softbusConnector->HandleDeviceOnline(deviceId, DmAuthForm::ACROSS_ACCOUNT);
917 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), true);
918 }
919
920 /**
921 * @tc.name: HandleDeviceOffline_001
922 * @tc.type: FUNC
923 */
HWTEST_F(SoftbusConnectorTest, HandleDeviceOffline_001, testing::ext::TestSize.Level0)924 HWTEST_F(SoftbusConnectorTest, HandleDeviceOffline_001, testing::ext::TestSize.Level0)
925 {
926 std::string deviceId = "deviceId";
927 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
928 std::shared_ptr<ISoftbusStateCallback> callback = std::make_shared<SoftbusStateCallbackTest>();
929 softbusConnector->RegisterSoftbusStateCallback(callback);
930 softbusConnector->HandleDeviceOffline(deviceId);
931 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), true);
932 }
933
934 /**
935 * @tc.name: CheckIsOnline_001
936 * @tc.type: FUNC
937 */
HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0)938 HWTEST_F(SoftbusConnectorTest, CheckIsOnline_001, testing::ext::TestSize.Level0)
939 {
940 std::string targetDeviceId = "targetDeviceId";
941 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
942 softbusConnector->CheckIsOnline(targetDeviceId);
943 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), true);
944 }
945
946 /**
947 * @tc.name: GetDeviceInfoByDeviceId_001
948 * @tc.type: FUNC
949 */
HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSize.Level0)950 HWTEST_F(SoftbusConnectorTest, GetDeviceInfoByDeviceId_001, testing::ext::TestSize.Level0)
951 {
952 std::string deviceId = "deviceId";
953 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
954 auto ret = softbusConnector->GetDeviceInfoByDeviceId(deviceId);
955 EXPECT_EQ(ret.deviceId == deviceId, false);
956 }
957
958 /**
959 * @tc.name: ConvertNodeBasicInfoToDmDevice_001
960 * @tc.type: FUNC
961 */
HWTEST_F(SoftbusConnectorTest, ConvertNodeBasicInfoToDmDevice_001, testing::ext::TestSize.Level0)962 HWTEST_F(SoftbusConnectorTest, ConvertNodeBasicInfoToDmDevice_001, testing::ext::TestSize.Level0)
963 {
964 NodeBasicInfo nodeBasicInfo = {
965 .networkId = "123456",
966 .deviceName = "name",
967 };
968 DmDeviceInfo dmDeviceInfo;
969 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
970 softbusConnector->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo);
971 EXPECT_EQ(softbusConnector->pkgNameVec_.empty(), true);
972 }
973 } // namespace
974 } // namespace DistributedHardware
975 } // namespace OHOS-