1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "UTTest_device_manager_notify.h"
17 #include "device_manager_notify.h"
18 #include "dm_device_info.h"
19 #include "ipc_remote_broker.h"
20 #include "iremote_object.h"
21 #include "iservice_registry.h"
22 #include "system_ability_definition.h"
23 #include "ipc_client_manager.h"
24 #include "ipc_set_useroperation_req.h"
25 #include "ipc_rsp.h"
26 #include "ipc_def.h"
27
28 #include <unistd.h>
29
30 namespace OHOS {
31 namespace DistributedHardware {
SetUp()32 void DeviceManagerNotifyTest::SetUp()
33 {
34 }
35
TearDown()36 void DeviceManagerNotifyTest::TearDown()
37 {
38 }
39
SetUpTestCase()40 void DeviceManagerNotifyTest::SetUpTestCase()
41 {
42 }
43
TearDownTestCase()44 void DeviceManagerNotifyTest::TearDownTestCase()
45 {
46 }
47
48 namespace {
49 /**
50 * @tc.name: RegisterDeathRecipientCallback_001
51 * @tc.desc: 1. set pkgName not null
52 * set dmInitCallback not null
53 * 2. set checkMap null
54 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
55 * 4. Get checkMap from DeviceManagerNotify
56 * 5. check checkMap not null
57 * deviceTypeId
58 * @tc.type: FUNC
59 * @tc.require: AR000GHSJK
60 */
61 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_001, testing::ext::TestSize.Level0)
62 {
63 // 1. set pkgName not null
64 std::string pkgName = "com.ohos.test";
65 // set dmInitCallback not null
66 int count = 0;
67 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
68 // 2. set checkMap null
69 std::shared_ptr<DmInitCallback> checkMap = nullptr;
70 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
71 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
72 // 4. Get checkMap from DeviceManagerNotify
73 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
74 // 5. check checkMap not null
75 ASSERT_NE(checkMap, nullptr);
76 }
77
78 /**
79 * @tc.name: RegisterDeathRecipientCallback_002
80 * @tc.desc: 1. set pkgName not null
81 * set dmInitCallback null
82 * 2. set checkMap null
83 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
84 * 4. Get checkMap from DeviceManagerNotify
85 * 5. check checkMap null
86 * deviceTypeId
87 * @tc.type: FUNC
88 * @tc.require: AR000GHSJK
89 */
90 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_002, testing::ext::TestSize.Level0)
91 {
92 // 1. set pkgName not null
93 std::string pkgName = "com.ohos.test";
94 // set dmInitCallback null
95 std::shared_ptr<DmInitCallback> dmInitCallback = nullptr;
96 // 2. set checkMap not null
97 std::shared_ptr<DmInitCallback> checkMap = nullptr;
98 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
99 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
100 // 4. Get checkMap from DeviceManagerNotify
101 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
102 // 5. check checkMap null
103 ASSERT_EQ(checkMap, nullptr);
104 }
105
106 /**
107 * @tc.name: RegisterDeathRecipientCallback_003
108 * @tc.desc: 1. set pkgName com.ohos.test
109 * set dmInitCallback not null
110 * 2. set checkMap null
111 * 3. set testpkcName com.ohos.test1
112 * 4. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
113 * 5. Get checkMap from DeviceManagerNotify with testpkcName
114 * 6. check checkMap null
115 * deviceTypeId
116 * @tc.type: FUNC
117 * @tc.require: AR000GHSJK
118 */
119 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_003, testing::ext::TestSize.Level0)
120 {
121 // 1. set pkgName com.ohos.test
122 std::string pkgName = "com.ohos.test";
123 // set dmInitCallback not null
124 std::shared_ptr<DmInitCallback> dmInitCallback = nullptr;
125 // 2. set checkMap null
126 std::shared_ptr<DmInitCallback> checkMap = nullptr;
127 // 3. set testpkcName com.ohos.test1
128 std::string testPkgName = "com.ohos.test1";
129 // 4. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
130 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
131 // 5. Get checkMap from DeviceManagerNotify with testpkcName
132 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[testPkgName];
133 // 6. check checkMap not null
134 ASSERT_EQ(checkMap, nullptr);
135 }
136
137 /**
138 * @tc.name: RegisterDeathRecipientCallback_004
139 * @tc.desc: 1. set pkgName not null
140 * set dmInitCallback not null
141 * 2. set checkMap null
142 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
143 * 4. Get checkMap from DeviceManagerNotify
144 * 5. check checkMap not null
145 * 6. call checkMap OnRemoteDied
146 * 7. check count is 1
147 * deviceTypeId
148 * @tc.type: FUNC
149 * @tc.require: AR000GHSJK
150 */
151 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_004, testing::ext::TestSize.Level0)
152 {
153 // 1. set pkgName not null
154 std::string pkgName = "com.ohos.test";
155 // set dmInitCallback not null
156 int count = 0;
157 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
158 // 2. set checkMap null
159 std::shared_ptr<DmInitCallback> checkMap = nullptr;
160 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
161 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
162 // 4. Get checkMap from DeviceManagerNotify
163 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
164 // 5. check checkMap not null
165 ASSERT_NE(checkMap, nullptr);
166 // 6. call checkMap OnRemoteDied
167 checkMap->OnRemoteDied();
168 // 7. check count is 1
169 ASSERT_EQ(count, 1);
170 }
171
172 /**
173 * @tc.name: RegisterDeathRecipientCallback_005
174 * @tc.desc: 1. set pkgName not null
175 * set dmInitCallback not null
176 * 2. set checkMap null
177 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
178 * 4. Get checkMap from DeviceManagerNotify
179 * 5. check checkMap not null
180 * 6. call checkMap OnRemoteDied
181 * 7. check count is 1
182 * deviceTypeId
183 * @tc.type: FUNC
184 * @tc.require: AR000GHSJK
185 */
186 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_005, testing::ext::TestSize.Level0)
187 {
188 // 1. set pkgName not null
189 std::string pkgName = "com.ohos.test";
190 // set dmInitCallback not null
191 int count = 0;
192 std::shared_ptr<DmInitCallback> dmInitCallback = nullptr;
193 // 2. set checkMap null
194 std::shared_ptr<DmInitCallback> checkMap = nullptr;
195 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
196 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
197 // 4. Get checkMap from DeviceManagerNotify
198 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
199 // 5. check checkMap not null
200 if (checkMap == nullptr) {
201 ASSERT_NE(count, 1);
202 return;
203 }
204 ASSERT_NE(checkMap, nullptr);
205 }
206
207 /**
208 * @tc.name: RegisterDeathRecipientCallback_005
209 * @tc.type: FUNC
210 */
211 HWTEST_F(DeviceManagerNotifyTest, RegisterDeathRecipientCallback_006, testing::ext::TestSize.Level0)
212 {
213 std::string pkgName;
214 int count = 0;
215 std::shared_ptr<DmInitCallback> dmInitCallback = nullptr;
216 std::shared_ptr<DmInitCallback> checkMap = nullptr;
217 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
218 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
219 if (checkMap == nullptr) {
220 ASSERT_NE(count, 1);
221 return;
222 }
223 ASSERT_NE(checkMap, nullptr);
224 }
225
226 /**
227 * @tc.name: UnRegisterDeathRecipientCallback_001
228 * @tc.desc: 1. set pkgName not null
229 * set dmInitCallback not null
230 * 2. set checkMap null
231 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
232 * 4. Get checkMap from DeviceManagerNotify
233 * 5. check checkMap not null
234 * 6. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with parameter
235 * 7. Get checkMap from DeviceManagerNotify
236 * 8. check checkMap null
237 * deviceTypeId
238 * @tc.type: FUNC
239 * @tc.require: AR000GHSJK
240 */
241 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_001, testing::ext::TestSize.Level0)
242 {
243 // 1. set pkgName not null
244 std::string pkgName = "com.ohos.test";
245 // set dmInitCallback not null
246 int count = 0;
247 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
248 // 2. set checkMap null
249 std::shared_ptr<DmInitCallback> checkMap = nullptr;
250 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
251 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
252 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
253 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
254 // 5. check checkMap not null
255 ASSERT_NE(checkMap, nullptr);
256 // 6. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with parameter
257 DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(pkgName);
258 // 7. Get checkMap from DeviceManagerNotify
259 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
260 // 8 check checkMap null
261 ASSERT_EQ(checkMap, nullptr);
262 }
263
264 /**
265 * @tc.name: UnRegisterDeathRecipientCallback_002
266 * @tc.desc: 1. set pkgName com.ohos.test
267 * set dmInitCallback not null
268 * 2. set checkMap null
269 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
270 * 4. Get checkMap from DeviceManagerNotify
271 * 5. check checkMap not null
272 * 6. set testpkcName com.ohos.test1
273 * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
274 * 8. Get checkMap from DeviceManagerNotify
275 * 9. check checkMap not null
276 * deviceTypeId
277 * @tc.type: FUNC
278 * @tc.require: AR000GHSJK
279 */
280 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_002, testing::ext::TestSize.Level0)
281 {
282 // 1. set pkgName not null
283 std::string pkgName = "com.ohos.test";
284 // set dmInitCallback not null
285 int count = 0;
286 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
287 // 2. set checkMap null
288 std::shared_ptr<DmInitCallback> checkMap = nullptr;
289 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
290 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
291 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
292 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
293 // 5. check checkMap not null
294 ASSERT_NE(checkMap, nullptr);
295 // 6. set testpkcName com.ohos.test1
296 std::string testPkgName = "com.ohos.test1";
297 // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
298 DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName);
299 // 8. Get checkMap from DeviceManagerNotify
300 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
301 // 8 check checkMap not null
302 ASSERT_NE(checkMap, nullptr);
303 }
304
305 /**
306 * @tc.name: UnRegisterDeathRecipientCallback_003
307 * @tc.desc: 1. set pkgName com.ohos.test
308 * set dmInitCallback not null
309 * 2. set checkMap null
310 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
311 * 4. Get checkMap from DeviceManagerNotify
312 * 5. check checkMap not null
313 * 6. set testpkcName com.ohos.test1
314 * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
315 * 8. Get checkMap from DeviceManagerNotify
316 * 9. call checkMap OnRemoteDied
317 * 10. check count is 1
318 * deviceTypeId
319 * @tc.type: FUNC
320 * @tc.require: AR000GHSJK
321 */
322 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_003, testing::ext::TestSize.Level0)
323 {
324 // 1. set pkgName not null
325 std::string pkgName = "com.ohos.test";
326 // set dmInitCallback not null
327 int count = 0;
328 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
329 // 2. set checkMap null
330 std::shared_ptr<DmInitCallback> checkMap = nullptr;
331 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
332 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
333 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
334 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
335 // 5. check checkMap not null
336 ASSERT_NE(checkMap, nullptr);
337 // 6. set testpkcName com.ohos.test1
338 std::string testPkgName = "com.ohos.test1";
339 // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
340 DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName);
341 // 8. Get checkMap from DeviceManagerNotify
342 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
343 // 9. call checkMap OnRemoteDied
344 checkMap->OnRemoteDied();
345 // 10. check count is 1
346 ASSERT_EQ(count, 1);
347 }
348
349 /**
350 * @tc.name: UnRegisterDeathRecipientCallback_004
351 * @tc.desc: 1. set pkgName com.ohos.test
352 * set dmInitCallback not null
353 * 2. set checkMap null
354 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
355 * 4. Get checkMap from DeviceManagerNotify
356 * 5. check checkMap not null
357 * 6. set testpkcName com.ohos.test1
358 * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
359 * 8. Get checkMap from DeviceManagerNotify
360 * 9. check checkMap not null
361 * deviceTypeId
362 * @tc.type: FUNC
363 * @tc.require: AR000GHSJK
364 */
365 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_004, testing::ext::TestSize.Level0)
366 {
367 // 1. set pkgName not null
368 std::string pkgName = "com.ohos.test";
369 // set dmInitCallback not null
370 int count = 0;
371 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
372 // 2. set checkMap null
373 std::shared_ptr<DmInitCallback> checkMap = nullptr;
374 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
375 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
376 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
377 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
378 // 5. check checkMap not null
379 ASSERT_NE(checkMap, nullptr);
380 // 6. set testpkcName com.ohos.test1
381 std::string testPkgName = "com.ohos.test1";
382 // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
383 DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName);
384 // 8. Get checkMap from DeviceManagerNotify
385 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
386 // 9. check checkMap not null
387 if (checkMap == nullptr) {
388 ASSERT_NE(count, 1);
389 return;
390 }
391 ASSERT_NE(checkMap, nullptr);
392 }
393
394 /**
395 * @tc.name: UnRegisterDeathRecipientCallback_005
396 * @tc.desc: 1. set pkgName com.ohos.test
397 * set dmInitCallback not null
398 * 2. set checkMap null
399 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
400 * 4. Get checkMap from DeviceManagerNotify
401 * 5. check checkMap not null
402 * 6. set testpkcName com.ohos.test1
403 * 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
404 * 8. Get checkMap from DeviceManagerNotify
405 * 9. check checkMap not null
406 * deviceTypeId
407 * @tc.type: FUNC
408 * @tc.require: AR000GHSJK
409 */
410 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeathRecipientCallback_005, testing::ext::TestSize.Level0)
411 {
412 // 1. set pkgName not null
413 std::string pkgName = "com.ohos.test";
414 // set dmInitCallback not null
415 int count = 0;
416 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
417 // 2. set checkMap null
418 std::shared_ptr<DmInitCallback> checkMap = nullptr;
419 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
420 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
421 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
422 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
423 // 5. check checkMap not null
424 ASSERT_NE(checkMap, nullptr);
425 // 6. set testpkcName nullptr
426 std::string testPkgName = "";
427 // 7. call DeviceManagerNotifyTest UnRegisterDeathRecipientCallback with testpkcName
428 DeviceManagerNotify::GetInstance().UnRegisterDeathRecipientCallback(testPkgName);
429 // 8. Get checkMap from DeviceManagerNotify
430 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
431 // 8 check checkMap not null
432 ASSERT_NE(checkMap, nullptr);
433 }
434
435 /**
436 * @tc.name: RegisterDeviceStateCallback_001
437 * @tc.desc: 1. set pkgName not null
438 * set Callback not null
439 * 2. set checkMap null
440 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
441 * 4. Get checkMap from DeviceManagerNotify
442 * 5. check checkMap not null
443 * deviceTypeId
444 * @tc.type: FUNC
445 * @tc.require: AR000GHSJK
446 */
447 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_001, testing::ext::TestSize.Level0)
448 {
449 // 1. set pkgName not null
450 std::string pkgName = "com.ohos.test";
451 // set Callback not null
452 int count = 0;
453 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
454 // 2. set checkMap null
455 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
456 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
457 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
458 // 4. Get checkMap from DeviceManagerNotify
459 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
460 // 5. check checkMap not null
461 ASSERT_NE(checkMap, nullptr);
462 }
463
464 /**
465 * @tc.name: RegisterDeviceStateCallback_002
466 * @tc.desc: 1. set pkgName not null
467 * set Callback null
468 * 2. set checkMap null
469 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
470 * 4. Get checkMap from DeviceManagerNotify
471 * 5. check checkMap null
472 * @tc.type: FUNC
473 * @tc.require: AR000GHSJK
474 */
475 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_002, testing::ext::TestSize.Level0)
476 {
477 // 1. set pkgName not null
478 std::string pkgName = "com.ohos.test";
479 // set dmInitCallback null
480 std::shared_ptr<DeviceStateCallback> callback = nullptr;
481 // 2. set checkMap not null
482 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
483 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
484 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
485 // 4. Get checkMap from DeviceManagerNotify
486 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
487 // 5. check checkMap null
488 ASSERT_EQ(checkMap, nullptr);
489 }
490
491 /**
492 * @tc.name: RegisterDeviceStateCallback_003
493 * @tc.desc: 1. set pkgName com.ohos.test
494 * set Callback not null
495 * 2. set checkMap null
496 * 3. set testpkcName com.ohos.test1
497 * 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
498 * 5. Get checkMap from DeviceManagerNotify with testpkcName
499 * 6. check checkMap null
500 * @tc.type: FUNC
501 * @tc.require: AR000GHSJK
502 */
503 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_003, testing::ext::TestSize.Level0)
504 {
505 // 1. set pkgName com.ohos.test
506 std::string pkgName = "com.ohos.test";
507 // set dmInitCallback not null
508 std::shared_ptr<DeviceStateCallback> callback = nullptr;
509 // 2. set checkMap null
510 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
511 // 3. set testpkcName com.ohos.test1
512 std::string testPkgName = "com.ohos.test1";
513 // 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
514 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
515 // 5. Get checkMap from DeviceManagerNotify with testpkcName
516 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[testPkgName];
517 // 6. check checkMap not null
518 ASSERT_EQ(checkMap, nullptr);
519 }
520
521 /**
522 * @tc.name: RegisterDeviceStateCallback_004
523 * @tc.desc: 1. set pkgName not null
524 * set Callback not null
525 * 2. set checkMap null
526 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
527 * 4. Get checkMap from DeviceManagerNotify
528 * 5. check checkMap not null
529 * 6. call checkMap OnDeviceOnline
530 * 7. check count is 1
531 * @tc.type: FUNC
532 * @tc.require: AR000GHSJK
533 */
534 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_004, testing::ext::TestSize.Level0)
535 {
536 // 1. set pkgName not null
537 std::string pkgName = "com.ohos.test";
538 // set Callback not null
539 int count = 0;
540 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
541 // 2. set checkMap null
542 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
543 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
544 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
545 // 4. Get checkMap from DeviceManagerNotify
546 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
547 // 5. check checkMap not null
548 ASSERT_NE(checkMap, nullptr);
549 // 6. call checkMap OnDeviceOnline
550 DmDeviceInfo deviceInfo;
551 checkMap->OnDeviceOnline(deviceInfo);
552 // 7. check count is 1
553 ASSERT_EQ(count, 1);
554 }
555
556 /**
557 * @tc.name: RegisterDeviceStateCallback_005
558 * @tc.desc: 1. set pkgName com.ohos.test
559 * set Callback not null
560 * 2. set checkMap null
561 * 3. set testpkcName com.ohos.test1
562 * 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
563 * 5. Get checkMap from DeviceManagerNotify with testpkcName
564 * 6. check checkMap null
565 * @tc.type: FUNC
566 * @tc.require: AR000GHSJK
567 */
568 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStateCallback_005, testing::ext::TestSize.Level0)
569 {
570 // 1. set pkgName com.ohos.test
571 std::string pkgName = "com.ohos.test";
572 int count = 0;
573 // set dmInitCallback not null
574 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
575 // 2. set checkMap null
576 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
577 // 3. set testpkcName com.ohos.test1
578 std::string testPkgName = "com.ohos.test1";
579 // 4. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
580 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
581 // 5. Get checkMap from DeviceManagerNotify with testpkcName
582 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[testPkgName];
583 // 6. check checkMap not null
584 if (checkMap == nullptr) {
585 ASSERT_NE(count, 1);
586 return;
587 }
588 ASSERT_NE(checkMap, nullptr);
589 }
590
591 /**
592 * @tc.name: UnRegisterDeviceStateCallback_001
593 * @tc.desc: 1. set pkgName not null
594 * set Callback not null
595 * 2. set checkMap null
596 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
597 * 4. Get checkMap from DeviceManagerNotify
598 * 5. check checkMap not null
599 * 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter
600 * 7. Get checkMap from DeviceManagerNotify
601 * 8. check checkMap null
602 * @tc.type: FUNC
603 * @tc.require: AR000GHSJK
604 */
605 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_001, testing::ext::TestSize.Level0)
606 {
607 // 1. set pkgName not null
608 std::string pkgName = "com.ohos.test";
609 // set dmInitCallback not null
610 int count = 0;
611 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
612 // 2. set checkMap null
613 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
614 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
615 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
616 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
617 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
618 // 5. check checkMap not null
619 ASSERT_NE(checkMap, nullptr);
620 // 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter
621 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName);
622 // 7. Get checkMap from DeviceManagerNotify
623 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
624 // 8 check checkMap null
625 ASSERT_EQ(checkMap, nullptr);
626 }
627
628 /**
629 * @tc.name: UnRegisterDeviceStateCallback_002
630 * @tc.desc: 1. set pkgName com.ohos.test
631 * set Callback not null
632 * 2. set checkMap null
633 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
634 * 4. Get checkMap from DeviceManagerNotify
635 * 5. check checkMap not null
636 * 6. set testpkcName com.ohos.test1
637 * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
638 * 8. Get checkMap from DeviceManagerNotify
639 * 9. check checkMap not null
640 * @tc.type: FUNC
641 * @tc.require: AR000GHSJK
642 */
643 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_002, testing::ext::TestSize.Level0)
644 {
645 // 1. set pkgName not null
646 std::string pkgName = "com.ohos.test";
647 // set dmInitCallback not null
648 int count = 0;
649 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
650 // 2. set checkMap null
651 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
652 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
653 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
654 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
655 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
656 // 5. check checkMap not null
657 ASSERT_NE(checkMap, nullptr);
658 // 6. set testpkcName com.ohos.test1
659 std::string testPkgName = "com.ohos.test1";
660 // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
661 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
662 // 8. Get checkMap from DeviceManagerNotify
663 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
664 // 8 check checkMap not null
665 ASSERT_NE(checkMap, nullptr);
666 }
667
668 /**
669 * @tc.name: UnRegisterDeviceStateCallback_003
670 * @tc.desc: 1. set pkgName com.ohos.test
671 * set Callback not null
672 * 2. set checkMap null
673 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
674 * 4. Get checkMap from DeviceManagerNotify
675 * 5. check checkMap not null
676 * 6. set testpkcName com.ohos.test1
677 * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
678 * 8. Get checkMap from DeviceManagerNotify
679 * 9. check checkMap not null
680 * @tc.type: FUNC
681 * @tc.require: AR000GHSJK
682 */
683 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_003, testing::ext::TestSize.Level0)
684 {
685 // 1. set pkgName not null
686 std::string pkgName = "com.ohos.test";
687 // set dmInitCallback not null
688 int count = 0;
689 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
690 // 2. set checkMap null
691 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
692 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
693 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
694 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
695 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
696 // 5. check checkMap not null
697 ASSERT_NE(checkMap, nullptr);
698 // 6. set testpkcName com.ohos.test1
699 std::string testPkgName = "com.ohos.test1";
700 // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
701 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
702 // 8. Get checkMap from DeviceManagerNotify
703 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
704 // 8 check checkMap not null
705 ASSERT_NE(checkMap, nullptr);
706 // 9. call checkMap OnDeviceOnline
707 DmDeviceInfo deviceInfo;
708 checkMap->OnDeviceOnline(deviceInfo);
709 // 10. check count is 1
710 ASSERT_EQ(count, 1);
711 }
712
713 /**
714 * @tc.name: UnRegisterDeviceStateCallback_004
715 * @tc.desc: 1. set pkgName not null
716 * set Callback not null
717 * 2. set checkMap null
718 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
719 * 4. Get checkMap from DeviceManagerNotify
720 * 5. check checkMap not null
721 * 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter
722 * 7. Get checkMap from DeviceManagerNotify
723 * 8. check checkMap null
724 * @tc.type: FUNC
725 * @tc.require: AR000GHSJK
726 */
727 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_004, testing::ext::TestSize.Level0)
728 {
729 // 1. set pkgName not null
730 std::string pkgName = "com.ohos.test";
731 // set dmInitCallback not null
732 int count = 0;
733 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
734 // 2. set checkMap null
735 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
736 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
737 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
738 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
739 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
740 // 5. check checkMap not null
741 ASSERT_NE(checkMap, nullptr);
742 // 6. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with parameter
743 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(pkgName);
744 // 7. Get checkMap from DeviceManagerNotify
745 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
746 // 8 check checkMap null
747 if (checkMap == nullptr) {
748 ASSERT_NE(count, 1);
749 return;
750 }
751 ASSERT_NE(checkMap, nullptr);
752 }
753
754 /**
755 * @tc.name: UnRegisterDeviceStateCallback_005
756 * @tc.desc: 1. set pkgName com.ohos.test
757 * set Callback not null
758 * 2. set checkMap null
759 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
760 * 4. Get checkMap from DeviceManagerNotify
761 * 5. check checkMap not null
762 * 6. set testpkcName com.ohos.test1
763 * 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
764 * 8. Get checkMap from DeviceManagerNotify
765 * 9. check checkMap not null
766 * @tc.type: FUNC
767 * @tc.require: AR000GHSJK
768 */
769 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStateCallback_005, testing::ext::TestSize.Level0)
770 {
771 // 1. set pkgName not null
772 std::string pkgName = "com.ohos.test";
773 // set dmInitCallback not null
774 int count = 0;
775 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
776 // 2. set checkMap null
777 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
778 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
779 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
780 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
781 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
782 // 5. check checkMap not null
783 ASSERT_NE(checkMap, nullptr);
784 // 6. set testpkcName com.ohos.test1
785 std::string testPkgName = "";
786 // 7. call DeviceManagerNotifyTest UnRegisterDeviceStateCallback with testpkcName
787 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
788 // 8. Get checkMap from DeviceManagerNotify
789 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
790 // 8 check checkMap not null
791 ASSERT_NE(checkMap, nullptr);
792 // 9. call checkMap OnDeviceOnline
793 DmDeviceInfo deviceInfo;
794 checkMap->OnDeviceOnline(deviceInfo);
795 // 10. check count is 1
796 ASSERT_EQ(count, 1);
797 }
798
799 /**
800 * @tc.name: RegisterDiscoverCallback_001
801 * @tc.desc: 1. set pkgName not null
802 * set Callback not null
803 * set subscribeId not null
804 * 2. set checkMap null
805 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
806 * 4. Get checkMap from DeviceManagerNotify
807 * 5. check checkMap not null
808 * @tc.type: FUNC
809 * @tc.require: AR000GHSJK
810 */
811 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_001, testing::ext::TestSize.Level0)
812 {
813 // 1. set pkgName not null
814 std::string pkgName = "com.ohos.test";
815 // set dmInitCallback not null
816 int count = 0;
817 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
818 // set subscribeId not null
819 uint16_t subscribeId = 0;
820 // 2. set checkMap null
821 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
822 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
823 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
824 // 4. Get checkMap from DeviceManagerNotify
825 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
826 // 5. check checkMap not null
827 ASSERT_NE(checkMap, nullptr);
828 }
829
830 /**
831 * @tc.name: RegisterDiscoverCallback_002
832 * @tc.desc: 1. set pkgName not null
833 * set Callback null
834 * set subscribeId not null
835 * 2. set checkMap null
836 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
837 * 4. Get checkMap from DeviceManagerNotify
838 * 5. check checkMap null
839 * @tc.type: FUNC
840 * @tc.require: AR000GHSJK
841 */
842 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_002, testing::ext::TestSize.Level0)
843 {
844 // 1. set pkgName not null
845 std::string pkgName = "com.ohos.test";
846 // set dmInitCallback null
847 std::shared_ptr<DiscoveryCallback> callback = nullptr;
848 // set subscribeId not null
849 uint16_t subscribeId = 0;
850 // 2. set checkMap not null
851 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
852 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
853 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
854 // 4. Get checkMap from DeviceManagerNotify
855 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
856 // 5. check checkMap null
857 ASSERT_EQ(checkMap, nullptr);
858 }
859
860 /**
861 * @tc.name: RegisterDiscoverCallback_003
862 * @tc.desc: 1. set pkgName com.ohos.test
863 * set Callback not null
864 * set subscribeId not null
865 * 2. set checkMap null
866 * 3. set testpkcName com.ohos.test1
867 * 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
868 * 5. Get checkMap from DeviceManagerNotify with testpkcName
869 * 6. check checkMap null
870 * @tc.type: FUNC
871 * @tc.require: AR000GHSJK
872 */
873 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_003, testing::ext::TestSize.Level0)
874 {
875 // 1. set pkgName com.ohos.test
876 std::string pkgName = "com.ohos.test";
877 // set dmInitCallback not null
878 std::shared_ptr<DiscoveryCallback> callback = nullptr;
879 // set subscribeId not null
880 uint16_t subscribeId = 0;
881 // 2. set checkMap null
882 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
883 // 3. set testpkcName com.ohos.test1
884 std::string testPkgName = "com.ohos.test1";
885 // 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
886 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
887 // 5. Get checkMap from DeviceManagerNotify with testpkcName
888 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
889 // 6. check checkMap not null
890 ASSERT_EQ(checkMap, nullptr);
891 }
892
893 /**
894 * @tc.name: RegisterDiscoverCallback_004
895 * @tc.desc: 1. set pkgName not null
896 * set Callback not null
897 * set subscribeId not null
898 * 2. set checkMap null
899 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
900 * 4. Get checkMap from DeviceManagerNotify
901 * 5. check checkMap not null
902 * 6. call checkMap OnDiscoverySuccess
903 * 7. check count is 1
904 * @tc.type: FUNC
905 * @tc.require: AR000GHSJK
906 */
907 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_004, testing::ext::TestSize.Level0)
908 {
909 // 1. set pkgName not null
910 std::string pkgName = "com.ohos.test";
911 // set dmInitCallback not null
912 int count = 0;
913 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
914 // set subscribeId not null
915 uint16_t subscribeId = 0;
916 // 2. set checkMap null
917 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
918 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
919 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
920 // 4. Get checkMap from DeviceManagerNotify
921 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
922 // 5. check checkMap not null
923 ASSERT_NE(checkMap, nullptr);
924 // 6. call checkMap OnDiscoverySuccess
925 checkMap->OnDiscoverySuccess(subscribeId);
926 // 7. check count is 1
927 ASSERT_EQ(count, 1);
928 }
929
930 /**
931 * @tc.name: RegisterDiscoverCallback_005
932 * @tc.desc: 1. set pkgName com.ohos.test
933 * set Callback not null
934 * set subscribeId not null
935 * 2. set checkMap null
936 * 3. set testpkcName com.ohos.test1
937 * 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
938 * 5. Get checkMap from DeviceManagerNotify with testpkcName
939 * 6. check checkMap null
940 * @tc.type: FUNC
941 * @tc.require: AR000GHSJK
942 */
943 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_005, testing::ext::TestSize.Level0)
944 {
945 // 1. set pkgName com.ohos.test
946 std::string pkgName = "com.ohos.test";
947 int count = 0;
948 // set dmInitCallback not null
949 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
950 uint16_t subscribeId = 0;
951 // 2. set checkMap null
952 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
953 // 3. set testpkcName com.ohos.test1
954 std::string testPkgName = "com.ohos.test1";
955 // 4. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
956 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
957 // 5. Get checkMap from DeviceManagerNotify with testpkcName
958 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
959 // 6. check checkMap not null
960 if (checkMap == nullptr) {
961 ASSERT_NE(count, 1);
962 return;
963 }
964 ASSERT_NE(checkMap, nullptr);
965 }
966
967 /**
968 * @tc.name: RegisterDiscoverCallback_006
969 * @tc.type: FUNC
970 */
971 HWTEST_F(DeviceManagerNotifyTest, RegisterDiscoveryCallback_006, testing::ext::TestSize.Level0)
972 {
973 std::string pkgName;
974 int count = 0;
975 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
976 uint16_t subscribeId = 0;
977 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
978 }
979
980 /**
981 * @tc.name: UnRegisterDiscoverCallback_001
982 * @tc.desc: 1. set pkgName not null
983 * set callback not null
984 * set subscribeId not null
985 * 2. set checkMap null
986 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
987 * 4. Get checkMap from DeviceManagerNotify
988 * 5. check checkMap not null
989 * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
990 * 7. Get checkMap from DeviceManagerNotify
991 * 8. check checkMap null
992 * @tc.type: FUNC
993 * @tc.require: AR000GHSJK
994 */
995 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_001, testing::ext::TestSize.Level0)
996 {
997 // 1. set pkgName not null
998 std::string pkgName = "com.ohos.test";
999 // set dmInitCallback not null
1000 int count = 0;
1001 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1002 // set subscribeId not null
1003 uint16_t subscribeId = 0;
1004 // 2. set checkMap null
1005 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1006 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1007 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1008 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1009 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1010 // 5. check checkMap not null
1011 ASSERT_NE(checkMap, nullptr);
1012 // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1013 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
1014 // 7. Get checkMap from DeviceManagerNotify
1015 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1016 // 8 check checkMap null
1017 ASSERT_EQ(checkMap, nullptr);
1018 }
1019
1020 /**
1021 * @tc.name: UnRegisterDiscoverCallback_002
1022 * @tc.desc: 1. set pkgName com.ohos.test
1023 * set dmInitCallback not null
1024 * set subscribeId not null
1025 * 2. set checkMap null
1026 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1027 * 4. Get checkMap from DeviceManagerNotify
1028 * 5. check checkMap not null
1029 * 6. set testpkcName com.ohos.test1
1030 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1031 * 8. Get checkMap from DeviceManagerNotify
1032 * 9. check checkMap not null
1033 * @tc.type: FUNC
1034 * @tc.require: AR000GHSJK
1035 */
1036 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_002, testing::ext::TestSize.Level0)
1037 {
1038 // 1. set pkgName not null
1039 std::string pkgName = "com.ohos.test";
1040 // set dmInitCallback not null
1041 int count = 0;
1042 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1043 // set subscribeId not null
1044 uint16_t subscribeId = 0;
1045 // 2. set checkMap null
1046 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1047 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1048 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1049 // 4. Get checkMap from DeviceManagerNotify
1050 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1051 // 5. check checkMap not null
1052 ASSERT_NE(checkMap, nullptr);
1053 // 6. set testpkcName com.ohos.test1
1054 std::string testPkgName = "com.ohos.test1";
1055 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1056 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1057 // 8. Get checkMap from DeviceManagerNotify
1058 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1059 // 8 check checkMap not null
1060 ASSERT_NE(checkMap, nullptr);
1061 }
1062
1063 /**
1064 * @tc.name: UnRegisterDiscoverCallback_003
1065 * @tc.desc: 1. set pkgName com.ohos.test
1066 * set dmInitCallback not null
1067 * set subscribeId not null
1068 * 2. set checkMap null
1069 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1070 * 4. Get checkMap from DeviceManagerNotify
1071 * 5. check checkMap not null
1072 * 6. set testpkcName com.ohos.test1
1073 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1074 * 8. Get checkMap from DeviceManagerNotify
1075 * 9. check checkMap not null
1076 * 10. call checkMap OnDiscoverySuccess
1077 * 11. check count is 1
1078 * @tc.type: FUNC
1079 * @tc.require: AR000GHSJK
1080 */
1081 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_003, testing::ext::TestSize.Level0)
1082 {
1083 // 1. set pkgName not null
1084 std::string pkgName = "com.ohos.test";
1085 // set dmInitCallback not null
1086 int count = 0;
1087 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1088 // set subscribeId not null
1089 uint16_t subscribeId = 0;
1090 // 2. set checkMap null
1091 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1092 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1093 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1094 // 4. Get checkMap from DeviceManagerNotify
1095 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1096 // 5. check checkMap not null
1097 ASSERT_NE(checkMap, nullptr);
1098 // 6. set testpkcName com.ohos.test1
1099 std::string testPkgName = "com.ohos.test1";
1100 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1101 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1102 // 8. Get checkMap from DeviceManagerNotify
1103 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1104 // 9 check checkMap not null
1105 ASSERT_NE(checkMap, nullptr);
1106 // 10. call checkMap OnDiscoverySuccess
1107 checkMap->OnDiscoverySuccess(subscribeId);
1108 // 11. check count is 1
1109 ASSERT_EQ(count, 1);
1110 }
1111
1112 /**
1113 * @tc.name: UnRegisterDiscoverCallback_004
1114 * @tc.desc: 1. set pkgName not null
1115 * set callback not null
1116 * set subscribeId not null
1117 * 2. set checkMap null
1118 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1119 * 4. Get checkMap from DeviceManagerNotify
1120 * 5. check checkMap not null
1121 * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1122 * 7. Get checkMap from DeviceManagerNotify
1123 * 8. check checkMap null
1124 * @tc.type: FUNC
1125 * @tc.require: AR000GHSJK
1126 */
1127 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_004, testing::ext::TestSize.Level0)
1128 {
1129 // 1. set pkgName not null
1130 std::string pkgName = "com.ohos.test";
1131 // set dmInitCallback not null
1132 int count = 0;
1133 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1134 // set subscribeId not null
1135 uint16_t subscribeId = 0;
1136 // 2. set checkMap null
1137 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1138 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1139 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1140 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1141 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1142 // 5. check checkMap not null
1143 ASSERT_NE(checkMap, nullptr);
1144 // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1145 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
1146 // 7. Get checkMap from DeviceManagerNotify
1147 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1148 // 8 check checkMap null
1149 if (checkMap == nullptr) {
1150 ASSERT_NE(count, 1);
1151 return;
1152 }
1153 ASSERT_NE(checkMap, nullptr);
1154 }
1155
1156 /**
1157 * @tc.name: UnRegisterDiscoverCallback_005
1158 * @tc.desc: 1. set pkgName com.ohos.test
1159 * set dmInitCallback not null
1160 * set subscribeId not null
1161 * 2. set checkMap null
1162 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1163 * 4. Get checkMap from DeviceManagerNotify
1164 * 5. check checkMap not null
1165 * 6. set testpkcName com.ohos.test1
1166 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1167 * 8. Get checkMap from DeviceManagerNotify
1168 * 9. check checkMap not null
1169 * 10. call checkMap OnDiscoverySuccess
1170 * 11. check count is 1
1171 * @tc.type: FUNC
1172 * @tc.require: AR000GHSJK
1173 */
1174 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_005, testing::ext::TestSize.Level0)
1175 {
1176 // 1. set pkgName not null
1177 std::string pkgName = "com.ohos.test";
1178 // set dmInitCallback not null
1179 int count = 0;
1180 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1181 // set subscribeId not null
1182 uint16_t subscribeId = 0;
1183 // 2. set checkMap null
1184 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1185 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1186 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1187 // 4. Get checkMap from DeviceManagerNotify
1188 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1189 // 5. check checkMap not null
1190 ASSERT_NE(checkMap, nullptr);
1191 // 6. set testpkcName com.ohos.test1
1192 std::string testPkgName = "";
1193 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1194 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1195 // 8. Get checkMap from DeviceManagerNotify
1196 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1197 // 9 check checkMap not null
1198 ASSERT_NE(checkMap, nullptr);
1199 // 10. call checkMap OnDiscoverySuccess
1200 checkMap->OnDiscoverySuccess(subscribeId);
1201 // 11. check count is 1
1202 ASSERT_EQ(count, 1);
1203 }
1204
1205 /**
1206 * @tc.name: RegisterAuthenticateCallback_001
1207 * @tc.desc: 1. set pkgName not null
1208 * set Callback not null
1209 * set deviceId not null
1210 * 2. set checkMap null
1211 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1212 * 4. Get checkMap from DeviceManagerNotify
1213 * 5. check checkMap not null
1214 * @tc.type: FUNC
1215 * @tc.require: AR000GHSJK
1216 */
1217 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_001, testing::ext::TestSize.Level0)
1218 {
1219 // 1. set pkgName not null
1220 std::string pkgName = "com.ohos.test";
1221 // set dmInitCallback not null
1222 int count = 0;
1223 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1224 // set subscribeId not null
1225 std::string deviceId = "1";
1226 // 2. set checkMap null
1227 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1228 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1229 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1230 // 4. Get checkMap from DeviceManagerNotify
1231 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1232 // 5. check checkMap not null
1233 ASSERT_NE(checkMap, nullptr);
1234 }
1235
1236 /**
1237 * @tc.name: RegisterAuthenticateCallback_002
1238 * @tc.desc: 1. set pkgName not null
1239 * set Callback null
1240 * set deviceId not null
1241 * 2. set checkMap null
1242 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1243 * 4. Get checkMap from DeviceManagerNotify
1244 * 5. check checkMap null
1245 * @tc.type: FUNC
1246 * @tc.require: AR000GHSJK
1247 */
1248 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_002, testing::ext::TestSize.Level0)
1249 {
1250 // 1. set pkgName not null
1251 std::string pkgName = "com.ohos.test";
1252 // set dmInitCallback null
1253 std::shared_ptr<AuthenticateCallback> callback = nullptr;
1254 // set subscribeId not null
1255 std::string deviceId = "1";
1256 // 2. set checkMap not null
1257 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1258 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1259 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1260 // 4. Get checkMap from DeviceManagerNotify
1261 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1262 // 5. check checkMap null
1263 ASSERT_EQ(checkMap, nullptr);
1264 }
1265
1266 /**
1267 * @tc.name: RegisterAuthenticateCallback_003
1268 * @tc.desc: 1. set pkgName com.ohos.test
1269 * set Callback not null
1270 * set deviceId not null
1271 * 2. set checkMap null
1272 * 3. set testpkcName com.ohos.test1
1273 * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1274 * 5. Get checkMap from DeviceManagerNotify with testpkcName
1275 * 6. check checkMap null
1276 * @tc.type: FUNC
1277 * @tc.require: AR000GHSJK
1278 */
1279 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_003, testing::ext::TestSize.Level0)
1280 {
1281 // 1. set pkgName com.ohos.test
1282 std::string pkgName = "com.ohos.test";
1283 // set dmInitCallback not null
1284 std::shared_ptr<AuthenticateCallback> callback = nullptr;
1285 // set subscribeId not null
1286 std::string deviceId = "1";
1287 // 2. set checkMap null
1288 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1289 // 3. set testpkcName com.ohos.test1
1290 std::string testPkgName = "com.ohos.test1";
1291 // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1292 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1293 // 5. Get checkMap from DeviceManagerNotify with testpkcName
1294 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1295 // 6. check checkMap not null
1296 ASSERT_EQ(checkMap, nullptr);
1297 }
1298
1299 /**
1300 * @tc.name: RegisterAuthenticateCallback_004
1301 * @tc.desc: 1. set pkgName not null
1302 * set Callback not null
1303 * set deviceId not null
1304 * 2. set checkMap null
1305 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1306 * 4. Get checkMap from DeviceManagerNotify
1307 * 5. check checkMap not null
1308 * @tc.type: FUNC
1309 * @tc.require: AR000GHSJK
1310 */
1311 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_004, testing::ext::TestSize.Level0)
1312 {
1313 // 1. set pkgName not null
1314 std::string pkgName = "com.ohos.test";
1315 // set dmInitCallback not null
1316 int count = 0;
1317 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1318 // set subscribeId not null
1319 std::string deviceId = "1";
1320 // 2. set checkMap null
1321 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1322 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1323 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1324 // 4. Get checkMap from DeviceManagerNotify
1325 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1326 // 5. check checkMap not null
1327 ASSERT_NE(checkMap, nullptr);
1328 // 6. call checkMap OnAuthResult
1329 std::string token ="1";
1330 int32_t status = 1;
1331 int32_t reason = 1;
1332 checkMap->OnAuthResult(deviceId, token, status, reason);
1333 // 7. check count is 1
1334 ASSERT_EQ(count, 1);
1335 }
1336
1337 /**
1338 * @tc.name: RegisterAuthenticateCallback_005
1339 * @tc.desc: 1. set pkgName com.ohos.test
1340 * set Callback not null
1341 * set deviceId not null
1342 * 2. set checkMap null
1343 * 3. set testpkcName com.ohos.test1
1344 * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1345 * 5. Get checkMap from DeviceManagerNotify with testpkcName
1346 * 6. check checkMap null
1347 * @tc.type: FUNC
1348 * @tc.require: AR000GHSJK
1349 */
1350 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_005, testing::ext::TestSize.Level0)
1351 {
1352 // 1. set pkgName com.ohos.test
1353 std::string pkgName = "com.ohos.test";
1354 int count = 0;
1355 // set dmInitCallback not null
1356 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1357 // set subscribeId not null
1358 std::string deviceId = "1";
1359 // 2. set checkMap null
1360 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1361 // 3. set testpkcName com.ohos.test1
1362 std::string testPkgName = "com.ohos.test1";
1363 // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1364 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1365 // 5. Get checkMap from DeviceManagerNotify with testpkcName
1366 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1367 // 6. check checkMap not null
1368 if (checkMap == nullptr) {
1369 ASSERT_NE(count, 1);
1370 return;
1371 }
1372 ASSERT_NE(checkMap, nullptr);
1373 }
1374
1375 /**
1376 * @tc.name: UnRegisterAuthenticateCallback_001
1377 * @tc.desc: 1. set pkgName not null
1378 * set callback not null
1379 * set deviceId not null
1380 * 2. set checkMap null
1381 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1382 * 4. Get checkMap from DeviceManagerNotify
1383 * 5. check checkMap not null
1384 * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1385 * 7. Get checkMap from DeviceManagerNotify
1386 * 8. check checkMap null
1387 * @tc.type: FUNC
1388 * @tc.require: AR000GHSJK
1389 */
1390 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_001, testing::ext::TestSize.Level0)
1391 {
1392 // 1. set pkgName not null
1393 std::string pkgName = "com.ohos.test";
1394 // set dmInitCallback not null
1395 int count = 0;
1396 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1397 // set subscribeId not null
1398 std::string deviceId = "1";
1399 // 2. set checkMap null
1400 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1401 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1402 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1403 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1404 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1405 // 5. check checkMap not null
1406 ASSERT_NE(checkMap, nullptr);
1407 // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1408 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId);
1409 // 7. Get checkMap from DeviceManagerNotify
1410 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1411 // 8 check checkMap null
1412 ASSERT_EQ(checkMap, nullptr);
1413 }
1414
1415 /**
1416 * @tc.name: UnRegisterAuthenticateCallback_002
1417 * @tc.desc: 1. set pkgName com.ohos.test
1418 * set dmInitCallback not null
1419 * set subscribeId not null
1420 * 2. set checkMap null
1421 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1422 * 4. Get checkMap from DeviceManagerNotify
1423 * 5. check checkMap not null
1424 * 6. set testpkcName com.ohos.test1
1425 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1426 * 8. Get checkMap from DeviceManagerNotify
1427 * 9. check checkMap not null
1428 * @tc.type: FUNC
1429 * @tc.require: AR000GHSJK
1430 */
1431 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_002, testing::ext::TestSize.Level0)
1432 {
1433 // 1. set pkgName not null
1434 std::string pkgName = "com.ohos.test";
1435 // set dmInitCallback not null
1436 int count = 0;
1437 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1438 // set subscribeId not null
1439 std::string deviceId = "1";
1440 // 2. set checkMap null
1441 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1442 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1443 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1444 // 4. Get checkMap from DeviceManagerNotify
1445 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1446 // 5. check checkMap not null
1447 ASSERT_NE(checkMap, nullptr);
1448 // 6. set testpkcName com.ohos.test1
1449 std::string testPkgName = "com.ohos.test1";
1450 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1451 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1452 // 8. Get checkMap from DeviceManagerNotify
1453 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1454 // 8 check checkMap not null
1455 ASSERT_NE(checkMap, nullptr);
1456 }
1457
1458 /**
1459 * @tc.name: UnRegisterAuthenticateCallback_003
1460 * @tc.desc: 1. set pkgName com.ohos.test
1461 * set dmInitCallback not null
1462 * set subscribeId not null
1463 * 2. set checkMap null
1464 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1465 * 4. Get checkMap from DeviceManagerNotify
1466 * 5. check checkMap not null
1467 * 6. set testpkcName com.ohos.test1
1468 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1469 * 8. Get checkMap from DeviceManagerNotify
1470 * 9. check checkMap not null
1471 * 10. call checkMap OnAuthResult
1472 * 11. check count is 1
1473 * @tc.type: FUNC
1474 * @tc.require: AR000GHSJK
1475 */
1476 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_003, testing::ext::TestSize.Level0)
1477 {
1478 // 1. set pkgName not null
1479 std::string pkgName = "com.ohos.test";
1480 // set dmInitCallback not null
1481 int count = 0;
1482 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1483 // set subscribeId not null
1484 std::string deviceId = "1";
1485 // 2. set checkMap null
1486 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1487 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1488 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1489 // 4. Get checkMap from DeviceManagerNotify
1490 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1491 // 5. check checkMap not null
1492 ASSERT_NE(checkMap, nullptr);
1493 // 6. set testpkcName com.ohos.test1
1494 std::string testPkgName = "com.ohos.test1";
1495 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1496 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1497 // 8. Get checkMap from DeviceManagerNotify
1498 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1499 // 9 check checkMap not null
1500 ASSERT_NE(checkMap, nullptr);
1501 // 10. call checkMap OnAuthResult
1502 std::string token ="1";
1503 int32_t status = 1;
1504 int32_t reason = 1;
1505 checkMap->OnAuthResult(deviceId, token, status, reason);
1506 // 11. check count is 1
1507 ASSERT_EQ(count, 1);
1508 }
1509
1510 /**
1511 * @tc.name: UnRegisterAuthenticateCallback_004
1512 * @tc.desc: 1. set pkgName not null
1513 * set callback not null
1514 * set deviceId not null
1515 * 2. set checkMap null
1516 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1517 * 4. Get checkMap from DeviceManagerNotify
1518 * 5. check checkMap not null
1519 * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1520 * 7. Get checkMap from DeviceManagerNotify
1521 * 8. check checkMap null
1522 * @tc.type: FUNC
1523 * @tc.require: AR000GHSJK
1524 */
1525 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_004, testing::ext::TestSize.Level0)
1526 {
1527 // 1. set pkgName not null
1528 std::string pkgName = "com.ohos.test";
1529 // set dmInitCallback not null
1530 int count = 0;
1531 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1532 // set subscribeId not null
1533 std::string deviceId = "1";
1534 // 2. set checkMap null
1535 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1536 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1537 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1538 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1539 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1540 // 5. check checkMap not null
1541 ASSERT_NE(checkMap, nullptr);
1542 // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1543 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId);
1544 // 7. Get checkMap from DeviceManagerNotify
1545 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1546 // 8. check checkMap not null
1547 if (checkMap == nullptr) {
1548 ASSERT_NE(count, 1);
1549 return;
1550 }
1551 ASSERT_NE(checkMap, nullptr);
1552 }
1553
1554 /**
1555 * @tc.name: UnRegisterAuthenticateCallback_005
1556 * @tc.desc: 1. set pkgName com.ohos.test
1557 * set dmInitCallback not null
1558 * set subscribeId not null
1559 * 2. set checkMap null
1560 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1561 * 4. Get checkMap from DeviceManagerNotify
1562 * 5. check checkMap not null
1563 * 6. set testpkcName com.ohos.test1
1564 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1565 * 8. Get checkMap from DeviceManagerNotify
1566 * 9. check checkMap not null
1567 * @tc.type: FUNC
1568 * @tc.require: AR000GHSJK
1569 */
1570 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_005, testing::ext::TestSize.Level0)
1571 {
1572 // 1. set pkgName not null
1573 std::string pkgName = "com.ohos.test";
1574 // set dmInitCallback not null
1575 int count = 0;
1576 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1577 // set subscribeId not null
1578 std::string deviceId = "1";
1579 // 2. set checkMap null
1580 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1581 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1582 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1583 // 4. Get checkMap from DeviceManagerNotify
1584 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1585 // 5. check checkMap not null
1586 ASSERT_NE(checkMap, nullptr);
1587 // 6. set testpkcName com.ohos.test1
1588 std::string testPkgName = "";
1589 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1590 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1591 // 8. Get checkMap from DeviceManagerNotify
1592 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1593 // 8 check checkMap not null
1594 ASSERT_NE(checkMap, nullptr);
1595 }
1596
1597 /**
1598 * @tc.name: UnRegisterPackageCallback_001
1599 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1600 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1601 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1602 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1603 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1604 * 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1605 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1606 * @tc.type: FUNC
1607 * @tc.require: AR000GHSJK
1608 */
1609 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_001, testing::ext::TestSize.Level0)
1610 {
1611 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1612 std::string pkgName = "com.ohos.test";
1613 int count = 0;
1614 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1615 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1616 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1617 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1618 ASSERT_NE(checkMap, nullptr);
1619 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1620 int count1 = 0;
1621 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1622 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1623 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1624 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1625 ASSERT_NE(checkMap1, nullptr);
1626 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1627 int count2 = 0;
1628 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1629 uint16_t subscribeId = 0;
1630 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1631 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1632 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1633 ASSERT_NE(checkMap2, nullptr);
1634 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1635 int count3 = 0;
1636 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1637 std::string deviceId = "1";
1638 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1639 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1640 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1641 ASSERT_NE(checkMap3, nullptr);
1642 // 5. RegisterPublishCallback with pkgName and deviceStateCallback and subscribeId
1643 int count4 = 0;
1644 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1645 int32_t publishId = 0;
1646 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1647 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1648 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1649 ASSERT_NE(checkMap4, nullptr);
1650 // 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1651 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
1652 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1653 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1654 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1655 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1656 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1657 // 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1658 ASSERT_EQ(checkMap, nullptr);
1659 ASSERT_EQ(checkMap1, nullptr);
1660 ASSERT_EQ(checkMap2, nullptr);
1661 ASSERT_EQ(checkMap3, nullptr);
1662 ASSERT_EQ(checkMap4, nullptr);
1663 }
1664
1665 /**
1666 * @tc.name: UnRegisterPackageCallback_002
1667 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1668 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1669 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1670 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1671 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1672 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1673 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1674 * @tc.type: FUNC
1675 * @tc.require: AR000GHSJK
1676 */
1677 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_002, testing::ext::TestSize.Level0)
1678 {
1679 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1680 std::string pkgName = "com.ohos.test";
1681 int count = 0;
1682 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1683 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1684 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1685 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1686 ASSERT_NE(checkMap, nullptr);
1687 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1688 int count1 = 0;
1689 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1690 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1691 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1692 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1693 ASSERT_NE(checkMap1, nullptr);
1694 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1695 int count2 = 0;
1696 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1697 uint16_t subscribeId = 0;
1698 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1699 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1700 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1701 ASSERT_NE(checkMap2, nullptr);
1702 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1703 int count3 = 0;
1704 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1705 std::string deviceId = "1";
1706 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1707 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1708 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1709 ASSERT_NE(checkMap3, nullptr);
1710 // 5. RegisterPublishCallback with pkgName and deviceStateCallback and publishId
1711 int count4 = 0;
1712 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1713 int32_t publishId = 0;
1714 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1715 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1716 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1717 ASSERT_NE(checkMap4, nullptr);
1718 // 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1719 std::string testPkgName = "com.ohos.test1";
1720 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1721 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1722 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1723 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1724 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1725 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1726 // 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1727 ASSERT_NE(checkMap, nullptr);
1728 ASSERT_NE(checkMap1, nullptr);
1729 ASSERT_NE(checkMap2, nullptr);
1730 ASSERT_NE(checkMap3, nullptr);
1731 ASSERT_NE(checkMap4, nullptr);
1732 }
1733
1734 /**
1735 * @tc.name: UnRegisterPackageCallback_003
1736 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1737 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1738 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1739 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1740 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1741 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1742 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1743 * @tc.type: FUNC
1744 * @tc.require: AR000GHSJK
1745 */
1746 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_003, testing::ext::TestSize.Level0)
1747 {
1748 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1749 std::string pkgName = "com.ohos.test";
1750 int count[5] = {0, 0, 0, 0, 0};
1751 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count[0]);
1752 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1753 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1754 ASSERT_NE(DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName], nullptr);
1755 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1756 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count[1]);
1757 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1758 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1759 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName], nullptr);
1760 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1761 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count[2]);
1762 uint16_t subscribeId = 0;
1763 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1764 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1765 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId], nullptr);
1766 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1767 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count[3]);
1768 std::string deviceId = "1";
1769 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1770 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1771 ASSERT_NE(DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId], nullptr);
1772 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1773 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count[4]);
1774 int32_t publishId = 0;
1775 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1776 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1777 ASSERT_NE(DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId], nullptr);
1778 // 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1779 std::string testPkgName = "com.ohos.test1";
1780 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1781 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1782 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1783 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1784 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1785 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1786 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1787 ASSERT_NE(checkMap, nullptr);
1788 ASSERT_NE(checkMap1, nullptr);
1789 ASSERT_NE(checkMap2, nullptr);
1790 ASSERT_NE(checkMap3, nullptr);
1791 ASSERT_NE(checkMap4, nullptr);
1792 // 7. call checkMap OnRemoteDied()
1793 checkMap->OnRemoteDied();
1794 // call checkMap1 OnDeviceOnline
1795 DmDeviceInfo deviceInfo;
1796 checkMap1->OnDeviceOnline(deviceInfo);
1797 // call checkMap2 OnDeviceFound
1798 checkMap2->OnDeviceFound(subscribeId, deviceInfo);
1799 // call checkMap3 OnAuthResult
1800 checkMap3->OnAuthResult(deviceId, "1", 1, 1);
1801 // call checkMap4 OnPublishResult
1802 checkMap4->OnPublishResult(publishId, 0);
1803 // 8. check count count1 count2 count3 is 1
1804 for (uint32_t i = 0; i < 5; i++) {
1805 ASSERT_EQ(count[i], 1);
1806 }
1807 }
1808
1809 /**
1810 * @tc.name: UnRegisterPackageCallback_004
1811 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1812 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1813 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1814 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1815 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1816 * 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1817 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1818 * @tc.type: FUNC
1819 * @tc.require: AR000GHSJK
1820 */
1821 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_004, testing::ext::TestSize.Level0)
1822 {
1823 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1824 std::string pkgName = "com.ohos.test";
1825 int count[5] = {0, 0, 0, 0, 0};
1826 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count[0]);
1827 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1828 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1829 ASSERT_NE(DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName], nullptr);
1830 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1831 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count[1]);
1832 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1833 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1834 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName], nullptr);
1835 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1836 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count[2]);
1837 uint16_t subscribeId = 0;
1838 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1839 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1840 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId], nullptr);
1841 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1842 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count[3]);
1843 std::string deviceId = "1";
1844 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1845 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1846 ASSERT_NE(DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId], nullptr);
1847 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1848 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count[4]);
1849 int32_t publishId = 0;
1850 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1851 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1852 ASSERT_NE(DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId], nullptr);
1853 // 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1854 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
1855 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1856 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1857 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1858 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1859 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1860 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1861 if (checkMap == nullptr && checkMap1 == nullptr && checkMap2 == nullptr && checkMap3 == nullptr &&
1862 checkMap4 == nullptr) {
1863 for (uint32_t i = 0; i < 5; i++) {
1864 ASSERT_NE(count[i], 1);
1865 }
1866 return;
1867 }
1868 ASSERT_EQ(checkMap, nullptr);
1869 ASSERT_EQ(checkMap1, nullptr);
1870 ASSERT_EQ(checkMap2, nullptr);
1871 ASSERT_EQ(checkMap3, nullptr);
1872 ASSERT_EQ(checkMap4, nullptr);
1873 }
1874
1875 /**
1876 * @tc.name: UnRegisterPackageCallback_005
1877 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1878 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1879 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1880 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1881 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1882 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1883 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1884 * @tc.type: FUNC
1885 * @tc.require: AR000GHSJK
1886 */
1887 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_005, testing::ext::TestSize.Level0)
1888 {
1889 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1890 std::string pkgName = "com.ohos.test";
1891 int count = 0;
1892 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1893 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1894 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1895 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1896 ASSERT_NE(checkMap, nullptr);
1897 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1898 int count1 = 0;
1899 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1900 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1901 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1902 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1903 ASSERT_NE(checkMap1, nullptr);
1904 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1905 int count2 = 0;
1906 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1907 uint16_t subscribeId = 0;
1908 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1909 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1910 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1911 ASSERT_NE(checkMap2, nullptr);
1912 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1913 int count3 = 0;
1914 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1915 std::string deviceId = "1";
1916 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1917 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1918 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1919 ASSERT_NE(checkMap3, nullptr);
1920 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1921 int count4 = 0;
1922 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1923 int32_t publishId = 0;
1924 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1925 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1926 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][subscribeId];
1927 ASSERT_NE(checkMap4, nullptr);
1928 // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1929 std::string testPkgName = "";
1930 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1931 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1932 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1933 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1934 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1935 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1936 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1937 ASSERT_NE(checkMap, nullptr);
1938 ASSERT_NE(checkMap1, nullptr);
1939 ASSERT_NE(checkMap2, nullptr);
1940 ASSERT_NE(checkMap3, nullptr);
1941 ASSERT_NE(checkMap4, nullptr);
1942 }
1943
1944 /**
1945 * @tc.name: UnRegisterPackageCallback_005
1946 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1947 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1948 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1949 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1950 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1951 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1952 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1953 * @tc.type: FUNC
1954 * @tc.require: AR000GHSJK
1955 */
1956 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_006, testing::ext::TestSize.Level0)
1957 {
1958 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1959 std::string pkgName;
1960 int count = 0;
1961 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1962 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1963 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1964 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1965 ASSERT_EQ(checkMap, nullptr);
1966 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1967 int count1 = 0;
1968 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1969 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1970 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1971 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1972 ASSERT_EQ(checkMap1, nullptr);
1973 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1974 int count2 = 0;
1975 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1976 uint16_t subscribeId = 0;
1977 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1978 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1979 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1980 ASSERT_EQ(checkMap2, nullptr);
1981 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1982 int count3 = 0;
1983 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1984 std::string deviceId = "1";
1985 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1986 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1987 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1988 ASSERT_EQ(checkMap3, nullptr);
1989 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1990 int count4 = 0;
1991 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1992 int32_t publishId = 0;
1993 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1994 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1995 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][subscribeId];
1996 ASSERT_EQ(checkMap4, nullptr);
1997 // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1998 std::string testPkgName = "";
1999 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
2000 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
2001 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2002 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
2003 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
2004 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
2005 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
2006 ASSERT_EQ(checkMap, nullptr);
2007 ASSERT_EQ(checkMap1, nullptr);
2008 ASSERT_EQ(checkMap2, nullptr);
2009 ASSERT_EQ(checkMap3, nullptr);
2010 ASSERT_EQ(checkMap4, nullptr);
2011 }
2012
2013 /*
2014 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2015 * Function: DeviceManagerNotifyTest
2016 * SubFunction: RegisterDeviceManagerFaCallback
2017 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2018 * EnvConditions: RegisterDeviceManagerFaCallback success.
2019 * CaseDescription: 1. set pkgName not null
2020 * set dmUiCallback_ not null
2021 * 2. set checkMap null
2022 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2023 * 4. Get checkMap from DeviceManagerNotify
2024 * 5. check checkMap not null
2025 */
2026 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0)
2027 {
2028 // 1. set pkgName not null
2029 std::string pkgName = "com.ohos.test";
2030 // set dmUiCallback_ not null
2031 int count = 0;
2032 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2033 // 2. set checkMap null
2034 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2035 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2036 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2037 // 4. Get checkMap from DeviceManagerNotify
2038 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2039 // 5. check checkMap not null
2040 ASSERT_NE(checkMap, nullptr);
2041 }
2042
2043 /*
2044 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2045 * Function: DeviceManagerNotifyTest
2046 * SubFunction: RegisterDeviceManagerFaCallback
2047 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2048 * EnvConditions: N/A.
2049 * CaseDescription: 1. set pkgName not null
2050 * set dmUiCallback_ null
2051 * 2. set checkMap null
2052 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2053 * 4. Get checkMap from DeviceManagerNotify
2054 * 5. check checkMap null
2055 */
2056 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0)
2057 {
2058 // 1. set pkgName not null
2059 std::string pkgName = "com.ohos.test";
2060 // set dmInitCallback null
2061 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr;
2062 // 2. set checkMap not null
2063 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2064 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2065 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2066 // 4. Get checkMap from DeviceManagerNotify
2067 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2068 // 5. check checkMap null
2069 ASSERT_EQ(checkMap, nullptr);
2070 }
2071
2072 /*
2073 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2074 * Function: DeviceManagerNotifyTest
2075 * SubFunction: RegisterDeviceManagerFaCallback
2076 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2077 * EnvConditions: N/A.
2078 * CaseDescription: 1. set pkgName com.ohos.test
2079 * set dmUiCallback_ not null
2080 * 2. set checkMap null
2081 * 3. set testpkcName com.ohos.test1
2082 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2083 * 5. Get checkMap from DeviceManagerNotify with testpkcName
2084 * 6. check checkMap null
2085 */
2086 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0)
2087 {
2088 // 1. set pkgName com.ohos.test
2089 std::string pkgName = "com.ohos.test";
2090 // set dmInitCallback not null
2091 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr;
2092 // 2. set checkMap null
2093 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2094 // 3. set testpkcName com.ohos.test1
2095 std::string testPkgName = "com.ohos.test1";
2096 // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2097 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2098 // 5. Get checkMap from DeviceManagerNotify with testpkcName
2099 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName];
2100 // 6. check checkMap not null
2101 ASSERT_EQ(checkMap, nullptr);
2102 }
2103
2104 /*
2105 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2106 * Function: DeviceManagerNotifyTest
2107 * SubFunction: RegisterDeviceManagerFaCallback
2108 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2109 * EnvConditions: RegisterDeviceManagerFaCallback success.
2110 * CaseDescription: 1. set pkgName not null
2111 * set dmUiCallback_ not null
2112 * 2. set checkMap null
2113 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2114 * 4. Get checkMap from DeviceManagerNotify
2115 * 5. check checkMap not null
2116 */
2117 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0)
2118 {
2119 // 1. set pkgName not null
2120 std::string pkgName = "com.ohos.test";
2121 // set dmUiCallback_ not null
2122 int count = 0;
2123 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2124 // 2. set checkMap null
2125 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2126 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2127 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2128 // 4. Get checkMap from DeviceManagerNotify
2129 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2130 // 5. check checkMap not null
2131 ASSERT_NE(checkMap, nullptr);
2132 // 6. call checkMap OnCall
2133 std::string paramJson = "test";
2134 checkMap->OnCall(paramJson);
2135 ASSERT_EQ(count, 1);
2136 }
2137
2138 /*
2139 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2140 * Function: DeviceManagerNotifyTest
2141 * SubFunction: RegisterDeviceManagerFaCallback
2142 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2143 * EnvConditions: N/A.
2144 * CaseDescription: 1. set pkgName com.ohos.test
2145 * set dmUiCallback_ not null
2146 * 2. set checkMap null
2147 * 3. set testpkcName com.ohos.test1
2148 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2149 * 5. Get checkMap from DeviceManagerNotify with testpkcName
2150 * 6. check checkMap null
2151 */
2152 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0)
2153 {
2154 // 1. set pkgName com.ohos.test
2155 std::string pkgName = "com.ohos.test";
2156 // set dmInitCallback not null
2157 int count = 0;
2158 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2159 // 2. set checkMap null
2160 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2161 // 3. set testpkcName com.ohos.test1
2162 std::string testPkgName = "com.ohos.test1";
2163 // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2164 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2165 // 5. Get checkMap from DeviceManagerNotify with testpkcName
2166 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName];
2167 // 6. check checkMap not null
2168 if (checkMap == nullptr) {
2169 ASSERT_NE(count, 1);
2170 return;
2171 }
2172 ASSERT_EQ(checkMap, nullptr);
2173 }
2174
2175 /*
2176 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2177 * Function: DeviceManagerNotifyTest
2178 * SubFunction: UnRegisterDeviceManagerFaCallback
2179 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2180 * EnvConditions: UnRegisterDeviceManagerFaCallback success.
2181 * CaseDescription: 1. set pkgName not null
2182 * set dmUiCallback_ not null
2183 * 2. set checkMap null
2184 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2185 * 4. Get checkMap from DeviceManagerNotify
2186 * 5. check checkMap not null
2187 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2188 * 7. Get checkMap from DeviceManagerNotify
2189 * 8. check checkMap null
2190 */
2191 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0)
2192 {
2193 // 1. set pkgName not null
2194 std::string pkgName = "com.ohos.test";
2195 // set dmInitCallback not null
2196 int count = 0;
2197 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2198 // 2. set checkMap null
2199 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2200 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2201 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2202 // 4. Get checkMap from DeviceManagerNotify
2203 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2204 // 5. check checkMap not null
2205 ASSERT_NE(checkMap, nullptr);
2206 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2207 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
2208 // 7. Get checkMap from DeviceManagerNotify
2209 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2210 // 8 check checkMap null
2211 ASSERT_EQ(checkMap, nullptr);
2212 }
2213
2214 /*
2215 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2216 * Function: DeviceManagerNotifyTest
2217 * SubFunction: UnRegisterDeviceManagerFaCallback
2218 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2219 * EnvConditions: N/A.
2220 * CaseDescription: 1. set pkgName com.ohos.test
2221 * set dmInitCallback not null
2222 * 2. set checkMap null
2223 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2224 * 4. Get checkMap from DeviceManagerNotify
2225 * 5. check checkMap not null
2226 * 6. set testpkcName com.ohos.test1
2227 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2228 * 8. Get checkMap from DeviceManagerNotify
2229 * 9. check checkMap not null
2230 */
2231 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0)
2232 {
2233 // 1. set pkgName not null
2234 std::string pkgName = "com.ohos.test";
2235 // set dmUiCallback_ not null
2236 int count = 0;
2237 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2238 // 2. set checkMap null
2239 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2240 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2241 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2242 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2243 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2244 // 5. check checkMap not null
2245 ASSERT_NE(checkMap, nullptr);
2246 // 6. set testpkcName com.ohos.test1
2247 std::string testPkgName = "com.ohos.test1";
2248 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2249 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2250 // 8. Get checkMap from DeviceManagerNotify
2251 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2252 // 8 check checkMap not null
2253 ASSERT_NE(checkMap, nullptr);
2254 }
2255
2256 /*
2257 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_003
2258 * Function: DeviceManagerNotifyTest
2259 * SubFunction: UnRegisterDeviceManagerFaCallback
2260 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2261 * EnvConditions: N/A.
2262 * CaseDescription: 1. set pkgName com.ohos.test
2263 * set dmInitCallback not null
2264 * 2. set checkMap null
2265 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2266 * 4. Get checkMap from DeviceManagerNotify
2267 * 5. check checkMap not null
2268 * 6. set testpkcName com.ohos.test1
2269 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2270 * 8. Get checkMap from DeviceManagerNotify
2271 * 9. check checkMap not null
2272 */
2273 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0)
2274 {
2275 // 1. set pkgName not null
2276 std::string pkgName = "com.ohos.test";
2277 // set dmUiCallback_ not null
2278 int count = 0;
2279 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2280 // 2. set checkMap null
2281 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2282 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2283 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2284 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2285 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2286 // 5. check checkMap not null
2287 ASSERT_NE(checkMap, nullptr);
2288 // 6. set testpkcName com.ohos.test1
2289 std::string testPkgName = "com.ohos.test1";
2290 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2291 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2292 // 8. Get checkMap from DeviceManagerNotify
2293 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2294 // 9. check checkMap not null
2295 ASSERT_NE(checkMap, nullptr);
2296 // 10. call checkMap OnCall
2297 std::string paramJson = "test";
2298 checkMap->OnCall(paramJson);
2299 ASSERT_EQ(count, 1);
2300 }
2301
2302 /*
2303 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_004
2304 * Function: DeviceManagerNotifyTest
2305 * SubFunction: UnRegisterDeviceManagerFaCallback
2306 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2307 * EnvConditions: UnRegisterDeviceManagerFaCallback success.
2308 * CaseDescription: 1. set pkgName not null
2309 * set dmUiCallback_ not null
2310 * 2. set checkMap null
2311 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2312 * 4. Get checkMap from DeviceManagerNotify
2313 * 5. check checkMap not null
2314 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2315 * 7. Get checkMap from DeviceManagerNotify
2316 * 8. check checkMap null
2317 */
2318 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0)
2319 {
2320 // 1. set pkgName not null
2321 std::string pkgName = "com.ohos.test";
2322 // set dmInitCallback not null
2323 int count = 0;
2324 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2325 // 2. set checkMap null
2326 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2327 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2328 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2329 // 4. Get checkMap from DeviceManagerNotify
2330 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2331 // 5. check checkMap not null
2332 ASSERT_NE(checkMap, nullptr);
2333 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2334 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
2335 // 7. Get checkMap from DeviceManagerNotify
2336 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2337 // 8 check checkMap null
2338 if (checkMap == nullptr) {
2339 ASSERT_NE(count, 1);
2340 return;
2341 }
2342 ASSERT_EQ(checkMap, nullptr);
2343 }
2344
2345 /*
2346 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_005
2347 * Function: DeviceManagerNotifyTest
2348 * SubFunction: UnRegisterDeviceManagerFaCallback
2349 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2350 * EnvConditions: N/A.
2351 * CaseDescription: 1. set pkgName com.ohos.test
2352 * set dmInitCallback not null
2353 * 2. set checkMap null
2354 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2355 * 4. Get checkMap from DeviceManagerNotify
2356 * 5. check checkMap not null
2357 * 6. set testpkcName com.ohos.test1
2358 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2359 * 8. Get checkMap from DeviceManagerNotify
2360 * 9. check checkMap not null
2361 */
2362 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0)
2363 {
2364 // 1. set pkgName not null
2365 std::string pkgName = "com.ohos.test";
2366 // set dmUiCallback_ not null
2367 int count = 0;
2368 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2369 // 2. set checkMap null
2370 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2371 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2372 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2373 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2374 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2375 // 5. check checkMap not null
2376 ASSERT_NE(checkMap, nullptr);
2377 // 6. set testpkcName com.ohos.test1
2378 std::string testPkgName = "";
2379 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2380 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2381 // 8. Get checkMap from DeviceManagerNotify
2382 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2383 // 9. check checkMap not null
2384 ASSERT_NE(checkMap, nullptr);
2385 // 10. call checkMap OnCall
2386 std::string paramJson = "test";
2387 checkMap->OnCall(paramJson);
2388 ASSERT_EQ(count, 1);
2389 }
2390
2391 /*
2392 * Feature: DeviceManagerNotifyTest OnRemoteDied
2393 * Function: DeviceManagerNotifyTest
2394 * SubFunction: OnRemoteDied
2395 * FunctionPoints: DeviceManagerNotifyTest OnRemoteDied
2396 * EnvConditions: OnRemoteDied success.
2397 * CaseDescription: 1. set pkgName not null
2398 * set dmInitCallback not null
2399 * 2. set checkMap null
2400 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
2401 * 4. Get checkMap from DeviceManagerNotify
2402 * 5. check checkMap not null
2403 * 6. call DeviceManagerNotify OnRemoteDied
2404 * 7. check if dmInitCallback OnRemoteDied called.
2405 */
2406 HWTEST_F(DeviceManagerNotifyTest, OnRemoteDied1, testing::ext::TestSize.Level0)
2407 {
2408 // 1. set pkgName not null
2409 std::string pkgName = "com.ohos.test";
2410 // set dmInitCallback not null
2411 int count = 0;
2412 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
2413 // 2. set checkMap null
2414 std::shared_ptr<DmInitCallback> checkMap = nullptr;
2415 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
2416 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
2417 // 4. Get checkMap from DeviceManagerNotify
2418 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
2419 // 5. check checkMap not null
2420 ASSERT_NE(checkMap, nullptr);
2421 // 6. call DeviceManagerNotify OnRemoteDied
2422 DeviceManagerNotify::GetInstance().OnRemoteDied();
2423 // 7. check if dmInitCallback OnRemoteDied called
2424 ASSERT_EQ(count, 1);
2425 }
2426
2427 /*
2428 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2429 * Function: DeviceManagerNotifyTest
2430 * SubFunction: OnDeviceOnline
2431 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2432 * EnvConditions: OnDeviceOnline success.
2433 * CaseDescription: 1. set pkgName not null
2434 * set Callback not null
2435 * 2. set checkMap null
2436 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2437 * 4. Get checkMap from DeviceManagerNotify
2438 * 5. check checkMap not null
2439 * 6. call DeviceManagerNotify OnDeviceOnline
2440 * 7. check if callback OnDeviceOnline called.
2441 */
2442 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_001, testing::ext::TestSize.Level0)
2443 {
2444 // 1. set pkgName not null
2445 std::string pkgName = "com.ohos.test";
2446 // set Callback not null
2447 int count = 0;
2448 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2449 // 2. set checkMap null
2450 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2451 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2452 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2453 // 4. Get checkMap from DeviceManagerNotify
2454 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2455 // 5. check checkMap not null
2456 ASSERT_NE(checkMap, nullptr);
2457 // 6. call DeviceManagerNotify OnDeviceOnline
2458 DmDeviceInfo deviceInfo;
2459 DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo);
2460 // 7. check if callback OnDeviceOnline called
2461 ASSERT_EQ(count, 1);
2462 }
2463
2464 /*
2465 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2466 * Function: DeviceManagerNotifyTest
2467 * SubFunction: OnDeviceOnline
2468 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2469 * EnvConditions: N/A.
2470 * CaseDescription: 1. set pkgName not null
2471 * set Callback not null
2472 * 2. set checkMap null
2473 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2474 * 4. Get checkMap from DeviceManagerNotify
2475 * 5. check checkMap not null
2476 * 6. set testpkcName com.ohos.test1
2477 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2478 * 8. check if callback OnDeviceOnline called.
2479 */
2480 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Level0)
2481 {
2482 // 1. set pkgName not null
2483 std::string pkgName = "com.ohos.test";
2484 // set Callback not null
2485 int count = 0;
2486 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2487 // 2. set checkMap null
2488 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2489 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2490 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2491 // 4. Get checkMap from DeviceManagerNotify
2492 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2493 // 5. check checkMap not null
2494 ASSERT_NE(checkMap, nullptr);
2495 // 6. set testpkcName com.ohos.test1
2496 std::string testPkgName = "com.ohos.test1";
2497 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2498 DmDeviceInfo deviceInfo;
2499 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2500 // 8. check if callback OnDeviceOnline called
2501 ASSERT_EQ(count, 0);
2502 }
2503
2504 /*
2505 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2506 * Function: DeviceManagerNotifyTest
2507 * SubFunction: OnDeviceOnline
2508 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2509 * EnvConditions: N/A.
2510 * CaseDescription: 1. set pkgName not null
2511 * set Callback not null
2512 * 2. set checkMap null
2513 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2514 * 4. Get checkMap from DeviceManagerNotify
2515 * 5. check checkMap not null
2516 * 6. set testpkcName com.ohos.test1
2517 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2518 * 8. check if callback OnDeviceOnline called.
2519 */
2520 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_003, testing::ext::TestSize.Level0)
2521 {
2522 // 1. set pkgName not null
2523 std::string pkgName = "com.ohos.test";
2524 // set Callback not null
2525 int count = 0;
2526 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2527 // 2. set checkMap null
2528 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2529 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2530 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2531 // 4. Get checkMap from DeviceManagerNotify
2532 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2533 // 5. check checkMap not null
2534 ASSERT_NE(checkMap, nullptr);
2535 // 6. set testpkcName com.ohos.test1
2536 std::string testPkgName = "";
2537 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2538 DmDeviceInfo deviceInfo;
2539 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2540 // 8. check if callback OnDeviceOnline called
2541 ASSERT_EQ(count, 0);
2542 }
2543
2544 /*
2545 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2546 * Function: DeviceManagerNotifyTest
2547 * SubFunction: OnDeviceOnline
2548 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2549 * EnvConditions: N/A.
2550 * CaseDescription: 1. set pkgName not null
2551 * set Callback not null
2552 * 2. set checkMap null
2553 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2554 * 4. Get checkMap from DeviceManagerNotify
2555 * 5. check checkMap not null
2556 * 6. set testpkcName com.ohos.test1
2557 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2558 * 8. check if callback OnDeviceOnline called.
2559 */
2560 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_004, testing::ext::TestSize.Level0)
2561 {
2562 // 1. set pkgName not null
2563 std::string pkgName = "com.ohos.test";
2564 // set Callback not null
2565 int count = 0;
2566 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2567 // 2. set checkMap null
2568 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2569 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2570 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2571 // 4. Get checkMap from DeviceManagerNotify
2572 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2573 // 5. check checkMap not null
2574 ASSERT_NE(checkMap, nullptr);
2575 // 6. set testpkcName com.ohos.test1
2576 std::string testPkgName = "111";
2577 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2578 DmDeviceInfo deviceInfo;
2579 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2580 // 8. check if callback OnDeviceOnline called
2581 ASSERT_NE(count, 1);
2582 }
2583
2584 /*
2585 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2586 * Function: DeviceManagerNotifyTest
2587 * SubFunction: OnDeviceOnline
2588 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2589 * EnvConditions: N/A.
2590 * CaseDescription: 1. set pkgName not null
2591 * set Callback not null
2592 * 2. set checkMap null
2593 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2594 * 4. Get checkMap from DeviceManagerNotify
2595 * 5. check checkMap not null
2596 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2597 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2598 * 8. check if callback OnDeviceOnline called
2599 */
2600 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_005, testing::ext::TestSize.Level0)
2601 {
2602 // 1. set pkgName not null
2603 std::string pkgName = "com.ohos.test";
2604 // set Callback not null
2605 int count = 0;
2606 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2607 // 2. set checkMap null
2608 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2609 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2610 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2611 // 4. Get checkMap from DeviceManagerNotify
2612 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2613 // 5. check checkMap not null
2614 ASSERT_NE(checkMap, nullptr);
2615 std::string testPkgName = "";
2616 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2617 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
2618 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2619 DmDeviceInfo deviceInfo;
2620 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2621 // 8. check if callback OnDeviceOnline called
2622 ASSERT_EQ(count, 0);
2623 }
2624
2625 /*
2626 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2627 * Function: DeviceManagerNotifyTest
2628 * SubFunction: OnDeviceOffline
2629 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2630 * EnvConditions: OnDeviceOffline success.
2631 * CaseDescription: 1. set pkgName not null
2632 * set Callback not null
2633 * 2. set checkMap null
2634 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2635 * 4. Get checkMap from DeviceManagerNotify
2636 * 5. check checkMap not null
2637 * 6. call DeviceManagerNotify OnDeviceOffline
2638 * 7. check if callback OnDeviceOffline called.
2639 */
2640 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_001, testing::ext::TestSize.Level0)
2641 {
2642 // 1. set pkgName not null
2643 std::string pkgName = "com.ohos.test";
2644 // set Callback not null
2645 int count = 0;
2646 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2647 // 2. set checkMap null
2648 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2649 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2650 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2651 // 4. Get checkMap from DeviceManagerNotify
2652 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2653 // 5. check checkMap not null
2654 ASSERT_NE(checkMap, nullptr);
2655 // 6. call DeviceManagerNotify OnDeviceOffline
2656 DmDeviceInfo deviceInfo;
2657 DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo);
2658 // 7. check if callback OnDeviceOffline called
2659 ASSERT_EQ(count, 1);
2660 }
2661
2662 /*
2663 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2664 * Function: DeviceManagerNotifyTest
2665 * SubFunction: OnDeviceOffline
2666 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2667 * EnvConditions: N/A.
2668 * CaseDescription: 1. set pkgName not null
2669 * set Callback not null
2670 * 2. set checkMap null
2671 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2672 * 4. Get checkMap from DeviceManagerNotify
2673 * 5. check checkMap not null
2674 * 6. set testpkcName com.ohos.test1
2675 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2676 * 8. check if callback OnDeviceOffline called.
2677 */
2678 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Level0)
2679 {
2680 // 1. set pkgName not null
2681 std::string pkgName = "com.ohos.test";
2682 // set Callback not null
2683 int count = 0;
2684 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2685 // 2. set checkMap null
2686 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2687 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2688 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2689 // 4. Get checkMap from DeviceManagerNotify
2690 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2691 // 5. check checkMap not null
2692 ASSERT_NE(checkMap, nullptr);
2693 // 6. set testpkcName com.ohos.test1
2694 std::string testPkgName = "com.ohos.test1";
2695 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2696 DmDeviceInfo deviceInfo;
2697 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2698 // 8. check if callback OnDeviceOffline called
2699 ASSERT_EQ(count, 0);
2700 }
2701
2702 /*
2703 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2704 * Function: DeviceManagerNotifyTest
2705 * SubFunction: OnDeviceOffline
2706 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2707 * EnvConditions: N/A.
2708 * CaseDescription: 1. set pkgName not null
2709 * set Callback not null
2710 * 2. set checkMap null
2711 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2712 * 4. Get checkMap from DeviceManagerNotify
2713 * 5. check checkMap not null
2714 * 6. set testpkcName com.ohos.test1
2715 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2716 * 8. check if callback OnDeviceOffline called.
2717 */
2718 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_003, testing::ext::TestSize.Level0)
2719 {
2720 // 1. set pkgName not null
2721 std::string pkgName = "com.ohos.test";
2722 // set Callback not null
2723 int count = 0;
2724 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2725 // 2. set checkMap null
2726 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2727 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2728 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2729 // 4. Get checkMap from DeviceManagerNotify
2730 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2731 // 5. check checkMap not null
2732 ASSERT_NE(checkMap, nullptr);
2733 // 6. set testpkcName null
2734 std::string testPkgName = "";
2735 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2736 DmDeviceInfo deviceInfo;
2737 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2738 // 8. check if callback OnDeviceOffline called
2739 ASSERT_EQ(count, 0);
2740 }
2741
2742 /*
2743 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2744 * Function: DeviceManagerNotifyTest
2745 * SubFunction: OnDeviceOffline
2746 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2747 * EnvConditions: N/A.
2748 * CaseDescription: 1. set pkgName not null
2749 * set Callback not null
2750 * 2. set checkMap null
2751 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2752 * 4. Get checkMap from DeviceManagerNotify
2753 * 5. check checkMap not null
2754 * 6. set testpkcName com.ohos.test1
2755 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2756 * 8. check if callback OnDeviceOffline called.
2757 */
2758 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_004, testing::ext::TestSize.Level0)
2759 {
2760 // 1. set pkgName not null
2761 std::string pkgName = "com.ohos.test";
2762 // set Callback not null
2763 int count = 0;
2764 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2765 // 2. set checkMap null
2766 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2767 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2768 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2769 // 4. Get checkMap from DeviceManagerNotify
2770 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2771 // 5. check checkMap not null
2772 ASSERT_NE(checkMap, nullptr);
2773 // 6. set testpkcName null
2774 std::string testPkgName = "";
2775 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2776 DmDeviceInfo deviceInfo;
2777 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2778 // 8. check if callback OnDeviceOffline called
2779 ASSERT_NE(count, 1);
2780 }
2781
2782 /*
2783 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2784 * Function: DeviceManagerNotifyTest
2785 * SubFunction: OnDeviceOffline
2786 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2787 * EnvConditions: N/A.
2788 * CaseDescription: 1. set pkgName not null
2789 * set Callback not null
2790 * 2. set checkMap null
2791 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2792 * 4. Get checkMap from DeviceManagerNotify
2793 * 5. check checkMap not null
2794 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2795 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2796 * 8. check if callback OnDeviceOffline called.
2797 */
2798 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_005, testing::ext::TestSize.Level0)
2799 {
2800 // 1. set pkgName not null
2801 std::string pkgName = "com.ohos.test";
2802 // set Callback not null
2803 int count = 0;
2804 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2805 // 2. set checkMap null
2806 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2807 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2808 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2809 // 4. Get checkMap from DeviceManagerNotify
2810 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2811 // 5. check checkMap not null
2812 ASSERT_NE(checkMap, nullptr);
2813 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2814 std::string testPkgName = "";
2815 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
2816 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2817 DmDeviceInfo deviceInfo;
2818 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2819 // 8. check if callback OnDeviceOffline called
2820 ASSERT_EQ(count, 0);
2821 }
2822
2823 /*
2824 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2825 * Function: DeviceManagerNotifyTest
2826 * SubFunction: OnDeviceChanged
2827 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2828 * EnvConditions: OnDeviceChanged success.
2829 * CaseDescription: 1. set pkgName not null
2830 * set Callback not null
2831 * 2. set checkMap null
2832 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2833 * 4. Get checkMap from DeviceManagerNotify
2834 * 5. check checkMap not null
2835 * 6. call DeviceManagerNotify OnDeviceChanged
2836 * 7. check if callback OnDeviceChanged called.
2837 */
2838 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_001, testing::ext::TestSize.Level0)
2839 {
2840 // 1. set pkgName not null
2841 std::string pkgName = "com.ohos.test";
2842 // set Callback not null
2843 int count = 0;
2844 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2845 // 2. set checkMap null
2846 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2847 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2848 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2849 // 4. Get checkMap from DeviceManagerNotify
2850 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2851 // 5. check checkMap not null
2852 ASSERT_NE(checkMap, nullptr);
2853 // 6. call DeviceManagerNotify OnDeviceChanged
2854 DmDeviceInfo deviceInfo;
2855 DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo);
2856 // 7. check if callback OnDeviceChanged called
2857 ASSERT_EQ(count, 1);
2858 }
2859
2860 /*
2861 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2862 * Function: DeviceManagerNotifyTest
2863 * SubFunction: OnDeviceChanged
2864 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2865 * EnvConditions: N/A.
2866 * CaseDescription: 1. set pkgName not null
2867 * set Callback not null
2868 * 2. set checkMap null
2869 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2870 * 4. Get checkMap from DeviceManagerNotify
2871 * 5. check checkMap not null
2872 * 6. set testpkcName com.ohos.test1
2873 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2874 * 8. check if callback OnDeviceChanged called.
2875 */
2876 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Level0)
2877 {
2878 // 1. set pkgName not null
2879 std::string pkgName = "com.ohos.test";
2880 // set Callback not null
2881 int count = 0;
2882 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2883 // 2. set checkMap null
2884 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2885 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2886 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2887 // 4. Get checkMap from DeviceManagerNotify
2888 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2889 // 5. check checkMap not null
2890 ASSERT_NE(checkMap, nullptr);
2891 // 6. set testpkcName com.ohos.test1
2892 std::string testPkgName = "com.ohos.test1";
2893 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2894 DmDeviceInfo deviceInfo;
2895 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2896 // 8. check if callback OnDeviceChanged called
2897 ASSERT_EQ(count, 0);
2898 }
2899
2900 /*
2901 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2902 * Function: DeviceManagerNotifyTest
2903 * SubFunction: OnDeviceChanged
2904 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2905 * EnvConditions: N/A.
2906 * CaseDescription: 1. set pkgName not null
2907 * set Callback not null
2908 * 2. set checkMap null
2909 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2910 * 4. Get checkMap from DeviceManagerNotify
2911 * 5. check checkMap not null
2912 * 6. set testpkcName com.ohos.test1
2913 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2914 * 8. check if callback OnDeviceChanged called.
2915 */
2916 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_003, testing::ext::TestSize.Level0)
2917 {
2918 // 1. set pkgName not null
2919 std::string pkgName = "com.ohos.test";
2920 // set Callback not null
2921 int count = 0;
2922 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2923 // 2. set checkMap null
2924 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2925 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2926 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2927 // 4. Get checkMap from DeviceManagerNotify
2928 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2929 // 5. check checkMap not null
2930 ASSERT_NE(checkMap, nullptr);
2931 // 6. set testpkcName com.ohos.test1
2932 std::string testPkgName = "";
2933 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2934 DmDeviceInfo deviceInfo;
2935 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2936 // 8. check if callback OnDeviceChanged called
2937 ASSERT_EQ(count, 0);
2938 }
2939
2940 /*
2941 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2942 * Function: DeviceManagerNotifyTest
2943 * SubFunction: OnDeviceChanged
2944 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2945 * EnvConditions: N/A.
2946 * CaseDescription: 1. set pkgName not null
2947 * set Callback not null
2948 * 2. set checkMap null
2949 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2950 * 4. Get checkMap from DeviceManagerNotify
2951 * 5. check checkMap not null
2952 * 6. set testpkcName com.ohos.test1
2953 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2954 * 8. check if callback OnDeviceChanged called.
2955 */
2956 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0)
2957 {
2958 // 1. set pkgName not null
2959 std::string pkgName = "com.ohos.test";
2960 // set Callback not null
2961 int count = 0;
2962 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2963 // 2. set checkMap null
2964 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2965 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2966 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2967 // 4. Get checkMap from DeviceManagerNotify
2968 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2969 // 5. check checkMap not null
2970 ASSERT_NE(checkMap, nullptr);
2971 // 6. set testpkcName com.ohos.test1
2972 std::string testPkgName = "";
2973 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2974 DmDeviceInfo deviceInfo;
2975 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2976 // 8. check if callback OnDeviceChanged called
2977 ASSERT_NE(count, 1);
2978 }
2979
2980 /*
2981 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2982 * Function: DeviceManagerNotifyTest
2983 * SubFunction: OnDeviceChanged
2984 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2985 * EnvConditions: N/A.
2986 * CaseDescription: 1. set pkgName not null
2987 * set Callback not null
2988 * 2. set checkMap null
2989 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2990 * 4. Get checkMap from DeviceManagerNotify
2991 * 5. check checkMap not null
2992 * 6. set testpkcName com.ohos.test1
2993 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2994 * 8. check if callback OnDeviceChanged called.
2995 */
2996 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_005, testing::ext::TestSize.Level0)
2997 {
2998 // 1. set pkgName not null
2999 std::string pkgName = "com.ohos.test";
3000 // set Callback not null
3001 int count = 0;
3002 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
3003 // 2. set checkMap null
3004 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
3005 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
3006 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
3007 // 4. Get checkMap from DeviceManagerNotify
3008 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
3009 // 5. check checkMap not null
3010 ASSERT_NE(checkMap, nullptr);
3011 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
3012 std::string testPkgName = "";
3013 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
3014 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
3015 DmDeviceInfo deviceInfo;
3016 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
3017 // 8. check if callback OnDeviceChanged called
3018 ASSERT_EQ(count, 0);
3019 }
3020
3021 /*
3022 * Feature: DeviceManagerNotifyTest OnDeviceFound
3023 * Function: DeviceManagerNotifyTest
3024 * SubFunction: OnDeviceFound
3025 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3026 * EnvConditions: OnDeviceFound success.
3027 * CaseDescription: 1. set pkgName not null
3028 * set callback not null
3029 * set subscribeId not null
3030 * 2. set checkMap null
3031 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3032 * 4. Get checkMap from DeviceManagerNotify
3033 * 5. check checkMap not null
3034 * 6. call DeviceManagerNotify OnDeviceFound
3035 * 7. check if callback OnDeviceFound called.
3036 */
3037 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound1, testing::ext::TestSize.Level0)
3038 {
3039 // 1. set pkgName not null
3040 std::string pkgName = "com.ohos.test";
3041 // set callback not null
3042 int count = 0;
3043 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3044 // set subscribeId not null
3045 uint16_t subscribeId = 0;
3046 // 2. set checkMap null
3047 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3048 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3049 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3050 // 4. Get checkMap from DeviceManagerNotify
3051 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3052 // 5. check checkMap not null
3053 ASSERT_NE(checkMap, nullptr);
3054 DmDeviceInfo deviceInfo;
3055 // 6. call DeviceManagerNotify OnDeviceFound
3056 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo);
3057 // 7. check if callback OnDeviceFound called
3058 ASSERT_EQ(count, 1);
3059 }
3060
3061 /*
3062 * Feature: DeviceManagerNotifyTest OnDeviceFound
3063 * Function: DeviceManagerNotifyTest
3064 * SubFunction: OnDeviceFound
3065 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3066 * EnvConditions: N/A.
3067 * CaseDescription: 1. set pkgName not null
3068 * set callback not null
3069 * set subscribeId not null
3070 * 2. set checkMap null
3071 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3072 * 4. Get checkMap from DeviceManagerNotify
3073 * 5. check checkMap not null
3074 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3075 * 7. check if callback OnDeviceFound called.
3076 */
3077 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound2, testing::ext::TestSize.Level0)
3078 {
3079 // 1. set pkgName not null
3080 std::string pkgName = "com.ohos.test";
3081 // set callback not null
3082 int count = 0;
3083 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3084 // set subscribeId not null
3085 uint16_t subscribeId = 0;
3086 // 2. set checkMap null
3087 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3088 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3089 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3090 // 4. Get checkMap from DeviceManagerNotify
3091 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3092 // 5. check checkMap not null
3093 ASSERT_NE(checkMap, nullptr);
3094 DmDeviceInfo deviceInfo;
3095 std::string testPkgName = "com.ohos.test1";
3096 // 6. call DeviceManagerNotify OnDeviceFound
3097 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3098 // 7. check if callback OnDeviceFound called
3099 ASSERT_EQ(count, 0);
3100 }
3101
3102 /*
3103 * Feature: DeviceManagerNotifyTest OnDeviceFound
3104 * Function: DeviceManagerNotifyTest
3105 * SubFunction: OnDeviceFound
3106 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3107 * EnvConditions: N/A.
3108 * CaseDescription: 1. set pkgName not null
3109 * set callback not null
3110 * set subscribeId not null
3111 * 2. set checkMap null
3112 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3113 * 4. Get checkMap from DeviceManagerNotify
3114 * 5. check checkMap not null
3115 * 6. call DeviceManagerNotify OnDeviceFound With testsubscribeId
3116 * 7. check if callback OnDeviceFound called.
3117 */
3118 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound3, testing::ext::TestSize.Level0)
3119 {
3120 // 1. set pkgName not null
3121 std::string pkgName = "com.ohos.test";
3122 // set callback not null
3123 int count = 0;
3124 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3125 // set subscribeId not null
3126 uint16_t subscribeId = 0;
3127 // 2. set checkMap null
3128 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3129 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3130 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3131 // 4. Get checkMap from DeviceManagerNotify
3132 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3133 // 5. check checkMap not null
3134 ASSERT_NE(checkMap, nullptr);
3135 DmDeviceInfo deviceInfo;
3136 uint16_t testsubscribeId = 1;
3137 // 6. call DeviceManagerNotify OnDeviceFound
3138 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, testsubscribeId, deviceInfo);
3139 // 7. check if callback OnDeviceFound called
3140 ASSERT_EQ(count, 0);
3141 }
3142
3143 /*
3144 * Feature: DeviceManagerNotifyTest OnDeviceFound
3145 * Function: DeviceManagerNotifyTest
3146 * SubFunction: OnDeviceFound
3147 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3148 * EnvConditions: N/A.
3149 * CaseDescription: 1. set pkgName not null
3150 * set callback not null
3151 * set subscribeId not null
3152 * 2. set checkMap null
3153 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3154 * 4. Get checkMap from DeviceManagerNotify
3155 * 5. check checkMap not null
3156 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3157 * 7. check if callback OnDeviceFound called.
3158 */
3159 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound4, testing::ext::TestSize.Level0)
3160 {
3161 // 1. set pkgName not null
3162 std::string pkgName = "com.ohos.test";
3163 // set callback not null
3164 int count = 0;
3165 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3166 // set subscribeId not null
3167 uint16_t subscribeId = 0;
3168 // 2. set checkMap null
3169 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3170 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3171 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3172 // 4. Get checkMap from DeviceManagerNotify
3173 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3174 // 5. check checkMap not null
3175 ASSERT_NE(checkMap, nullptr);
3176 DmDeviceInfo deviceInfo;
3177 std::string testPkgName = "";
3178 // 6. call DeviceManagerNotify OnDeviceFound
3179 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3180 // 7. check if callback OnDeviceFound called
3181 ASSERT_EQ(count, 0);
3182 }
3183
3184 /*
3185 * Feature: DeviceManagerNotifyTest OnDeviceFound
3186 * Function: DeviceManagerNotifyTest
3187 * SubFunction: OnDeviceFound
3188 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3189 * EnvConditions: N/A.
3190 * CaseDescription: 1. set pkgName not null
3191 * set callback not null
3192 * set subscribeId not null
3193 * 2. set checkMap null
3194 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3195 * 4. Get checkMap from DeviceManagerNotify
3196 * 5. check checkMap not null
3197 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3198 * 7. check if callback OnDeviceFound called.
3199 */
3200 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound5, testing::ext::TestSize.Level0)
3201 {
3202 // 1. set pkgName not null
3203 std::string pkgName = "com.ohos.test";
3204 // set callback not null
3205 int count = 0;
3206 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3207 // set subscribeId not null
3208 uint16_t subscribeId = 0;
3209 // 2. set checkMap null
3210 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3211 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3212 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3213 // 4. Get checkMap from DeviceManagerNotify
3214 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3215 // 5. check checkMap not null
3216 ASSERT_NE(checkMap, nullptr);
3217 DmDeviceInfo deviceInfo;
3218 std::string testPkgName = "";
3219 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3220 // 6. call DeviceManagerNotify OnDeviceFound
3221 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3222 // 7. check if callback OnDeviceFound called
3223 ASSERT_EQ(count, 0);
3224 }
3225
3226 /*
3227 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3228 * Function: DeviceManagerNotifyTest
3229 * SubFunction: OnDiscoverFailed
3230 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3231 * EnvConditions: OnDiscoverFailed success.
3232 * CaseDescription: 1. set pkgName not null
3233 * set callback not null
3234 * set subscribeId not null
3235 * 2. set checkMap null
3236 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3237 * 4. Get checkMap from DeviceManagerNotify
3238 * 5. check checkMap not null
3239 * 6. call DeviceManagerNotify OnDiscoverFailed
3240 * 7. check if callback OnDiscoverFailed called.
3241 */
3242 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed1, testing::ext::TestSize.Level0)
3243 {
3244 // 1. set pkgName not null
3245 std::string pkgName = "com.ohos.test";
3246 // set callback not null
3247 int count = 0;
3248 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3249 // set subscribeId not null
3250 uint16_t subscribeId = 0;
3251 // 2. set checkMap null
3252 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3253 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3254 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3255 // 4. Get checkMap from DeviceManagerNotify
3256 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3257 // 5. check checkMap not null
3258 ASSERT_NE(checkMap, nullptr);
3259 int32_t failedReason = 0;
3260 // 6. call DeviceManagerNotify OnDiscoverFailed
3261 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
3262 // 7. check if callback OnDiscoverFailed called
3263 ASSERT_EQ(count, 1);
3264 }
3265
3266 /*
3267 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3268 * Function: DeviceManagerNotifyTest
3269 * SubFunction: OnDiscoverFailed
3270 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3271 * EnvConditions: N/A.
3272 * CaseDescription: 1. set pkgName not null
3273 * set callback not null
3274 * set subscribeId not null
3275 * 2. set checkMap null
3276 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3277 * 4. Get checkMap from DeviceManagerNotify
3278 * 5. check checkMap not null
3279 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3280 * 7. check if callback OnDiscoverFailed called.
3281 */
3282 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed2, testing::ext::TestSize.Level0)
3283 {
3284 // 1. set pkgName not null
3285 std::string pkgName = "com.ohos.test";
3286 // set callback not null
3287 int count = 0;
3288 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3289 // set subscribeId not null
3290 uint16_t subscribeId = 0;
3291 // 2. set checkMap null
3292 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3293 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3294 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3295 // 4. Get checkMap from DeviceManagerNotify
3296 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3297 // 5. check checkMap not null
3298 ASSERT_NE(checkMap, nullptr);
3299 std::string testPkgName = "com.ohos.test1";
3300 int32_t failedReason = 0;
3301 // 6. call DeviceManagerNotify OnDiscoverFailed
3302 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3303 // 7. check if callback OnDiscoverFailed called
3304 ASSERT_EQ(count, 0);
3305 }
3306
3307 /*
3308 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3309 * Function: DeviceManagerNotifyTest
3310 * SubFunction: OnDiscoverFailed
3311 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3312 * EnvConditions: N/A.
3313 * CaseDescription: 1. set pkgName not null
3314 * set callback not null
3315 * set subscribeId not null
3316 * 2. set checkMap null
3317 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3318 * 4. Get checkMap from DeviceManagerNotify
3319 * 5. check checkMap not null
3320 * 6. call DeviceManagerNotify OnDiscoverFailed With testsubscribeId
3321 * 7. check if callback OnDiscoverFailed called.
3322 */
3323 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed3, testing::ext::TestSize.Level0)
3324 {
3325 // 1. set pkgName not null
3326 std::string pkgName = "com.ohos.test";
3327 // set callback not null
3328 int count = 0;
3329 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3330 // set subscribeId not null
3331 uint16_t subscribeId = 0;
3332 // 2. set checkMap null
3333 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3334 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3335 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3336 // 4. Get checkMap from DeviceManagerNotify
3337 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3338 // 5. check checkMap not null
3339 ASSERT_NE(checkMap, nullptr);
3340 int32_t failedReason = 0;
3341 uint16_t testsubscribeId = 1;
3342 // 6. call DeviceManagerNotify OnDiscoverFailed
3343 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason);
3344 // 7. check if callback OnDiscoverFailed called
3345 ASSERT_EQ(count, 0);
3346 }
3347
3348 /*
3349 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3350 * Function: DeviceManagerNotifyTest
3351 * SubFunction: OnDiscoverFailed
3352 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3353 * EnvConditions: N/A.
3354 * CaseDescription: 1. set pkgName not null
3355 * set callback not null
3356 * set subscribeId not null
3357 * 2. set checkMap null
3358 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3359 * 4. Get checkMap from DeviceManagerNotify
3360 * 5. check checkMap not null
3361 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3362 * 7. check if callback OnDiscoverFailed called.
3363 */
3364 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed4, testing::ext::TestSize.Level0)
3365 {
3366 // 1. set pkgName not null
3367 std::string pkgName = "com.ohos.test";
3368 // set callback not null
3369 int count = 0;
3370 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3371 // set subscribeId not null
3372 uint16_t subscribeId = 0;
3373 // 2. set checkMap null
3374 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3375 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3376 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3377 // 4. Get checkMap from DeviceManagerNotify
3378 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3379 // 5. check checkMap not null
3380 ASSERT_NE(checkMap, nullptr);
3381 std::string testPkgName = "";
3382 int32_t failedReason = 0;
3383 // 6. call DeviceManagerNotify OnDiscoverFailed
3384 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3385 // 7. check if callback OnDiscoverFailed called
3386 ASSERT_EQ(count, 0);
3387 }
3388
3389 /*
3390 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3391 * Function: DeviceManagerNotifyTest
3392 * SubFunction: OnDiscoverFailed
3393 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3394 * EnvConditions: N/A.
3395 * CaseDescription: 1. set pkgName not null
3396 * set callback not null
3397 * set subscribeId not null
3398 * 2. set checkMap null
3399 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3400 * 4. Get checkMap from DeviceManagerNotify
3401 * 5. check checkMap not null
3402 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3403 * 7. check if callback OnDiscoverFailed called.
3404 */
3405 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed5, testing::ext::TestSize.Level0)
3406 {
3407 // 1. set pkgName not null
3408 std::string pkgName = "com.ohos.test";
3409 // set callback not null
3410 int count = 0;
3411 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3412 // set subscribeId not null
3413 uint16_t subscribeId = 0;
3414 // 2. set checkMap null
3415 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3416 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3417 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3418 // 4. Get checkMap from DeviceManagerNotify
3419 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3420 // 5. check checkMap not null
3421 ASSERT_NE(checkMap, nullptr);
3422 std::string testPkgName = "";
3423 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3424 int32_t failedReason = 0;
3425 // 6. call DeviceManagerNotify OnDiscoverFailed
3426 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3427 // 7. check if callback OnDiscoverFailed called
3428 ASSERT_EQ(count, 0);
3429 }
3430
3431 /*
3432 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3433 * Function: DeviceManagerNotifyTest
3434 * SubFunction: OnDiscoverySuccess
3435 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3436 * EnvConditions: OnDiscoverySuccess success.
3437 * CaseDescription: 1. set pkgName not null
3438 * set callback not null
3439 * set subscribeId not null
3440 * 2. set checkMap null
3441 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3442 * 4. Get checkMap from DeviceManagerNotify
3443 * 5. check checkMap not null
3444 * 6. call DeviceManagerNotify OnDiscoverySuccess
3445 * 7. check if callback OnDiscoverySuccess called.
3446 */
3447 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess1, testing::ext::TestSize.Level0)
3448 {
3449 // 1. set pkgName not null
3450 std::string pkgName = "com.ohos.test";
3451 // set callback not null
3452 int count = 0;
3453 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3454 // set subscribeId not null
3455 uint16_t subscribeId = 0;
3456 // 2. set checkMap null
3457 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3458 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3459 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3460 // 4. Get checkMap from DeviceManagerNotify
3461 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3462 // 5. check checkMap not null
3463 ASSERT_NE(checkMap, nullptr);
3464 // 6. call DeviceManagerNotify OnDiscoverySuccess
3465 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
3466 // 7. check if callback OnDiscoverySuccess called
3467 ASSERT_EQ(count, 1);
3468 }
3469
3470 /*
3471 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3472 * Function: DeviceManagerNotifyTest
3473 * SubFunction: OnDiscoverySuccess
3474 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3475 * EnvConditions: N/A.
3476 * CaseDescription: 1. set pkgName not null
3477 * set callback not null
3478 * set subscribeId not null
3479 * 2. set checkMap null
3480 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3481 * 4. Get checkMap from DeviceManagerNotify
3482 * 5. check checkMap not null
3483 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3484 * 7. check if callback OnDiscoverySuccess called.
3485 */
3486 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess2, testing::ext::TestSize.Level0)
3487 {
3488 // 1. set pkgName not null
3489 std::string pkgName = "com.ohos.test";
3490 // set callback not null
3491 int count = 0;
3492 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3493 // set subscribeId not null
3494 uint16_t subscribeId = 0;
3495 // 2. set checkMap null
3496 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3497 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3498 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3499 // 4. Get checkMap from DeviceManagerNotify
3500 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3501 // 5. check checkMap not null
3502 ASSERT_NE(checkMap, nullptr);
3503 std::string testPkgName = "com.ohos.test1";
3504 // 6. call DeviceManagerNotify OnDiscoverySuccess
3505 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3506 // 7. check if callback OnDiscoverySuccess called
3507 ASSERT_EQ(count, 0);
3508 }
3509
3510 /*
3511 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3512 * Function: DeviceManagerNotifyTest
3513 * SubFunction: OnDiscoverySuccess
3514 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3515 * EnvConditions: N/A.
3516 * CaseDescription: 1. set pkgName not null
3517 * set callback not null
3518 * set subscribeId not null
3519 * 2. set checkMap null
3520 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3521 * 4. Get checkMap from DeviceManagerNotify
3522 * 5. check checkMap not null
3523 * 6. call DeviceManagerNotify OnDiscoverySuccess With testsubscribeId
3524 * 7. check if callback OnDiscoverySuccess called.
3525 */
3526 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess3, testing::ext::TestSize.Level0)
3527 {
3528 // 1. set pkgName not null
3529 std::string pkgName = "com.ohos.test";
3530 // set callback not null
3531 int count = 0;
3532 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3533 // set subscribeId not null
3534 uint16_t subscribeId = 0;
3535 // 2. set checkMap null
3536 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3537 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3538 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3539 // 4. Get checkMap from DeviceManagerNotify
3540 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3541 // 5. check checkMap not null
3542 ASSERT_NE(checkMap, nullptr);
3543 uint16_t testsubscribeId = 1;
3544 // 6. call DeviceManagerNotify OnDiscoverySuccess
3545 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, testsubscribeId);
3546 // 7. check if callback OnDiscoverySuccess called
3547 ASSERT_EQ(count, 0);
3548 }
3549
3550 /*
3551 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3552 * Function: DeviceManagerNotifyTest
3553 * SubFunction: OnDiscoverySuccess
3554 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3555 * EnvConditions: N/A.
3556 * CaseDescription: 1. set pkgName not null
3557 * set callback not null
3558 * set subscribeId not null
3559 * 2. set checkMap null
3560 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3561 * 4. Get checkMap from DeviceManagerNotify
3562 * 5. check checkMap not null
3563 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3564 * 7. check if callback OnDiscoverySuccess called.
3565 */
3566 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess4, testing::ext::TestSize.Level0)
3567 {
3568 // 1. set pkgName not null
3569 std::string pkgName = "com.ohos.test";
3570 // set callback not null
3571 int count = 0;
3572 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3573 // set subscribeId not null
3574 uint16_t subscribeId = 0;
3575 // 2. set checkMap null
3576 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3577 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3578 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3579 // 4. Get checkMap from DeviceManagerNotify
3580 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3581 // 5. check checkMap not null
3582 ASSERT_NE(checkMap, nullptr);
3583 std::string testPkgName = "";
3584 // 6. call DeviceManagerNotify OnDiscoverySuccess
3585 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3586 // 7. check if callback OnDiscoverySuccess called
3587 ASSERT_EQ(count, 0);
3588 }
3589
3590 /*
3591 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3592 * Function: DeviceManagerNotifyTest
3593 * SubFunction: OnDiscoverySuccess
3594 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3595 * EnvConditions: N/A.
3596 * CaseDescription: 1. set pkgName not null
3597 * set callback not null
3598 * set subscribeId not null
3599 * 2. set checkMap null
3600 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3601 * 4. Get checkMap from DeviceManagerNotify
3602 * 5. check checkMap not null
3603 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3604 * 7. check if callback OnDiscoverySuccess called.
3605 */
3606 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess5, testing::ext::TestSize.Level0)
3607 {
3608 // 1. set pkgName not null
3609 std::string pkgName = "com.ohos.test";
3610 // set callback not null
3611 int count = 0;
3612 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3613 // set subscribeId not null
3614 uint16_t subscribeId = 0;
3615 // 2. set checkMap null
3616 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3617 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3618 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3619 // 4. Get checkMap from DeviceManagerNotify
3620 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3621 // 5. check checkMap not null
3622 ASSERT_NE(checkMap, nullptr);
3623 std::string testPkgName = "";
3624 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3625 // 6. call DeviceManagerNotify OnDiscoverySuccess
3626 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3627 // 7. check if callback OnDiscoverySuccess called
3628 ASSERT_EQ(count, 0);
3629 }
3630
3631 /*
3632 * Feature: DeviceManagerNotifyTest OnPublishResult
3633 * Function: DeviceManagerNotifyTest
3634 * SubFunction: OnPublishResult Failed
3635 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3636 * EnvConditions: OnPublishResult.
3637 * CaseDescription: 1. set pkgName not null
3638 * set callback not null
3639 * set publishId not null
3640 * 2. set checkMap null
3641 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3642 * 4. Get checkMap from DeviceManagerNotify
3643 * 5. check checkMap not null
3644 * 6. call DeviceManagerNotify OnPublishResult
3645 * 7. check if callback OnPublishResult called.
3646 */
3647 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult1, testing::ext::TestSize.Level0)
3648 {
3649 // 1. set pkgName not null
3650 std::string pkgName = "com.ohos.test";
3651 // set callback not null
3652 int count = 0;
3653 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3654 // set publishId not null
3655 int32_t publishId = 0;
3656 // 2. set checkMap null
3657 std::shared_ptr<PublishCallback> checkMap = nullptr;
3658 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3659 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3660 // 4. Get checkMap from DeviceManagerNotify
3661 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3662 // 5. check checkMap not null
3663 ASSERT_NE(checkMap, nullptr);
3664 int32_t failedReason = 1;
3665 // 6. call DeviceManagerNotify OnPublishResult
3666 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, failedReason);
3667 // 7. check if callback OnPublishResult called
3668 ASSERT_EQ(count, 1);
3669 }
3670
3671 /*
3672 * Feature: DeviceManagerNotifyTest OnPublishResult
3673 * Function: DeviceManagerNotifyTest
3674 * SubFunction: OnPublishResult Failed
3675 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3676 * EnvConditions: N/A.
3677 * CaseDescription: 1. set pkgName not null
3678 * set callback not null
3679 * set publishId not null
3680 * 2. set checkMap null
3681 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3682 * 4. Get checkMap from DeviceManagerNotify
3683 * 5. check checkMap not null
3684 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3685 * 7. check if callback OnPublishResult called.
3686 */
3687 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult2, testing::ext::TestSize.Level0)
3688 {
3689 // 1. set pkgName not null
3690 std::string pkgName = "com.ohos.test";
3691 // set callback not null
3692 int count = 0;
3693 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3694 // set publishId not null
3695 int32_t publishId = 0;
3696 // 2. set checkMap null
3697 std::shared_ptr<PublishCallback> checkMap = nullptr;
3698 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3699 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3700 // 4. Get checkMap from DeviceManagerNotify
3701 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3702 // 5. check checkMap not null
3703 ASSERT_NE(checkMap, nullptr);
3704 std::string testPkgName = "com.ohos.test1";
3705 int32_t failedReason = 1;
3706 // 6. call DeviceManagerNotify OnPublishResult
3707 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3708 // 7. check if callback OnPublishResult called
3709 ASSERT_EQ(count, 0);
3710 }
3711
3712 /*
3713 * Feature: DeviceManagerNotifyTest OnPublishResult
3714 * Function: DeviceManagerNotifyTest
3715 * SubFunction: OnPublishResult Failed
3716 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3717 * EnvConditions: N/A.
3718 * CaseDescription: 1. set pkgName not null
3719 * set callback not null
3720 * set publishId not null
3721 * 2. set checkMap null
3722 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3723 * 4. Get checkMap from DeviceManagerNotify
3724 * 5. check checkMap not null
3725 * 6. call DeviceManagerNotify OnPublishFailed With testpublishId
3726 * 7. check if callback OnPublishResult called.
3727 */
3728 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult3, testing::ext::TestSize.Level0)
3729 {
3730 // 1. set pkgName not null
3731 std::string pkgName = "com.ohos.test";
3732 // set callback not null
3733 int count = 0;
3734 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3735 // set publishId not null
3736 int32_t publishId = 0;
3737 // 2. set checkMap null
3738 std::shared_ptr<PublishCallback> checkMap = nullptr;
3739 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3740 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3741 // 4. Get checkMap from DeviceManagerNotify
3742 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3743 // 5. check checkMap not null
3744 ASSERT_NE(checkMap, nullptr);
3745 int32_t failedReason = 1;
3746 int32_t testpublishId = 1;
3747 // 6. call DeviceManagerNotify OnPublishResult
3748 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, failedReason);
3749 // 7. check if callback OnPublishResult called
3750 ASSERT_EQ(count, 0);
3751 }
3752
3753 /*
3754 * Feature: DeviceManagerNotifyTest OnPublishResult
3755 * Function: DeviceManagerNotifyTest
3756 * SubFunction: OnPublishResult Failed
3757 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3758 * EnvConditions: N/A.
3759 * CaseDescription: 1. set pkgName not null
3760 * set callback not null
3761 * set publishId not null
3762 * 2. set checkMap null
3763 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3764 * 4. Get checkMap from DeviceManagerNotify
3765 * 5. check checkMap not null
3766 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3767 * 7. check if callback OnPublishResult called.
3768 */
3769 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed4, testing::ext::TestSize.Level0)
3770 {
3771 // 1. set pkgName not null
3772 std::string pkgName = "com.ohos.test";
3773 // set callback not null
3774 int count = 0;
3775 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3776 // set publishId not null
3777 int32_t publishId = 0;
3778 // 2. set checkMap null
3779 std::shared_ptr<PublishCallback> checkMap = nullptr;
3780 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3781 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3782 // 4. Get checkMap from DeviceManagerNotify
3783 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3784 // 5. check checkMap not null
3785 ASSERT_NE(checkMap, nullptr);
3786 std::string testPkgName = "";
3787 int32_t failedReason = 1;
3788 // 6. call DeviceManagerNotify OnPublishResult
3789 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3790 // 7. check if callback OnPublishResult called
3791 ASSERT_EQ(count, 0);
3792 }
3793
3794 /*
3795 * Feature: DeviceManagerNotifyTest OnPublishResult
3796 * Function: DeviceManagerNotifyTest
3797 * SubFunction: OnPublishResult Failed
3798 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3799 * EnvConditions: N/A.
3800 * CaseDescription: 1. set pkgName not null
3801 * set callback not null
3802 * set publishId not null
3803 * 2. set checkMap null
3804 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3805 * 4. Get checkMap from DeviceManagerNotify
3806 * 5. check checkMap not null
3807 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3808 * 7. check if callback OnPublishResult called.
3809 */
3810 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed5, testing::ext::TestSize.Level0)
3811 {
3812 // 1. set pkgName not null
3813 std::string pkgName = "com.ohos.test";
3814 // set callback not null
3815 int count = 0;
3816 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3817 // set publishId not null
3818 int32_t publishId = 2;
3819 // 2. set checkMap null
3820 std::shared_ptr<PublishCallback> checkMap = nullptr;
3821 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3822 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3823 // 4. Get checkMap from DeviceManagerNotify
3824 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3825 // 5. check checkMap not null
3826 ASSERT_NE(checkMap, nullptr);
3827 std::string testPkgName = "";
3828 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId);
3829 int32_t failedReason = 1;
3830 // 6. call DeviceManagerNotify OnPublishResult
3831 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3832 // 7. check if callback OnPublishResult called
3833 ASSERT_EQ(count, 0);
3834 }
3835
3836 /*
3837 * Feature: DeviceManagerNotifyTest OnPublishResult
3838 * Function: DeviceManagerNotifyTest
3839 * SubFunction: OnPublishResult
3840 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3841 * EnvConditions: OnPublishResult success.
3842 * CaseDescription: 1. set pkgName not null
3843 * set callback not null
3844 * set publishId not null
3845 * 2. set checkMap null
3846 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3847 * 4. Get checkMap from DeviceManagerNotify
3848 * 5. check checkMap not null
3849 * 6. call DeviceManagerNotify OnPublishResult
3850 * 7. check if callback OnPublishResult called.
3851 */
3852 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess1, testing::ext::TestSize.Level0)
3853 {
3854 // 1. set pkgName not null
3855 std::string pkgName = "com.ohos.test";
3856 // set callback not null
3857 int count = 0;
3858 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3859 // set publishId not null
3860 int32_t publishId = 0;
3861 // 2. set checkMap null
3862 std::shared_ptr<PublishCallback> checkMap = nullptr;
3863 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3864 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3865 // 4. Get checkMap from DeviceManagerNotify
3866 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3867 // 5. check checkMap not null
3868 ASSERT_NE(checkMap, nullptr);
3869 // 6. call DeviceManagerNotify OnPublishResult
3870 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, 0);
3871 // 7. check if callback OnPublishResult called
3872 ASSERT_EQ(count, 1);
3873 }
3874
3875 /*
3876 * Feature: DeviceManagerNotifyTest OnPublishResult
3877 * Function: DeviceManagerNotifyTest
3878 * SubFunction: OnPublishResult
3879 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3880 * EnvConditions: N/A.
3881 * CaseDescription: 1. set pkgName not null
3882 * set callback not null
3883 * set publishId not null
3884 * 2. set checkMap null
3885 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3886 * 4. Get checkMap from DeviceManagerNotify
3887 * 5. check checkMap not null
3888 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3889 * 7. check if callback OnPublishResult called.
3890 */
3891 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess2, testing::ext::TestSize.Level0)
3892 {
3893 // 1. set pkgName not null
3894 std::string pkgName = "com.ohos.test";
3895 // set callback not null
3896 int count = 0;
3897 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3898 // set publishId not null
3899 int32_t publishId = 0;
3900 // 2. set checkMap null
3901 std::shared_ptr<PublishCallback> checkMap = nullptr;
3902 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3903 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3904 // 4. Get checkMap from DeviceManagerNotify
3905 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3906 // 5. check checkMap not null
3907 ASSERT_NE(checkMap, nullptr);
3908 std::string testPkgName = "com.ohos.test1";
3909 // 6. call DeviceManagerNotify OnPublishResult
3910 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
3911 // 7. check if callback OnPublishResult called
3912 ASSERT_EQ(count, 0);
3913 }
3914
3915 /*
3916 * Feature: DeviceManagerNotifyTest OnPublishResult
3917 * Function: DeviceManagerNotifyTest
3918 * SubFunction: OnPublishResult
3919 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3920 * EnvConditions: N/A.
3921 * CaseDescription: 1. set pkgName not null
3922 * set callback not null
3923 * set publishId not null
3924 * 2. set checkMap null
3925 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3926 * 4. Get checkMap from DeviceManagerNotify
3927 * 5. check checkMap not null
3928 * 6. call DeviceManagerNotify OnPublishResult With testpublishId
3929 * 7. check if callback OnPublishResult called.
3930 */
3931 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess3, testing::ext::TestSize.Level0)
3932 {
3933 // 1. set pkgName not null
3934 std::string pkgName = "com.ohos.test";
3935 // set callback not null
3936 int count = 0;
3937 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3938 // set publishId not null
3939 int32_t publishId = 0;
3940 // 2. set checkMap null
3941 std::shared_ptr<PublishCallback> checkMap = nullptr;
3942 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3943 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3944 // 4. Get checkMap from DeviceManagerNotify
3945 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3946 // 5. check checkMap not null
3947 ASSERT_NE(checkMap, nullptr);
3948 int32_t testpublishId = 1;
3949 // 6. call DeviceManagerNotify OnPublishResult
3950 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, 0);
3951 // 7. check if callback OnPublishResult called
3952 ASSERT_EQ(count, 0);
3953 }
3954
3955 /*
3956 * Feature: DeviceManagerNotifyTest OnPublishResult
3957 * Function: DeviceManagerNotifyTest
3958 * SubFunction: OnPublishResult Success
3959 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3960 * EnvConditions: N/A.
3961 * CaseDescription: 1. set pkgName not null
3962 * set callback not null
3963 * set publishId not null
3964 * 2. set checkMap null
3965 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3966 * 4. Get checkMap from DeviceManagerNotify
3967 * 5. check checkMap not null
3968 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3969 * 7. check if callback OnPublishResult called.
3970 */
3971 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess4, testing::ext::TestSize.Level0)
3972 {
3973 // 1. set pkgName not null
3974 std::string pkgName = "com.ohos.test";
3975 // set callback not null
3976 int count = 0;
3977 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3978 // set publishId not null
3979 int32_t publishId = 0;
3980 // 2. set checkMap null
3981 std::shared_ptr<PublishCallback> checkMap = nullptr;
3982 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3983 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3984 // 4. Get checkMap from DeviceManagerNotify
3985 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3986 // 5. check checkMap not null
3987 ASSERT_NE(checkMap, nullptr);
3988 std::string testPkgName = "";
3989 // 6. call DeviceManagerNotify OnPublishResult
3990 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
3991 // 7. check if callback OnPublishResult called
3992 ASSERT_EQ(count, 0);
3993 }
3994
3995 /*
3996 * Feature: DeviceManagerNotifyTest OnPublishResult
3997 * Function: DeviceManagerNotifyTest
3998 * SubFunction: OnPublishResult Success
3999 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
4000 * EnvConditions: N/A.
4001 * CaseDescription: 1. set pkgName not null
4002 * set callback not null
4003 * set subscribeId not null
4004 * 2. set checkMap null
4005 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
4006 * 4. Get checkMap from DeviceManagerNotify
4007 * 5. check checkMap not null
4008 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
4009 * 7. check if callback OnPublishResult called.
4010 */
4011 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess5, testing::ext::TestSize.Level0)
4012 {
4013 // 1. set pkgName not null
4014 std::string pkgName = "com.ohos.test";
4015 // set callback not null
4016 int count = 0;
4017 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
4018 // set publishId not null
4019 int32_t publishId = 0;
4020 // 2. set checkMap null
4021 std::shared_ptr<PublishCallback> checkMap = nullptr;
4022 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
4023 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
4024 // 4. Get checkMap from DeviceManagerNotify
4025 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
4026 // 5. check checkMap not null
4027 ASSERT_NE(checkMap, nullptr);
4028 std::string testPkgName = "";
4029 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId);
4030 // 6. call DeviceManagerNotify OnPublishResult
4031 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
4032 // 7. check if callback OnPublishSuccess called
4033 ASSERT_EQ(count, 0);
4034 }
4035
4036 /*
4037 * Feature: DeviceManagerNotifyTest OnAuthResult
4038 * Function: OnAuthResult
4039 * SubFunction: RegisterAuthenticateCallback
4040 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4041 * EnvConditions: OnAuthResult success.
4042 * CaseDescription: 1. set pkgName not null
4043 * set Callback not null
4044 * set deviceId not null
4045 * 2. set checkMap null
4046 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4047 * 4. Get checkMap from DeviceManagerNotify
4048 * 5. check checkMap not null
4049 * 6. call DeviceManagerNotify OnAuthResult
4050 * 7. check if callback OnDiscoverySuccess called
4051 */
4052 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult1, testing::ext::TestSize.Level0)
4053 {
4054 // 1. set pkgName not null
4055 std::string pkgName = "com.ohos.test";
4056 // set callback not null
4057 int count = 0;
4058 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4059 // set subscribeId not null
4060 std::string deviceId = "1";
4061 // 2. set checkMap null
4062 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4063 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4064 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4065 // 4. Get checkMap from DeviceManagerNotify
4066 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4067 // 5. check checkMap not null
4068 ASSERT_NE(checkMap, nullptr);
4069 // 6. call DeviceManagerNotify OnAuthResult
4070 std::string token = "111";
4071 uint32_t status = 0;
4072 uint32_t reason = 0;
4073 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4074 // 7. check if callback OnDiscoverySuccess called
4075 ASSERT_EQ(count, 1);
4076 }
4077
4078 /*
4079 * Feature: DeviceManagerNotifyTest OnAuthResult
4080 * Function: OnAuthResult
4081 * SubFunction: RegisterAuthenticateCallback
4082 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4083 * EnvConditions: OnAuthResult success.
4084 * CaseDescription: 1. set pkgName not null
4085 * set Callback not null
4086 * set deviceId not null
4087 * 2. set checkMap null
4088 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4089 * 4. Get checkMap from DeviceManagerNotify
4090 * 5. check checkMap not null
4091 * 6. call DeviceManagerNotify OnAuthResult with testPkgName
4092 * 7. check if callback OnDiscoverySuccess called
4093 */
4094 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult2, testing::ext::TestSize.Level0)
4095 {
4096 // 1. set pkgName not null
4097 std::string pkgName = "com.ohos.test";
4098 // set callback not null
4099 int count = 0;
4100 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4101 // set subscribeId not null
4102 std::string deviceId = "1";
4103 // 2. set checkMap null
4104 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4105 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4106 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4107 // 4. Get checkMap from DeviceManagerNotify
4108 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4109 // 5. check checkMap not null
4110 ASSERT_NE(checkMap, nullptr);
4111 // 6. call DeviceManagerNotify OnAuthResult
4112 std::string testPkgName = "com.ohos.test1";
4113 std::string token = "111";
4114 uint32_t status = 0;
4115 uint32_t reason = 0;
4116 DeviceManagerNotify::GetInstance().OnAuthResult(testPkgName, deviceId, token, status, reason);
4117 // 7. check if callback OnDiscoverySuccess called
4118 ASSERT_EQ(count, 0);
4119 }
4120
4121 /*
4122 * Feature: DeviceManagerNotifyTest OnAuthResult
4123 * Function: OnAuthResult
4124 * SubFunction: RegisterAuthenticateCallback
4125 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4126 * EnvConditions: OnAuthResult success.
4127 * CaseDescription: 1. set pkgName not null
4128 * set Callback not null
4129 * set deviceId not null
4130 * 2. set checkMap null
4131 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4132 * 4. Get checkMap from DeviceManagerNotify
4133 * 5. check checkMap not null
4134 * 6. call DeviceManagerNotify OnAuthResult with testDeviceId
4135 * 7. check if callback OnDiscoverySuccess called
4136 */
4137 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult3, testing::ext::TestSize.Level0)
4138 {
4139 // 1. set pkgName not null
4140 std::string pkgName = "com.ohos.test";
4141 // set callback not null
4142 int count = 0;
4143 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4144 // set subscribeId not null
4145 std::string deviceId = "1";
4146 // 2. set checkMap null
4147 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4148 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4149 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4150 // 4. Get checkMap from DeviceManagerNotify
4151 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4152 // 5. check checkMap not null
4153 ASSERT_NE(checkMap, nullptr);
4154 // 6. call DeviceManagerNotify OnAuthResult
4155 std::string testDeviceId = "2";
4156 std::string token = "111";
4157 uint32_t status = 0;
4158 uint32_t reason = 0;
4159 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason);
4160 // 7. check if callback OnDiscoverySuccess called
4161 ASSERT_EQ(count, 0);
4162 }
4163
4164 /*
4165 * Feature: DeviceManagerNotifyTest OnAuthResult
4166 * Function: OnAuthResult
4167 * SubFunction: RegisterAuthenticateCallback
4168 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4169 * EnvConditions: OnAuthResult success.
4170 * CaseDescription: 1. set pkgName not null
4171 * set Callback not null
4172 * set deviceId not null
4173 * 2. set checkMap null
4174 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4175 * 4. Get checkMap from DeviceManagerNotify
4176 * 5. check checkMap not null
4177 * 6. call DeviceManagerNotify OnAuthResult
4178 * 7. check if callback OnDiscoverySuccess called
4179 */
4180 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult4, testing::ext::TestSize.Level0)
4181 {
4182 // 1. set pkgName not null
4183 std::string pkgName = "com.ohos.test";
4184 // set callback not null
4185 int count = 0;
4186 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4187 // set subscribeId not null
4188 std::string deviceId = "1";
4189 // 2. set checkMap null
4190 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4191 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4192 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4193 // 4. Get checkMap from DeviceManagerNotify
4194 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4195 // 5. check checkMap not null
4196 ASSERT_NE(checkMap, nullptr);
4197 // 6. call DeviceManagerNotify OnAuthResult
4198 std::string token = "111";
4199 uint32_t status = 0;
4200 uint32_t reason = 0;
4201 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4202 // 7. check if callback OnDiscoverySuccess called
4203 ASSERT_EQ(count, 1);
4204 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4205 ASSERT_EQ(checkMap, nullptr);
4206 }
4207
4208 /*
4209 * Feature: DeviceManagerNotifyTest OnAuthResult
4210 * Function: OnAuthResult
4211 * SubFunction: RegisterAuthenticateCallback
4212 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4213 * EnvConditions: OnAuthResult success.
4214 * CaseDescription: 1. set pkgName not null
4215 * set Callback not null
4216 * set deviceId not null
4217 * 2. set checkMap null
4218 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4219 * 4. Get checkMap from DeviceManagerNotify
4220 * 5. check checkMap not null
4221 * 6. call DeviceManagerNotify OnAuthResult
4222 * 7. check if callback OnDiscoverySuccess called
4223 */
4224 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult5, testing::ext::TestSize.Level0)
4225 {
4226 // 1. set pkgName not null
4227 std::string pkgName = "com.ohos.test";
4228 // set callback not null
4229 int count = 0;
4230 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4231 // set subscribeId not null
4232 std::string deviceId = "1";
4233 // 2. set checkMap null
4234 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4235 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4236 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4237 // 4. Get checkMap from DeviceManagerNotify
4238 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4239 // 5. check checkMap not null
4240 ASSERT_NE(checkMap, nullptr);
4241 // 6. call DeviceManagerNotify OnAuthResult
4242 std::string testPkaName = "com.ohos.test1";
4243 std::string token = "111";
4244 uint32_t status = 0;
4245 uint32_t reason = 0;
4246 DeviceManagerNotify::GetInstance().OnAuthResult(testPkaName, deviceId, token, status, reason);
4247 // 7. check if callback OnDiscoverySuccess called
4248 ASSERT_EQ(count, 0);
4249 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4250 ASSERT_NE(checkMap, nullptr);
4251 }
4252
4253 /*
4254 * Feature: DeviceManagerNotifyTest OnAuthResult
4255 * Function: OnAuthResult
4256 * SubFunction: RegisterAuthenticateCallback
4257 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4258 * EnvConditions: OnAuthResult success.
4259 * CaseDescription: 1. set pkgName not null
4260 * set Callback not null
4261 * set deviceId not null
4262 * 2. set checkMap null
4263 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4264 * 4. Get checkMap from DeviceManagerNotify
4265 * 5. check checkMap not null
4266 * 6. call DeviceManagerNotify OnAuthResult
4267 * 7. check if callback OnDiscoverySuccess called
4268 */
4269 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult6, testing::ext::TestSize.Level0)
4270 {
4271 // 1. set pkgName not null
4272 std::string pkgName = "com.ohos.test";
4273 // set callback not null
4274 int count = 0;
4275 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4276 // set subscribeId not null
4277 std::string deviceId = "1";
4278 // 2. set checkMap null
4279 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4280 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4281 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4282 // 4. Get checkMap from DeviceManagerNotify
4283 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4284 // 5. check checkMap not null
4285 ASSERT_NE(checkMap, nullptr);
4286 // 6. call DeviceManagerNotify OnAuthResult
4287 std::string testDeviceId = "2";
4288 std::string token = "111";
4289 uint32_t status = 0;
4290 uint32_t reason = 0;
4291 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason);
4292 // 7. check if callback OnDiscoverySuccess called
4293 ASSERT_EQ(count, 0);
4294 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4295 ASSERT_NE(checkMap, nullptr);
4296 }
4297
4298 /*
4299 * Feature: DeviceManagerNotifyTest OnAuthResult
4300 * Function: OnAuthResult
4301 * SubFunction: RegisterAuthenticateCallback
4302 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4303 * EnvConditions: OnAuthResult success.
4304 * CaseDescription: 1. set pkgName not null
4305 * set Callback not null
4306 * set deviceId not null
4307 * 2. set checkMap null
4308 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4309 * 4. Get checkMap from DeviceManagerNotify
4310 * 5. check checkMap not null
4311 * 6. call DeviceManagerNotify OnAuthResult
4312 * 7. check if callback OnDiscoverySuccess called
4313 */
4314 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult7, testing::ext::TestSize.Level0)
4315 {
4316 // 1. set pkgName not null
4317 std::string pkgName = "com.ohos.test";
4318 // set callback not null
4319 int count = 0;
4320 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4321 // set subscribeId not null
4322 std::string deviceId = "1";
4323 // 2. set checkMap null
4324 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4325 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4326 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4327 // 4. Get checkMap from DeviceManagerNotify
4328 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4329 // 5. check checkMap not null
4330 ASSERT_NE(checkMap, nullptr);
4331 // 6. call DeviceManagerNotify OnAuthResult
4332 std::string token = "111";
4333 uint32_t status = 0;
4334 uint32_t reason = 0;
4335 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4336 // 7. check if callback OnDiscoverySuccess called
4337 ASSERT_EQ(count, 1);
4338 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4339 ASSERT_EQ(checkMap, nullptr);
4340 }
4341
4342 /*
4343 * Feature: DeviceManagerNotifyTest OnUiCall
4344 * Function: DeviceManagerNotifyTest
4345 * SubFunction: OnUiCall
4346 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4347 * EnvConditions: OnUiCall success.
4348 * CaseDescription: 1. set pkgName not null
4349 * set dmUiCallback_ not null
4350 * 2. set checkMap null
4351 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4352 * 4. Get checkMap from DeviceManagerNotify
4353 * 5. check checkMap not null
4354 * 6. call DeviceManagerNotify OnUiCall
4355 * 7. check if callback OnCheckAuthResult called
4356 */
4357 HWTEST_F(DeviceManagerNotifyTest, OnUiCall1, testing::ext::TestSize.Level0)
4358 {
4359 // 1. set pkgName not null
4360 std::string pkgName = "com.ohos.test";
4361 // set dmUiCallback_ not null
4362 int count = 0;
4363 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4364 // 2. set checkMap null
4365 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4366 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4367 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4368 // 4. Get checkMap from DeviceManagerNotify
4369 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4370 // 5. check checkMap not null
4371 ASSERT_NE(checkMap, nullptr);
4372 // 6. call DeviceManagerNotify OnUiCall
4373 std::string paramJson = "trstParamJson";
4374 DeviceManagerNotify::GetInstance().OnUiCall(pkgName, paramJson);
4375 // 7. check if callback OnCheckAuthResult called
4376 ASSERT_EQ(count, 1);
4377 }
4378
4379 /*
4380 * Feature: DeviceManagerNotifyTest OnUiCall
4381 * Function: DeviceManagerNotifyTest
4382 * SubFunction: OnUiCall
4383 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4384 * EnvConditions: OnUiCall success.
4385 * CaseDescription: 1. set pkgName not null
4386 * set dmUiCallback_ not null
4387 * 2. set checkMap null
4388 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4389 * 4. Get checkMap from DeviceManagerNotify
4390 * 5. check checkMap not null
4391 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4392 * 7. check if callback OnCheckAuthResult called
4393 */
4394 HWTEST_F(DeviceManagerNotifyTest, OnUiCall2, testing::ext::TestSize.Level0)
4395 {
4396 // 1. set pkgName not null
4397 std::string pkgName = "com.ohos.test";
4398 // set dmUiCallback_ not null
4399 int count = 0;
4400 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4401 // 2. set checkMap null
4402 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4403 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4404 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4405 // 4. Get checkMap from DeviceManagerNotify
4406 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4407 // 5. check checkMap not null
4408 ASSERT_NE(checkMap, nullptr);
4409 // 6. call DeviceManagerNotify OnUiCall
4410 std::string testPkgName = "com.ohos.test1";
4411 std::string paramJson = "trstParamJson";
4412 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4413 // 7. check if callback OnCheckAuthResult called
4414 ASSERT_EQ(count, 0);
4415 }
4416
4417 /*
4418 * Feature: DeviceManagerNotifyTest OnUiCall
4419 * Function: DeviceManagerNotifyTest
4420 * SubFunction: OnUiCall
4421 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4422 * EnvConditions: OnUiCall success.
4423 * CaseDescription: 1. set pkgName not null
4424 * set dmUiCallback_ not null
4425 * 2. set checkMap null
4426 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4427 * 4. Get checkMap from DeviceManagerNotify
4428 * 5. check checkMap not null
4429 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4430 * 7. check if callback OnCheckAuthResult called
4431 */
4432 HWTEST_F(DeviceManagerNotifyTest, OnUiCall3, testing::ext::TestSize.Level0)
4433 {
4434 // 1. set pkgName not null
4435 std::string pkgName = "com.ohos.test";
4436 // set dmUiCallback_ not null
4437 int count = 0;
4438 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4439 // 2. set checkMap null
4440 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4441 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4442 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4443 // 4. Get checkMap from DeviceManagerNotify
4444 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4445 // 5. check checkMap not null
4446 ASSERT_NE(checkMap, nullptr);
4447 // 6. call DeviceManagerNotify OnUiCall
4448 std::string testPkgName = "";
4449 std::string paramJson = "trstParamJson";
4450 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4451 // 7. check if callback OnCheckAuthResult called
4452 ASSERT_EQ(count, 0);
4453 }
4454
4455 /*
4456 * Feature: DeviceManagerNotifyTest OnUiCall
4457 * Function: DeviceManagerNotifyTest
4458 * SubFunction: OnUiCall
4459 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4460 * EnvConditions: OnUiCall success.
4461 * CaseDescription: 1. set pkgName not null
4462 * set dmUiCallback_ not null
4463 * 2. set checkMap null
4464 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4465 * 4. Get checkMap from DeviceManagerNotify
4466 * 5. check checkMap not null
4467 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4468 * 7. check if callback OnCheckAuthResult called
4469 */
4470 HWTEST_F(DeviceManagerNotifyTest, OnUiCall4, testing::ext::TestSize.Level0)
4471 {
4472 // 1. set pkgName not null
4473 std::string pkgName = "com.ohos.test";
4474 // set dmUiCallback_ not null
4475 int count = 0;
4476 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4477 // 2. set checkMap null
4478 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4479 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4480 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4481 // 4. Get checkMap from DeviceManagerNotify
4482 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4483 // 5. check checkMap not null
4484 ASSERT_NE(checkMap, nullptr);
4485 // 6. call DeviceManagerNotify OnUiCall
4486 std::string testPkgName = "com.ohos.test";
4487 std::string paramJson = "trstParamJson";
4488 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4489 // 7. check if callback OnCheckAuthResult called
4490 ASSERT_EQ(count, 1);
4491 }
4492
4493 /*
4494 * Feature: DeviceManagerNotifyTest OnUiCall
4495 * Function: DeviceManagerNotifyTest
4496 * SubFunction: OnUiCall
4497 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4498 * EnvConditions: OnUiCall success.
4499 * CaseDescription: 1. set pkgName not null
4500 * set dmUiCallback_ not null
4501 * 2. set checkMap null
4502 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4503 * 4. Get checkMap from DeviceManagerNotify
4504 * 5. check checkMap not null
4505 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4506 * 7. check if callback OnCheckAuthResult called
4507 */
4508 HWTEST_F(DeviceManagerNotifyTest, OnUiCall5, testing::ext::TestSize.Level0)
4509 {
4510 // 1. set pkgName not null
4511 std::string pkgName = "";
4512 // set dmUiCallback_ not null
4513 int count = 0;
4514 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4515 // 2. set checkMap null
4516 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4517 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4518 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4519 // 4. Get checkMap from DeviceManagerNotify
4520 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4521 // 5. check checkMap not null
4522 ASSERT_NE(checkMap, nullptr);
4523 // 6. call DeviceManagerNotify OnUiCall
4524 std::string testPkgName = "";
4525 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
4526 std::string paramJson = "trstParamJson";
4527 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4528 // 7. check if callback OnCheckAuthResult called
4529 ASSERT_EQ(count, 0);
4530 }
4531
4532 /**
4533 * @tc.name: OnCredentialResult1
4534 * @tc.type: FUNC
4535 */
4536 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult1, testing::ext::TestSize.Level0)
4537 {
4538 std::string pkgName = "";
4539 int32_t action = 1;
4540 std::string credentialResult = "failed";
4541 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4542 }
4543 /**
4544 * @tc.name: OnCredentialResult2
4545 * @tc.type: FUNC
4546 */
4547 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult2, testing::ext::TestSize.Level0)
4548 {
4549 std::string pkgName = "com.ohos.test";
4550 int32_t action = 1;
4551 std::string credentialResult = "failed";
4552 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4553 }
4554
4555 /**
4556 * @tc.name: OnVerifyAuthResult1
4557 * @tc.type: FUNC
4558 */
4559 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult1, testing::ext::TestSize.Level0)
4560 {
4561 std::string pkgName = "";
4562 std::string deviceId = "123";
4563 int32_t resultCode = 0;
4564 int32_t flag = 0;
4565 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4566 }
4567
4568 /**
4569 * @tc.name: OnVerifyAuthResult2
4570 * @tc.type: FUNC
4571 */
4572 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult2, testing::ext::TestSize.Level0)
4573 {
4574 std::string pkgName = "com.ohos.test";
4575 std::string deviceId = "123";
4576 int32_t resultCode = 0;
4577 int32_t flag = 0;
4578 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4579 }
4580 } // namespace
4581
DmInitCallbackTest(int & count)4582 DmInitCallbackTest::DmInitCallbackTest(int &count) : DmInitCallback()
4583 {
4584 count_ = &count;
4585 }
OnRemoteDied()4586 void DmInitCallbackTest::OnRemoteDied()
4587 {
4588 *count_ = *count_ + 1;
4589 }
4590
DeviceStateCallbackTest(int & count)4591 DeviceStateCallbackTest::DeviceStateCallbackTest(int &count) : DeviceStateCallback()
4592 {
4593 count_ = &count;
4594 }
4595
OnDeviceOnline(const DmDeviceInfo & deviceInfo)4596 void DeviceStateCallbackTest::OnDeviceOnline(const DmDeviceInfo &deviceInfo)
4597 {
4598 *count_ = *count_ + 1;
4599 }
4600
OnDeviceReady(const DmDeviceInfo & deviceInfo)4601 void DeviceStateCallbackTest::OnDeviceReady(const DmDeviceInfo &deviceInfo)
4602 {
4603 *count_ = *count_ + 1;
4604 }
4605
OnDeviceOffline(const DmDeviceInfo & deviceInfo)4606 void DeviceStateCallbackTest::OnDeviceOffline(const DmDeviceInfo &deviceInfo)
4607 {
4608 *count_ = *count_ + 1;
4609 }
4610
OnDeviceChanged(const DmDeviceInfo & deviceInfo)4611 void DeviceStateCallbackTest::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
4612 {
4613 *count_ = *count_ + 1;
4614 }
4615
DiscoveryCallbackTest(int & count)4616 DiscoveryCallbackTest::DiscoveryCallbackTest(int &count) : DiscoveryCallback()
4617 {
4618 count_ = &count;
4619 }
4620
OnDeviceFound(uint16_t subscribeId,const DmDeviceInfo & deviceInfo)4621 void DiscoveryCallbackTest::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo)
4622 {
4623 *count_ = *count_ + 1;
4624 }
4625
OnDiscoveryFailed(uint16_t subscribeId,int32_t failedReason)4626 void DiscoveryCallbackTest::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason)
4627 {
4628 *count_ = *count_ + 1;
4629 }
4630
OnDiscoverySuccess(uint16_t subscribeId)4631 void DiscoveryCallbackTest::OnDiscoverySuccess(uint16_t subscribeId)
4632 {
4633 *count_ = *count_ + 1;
4634 }
4635
PublishCallbackTest(int & count)4636 PublishCallbackTest::PublishCallbackTest(int &count) : PublishCallback()
4637 {
4638 count_ = &count;
4639 }
4640
OnPublishResult(int32_t publishId,int32_t failedReason)4641 void PublishCallbackTest::OnPublishResult(int32_t publishId, int32_t failedReason)
4642 {
4643 *count_ = *count_ + 1;
4644 }
4645
AuthenticateCallbackTest(int & count)4646 AuthenticateCallbackTest::AuthenticateCallbackTest(int &count) : AuthenticateCallback()
4647 {
4648 count_ = &count;
4649 }
4650
OnAuthResult(const std::string & deviceId,const std::string & token,int32_t status,int32_t reason)4651 void AuthenticateCallbackTest::OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status,
4652 int32_t reason)
4653 {
4654 *count_ = *count_ + 1;
4655 }
4656
DeviceManagerFaCallbackTest(int & count)4657 DeviceManagerFaCallbackTest::DeviceManagerFaCallbackTest(int &count) : DeviceManagerUiCallback()
4658 {
4659 count_ = &count;
4660 }
4661
OnCall(const std::string & paramJson)4662 void DeviceManagerFaCallbackTest::OnCall(const std::string ¶mJson)
4663 {
4664 *count_ = *count_ + 1;
4665 }
4666 } // namespace DistributedHardware
4667 } // namespace OHOS
4668