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
18 #include "device/dm_adapter.h"
19 #include "device_manager.h"
20 #include "distributed_clip.h"
21 #include "pasteboard_error.h"
22
23 namespace OHOS::MiscServices {
24 using namespace testing::ext;
25 class DMAdapterTest : public testing::Test {
26 public:
27 static void SetUpTestCase(void);
28 static void TearDownTestCase(void);
29 void SetUp();
30 void TearDown();
31 };
32
SetUpTestCase(void)33 void DMAdapterTest::SetUpTestCase(void) { }
34
TearDownTestCase(void)35 void DMAdapterTest::TearDownTestCase(void) { }
36
SetUp(void)37 void DMAdapterTest::SetUp(void) { }
38
TearDown(void)39 void DMAdapterTest::TearDown(void) { }
40
41 /**
42 * @tc.name: OnDeviceOnline001
43 * @tc.desc: OnDeviceOnline.
44 * @tc.type: FUNC
45 * @tc.require:
46 * @tc.author:
47 */
48 HWTEST_F(DMAdapterTest, OnDeviceOnline001, TestSize.Level0)
49 {
50 #ifdef PB_DEVICE_MANAGER_ENABLE
51 DmDeviceInfo info;
52 info.authForm = INVALID_TYPE;
53 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb0102(const DmDeviceInfo &deviceInfo) 54 [](const DmDeviceInfo &deviceInfo) {
55 return;
56 },
__anon7cff2cbb0202(const DmDeviceInfo &deviceInfo) 57 [](const DmDeviceInfo &deviceInfo) {
58 return;
59 },
__anon7cff2cbb0302(const DmDeviceInfo &deviceInfo) 60 [](const DmDeviceInfo &deviceInfo) {
61 return;
62 });
63 stateObserver->OnDeviceOnline(info);
64 ASSERT_TRUE(true);
65 #else
66 ASSERT_TRUE(true);
67 #endif
68 }
69
70 /**
71 * @tc.name: OnDeviceOnline002
72 * @tc.desc: OnDeviceOnline.
73 * @tc.type: FUNC
74 * @tc.require:
75 * @tc.author:
76 */
77 HWTEST_F(DMAdapterTest, OnDeviceOnline002, TestSize.Level0)
78 {
79 #ifdef PB_DEVICE_MANAGER_ENABLE
80 DmDeviceInfo info;
81 info.authForm = IDENTICAL_ACCOUNT;
82 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb0402(const DmDeviceInfo &deviceInfo) 83 [](const DmDeviceInfo &deviceInfo) {
84 return;
85 },
__anon7cff2cbb0502(const DmDeviceInfo &deviceInfo) 86 [](const DmDeviceInfo &deviceInfo) {
87 return;
88 },
__anon7cff2cbb0602(const DmDeviceInfo &deviceInfo) 89 [](const DmDeviceInfo &deviceInfo) {
90 return;
91 });
92 stateObserver->OnDeviceOnline(info);
93 ASSERT_TRUE(true);
94 #else
95 ASSERT_TRUE(true);
96 #endif
97 }
98
99 /**
100 * @tc.name: OnDeviceOnline003
101 * @tc.desc: OnDeviceOnline.
102 * @tc.type: FUNC
103 * @tc.require:
104 * @tc.author:
105 */
106 HWTEST_F(DMAdapterTest, OnDeviceOnline003, TestSize.Level0)
107 {
108 #ifdef PB_DEVICE_MANAGER_ENABLE
109 DmDeviceInfo info;
110 info.authForm = INVALID_TYPE;
111 auto stateObserver = std::make_shared<DmStateObserver>(
112 nullptr,
__anon7cff2cbb0702(const DmDeviceInfo &deviceInfo) 113 [](const DmDeviceInfo &deviceInfo) {
114 return;
115 },
__anon7cff2cbb0802(const DmDeviceInfo &deviceInfo) 116 [](const DmDeviceInfo &deviceInfo) {
117 return;
118 });
119 stateObserver->OnDeviceOnline(info);
120 ASSERT_TRUE(true);
121 #else
122 ASSERT_TRUE(true);
123 #endif
124 }
125
126 /**
127 * @tc.name: OnDeviceOnline004
128 * @tc.desc: OnDeviceOnline.
129 * @tc.type: FUNC
130 * @tc.require:
131 * @tc.author:
132 */
133 HWTEST_F(DMAdapterTest, OnDeviceOnline004, TestSize.Level0)
134 {
135 #ifdef PB_DEVICE_MANAGER_ENABLE
136 DmDeviceInfo info;
137 info.authForm = IDENTICAL_ACCOUNT;
138 auto stateObserver = std::make_shared<DmStateObserver>(
139 nullptr,
__anon7cff2cbb0902(const DmDeviceInfo &deviceInfo) 140 [](const DmDeviceInfo &deviceInfo) {
141 return;
142 },
__anon7cff2cbb0a02(const DmDeviceInfo &deviceInfo) 143 [](const DmDeviceInfo &deviceInfo) {
144 return;
145 });
146 stateObserver->OnDeviceOnline(info);
147 ASSERT_TRUE(true);
148 #else
149 ASSERT_TRUE(true);
150 #endif
151 }
152
153 /**
154 * @tc.name: OnDeviceOffline001
155 * @tc.desc: OnDeviceOffline.
156 * @tc.type: FUNC
157 * @tc.require:
158 * @tc.author:
159 */
160 HWTEST_F(DMAdapterTest, OnDeviceOffline001, TestSize.Level0)
161 {
162 #ifdef PB_DEVICE_MANAGER_ENABLE
163 DmDeviceInfo info;
164 info.authForm = IDENTICAL_ACCOUNT;
165 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb0b02(const DmDeviceInfo &deviceInfo) 166 [](const DmDeviceInfo &deviceInfo) {
167 return;
168 },
__anon7cff2cbb0c02(const DmDeviceInfo &deviceInfo) 169 [](const DmDeviceInfo &deviceInfo) {
170 return;
171 },
172 nullptr);
173 stateObserver->OnDeviceOffline(info);
174 ASSERT_TRUE(true);
175 #else
176 ASSERT_TRUE(true);
177 #endif
178 }
179
180 /**
181 * @tc.name: OnDeviceOffline002
182 * @tc.desc: OnDeviceOffline.
183 * @tc.type: FUNC
184 * @tc.require:
185 * @tc.author:
186 */
187 HWTEST_F(DMAdapterTest, OnDeviceOffline002, TestSize.Level0)
188 {
189 #ifdef PB_DEVICE_MANAGER_ENABLE
190 DmDeviceInfo info;
191 info.authForm = IDENTICAL_ACCOUNT;
192 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb0d02(const DmDeviceInfo &deviceInfo) 193 [](const DmDeviceInfo &deviceInfo) {
194 return;
195 },
__anon7cff2cbb0e02(const DmDeviceInfo &deviceInfo) 196 [](const DmDeviceInfo &deviceInfo) {
197 return;
198 },
__anon7cff2cbb0f02(const DmDeviceInfo &deviceInfo) 199 [](const DmDeviceInfo &deviceInfo) {
200 return;
201 });
202 stateObserver->OnDeviceOffline(info);
203 ASSERT_TRUE(true);
204 #else
205 ASSERT_TRUE(true);
206 #endif
207 }
208
209 /**
210 * @tc.name: OnDeviceReady001
211 * @tc.desc: OnDeviceReady.
212 * @tc.type: FUNC
213 * @tc.require:
214 * @tc.author:
215 */
216 HWTEST_F(DMAdapterTest, OnDeviceReady001, TestSize.Level0)
217 {
218 #ifdef PB_DEVICE_MANAGER_ENABLE
219 DmDeviceInfo info;
220 info.authForm = INVALID_TYPE;
221 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb1002(const DmDeviceInfo &deviceInfo) 222 [](const DmDeviceInfo &deviceInfo) {
223 return;
224 },
__anon7cff2cbb1102(const DmDeviceInfo &deviceInfo) 225 [](const DmDeviceInfo &deviceInfo) {
226 return;
227 },
__anon7cff2cbb1202(const DmDeviceInfo &deviceInfo) 228 [](const DmDeviceInfo &deviceInfo) {
229 return;
230 });
231 stateObserver->OnDeviceReady(info);
232 ASSERT_TRUE(true);
233 #else
234 ASSERT_TRUE(true);
235 #endif
236 }
237
238 /**
239 * @tc.name: OnDeviceReady002
240 * @tc.desc: OnDeviceReady.
241 * @tc.type: FUNC
242 * @tc.require:
243 * @tc.author:
244 */
245 HWTEST_F(DMAdapterTest, OnDeviceReady002, TestSize.Level0)
246 {
247 #ifdef PB_DEVICE_MANAGER_ENABLE
248 DmDeviceInfo info;
249 info.authForm = IDENTICAL_ACCOUNT;
250 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb1302(const DmDeviceInfo &deviceInfo) 251 [](const DmDeviceInfo &deviceInfo) {
252 return;
253 },
__anon7cff2cbb1402(const DmDeviceInfo &deviceInfo) 254 [](const DmDeviceInfo &deviceInfo) {
255 return;
256 },
__anon7cff2cbb1502(const DmDeviceInfo &deviceInfo) 257 [](const DmDeviceInfo &deviceInfo) {
258 return;
259 });
260 stateObserver->OnDeviceReady(info);
261 ASSERT_TRUE(true);
262 #else
263 ASSERT_TRUE(true);
264 #endif
265 }
266
267 /**
268 * @tc.name: OnDeviceReady003
269 * @tc.desc: OnDeviceReady.
270 * @tc.type: FUNC
271 * @tc.require:
272 * @tc.author:
273 */
274 HWTEST_F(DMAdapterTest, OnDeviceReady003, TestSize.Level0)
275 {
276 #ifdef PB_DEVICE_MANAGER_ENABLE
277 DmDeviceInfo info;
278 info.authForm = INVALID_TYPE;
279 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb1602(const DmDeviceInfo &deviceInfo) 280 [](const DmDeviceInfo &deviceInfo) {
281 return;
282 },
283 nullptr,
__anon7cff2cbb1702(const DmDeviceInfo &deviceInfo) 284 [](const DmDeviceInfo &deviceInfo) {
285 return;
286 });
287 stateObserver->OnDeviceReady(info);
288 ASSERT_TRUE(true);
289 #else
290 ASSERT_TRUE(true);
291 #endif
292 }
293
294 /**
295 * @tc.name: OnDeviceReady004
296 * @tc.desc: OnDeviceReady.
297 * @tc.type: FUNC
298 * @tc.require:
299 * @tc.author:
300 */
301 HWTEST_F(DMAdapterTest, OnDeviceReady004, TestSize.Level0)
302 {
303 #ifdef PB_DEVICE_MANAGER_ENABLE
304 DmDeviceInfo info;
305 info.authForm = IDENTICAL_ACCOUNT;
306 auto stateObserver = std::make_shared<DmStateObserver>(
__anon7cff2cbb1802(const DmDeviceInfo &deviceInfo) 307 [](const DmDeviceInfo &deviceInfo) {
308 return;
309 },
310 nullptr,
__anon7cff2cbb1902(const DmDeviceInfo &deviceInfo) 311 [](const DmDeviceInfo &deviceInfo) {
312 return;
313 });
314 stateObserver->OnDeviceReady(info);
315 ASSERT_TRUE(true);
316 #else
317 ASSERT_TRUE(true);
318 #endif
319 }
320
321 /**
322 * @tc.name: GetNetworkIds001
323 * @tc.desc: GetNetworkIds.
324 * @tc.type: FUNC
325 * @tc.require:
326 * @tc.author:
327 */
328 HWTEST_F(DMAdapterTest, GetNetworkIds001, TestSize.Level0)
329 {
330 #ifdef PB_DEVICE_MANAGER_ENABLE
331 std::string networkId = "testNetworkId";
332 std::string testName = "testDeviceName";
333 DmDeviceInfo info;
334 info.authForm = IDENTICAL_ACCOUNT;
335 std::copy(networkId.begin(), networkId.end(), info.networkId);
336 std::copy(testName.begin(), testName.end(), info.deviceName);
337 DMAdapter::GetInstance().devices_.emplace_back(info);
338 auto ids = DMAdapter::GetInstance().GetNetworkIds();
339 ASSERT_NE(0, ids.size());
340 #else
341 ASSERT_TRUE(true);
342 #endif
343 }
344
345 /**
346 * @tc.name: GetLocalDeviceUdid001
347 * @tc.desc: Get the local device udid.
348 * @tc.type: FUNC
349 * @tc.require:
350 * @tc.author:
351 */
352 HWTEST_F(DMAdapterTest, GetLocalDeviceUdid001, TestSize.Level0)
353 {
354 std::string bundleName = "com.example.myapplication";
355 bool res = DMAdapter::GetInstance().Initialize(bundleName);
356 ASSERT_FALSE(res);
357 std::string device = "deviceTestName";
358 auto fromDevice = DMAdapter::GetInstance().GetDeviceName(device);
359 ASSERT_FALSE(fromDevice.empty());
360 auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
361 ASSERT_TRUE(udid.empty());
362 }
363
364 /**
365 * @tc.name: GetLocalDeviceUdid002
366 * @tc.desc: Get the local device udid.
367 * @tc.type: FUNC
368 * @tc.require:
369 * @tc.author:
370 */
371 HWTEST_F(DMAdapterTest, GetLocalDeviceUdid002, TestSize.Level0)
372 {
373 std::string bundleName = "com.example.myapplication";
374 bool res = DMAdapter::GetInstance().Initialize(bundleName);
375 std::string device = "deviceTestName";
376 auto fromDevice = DMAdapter::GetInstance().GetDeviceName(device);
377 DmDeviceInfo info;
378 std::string pkgName_ = "pkgName";
379 std::string localDeviceUdid_ = "localDeviceUdid";
380 DeviceManager::GetInstance().GetUdidByNetworkId(pkgName_, info.networkId, localDeviceUdid_);
381 auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
382 ASSERT_TRUE(udid.empty());
383 }
384
385 /**
386 * @tc.name: GetLocalDeviceUdid003
387 * @tc.desc: GetLocalDeviceUdid.
388 * @tc.type: FUNC
389 * @tc.require:
390 * @tc.author:
391 */
392 HWTEST_F(DMAdapterTest, GetLocalDeviceUdid003, TestSize.Level0)
393 {
394 #ifdef PB_DEVICE_MANAGER_ENABLE
395 DMAdapter::GetInstance().localDeviceUdid_ = "testUdid";
396 auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
397 ASSERT_FALSE(udid.empty());
398 #else
399 ASSERT_TRUE(udid.empty());
400 #endif
401 }
402
403 /**
404 * @tc.name: GetLocalDeviceUdid004
405 * @tc.desc: GetLocalDeviceUdid.
406 * @tc.type: FUNC
407 * @tc.require:
408 * @tc.author:
409 */
410 HWTEST_F(DMAdapterTest, GetLocalDeviceUdid004, TestSize.Level0)
411 {
412 #ifdef PB_DEVICE_MANAGER_ENABLE
413 DMAdapter::GetInstance().localDeviceUdid_ = "";
414 DMAdapter::GetInstance().pkgName_ = "testpkgName";
415 auto &udid = DMAdapter::GetInstance().GetLocalDeviceUdid();
416 ASSERT_TRUE(udid.empty());
417 #else
418 ASSERT_FALSE(udid.empty());
419 #endif
420 }
421
422 /**
423 * @tc.name: GetLocalNetworkId
424 * @tc.desc: Get the local network id.
425 * @tc.type: FUNC
426 * @tc.require:
427 * @tc.author:
428 */
429 HWTEST_F(DMAdapterTest, GetLocalNetworkId, TestSize.Level0)
430 {
431 std::string bundleName = "com.example.myapplication";
432 bool res = DMAdapter::GetInstance().Initialize(bundleName);
433 ASSERT_FALSE(res);
434 auto networkId = DMAdapter::GetInstance().GetLocalNetworkId();
435 ASSERT_FALSE(networkId.empty());
436 }
437
438 /**
439 * @tc.name: DistributedClipRegister
440 * @tc.desc: DistributedClip Register and Unregister.
441 * @tc.type: FUNC
442 * @tc.require:
443 * @tc.author:
444 */
445 HWTEST_F(DMAdapterTest, DistributedClipRegister, TestSize.Level0)
446 {
447 DistributedClip *observer = new DistributedClip();
448 DMAdapter::GetInstance().Register(observer);
449 DMAdapter::GetInstance().Unregister(observer);
450 ASSERT_TRUE(true);
451 }
452
453 /**
454 * @tc.name: GetRemoteDeviceInfo
455 * @tc.desc: Get the remote device info.
456 * @tc.type: FUNC
457 * @tc.require:
458 * @tc.author:
459 */
460 HWTEST_F(DMAdapterTest, GetRemoteDeviceInfo, TestSize.Level0)
461 {
462 #ifdef PB_DEVICE_MANAGER_ENABLE
463 DmDeviceInfo remoteDevice;
464 auto ret = DMAdapter::GetInstance().GetRemoteDeviceInfo("", remoteDevice);
465 ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR));
466 #else
467 ASSERT_TRUE(true);
468 #endif
469 }
470
471 /**
472 * @tc.name: GetRemoteDeviceInfo002
473 * @tc.desc: Get the remote device info.
474 * @tc.type: FUNC
475 * @tc.require:
476 * @tc.author:
477 */
478 HWTEST_F(DMAdapterTest, GetRemoteDeviceInfo002, TestSize.Level0)
479 {
480 #ifdef PB_DEVICE_MANAGER_ENABLE
481 std::string bundleName = "com.example.myapplication";
482 bool res = DMAdapter::GetInstance().Initialize(bundleName);
483 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
484 std::string testName = "testDeviceName";
485 DmDeviceInfo info;
486 info.authForm = IDENTICAL_ACCOUNT;
487 std::copy(networkId.begin(), networkId.end(), info.networkId);
488 std::copy(testName.begin(), testName.end(), info.deviceName);
489 DMAdapter::GetInstance().devices_.emplace_back(info);
490 DmDeviceInfo remoteDevice;
491 int32_t result = DMAdapter::GetInstance().GetRemoteDeviceInfo(networkId, remoteDevice);
492 ASSERT_EQ(static_cast<int32_t>(PasteboardError::E_OK), result);
493 #else
494 ASSERT_TRUE(true);
495 #endif
496 }
497
498 /**
499 * @tc.name: GetRemoteDeviceInfo003
500 * @tc.desc: Get the remote device info.
501 * @tc.type: FUNC
502 * @tc.require:
503 * @tc.author:
504 */
505 HWTEST_F(DMAdapterTest, GetRemoteDeviceInfo003, TestSize.Level0)
506 {
507 #ifdef PB_DEVICE_MANAGER_ENABLE
508 std::string bundleName = "com.example.myapplication";
509 bool res = DMAdapter::GetInstance().Initialize(bundleName);
510 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
511 std::string testName = "testDeviceName";
512 DmDeviceInfo info;
513 info.authForm = IDENTICAL_ACCOUNT;
514 std::copy(networkId.begin(), networkId.end(), info.networkId);
515 std::copy(testName.begin(), testName.end(), info.deviceName);
516 DMAdapter::GetInstance().devices_.emplace_back(info);
517 DmDeviceInfo remoteDevice;
518 int32_t result = DMAdapter::GetInstance().GetRemoteDeviceInfo("testNetworkId", remoteDevice);
519 ASSERT_EQ(static_cast<int32_t>(PasteboardError::NO_TRUST_DEVICE_ERROR), result);
520 #else
521 ASSERT_TRUE(true);
522 #endif
523 }
524
525 /**
526 * @tc.name: GetUdidByNetworkId
527 * @tc.desc: Get Udid By NetworkId.
528 * @tc.type: FUNC
529 * @tc.require:
530 * @tc.author:
531 */
532 HWTEST_F(DMAdapterTest, GetUdidByNetworkId, TestSize.Level0)
533 {
534 auto udid = DMAdapter::GetInstance().GetUdidByNetworkId("");
535 ASSERT_TRUE(udid.empty());
536 }
537
538 /**
539 * @tc.name: IsSameAccount
540 * @tc.desc: is same account.
541 * @tc.type: FUNC
542 * @tc.require:
543 * @tc.author:
544 */
545 HWTEST_F(DMAdapterTest, IsSameAccount, TestSize.Level0)
546 {
547 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
548 bool ret = DMAdapter::GetInstance().IsSameAccount(networkId);
549 ASSERT_TRUE(ret);
550 }
551
552 /**
553 * @tc.name: IsSameAccount002
554 * @tc.desc: is same account.
555 * @tc.type: FUNC
556 * @tc.require:
557 * @tc.author:
558 */
559 HWTEST_F(DMAdapterTest, IsSameAccount002, TestSize.Level0)
560 {
561 #ifdef PB_DEVICE_MANAGER_ENABLE
562 std::string networkId = "testNetworkId";
563 std::string testName = "testDeviceName";
564 DmDeviceInfo info;
565 info.authForm = IDENTICAL_ACCOUNT;
566 std::copy(networkId.begin(), networkId.end(), info.networkId);
567 std::copy(testName.begin(), testName.end(), info.deviceName);
568 DMAdapter::GetInstance().devices_.emplace_back(info);
569 bool ret = DMAdapter::GetInstance().IsSameAccount(networkId);
570 ASSERT_TRUE(ret);
571 #else
572 ASSERT_TRUE(true);
573 #endif
574 }
575
576 /**
577 * @tc.name: IsSameAccount003
578 * @tc.desc: is same account.
579 * @tc.type: FUNC
580 * @tc.require:
581 * @tc.author:
582 */
583 HWTEST_F(DMAdapterTest, IsSameAccount003, TestSize.Level0)
584 {
585 #ifdef PB_DEVICE_MANAGER_ENABLE
586 std::string bundleName = "com.example.myapplication";
587 bool res = DMAdapter::GetInstance().Initialize(bundleName);
588 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
589 std::string testName = "testDeviceName";
590 DmDeviceInfo info;
591 info.authForm = IDENTICAL_ACCOUNT;
592 std::copy(networkId.begin(), networkId.end(), info.networkId);
593 std::copy(testName.begin(), testName.end(), info.deviceName);
594 DMAdapter::GetInstance().devices_.emplace_back(info);
595 bool ret = DMAdapter::GetInstance().IsSameAccount("testNetworkId");
596 ASSERT_FALSE(ret);
597 #else
598 ASSERT_TRUE(true);
599 #endif
600 }
601
602 /**
603 * @tc.name: GetDevices
604 * @tc.desc: Get Devices.
605 * @tc.type: FUNC
606 * @tc.require:
607 * @tc.author:
608 */
609 HWTEST_F(DMAdapterTest, GetDevices, TestSize.Level0)
610 {
611 DMAdapter::GetInstance().SetDevices();
612 std::vector<DmDeviceInfo> devices = DMAdapter::GetInstance().GetDevices();
613 ASSERT_TRUE(devices.empty());
614 }
615
616 /**
617 * @tc.name: GetLocalDeviceType002
618 * @tc.desc: GetLocalDeviceType
619 * @tc.type: FUNC
620 * @tc.require:
621 * @tc.author:
622 */
623 HWTEST_F(DMAdapterTest, GetLocalDeviceType002, TestSize.Level0)
624 {
625 #ifdef PB_DEVICE_MANAGER_ENABLE
626 int32_t deviceType = DMAdapter::GetInstance().GetLocalDeviceType();
627 EXPECT_EQ(DmDeviceType::DEVICE_TYPE_UNKNOWN, deviceType);
628 deviceType = DMAdapter::GetInstance().GetLocalDeviceType();
629 EXPECT_EQ(DmDeviceType::DEVICE_TYPE_UNKNOWN, deviceType);
630 #else
631 ASSERT_TRUE(true);
632 #endif
633 }
634
635 /**
636 * @tc.name: GetDeviceName001
637 * @tc.desc: Get Local Device Type
638 * @tc.type: FUNC
639 * @tc.require:
640 * @tc.author:
641 */
642 HWTEST_F(DMAdapterTest, GetDeviceName001, TestSize.Level0)
643 {
644 std::string networkId = "invalidnetworkId";
645 std::string expectedDeviceName = "unknown";
646 (void)DMAdapter::GetInstance().GetLocalDeviceType();
647 std::string actualDeviceName = DMAdapter::GetInstance().GetDeviceName(networkId);
648 EXPECT_EQ(expectedDeviceName, actualDeviceName);
649 }
650
651 /**
652 * @tc.name: GetDeviceName002
653 * @tc.desc: Get Local Device Type
654 * @tc.type: FUNC
655 * @tc.require:
656 * @tc.author:
657 */
658 HWTEST_F(DMAdapterTest, GetDeviceName002, TestSize.Level0)
659 {
660 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
661 std::string expectedDeviceName = "unknown";
662 std::string actualDeviceName = DMAdapter::GetInstance().GetDeviceName(networkId);
663 EXPECT_EQ(expectedDeviceName, actualDeviceName);
664 }
665
666 /**
667 * @tc.name: GetDeviceName003
668 * @tc.desc: GetDeviceName.
669 * @tc.type: FUNC
670 * @tc.require:
671 * @tc.author:
672 */
673 HWTEST_F(DMAdapterTest, GetDeviceName003, TestSize.Level0)
674 {
675 #ifdef PB_DEVICE_MANAGER_ENABLE
676 std::string bundleName = "com.example.myapplication";
677 bool res = DMAdapter::GetInstance().Initialize(bundleName);
678 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
679 std::string expectedDeviceName = "testDeviceName";
680 DmDeviceInfo info;
681 info.authForm = IDENTICAL_ACCOUNT;
682 std::copy(networkId.begin(), networkId.end(), info.networkId);
683 std::copy(expectedDeviceName.begin(), expectedDeviceName.end(), info.deviceName);
684 DMAdapter::GetInstance().devices_.emplace_back(info);
685 std::string actualDeviceName = DMAdapter::GetInstance().GetDeviceName(networkId);
686 EXPECT_EQ(expectedDeviceName, actualDeviceName);
687 #else
688 ASSERT_TRUE(udid.empty());
689 #endif
690 }
691
692 /**
693 * @tc.name: GetDeviceName004
694 * @tc.desc: GetDeviceName.
695 * @tc.type: FUNC
696 * @tc.require:
697 * @tc.author:
698 */
699 HWTEST_F(DMAdapterTest, GetDeviceName004, TestSize.Level0)
700 {
701 #ifdef PB_DEVICE_MANAGER_ENABLE
702 std::string bundleName = "com.example.myapplication";
703 bool res = DMAdapter::GetInstance().Initialize(bundleName);
704 std::string networkId = DMAdapter::GetInstance().GetLocalNetworkId();
705 std::string testName = "testDeviceName";
706 DmDeviceInfo info;
707 info.authForm = IDENTICAL_ACCOUNT;
708 std::copy(networkId.begin(), networkId.end(), info.networkId);
709 std::copy(testName.begin(), testName.end(), info.deviceName);
710 DMAdapter::GetInstance().devices_.emplace_back(info);
711 std::string actualDeviceName = DMAdapter::GetInstance().GetDeviceName("testNetworkId");
712 EXPECT_EQ("unknown", actualDeviceName);
713 #else
714 ASSERT_TRUE(udid.empty());
715 #endif
716 }
717
718 /**
719 * @tc.name: DeInitialize
720 * @tc.desc: De Initialize
721 * @tc.type: FUNC
722 * @tc.require:
723 * @tc.author:
724 */
725 HWTEST_F(DMAdapterTest, DeInitialize, TestSize.Level0)
726 {
727 DMAdapter::GetInstance().DeInitialize();
728 ASSERT_TRUE(true);
729 }
730 } // namespace OHOS::MiscServices
731