1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "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 EXPECT_EQ(DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_.count(pkgName), 0);
979 }
980
981 /**
982 * @tc.name: UnRegisterDiscoverCallback_001
983 * @tc.desc: 1. set pkgName not null
984 * set callback not null
985 * set subscribeId not null
986 * 2. set checkMap null
987 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
988 * 4. Get checkMap from DeviceManagerNotify
989 * 5. check checkMap not null
990 * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
991 * 7. Get checkMap from DeviceManagerNotify
992 * 8. check checkMap null
993 * @tc.type: FUNC
994 * @tc.require: AR000GHSJK
995 */
996 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_001, testing::ext::TestSize.Level0)
997 {
998 // 1. set pkgName not null
999 std::string pkgName = "com.ohos.test";
1000 // set dmInitCallback not null
1001 int count = 0;
1002 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1003 // set subscribeId not null
1004 uint16_t subscribeId = 0;
1005 // 2. set checkMap null
1006 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1007 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1008 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1009 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1010 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1011 // 5. check checkMap not null
1012 ASSERT_NE(checkMap, nullptr);
1013 // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1014 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
1015 // 7. Get checkMap from DeviceManagerNotify
1016 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1017 // 8 check checkMap null
1018 ASSERT_EQ(checkMap, nullptr);
1019 }
1020
1021 /**
1022 * @tc.name: UnRegisterDiscoverCallback_002
1023 * @tc.desc: 1. set pkgName com.ohos.test
1024 * set dmInitCallback not null
1025 * set subscribeId not null
1026 * 2. set checkMap null
1027 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1028 * 4. Get checkMap from DeviceManagerNotify
1029 * 5. check checkMap not null
1030 * 6. set testpkcName com.ohos.test1
1031 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1032 * 8. Get checkMap from DeviceManagerNotify
1033 * 9. check checkMap not null
1034 * @tc.type: FUNC
1035 * @tc.require: AR000GHSJK
1036 */
1037 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_002, testing::ext::TestSize.Level0)
1038 {
1039 // 1. set pkgName not null
1040 std::string pkgName = "com.ohos.test";
1041 // set dmInitCallback not null
1042 int count = 0;
1043 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1044 // set subscribeId not null
1045 uint16_t subscribeId = 0;
1046 // 2. set checkMap null
1047 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1048 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1049 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1050 // 4. Get checkMap from DeviceManagerNotify
1051 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1052 // 5. check checkMap not null
1053 ASSERT_NE(checkMap, nullptr);
1054 // 6. set testpkcName com.ohos.test1
1055 std::string testPkgName = "com.ohos.test1";
1056 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1057 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1058 // 8. Get checkMap from DeviceManagerNotify
1059 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1060 // 8 check checkMap not null
1061 ASSERT_NE(checkMap, nullptr);
1062 }
1063
1064 /**
1065 * @tc.name: UnRegisterDiscoverCallback_003
1066 * @tc.desc: 1. set pkgName com.ohos.test
1067 * set dmInitCallback not null
1068 * set subscribeId not null
1069 * 2. set checkMap null
1070 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1071 * 4. Get checkMap from DeviceManagerNotify
1072 * 5. check checkMap not null
1073 * 6. set testpkcName com.ohos.test1
1074 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1075 * 8. Get checkMap from DeviceManagerNotify
1076 * 9. check checkMap not null
1077 * 10. call checkMap OnDiscoverySuccess
1078 * 11. check count is 1
1079 * @tc.type: FUNC
1080 * @tc.require: AR000GHSJK
1081 */
1082 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_003, testing::ext::TestSize.Level0)
1083 {
1084 // 1. set pkgName not null
1085 std::string pkgName = "com.ohos.test";
1086 // set dmInitCallback not null
1087 int count = 0;
1088 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1089 // set subscribeId not null
1090 uint16_t subscribeId = 0;
1091 // 2. set checkMap null
1092 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1093 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1094 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1095 // 4. Get checkMap from DeviceManagerNotify
1096 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1097 // 5. check checkMap not null
1098 ASSERT_NE(checkMap, nullptr);
1099 // 6. set testpkcName com.ohos.test1
1100 std::string testPkgName = "com.ohos.test1";
1101 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1102 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1103 // 8. Get checkMap from DeviceManagerNotify
1104 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1105 // 9 check checkMap not null
1106 ASSERT_NE(checkMap, nullptr);
1107 // 10. call checkMap OnDiscoverySuccess
1108 checkMap->OnDiscoverySuccess(subscribeId);
1109 // 11. check count is 1
1110 ASSERT_EQ(count, 1);
1111 }
1112
1113 /**
1114 * @tc.name: UnRegisterDiscoverCallback_004
1115 * @tc.desc: 1. set pkgName not null
1116 * set callback not null
1117 * set subscribeId not null
1118 * 2. set checkMap null
1119 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1120 * 4. Get checkMap from DeviceManagerNotify
1121 * 5. check checkMap not null
1122 * 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1123 * 7. Get checkMap from DeviceManagerNotify
1124 * 8. check checkMap null
1125 * @tc.type: FUNC
1126 * @tc.require: AR000GHSJK
1127 */
1128 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_004, testing::ext::TestSize.Level0)
1129 {
1130 // 1. set pkgName not null
1131 std::string pkgName = "com.ohos.test";
1132 // set dmInitCallback not null
1133 int count = 0;
1134 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1135 // set subscribeId not null
1136 uint16_t subscribeId = 0;
1137 // 2. set checkMap null
1138 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1139 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1140 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1141 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1142 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1143 // 5. check checkMap not null
1144 ASSERT_NE(checkMap, nullptr);
1145 // 6. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with parameter
1146 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(pkgName, subscribeId);
1147 // 7. Get checkMap from DeviceManagerNotify
1148 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1149 // 8 check checkMap null
1150 if (checkMap == nullptr) {
1151 ASSERT_NE(count, 1);
1152 return;
1153 }
1154 ASSERT_NE(checkMap, nullptr);
1155 }
1156
1157 /**
1158 * @tc.name: UnRegisterDiscoverCallback_005
1159 * @tc.desc: 1. set pkgName com.ohos.test
1160 * set dmInitCallback not null
1161 * set subscribeId not null
1162 * 2. set checkMap null
1163 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1164 * 4. Get checkMap from DeviceManagerNotify
1165 * 5. check checkMap not null
1166 * 6. set testpkcName com.ohos.test1
1167 * 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1168 * 8. Get checkMap from DeviceManagerNotify
1169 * 9. check checkMap not null
1170 * 10. call checkMap OnDiscoverySuccess
1171 * 11. check count is 1
1172 * @tc.type: FUNC
1173 * @tc.require: AR000GHSJK
1174 */
1175 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDiscoveryCallback_005, testing::ext::TestSize.Level0)
1176 {
1177 // 1. set pkgName not null
1178 std::string pkgName = "com.ohos.test";
1179 // set dmInitCallback not null
1180 int count = 0;
1181 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
1182 // set subscribeId not null
1183 uint16_t subscribeId = 0;
1184 // 2. set checkMap null
1185 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
1186 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
1187 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
1188 // 4. Get checkMap from DeviceManagerNotify
1189 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1190 // 5. check checkMap not null
1191 ASSERT_NE(checkMap, nullptr);
1192 // 6. set testpkcName com.ohos.test1
1193 std::string testPkgName = "";
1194 // 7. call DeviceManagerNotifyTest UnRegisterDiscoverCallback with testpkcName
1195 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
1196 // 8. Get checkMap from DeviceManagerNotify
1197 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1198 // 9 check checkMap not null
1199 ASSERT_NE(checkMap, nullptr);
1200 // 10. call checkMap OnDiscoverySuccess
1201 checkMap->OnDiscoverySuccess(subscribeId);
1202 // 11. check count is 1
1203 ASSERT_EQ(count, 1);
1204 }
1205
1206 /**
1207 * @tc.name: RegisterAuthenticateCallback_001
1208 * @tc.desc: 1. set pkgName not null
1209 * set Callback not null
1210 * set deviceId not null
1211 * 2. set checkMap null
1212 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1213 * 4. Get checkMap from DeviceManagerNotify
1214 * 5. check checkMap not null
1215 * @tc.type: FUNC
1216 * @tc.require: AR000GHSJK
1217 */
1218 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_001, testing::ext::TestSize.Level0)
1219 {
1220 // 1. set pkgName not null
1221 std::string pkgName = "com.ohos.test";
1222 // set dmInitCallback not null
1223 int count = 0;
1224 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1225 // set subscribeId not null
1226 std::string deviceId = "1";
1227 // 2. set checkMap null
1228 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1229 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1230 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1231 // 4. Get checkMap from DeviceManagerNotify
1232 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1233 // 5. check checkMap not null
1234 ASSERT_NE(checkMap, nullptr);
1235 }
1236
1237 /**
1238 * @tc.name: RegisterAuthenticateCallback_002
1239 * @tc.desc: 1. set pkgName not null
1240 * set Callback null
1241 * set deviceId not null
1242 * 2. set checkMap null
1243 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1244 * 4. Get checkMap from DeviceManagerNotify
1245 * 5. check checkMap null
1246 * @tc.type: FUNC
1247 * @tc.require: AR000GHSJK
1248 */
1249 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_002, testing::ext::TestSize.Level0)
1250 {
1251 // 1. set pkgName not null
1252 std::string pkgName = "com.ohos.test";
1253 // set dmInitCallback null
1254 std::shared_ptr<AuthenticateCallback> callback = nullptr;
1255 // set subscribeId not null
1256 std::string deviceId = "1";
1257 // 2. set checkMap not null
1258 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1259 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1260 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1261 // 4. Get checkMap from DeviceManagerNotify
1262 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1263 // 5. check checkMap null
1264 ASSERT_EQ(checkMap, nullptr);
1265 }
1266
1267 /**
1268 * @tc.name: RegisterAuthenticateCallback_003
1269 * @tc.desc: 1. set pkgName com.ohos.test
1270 * set Callback not null
1271 * set deviceId not null
1272 * 2. set checkMap null
1273 * 3. set testpkcName com.ohos.test1
1274 * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1275 * 5. Get checkMap from DeviceManagerNotify with testpkcName
1276 * 6. check checkMap null
1277 * @tc.type: FUNC
1278 * @tc.require: AR000GHSJK
1279 */
1280 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_003, testing::ext::TestSize.Level0)
1281 {
1282 // 1. set pkgName com.ohos.test
1283 std::string pkgName = "com.ohos.test";
1284 // set dmInitCallback not null
1285 std::shared_ptr<AuthenticateCallback> callback = nullptr;
1286 // set subscribeId not null
1287 std::string deviceId = "1";
1288 // 2. set checkMap null
1289 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1290 // 3. set testpkcName com.ohos.test1
1291 std::string testPkgName = "com.ohos.test1";
1292 // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1293 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1294 // 5. Get checkMap from DeviceManagerNotify with testpkcName
1295 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1296 // 6. check checkMap not null
1297 ASSERT_EQ(checkMap, nullptr);
1298 }
1299
1300 /**
1301 * @tc.name: RegisterAuthenticateCallback_004
1302 * @tc.desc: 1. set pkgName not null
1303 * set Callback not null
1304 * set deviceId not null
1305 * 2. set checkMap null
1306 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1307 * 4. Get checkMap from DeviceManagerNotify
1308 * 5. check checkMap not null
1309 * @tc.type: FUNC
1310 * @tc.require: AR000GHSJK
1311 */
1312 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_004, testing::ext::TestSize.Level0)
1313 {
1314 // 1. set pkgName not null
1315 std::string pkgName = "com.ohos.test";
1316 // set dmInitCallback not null
1317 int count = 0;
1318 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1319 // set subscribeId not null
1320 std::string deviceId = "1";
1321 // 2. set checkMap null
1322 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1323 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1324 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1325 // 4. Get checkMap from DeviceManagerNotify
1326 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1327 // 5. check checkMap not null
1328 ASSERT_NE(checkMap, nullptr);
1329 // 6. call checkMap OnAuthResult
1330 std::string token ="1";
1331 int32_t status = 1;
1332 int32_t reason = 1;
1333 checkMap->OnAuthResult(deviceId, token, status, reason);
1334 // 7. check count is 1
1335 ASSERT_EQ(count, 1);
1336 }
1337
1338 /**
1339 * @tc.name: RegisterAuthenticateCallback_005
1340 * @tc.desc: 1. set pkgName com.ohos.test
1341 * set Callback not null
1342 * set deviceId not null
1343 * 2. set checkMap null
1344 * 3. set testpkcName com.ohos.test1
1345 * 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1346 * 5. Get checkMap from DeviceManagerNotify with testpkcName
1347 * 6. check checkMap null
1348 * @tc.type: FUNC
1349 * @tc.require: AR000GHSJK
1350 */
1351 HWTEST_F(DeviceManagerNotifyTest, RegisterAuthenticateCallback_005, testing::ext::TestSize.Level0)
1352 {
1353 // 1. set pkgName com.ohos.test
1354 std::string pkgName = "com.ohos.test";
1355 int count = 0;
1356 // set dmInitCallback not null
1357 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1358 // set subscribeId not null
1359 std::string deviceId = "1";
1360 // 2. set checkMap null
1361 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1362 // 3. set testpkcName com.ohos.test1
1363 std::string testPkgName = "com.ohos.test1";
1364 // 4. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1365 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1366 // 5. Get checkMap from DeviceManagerNotify with testpkcName
1367 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1368 // 6. check checkMap not null
1369 if (checkMap == nullptr) {
1370 ASSERT_NE(count, 1);
1371 return;
1372 }
1373 ASSERT_NE(checkMap, nullptr);
1374 }
1375
1376 /**
1377 * @tc.name: UnRegisterAuthenticateCallback_001
1378 * @tc.desc: 1. set pkgName not null
1379 * set callback not null
1380 * set deviceId not null
1381 * 2. set checkMap null
1382 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1383 * 4. Get checkMap from DeviceManagerNotify
1384 * 5. check checkMap not null
1385 * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1386 * 7. Get checkMap from DeviceManagerNotify
1387 * 8. check checkMap null
1388 * @tc.type: FUNC
1389 * @tc.require: AR000GHSJK
1390 */
1391 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_001, testing::ext::TestSize.Level0)
1392 {
1393 // 1. set pkgName not null
1394 std::string pkgName = "com.ohos.test";
1395 // set dmInitCallback not null
1396 int count = 0;
1397 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1398 // set subscribeId not null
1399 std::string deviceId = "1";
1400 // 2. set checkMap null
1401 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1402 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1403 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1404 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1405 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1406 // 5. check checkMap not null
1407 ASSERT_NE(checkMap, nullptr);
1408 // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1409 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId);
1410 // 7. Get checkMap from DeviceManagerNotify
1411 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1412 // 8 check checkMap null
1413 ASSERT_EQ(checkMap, nullptr);
1414 }
1415
1416 /**
1417 * @tc.name: UnRegisterAuthenticateCallback_002
1418 * @tc.desc: 1. set pkgName com.ohos.test
1419 * set dmInitCallback not null
1420 * set subscribeId not null
1421 * 2. set checkMap null
1422 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1423 * 4. Get checkMap from DeviceManagerNotify
1424 * 5. check checkMap not null
1425 * 6. set testpkcName com.ohos.test1
1426 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1427 * 8. Get checkMap from DeviceManagerNotify
1428 * 9. check checkMap not null
1429 * @tc.type: FUNC
1430 * @tc.require: AR000GHSJK
1431 */
1432 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_002, testing::ext::TestSize.Level0)
1433 {
1434 // 1. set pkgName not null
1435 std::string pkgName = "com.ohos.test";
1436 // set dmInitCallback not null
1437 int count = 0;
1438 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1439 // set subscribeId not null
1440 std::string deviceId = "1";
1441 // 2. set checkMap null
1442 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1443 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1444 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1445 // 4. Get checkMap from DeviceManagerNotify
1446 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1447 // 5. check checkMap not null
1448 ASSERT_NE(checkMap, nullptr);
1449 // 6. set testpkcName com.ohos.test1
1450 std::string testPkgName = "com.ohos.test1";
1451 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1452 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1453 // 8. Get checkMap from DeviceManagerNotify
1454 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1455 // 8 check checkMap not null
1456 ASSERT_NE(checkMap, nullptr);
1457 }
1458
1459 /**
1460 * @tc.name: UnRegisterAuthenticateCallback_003
1461 * @tc.desc: 1. set pkgName com.ohos.test
1462 * set dmInitCallback not null
1463 * set subscribeId not null
1464 * 2. set checkMap null
1465 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1466 * 4. Get checkMap from DeviceManagerNotify
1467 * 5. check checkMap not null
1468 * 6. set testpkcName com.ohos.test1
1469 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1470 * 8. Get checkMap from DeviceManagerNotify
1471 * 9. check checkMap not null
1472 * 10. call checkMap OnAuthResult
1473 * 11. check count is 1
1474 * @tc.type: FUNC
1475 * @tc.require: AR000GHSJK
1476 */
1477 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_003, testing::ext::TestSize.Level0)
1478 {
1479 // 1. set pkgName not null
1480 std::string pkgName = "com.ohos.test";
1481 // set dmInitCallback not null
1482 int count = 0;
1483 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1484 // set subscribeId not null
1485 std::string deviceId = "1";
1486 // 2. set checkMap null
1487 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1488 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1489 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1490 // 4. Get checkMap from DeviceManagerNotify
1491 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1492 // 5. check checkMap not null
1493 ASSERT_NE(checkMap, nullptr);
1494 // 6. set testpkcName com.ohos.test1
1495 std::string testPkgName = "com.ohos.test1";
1496 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1497 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1498 // 8. Get checkMap from DeviceManagerNotify
1499 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1500 // 9 check checkMap not null
1501 ASSERT_NE(checkMap, nullptr);
1502 // 10. call checkMap OnAuthResult
1503 std::string token ="1";
1504 int32_t status = 1;
1505 int32_t reason = 1;
1506 checkMap->OnAuthResult(deviceId, token, status, reason);
1507 // 11. check count is 1
1508 ASSERT_EQ(count, 1);
1509 }
1510
1511 /**
1512 * @tc.name: UnRegisterAuthenticateCallback_004
1513 * @tc.desc: 1. set pkgName not null
1514 * set callback not null
1515 * set deviceId not null
1516 * 2. set checkMap null
1517 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1518 * 4. Get checkMap from DeviceManagerNotify
1519 * 5. check checkMap not null
1520 * 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1521 * 7. Get checkMap from DeviceManagerNotify
1522 * 8. check checkMap null
1523 * @tc.type: FUNC
1524 * @tc.require: AR000GHSJK
1525 */
1526 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_004, testing::ext::TestSize.Level0)
1527 {
1528 // 1. set pkgName not null
1529 std::string pkgName = "com.ohos.test";
1530 // set dmInitCallback not null
1531 int count = 0;
1532 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1533 // set subscribeId not null
1534 std::string deviceId = "1";
1535 // 2. set checkMap null
1536 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1537 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1538 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1539 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
1540 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1541 // 5. check checkMap not null
1542 ASSERT_NE(checkMap, nullptr);
1543 // 6. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with parameter
1544 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(pkgName, deviceId);
1545 // 7. Get checkMap from DeviceManagerNotify
1546 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1547 // 8. check checkMap not null
1548 if (checkMap == nullptr) {
1549 ASSERT_NE(count, 1);
1550 return;
1551 }
1552 ASSERT_NE(checkMap, nullptr);
1553 }
1554
1555 /**
1556 * @tc.name: UnRegisterAuthenticateCallback_005
1557 * @tc.desc: 1. set pkgName com.ohos.test
1558 * set dmInitCallback not null
1559 * set subscribeId not null
1560 * 2. set checkMap null
1561 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1562 * 4. Get checkMap from DeviceManagerNotify
1563 * 5. check checkMap not null
1564 * 6. set testpkcName com.ohos.test1
1565 * 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1566 * 8. Get checkMap from DeviceManagerNotify
1567 * 9. check checkMap not null
1568 * @tc.type: FUNC
1569 * @tc.require: AR000GHSJK
1570 */
1571 HWTEST_F(DeviceManagerNotifyTest, UnRegisterAuthenticateCallback_005, testing::ext::TestSize.Level0)
1572 {
1573 // 1. set pkgName not null
1574 std::string pkgName = "com.ohos.test";
1575 // set dmInitCallback not null
1576 int count = 0;
1577 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
1578 // set subscribeId not null
1579 std::string deviceId = "1";
1580 // 2. set checkMap null
1581 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
1582 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
1583 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
1584 // 4. Get checkMap from DeviceManagerNotify
1585 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1586 // 5. check checkMap not null
1587 ASSERT_NE(checkMap, nullptr);
1588 // 6. set testpkcName com.ohos.test1
1589 std::string testPkgName = "";
1590 // 7. call DeviceManagerNotifyTest UnRegisterAuthenticateCallback with testpkcName
1591 DeviceManagerNotify::GetInstance().UnRegisterAuthenticateCallback(testPkgName, deviceId);
1592 // 8. Get checkMap from DeviceManagerNotify
1593 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1594 // 8 check checkMap not null
1595 ASSERT_NE(checkMap, nullptr);
1596 }
1597
1598 /**
1599 * @tc.name: UnRegisterPackageCallback_001
1600 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1601 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1602 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1603 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1604 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1605 * 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1606 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1607 * @tc.type: FUNC
1608 * @tc.require: AR000GHSJK
1609 */
1610 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_001, testing::ext::TestSize.Level0)
1611 {
1612 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1613 std::string pkgName = "com.ohos.test";
1614 int count = 0;
1615 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1616 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1617 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1618 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1619 ASSERT_NE(checkMap, nullptr);
1620 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1621 int count1 = 0;
1622 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1623 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1624 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1625 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1626 ASSERT_NE(checkMap1, nullptr);
1627 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1628 int count2 = 0;
1629 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1630 uint16_t subscribeId = 0;
1631 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1632 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1633 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1634 ASSERT_NE(checkMap2, nullptr);
1635 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1636 int count3 = 0;
1637 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1638 std::string deviceId = "1";
1639 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1640 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1641 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1642 ASSERT_NE(checkMap3, nullptr);
1643 // 5. RegisterPublishCallback with pkgName and deviceStateCallback and subscribeId
1644 int count4 = 0;
1645 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1646 int32_t publishId = 0;
1647 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1648 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1649 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1650 ASSERT_NE(checkMap4, nullptr);
1651 // 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1652 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
1653 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1654 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1655 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1656 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1657 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1658 // 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1659 ASSERT_EQ(checkMap, nullptr);
1660 ASSERT_EQ(checkMap1, nullptr);
1661 ASSERT_EQ(checkMap2, nullptr);
1662 ASSERT_EQ(checkMap3, nullptr);
1663 ASSERT_EQ(checkMap4, nullptr);
1664 }
1665
1666 /**
1667 * @tc.name: UnRegisterPackageCallback_002
1668 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1669 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1670 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1671 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1672 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1673 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1674 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1675 * @tc.type: FUNC
1676 * @tc.require: AR000GHSJK
1677 */
1678 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_002, testing::ext::TestSize.Level0)
1679 {
1680 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1681 std::string pkgName = "com.ohos.test";
1682 int count = 0;
1683 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1684 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1685 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1686 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1687 ASSERT_NE(checkMap, nullptr);
1688 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1689 int count1 = 0;
1690 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1691 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1692 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1693 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1694 ASSERT_NE(checkMap1, nullptr);
1695 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1696 int count2 = 0;
1697 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1698 uint16_t subscribeId = 0;
1699 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1700 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1701 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1702 ASSERT_NE(checkMap2, nullptr);
1703 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1704 int count3 = 0;
1705 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1706 std::string deviceId = "1";
1707 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1708 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1709 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1710 ASSERT_NE(checkMap3, nullptr);
1711 // 5. RegisterPublishCallback with pkgName and deviceStateCallback and publishId
1712 int count4 = 0;
1713 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1714 int32_t publishId = 0;
1715 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1716 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1717 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1718 ASSERT_NE(checkMap4, nullptr);
1719 // 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1720 std::string testPkgName = "com.ohos.test1";
1721 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1722 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1723 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1724 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1725 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1726 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1727 // 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1728 ASSERT_NE(checkMap, nullptr);
1729 ASSERT_NE(checkMap1, nullptr);
1730 ASSERT_NE(checkMap2, nullptr);
1731 ASSERT_NE(checkMap3, nullptr);
1732 ASSERT_NE(checkMap4, nullptr);
1733 }
1734
1735 /**
1736 * @tc.name: UnRegisterPackageCallback_003
1737 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1738 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1739 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1740 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1741 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1742 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1743 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1744 * @tc.type: FUNC
1745 * @tc.require: AR000GHSJK
1746 */
1747 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_003, testing::ext::TestSize.Level0)
1748 {
1749 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1750 std::string pkgName = "com.ohos.test";
1751 int count[5] = {0, 0, 0, 0, 0};
1752 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count[0]);
1753 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1754 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1755 ASSERT_NE(DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName], nullptr);
1756 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1757 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count[1]);
1758 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1759 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1760 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName], nullptr);
1761 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1762 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count[2]);
1763 uint16_t subscribeId = 0;
1764 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1765 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1766 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId], nullptr);
1767 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1768 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count[3]);
1769 std::string deviceId = "1";
1770 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1771 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1772 ASSERT_NE(DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId], nullptr);
1773 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1774 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count[4]);
1775 int32_t publishId = 0;
1776 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1777 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1778 ASSERT_NE(DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId], nullptr);
1779 // 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1780 std::string testPkgName = "com.ohos.test1";
1781 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1782 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1783 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1784 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1785 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1786 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1787 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1788 ASSERT_NE(checkMap, nullptr);
1789 ASSERT_NE(checkMap1, nullptr);
1790 ASSERT_NE(checkMap2, nullptr);
1791 ASSERT_NE(checkMap3, nullptr);
1792 ASSERT_NE(checkMap4, nullptr);
1793 // 7. call checkMap OnRemoteDied()
1794 checkMap->OnRemoteDied();
1795 // call checkMap1 OnDeviceOnline
1796 DmDeviceInfo deviceInfo;
1797 checkMap1->OnDeviceOnline(deviceInfo);
1798 // call checkMap2 OnDeviceFound
1799 checkMap2->OnDeviceFound(subscribeId, deviceInfo);
1800 // call checkMap3 OnAuthResult
1801 checkMap3->OnAuthResult(deviceId, "1", 1, 1);
1802 // call checkMap4 OnPublishResult
1803 checkMap4->OnPublishResult(publishId, 0);
1804 // 8. check count count1 count2 count3 is 1
1805 for (uint32_t i = 0; i < 5; i++) {
1806 ASSERT_EQ(count[i], 1);
1807 }
1808 }
1809
1810 /**
1811 * @tc.name: UnRegisterPackageCallback_004
1812 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1813 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1814 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1815 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1816 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1817 * 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1818 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is null
1819 * @tc.type: FUNC
1820 * @tc.require: AR000GHSJK
1821 */
1822 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_004, testing::ext::TestSize.Level0)
1823 {
1824 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1825 std::string pkgName = "com.ohos.test";
1826 int count[5] = {0, 0, 0, 0, 0};
1827 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count[0]);
1828 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1829 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1830 ASSERT_NE(DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName], nullptr);
1831 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1832 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count[1]);
1833 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1834 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1835 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName], nullptr);
1836 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1837 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count[2]);
1838 uint16_t subscribeId = 0;
1839 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1840 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1841 ASSERT_NE(DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId], nullptr);
1842 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1843 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count[3]);
1844 std::string deviceId = "1";
1845 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1846 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1847 ASSERT_NE(DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId], nullptr);
1848 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1849 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count[4]);
1850 int32_t publishId = 0;
1851 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1852 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1853 ASSERT_NE(DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId], nullptr);
1854 // 6. call DeviceManagerNotify UnRegisterPackageCallback with PkgName
1855 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(pkgName);
1856 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1857 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1858 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1859 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1860 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1861 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1862 if (checkMap == nullptr && checkMap1 == nullptr && checkMap2 == nullptr && checkMap3 == nullptr &&
1863 checkMap4 == nullptr) {
1864 for (uint32_t i = 0; i < 5; i++) {
1865 ASSERT_NE(count[i], 1);
1866 }
1867 return;
1868 }
1869 ASSERT_EQ(checkMap, nullptr);
1870 ASSERT_EQ(checkMap1, nullptr);
1871 ASSERT_EQ(checkMap2, nullptr);
1872 ASSERT_EQ(checkMap3, nullptr);
1873 ASSERT_EQ(checkMap4, nullptr);
1874 }
1875
1876 /**
1877 * @tc.name: UnRegisterPackageCallback_005
1878 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1879 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1880 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1881 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1882 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1883 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1884 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1885 * @tc.type: FUNC
1886 * @tc.require: AR000GHSJK
1887 */
1888 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_005, testing::ext::TestSize.Level0)
1889 {
1890 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1891 std::string pkgName = "com.ohos.test";
1892 int count = 0;
1893 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1894 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1895 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1896 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1897 ASSERT_NE(checkMap, nullptr);
1898 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1899 int count1 = 0;
1900 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1901 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1902 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1903 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1904 ASSERT_NE(checkMap1, nullptr);
1905 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1906 int count2 = 0;
1907 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1908 uint16_t subscribeId = 0;
1909 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1910 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1911 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1912 ASSERT_NE(checkMap2, nullptr);
1913 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1914 int count3 = 0;
1915 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1916 std::string deviceId = "1";
1917 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1918 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1919 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1920 ASSERT_NE(checkMap3, nullptr);
1921 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1922 int count4 = 0;
1923 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1924 int32_t publishId = 0;
1925 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1926 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1927 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][subscribeId];
1928 ASSERT_NE(checkMap4, nullptr);
1929 // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1930 std::string testPkgName = "";
1931 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
1932 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1933 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1934 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1935 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1936 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
1937 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
1938 ASSERT_NE(checkMap, nullptr);
1939 ASSERT_NE(checkMap1, nullptr);
1940 ASSERT_NE(checkMap2, nullptr);
1941 ASSERT_NE(checkMap3, nullptr);
1942 ASSERT_NE(checkMap4, nullptr);
1943 }
1944
1945 /**
1946 * @tc.name: UnRegisterPackageCallback_005
1947 * @tc.desc: 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1948 * 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1949 * 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1950 * 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1951 * 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1952 * 6. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1953 * 7. check if checkMap checkMap1 checkMap2 checkMap3 is not null
1954 * @tc.type: FUNC
1955 * @tc.require: AR000GHSJK
1956 */
1957 HWTEST_F(DeviceManagerNotifyTest, UnRegisterPackageCallback_006, testing::ext::TestSize.Level0)
1958 {
1959 // 1. RegisterDeathRecipientCallback with pkgName and dmInitCallback
1960 std::string pkgName;
1961 int count = 0;
1962 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
1963 std::shared_ptr<DmInitCallback> checkMap = nullptr;
1964 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
1965 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
1966 ASSERT_EQ(checkMap, nullptr);
1967 // 2. RegisterDeviceStateCallback with pkgName and deviceStateCallback
1968 int count1 = 0;
1969 std::shared_ptr<DeviceStateCallback> deviceStateCallback = std::make_shared<DeviceStateCallbackTest>(count1);
1970 std::shared_ptr<DeviceStateCallback> checkMap1 = nullptr;
1971 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, deviceStateCallback);
1972 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
1973 ASSERT_EQ(checkMap1, nullptr);
1974 // 3. RegisterDiscoverCallback with pkgName and deviceStateCallback and subscribeId
1975 int count2 = 0;
1976 std::shared_ptr<DiscoveryCallback> deviceDiscoveryCallback = std::make_shared<DiscoveryCallbackTest>(count2);
1977 uint16_t subscribeId = 0;
1978 std::shared_ptr<DiscoveryCallback> checkMap2 = nullptr;
1979 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, deviceDiscoveryCallback);
1980 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
1981 ASSERT_EQ(checkMap2, nullptr);
1982 // 4. RegisterAuthenticateCallback with pkgName and deviceId and authenticateCallback
1983 int count3 = 0;
1984 std::shared_ptr<AuthenticateCallback> authenticateCallback = std::make_shared<AuthenticateCallbackTest>(count3);
1985 std::string deviceId = "1";
1986 std::shared_ptr<AuthenticateCallback> checkMap3 = nullptr;
1987 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, authenticateCallback);
1988 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
1989 ASSERT_EQ(checkMap3, nullptr);
1990 // 5. RegisterPublishCallback with pkgName and devicePublishCallback and publishId
1991 int count4 = 0;
1992 std::shared_ptr<PublishCallback> devicePublishCallback = std::make_shared<PublishCallbackTest>(count4);
1993 int32_t publishId = 0;
1994 std::shared_ptr<PublishCallback> checkMap4 = nullptr;
1995 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, devicePublishCallback);
1996 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][subscribeId];
1997 ASSERT_EQ(checkMap4, nullptr);
1998 // 5. call DeviceManagerNotify UnRegisterPackageCallback with testPkgName
1999 std::string testPkgName = "";
2000 DeviceManagerNotify::GetInstance().UnRegisterPackageCallback(testPkgName);
2001 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
2002 checkMap1 = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2003 checkMap2 = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
2004 checkMap3 = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
2005 checkMap4 = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
2006 // 6. check if checkMap checkMap1 checkMap2 checkMap3 is null
2007 ASSERT_EQ(checkMap, nullptr);
2008 ASSERT_EQ(checkMap1, nullptr);
2009 ASSERT_EQ(checkMap2, nullptr);
2010 ASSERT_EQ(checkMap3, nullptr);
2011 ASSERT_EQ(checkMap4, nullptr);
2012 }
2013
2014 /*
2015 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2016 * Function: DeviceManagerNotifyTest
2017 * SubFunction: RegisterDeviceManagerFaCallback
2018 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2019 * EnvConditions: RegisterDeviceManagerFaCallback success.
2020 * CaseDescription: 1. set pkgName not null
2021 * set dmUiCallback_ not null
2022 * 2. set checkMap null
2023 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2024 * 4. Get checkMap from DeviceManagerNotify
2025 * 5. check checkMap not null
2026 */
2027 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0)
2028 {
2029 // 1. set pkgName not null
2030 std::string pkgName = "com.ohos.test";
2031 // set dmUiCallback_ not null
2032 int count = 0;
2033 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2034 // 2. set checkMap null
2035 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2036 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2037 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2038 // 4. Get checkMap from DeviceManagerNotify
2039 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2040 // 5. check checkMap not null
2041 ASSERT_NE(checkMap, nullptr);
2042 }
2043
2044 /*
2045 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2046 * Function: DeviceManagerNotifyTest
2047 * SubFunction: RegisterDeviceManagerFaCallback
2048 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2049 * EnvConditions: N/A.
2050 * CaseDescription: 1. set pkgName not null
2051 * set dmUiCallback_ null
2052 * 2. set checkMap null
2053 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2054 * 4. Get checkMap from DeviceManagerNotify
2055 * 5. check checkMap null
2056 */
2057 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0)
2058 {
2059 // 1. set pkgName not null
2060 std::string pkgName = "com.ohos.test";
2061 // set dmInitCallback null
2062 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr;
2063 // 2. set checkMap not null
2064 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2065 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2066 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2067 // 4. Get checkMap from DeviceManagerNotify
2068 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2069 // 5. check checkMap null
2070 ASSERT_EQ(checkMap, nullptr);
2071 }
2072
2073 /*
2074 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2075 * Function: DeviceManagerNotifyTest
2076 * SubFunction: RegisterDeviceManagerFaCallback
2077 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2078 * EnvConditions: N/A.
2079 * CaseDescription: 1. set pkgName com.ohos.test
2080 * set dmUiCallback_ not null
2081 * 2. set checkMap null
2082 * 3. set testpkcName com.ohos.test1
2083 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2084 * 5. Get checkMap from DeviceManagerNotify with testpkcName
2085 * 6. check checkMap null
2086 */
2087 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0)
2088 {
2089 // 1. set pkgName com.ohos.test
2090 std::string pkgName = "com.ohos.test";
2091 // set dmInitCallback not null
2092 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr;
2093 // 2. set checkMap null
2094 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2095 // 3. set testpkcName com.ohos.test1
2096 std::string testPkgName = "com.ohos.test1";
2097 // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2098 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2099 // 5. Get checkMap from DeviceManagerNotify with testpkcName
2100 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName];
2101 // 6. check checkMap not null
2102 ASSERT_EQ(checkMap, nullptr);
2103 }
2104
2105 /*
2106 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2107 * Function: DeviceManagerNotifyTest
2108 * SubFunction: RegisterDeviceManagerFaCallback
2109 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2110 * EnvConditions: RegisterDeviceManagerFaCallback success.
2111 * CaseDescription: 1. set pkgName not null
2112 * set dmUiCallback_ not null
2113 * 2. set checkMap null
2114 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2115 * 4. Get checkMap from DeviceManagerNotify
2116 * 5. check checkMap not null
2117 */
2118 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0)
2119 {
2120 // 1. set pkgName not null
2121 std::string pkgName = "com.ohos.test";
2122 // set dmUiCallback_ not null
2123 int count = 0;
2124 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2125 // 2. set checkMap null
2126 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2127 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2128 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2129 // 4. Get checkMap from DeviceManagerNotify
2130 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2131 // 5. check checkMap not null
2132 ASSERT_NE(checkMap, nullptr);
2133 // 6. call checkMap OnCall
2134 std::string paramJson = "test";
2135 checkMap->OnCall(paramJson);
2136 ASSERT_EQ(count, 1);
2137 }
2138
2139 /*
2140 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2141 * Function: DeviceManagerNotifyTest
2142 * SubFunction: RegisterDeviceManagerFaCallback
2143 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback
2144 * EnvConditions: N/A.
2145 * CaseDescription: 1. set pkgName com.ohos.test
2146 * set dmUiCallback_ not null
2147 * 2. set checkMap null
2148 * 3. set testpkcName com.ohos.test1
2149 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2150 * 5. Get checkMap from DeviceManagerNotify with testpkcName
2151 * 6. check checkMap null
2152 */
2153 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0)
2154 {
2155 // 1. set pkgName com.ohos.test
2156 std::string pkgName = "com.ohos.test";
2157 // set dmInitCallback not null
2158 int count = 0;
2159 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2160 // 2. set checkMap null
2161 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2162 // 3. set testpkcName com.ohos.test1
2163 std::string testPkgName = "com.ohos.test1";
2164 // 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2165 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2166 // 5. Get checkMap from DeviceManagerNotify with testpkcName
2167 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName];
2168 // 6. check checkMap not null
2169 if (checkMap == nullptr) {
2170 ASSERT_NE(count, 1);
2171 return;
2172 }
2173 ASSERT_EQ(checkMap, nullptr);
2174 }
2175
2176 /*
2177 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2178 * Function: DeviceManagerNotifyTest
2179 * SubFunction: UnRegisterDeviceManagerFaCallback
2180 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2181 * EnvConditions: UnRegisterDeviceManagerFaCallback success.
2182 * CaseDescription: 1. set pkgName not null
2183 * set dmUiCallback_ not null
2184 * 2. set checkMap null
2185 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2186 * 4. Get checkMap from DeviceManagerNotify
2187 * 5. check checkMap not null
2188 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2189 * 7. Get checkMap from DeviceManagerNotify
2190 * 8. check checkMap null
2191 */
2192 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0)
2193 {
2194 // 1. set pkgName not null
2195 std::string pkgName = "com.ohos.test";
2196 // set dmInitCallback not null
2197 int count = 0;
2198 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2199 // 2. set checkMap null
2200 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2201 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2202 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2203 // 4. Get checkMap from DeviceManagerNotify
2204 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2205 // 5. check checkMap not null
2206 ASSERT_NE(checkMap, nullptr);
2207 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2208 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
2209 // 7. Get checkMap from DeviceManagerNotify
2210 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2211 // 8 check checkMap null
2212 ASSERT_EQ(checkMap, nullptr);
2213 }
2214
2215 /*
2216 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2217 * Function: DeviceManagerNotifyTest
2218 * SubFunction: UnRegisterDeviceManagerFaCallback
2219 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2220 * EnvConditions: N/A.
2221 * CaseDescription: 1. set pkgName com.ohos.test
2222 * set dmInitCallback not null
2223 * 2. set checkMap null
2224 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2225 * 4. Get checkMap from DeviceManagerNotify
2226 * 5. check checkMap not null
2227 * 6. set testpkcName com.ohos.test1
2228 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2229 * 8. Get checkMap from DeviceManagerNotify
2230 * 9. check checkMap not null
2231 */
2232 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0)
2233 {
2234 // 1. set pkgName not null
2235 std::string pkgName = "com.ohos.test";
2236 // set dmUiCallback_ not null
2237 int count = 0;
2238 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2239 // 2. set checkMap null
2240 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2241 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2242 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2243 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2244 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2245 // 5. check checkMap not null
2246 ASSERT_NE(checkMap, nullptr);
2247 // 6. set testpkcName com.ohos.test1
2248 std::string testPkgName = "com.ohos.test1";
2249 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2250 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2251 // 8. Get checkMap from DeviceManagerNotify
2252 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2253 // 8 check checkMap not null
2254 ASSERT_NE(checkMap, nullptr);
2255 }
2256
2257 /*
2258 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_003
2259 * Function: DeviceManagerNotifyTest
2260 * SubFunction: UnRegisterDeviceManagerFaCallback
2261 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2262 * EnvConditions: N/A.
2263 * CaseDescription: 1. set pkgName com.ohos.test
2264 * set dmInitCallback not null
2265 * 2. set checkMap null
2266 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2267 * 4. Get checkMap from DeviceManagerNotify
2268 * 5. check checkMap not null
2269 * 6. set testpkcName com.ohos.test1
2270 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2271 * 8. Get checkMap from DeviceManagerNotify
2272 * 9. check checkMap not null
2273 */
2274 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0)
2275 {
2276 // 1. set pkgName not null
2277 std::string pkgName = "com.ohos.test";
2278 // set dmUiCallback_ not null
2279 int count = 0;
2280 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2281 // 2. set checkMap null
2282 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2283 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2284 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2285 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2286 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2287 // 5. check checkMap not null
2288 ASSERT_NE(checkMap, nullptr);
2289 // 6. set testpkcName com.ohos.test1
2290 std::string testPkgName = "com.ohos.test1";
2291 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2292 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2293 // 8. Get checkMap from DeviceManagerNotify
2294 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2295 // 9. check checkMap not null
2296 ASSERT_NE(checkMap, nullptr);
2297 // 10. call checkMap OnCall
2298 std::string paramJson = "test";
2299 checkMap->OnCall(paramJson);
2300 ASSERT_EQ(count, 1);
2301 }
2302
2303 /*
2304 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_004
2305 * Function: DeviceManagerNotifyTest
2306 * SubFunction: UnRegisterDeviceManagerFaCallback
2307 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2308 * EnvConditions: UnRegisterDeviceManagerFaCallback success.
2309 * CaseDescription: 1. set pkgName not null
2310 * set dmUiCallback_ not null
2311 * 2. set checkMap null
2312 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2313 * 4. Get checkMap from DeviceManagerNotify
2314 * 5. check checkMap not null
2315 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2316 * 7. Get checkMap from DeviceManagerNotify
2317 * 8. check checkMap null
2318 */
2319 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0)
2320 {
2321 // 1. set pkgName not null
2322 std::string pkgName = "com.ohos.test";
2323 // set dmInitCallback not null
2324 int count = 0;
2325 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2326 // 2. set checkMap null
2327 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2328 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2329 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2330 // 4. Get checkMap from DeviceManagerNotify
2331 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2332 // 5. check checkMap not null
2333 ASSERT_NE(checkMap, nullptr);
2334 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter
2335 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName);
2336 // 7. Get checkMap from DeviceManagerNotify
2337 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2338 // 8 check checkMap null
2339 if (checkMap == nullptr) {
2340 ASSERT_NE(count, 1);
2341 return;
2342 }
2343 ASSERT_EQ(checkMap, nullptr);
2344 }
2345
2346 /*
2347 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_005
2348 * Function: DeviceManagerNotifyTest
2349 * SubFunction: UnRegisterDeviceManagerFaCallback
2350 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback
2351 * EnvConditions: N/A.
2352 * CaseDescription: 1. set pkgName com.ohos.test
2353 * set dmInitCallback not null
2354 * 2. set checkMap null
2355 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2356 * 4. Get checkMap from DeviceManagerNotify
2357 * 5. check checkMap not null
2358 * 6. set testpkcName com.ohos.test1
2359 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2360 * 8. Get checkMap from DeviceManagerNotify
2361 * 9. check checkMap not null
2362 */
2363 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0)
2364 {
2365 // 1. set pkgName not null
2366 std::string pkgName = "com.ohos.test";
2367 // set dmUiCallback_ not null
2368 int count = 0;
2369 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
2370 // 2. set checkMap null
2371 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
2372 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
2373 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
2374 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback
2375 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2376 // 5. check checkMap not null
2377 ASSERT_NE(checkMap, nullptr);
2378 // 6. set testpkcName com.ohos.test1
2379 std::string testPkgName = "";
2380 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName
2381 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
2382 // 8. Get checkMap from DeviceManagerNotify
2383 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
2384 // 9. check checkMap not null
2385 ASSERT_NE(checkMap, nullptr);
2386 // 10. call checkMap OnCall
2387 std::string paramJson = "test";
2388 checkMap->OnCall(paramJson);
2389 ASSERT_EQ(count, 1);
2390 }
2391
2392 /*
2393 * Feature: DeviceManagerNotifyTest OnRemoteDied
2394 * Function: DeviceManagerNotifyTest
2395 * SubFunction: OnRemoteDied
2396 * FunctionPoints: DeviceManagerNotifyTest OnRemoteDied
2397 * EnvConditions: OnRemoteDied success.
2398 * CaseDescription: 1. set pkgName not null
2399 * set dmInitCallback not null
2400 * 2. set checkMap null
2401 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
2402 * 4. Get checkMap from DeviceManagerNotify
2403 * 5. check checkMap not null
2404 * 6. call DeviceManagerNotify OnRemoteDied
2405 * 7. check if dmInitCallback OnRemoteDied called.
2406 */
2407 HWTEST_F(DeviceManagerNotifyTest, OnRemoteDied1, testing::ext::TestSize.Level0)
2408 {
2409 // 1. set pkgName not null
2410 std::string pkgName = "com.ohos.test";
2411 // set dmInitCallback not null
2412 int count = 0;
2413 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count);
2414 // 2. set checkMap null
2415 std::shared_ptr<DmInitCallback> checkMap = nullptr;
2416 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter
2417 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback);
2418 // 4. Get checkMap from DeviceManagerNotify
2419 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName];
2420 // 5. check checkMap not null
2421 ASSERT_NE(checkMap, nullptr);
2422 // 6. call DeviceManagerNotify OnRemoteDied
2423 DeviceManagerNotify::GetInstance().OnRemoteDied();
2424 // 7. check if dmInitCallback OnRemoteDied called
2425 ASSERT_EQ(count, 1);
2426 }
2427
2428 /*
2429 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2430 * Function: DeviceManagerNotifyTest
2431 * SubFunction: OnDeviceOnline
2432 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2433 * EnvConditions: OnDeviceOnline success.
2434 * CaseDescription: 1. set pkgName not null
2435 * set Callback not null
2436 * 2. set checkMap null
2437 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2438 * 4. Get checkMap from DeviceManagerNotify
2439 * 5. check checkMap not null
2440 * 6. call DeviceManagerNotify OnDeviceOnline
2441 * 7. check if callback OnDeviceOnline called.
2442 */
2443 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_001, testing::ext::TestSize.Level0)
2444 {
2445 // 1. set pkgName not null
2446 std::string pkgName = "com.ohos.test";
2447 // set Callback not null
2448 int count = 0;
2449 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2450 // 2. set checkMap null
2451 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2452 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2453 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2454 // 4. Get checkMap from DeviceManagerNotify
2455 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2456 // 5. check checkMap not null
2457 ASSERT_NE(checkMap, nullptr);
2458 // 6. call DeviceManagerNotify OnDeviceOnline
2459 DmDeviceInfo deviceInfo;
2460 DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo);
2461 // 7. check if callback OnDeviceOnline called
2462 ASSERT_EQ(count, 1);
2463 }
2464
2465 /*
2466 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2467 * Function: DeviceManagerNotifyTest
2468 * SubFunction: OnDeviceOnline
2469 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2470 * EnvConditions: N/A.
2471 * CaseDescription: 1. set pkgName not null
2472 * set Callback not null
2473 * 2. set checkMap null
2474 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2475 * 4. Get checkMap from DeviceManagerNotify
2476 * 5. check checkMap not null
2477 * 6. set testpkcName com.ohos.test1
2478 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2479 * 8. check if callback OnDeviceOnline called.
2480 */
2481 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Level0)
2482 {
2483 // 1. set pkgName not null
2484 std::string pkgName = "com.ohos.test";
2485 // set Callback not null
2486 int count = 0;
2487 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2488 // 2. set checkMap null
2489 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2490 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2491 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2492 // 4. Get checkMap from DeviceManagerNotify
2493 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2494 // 5. check checkMap not null
2495 ASSERT_NE(checkMap, nullptr);
2496 // 6. set testpkcName com.ohos.test1
2497 std::string testPkgName = "com.ohos.test1";
2498 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2499 DmDeviceInfo deviceInfo;
2500 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2501 // 8. check if callback OnDeviceOnline called
2502 ASSERT_EQ(count, 0);
2503 }
2504
2505 /*
2506 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2507 * Function: DeviceManagerNotifyTest
2508 * SubFunction: OnDeviceOnline
2509 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2510 * EnvConditions: N/A.
2511 * CaseDescription: 1. set pkgName not null
2512 * set Callback not null
2513 * 2. set checkMap null
2514 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2515 * 4. Get checkMap from DeviceManagerNotify
2516 * 5. check checkMap not null
2517 * 6. set testpkcName com.ohos.test1
2518 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2519 * 8. check if callback OnDeviceOnline called.
2520 */
2521 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_003, testing::ext::TestSize.Level0)
2522 {
2523 // 1. set pkgName not null
2524 std::string pkgName = "com.ohos.test";
2525 // set Callback not null
2526 int count = 0;
2527 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2528 // 2. set checkMap null
2529 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2530 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2531 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2532 // 4. Get checkMap from DeviceManagerNotify
2533 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2534 // 5. check checkMap not null
2535 ASSERT_NE(checkMap, nullptr);
2536 // 6. set testpkcName com.ohos.test1
2537 std::string testPkgName = "";
2538 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2539 DmDeviceInfo deviceInfo;
2540 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2541 // 8. check if callback OnDeviceOnline called
2542 ASSERT_EQ(count, 0);
2543 }
2544
2545 /*
2546 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2547 * Function: DeviceManagerNotifyTest
2548 * SubFunction: OnDeviceOnline
2549 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2550 * EnvConditions: N/A.
2551 * CaseDescription: 1. set pkgName not null
2552 * set Callback not null
2553 * 2. set checkMap null
2554 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2555 * 4. Get checkMap from DeviceManagerNotify
2556 * 5. check checkMap not null
2557 * 6. set testpkcName com.ohos.test1
2558 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2559 * 8. check if callback OnDeviceOnline called.
2560 */
2561 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_004, testing::ext::TestSize.Level0)
2562 {
2563 // 1. set pkgName not null
2564 std::string pkgName = "com.ohos.test";
2565 // set Callback not null
2566 int count = 0;
2567 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2568 // 2. set checkMap null
2569 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2570 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2571 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2572 // 4. Get checkMap from DeviceManagerNotify
2573 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2574 // 5. check checkMap not null
2575 ASSERT_NE(checkMap, nullptr);
2576 // 6. set testpkcName com.ohos.test1
2577 std::string testPkgName = "111";
2578 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2579 DmDeviceInfo deviceInfo;
2580 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2581 // 8. check if callback OnDeviceOnline called
2582 ASSERT_NE(count, 1);
2583 }
2584
2585 /*
2586 * Feature: DeviceManagerNotifyTest OnDeviceOnline
2587 * Function: DeviceManagerNotifyTest
2588 * SubFunction: OnDeviceOnline
2589 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline
2590 * EnvConditions: N/A.
2591 * CaseDescription: 1. set pkgName not null
2592 * set Callback not null
2593 * 2. set checkMap null
2594 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2595 * 4. Get checkMap from DeviceManagerNotify
2596 * 5. check checkMap not null
2597 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2598 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2599 * 8. check if callback OnDeviceOnline called
2600 */
2601 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_005, testing::ext::TestSize.Level0)
2602 {
2603 // 1. set pkgName not null
2604 std::string pkgName = "com.ohos.test";
2605 // set Callback not null
2606 int count = 0;
2607 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2608 // 2. set checkMap null
2609 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2610 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2611 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2612 // 4. Get checkMap from DeviceManagerNotify
2613 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2614 // 5. check checkMap not null
2615 ASSERT_NE(checkMap, nullptr);
2616 std::string testPkgName = "";
2617 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2618 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
2619 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName
2620 DmDeviceInfo deviceInfo;
2621 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo);
2622 // 8. check if callback OnDeviceOnline called
2623 ASSERT_EQ(count, 0);
2624 }
2625
2626 /*
2627 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2628 * Function: DeviceManagerNotifyTest
2629 * SubFunction: OnDeviceOffline
2630 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2631 * EnvConditions: OnDeviceOffline success.
2632 * CaseDescription: 1. set pkgName not null
2633 * set Callback not null
2634 * 2. set checkMap null
2635 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2636 * 4. Get checkMap from DeviceManagerNotify
2637 * 5. check checkMap not null
2638 * 6. call DeviceManagerNotify OnDeviceOffline
2639 * 7. check if callback OnDeviceOffline called.
2640 */
2641 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_001, testing::ext::TestSize.Level0)
2642 {
2643 // 1. set pkgName not null
2644 std::string pkgName = "com.ohos.test";
2645 // set Callback not null
2646 int count = 0;
2647 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2648 // 2. set checkMap null
2649 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2650 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2651 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2652 // 4. Get checkMap from DeviceManagerNotify
2653 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2654 // 5. check checkMap not null
2655 ASSERT_NE(checkMap, nullptr);
2656 // 6. call DeviceManagerNotify OnDeviceOffline
2657 DmDeviceInfo deviceInfo;
2658 DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo);
2659 // 7. check if callback OnDeviceOffline called
2660 ASSERT_EQ(count, 1);
2661 }
2662
2663 /*
2664 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2665 * Function: DeviceManagerNotifyTest
2666 * SubFunction: OnDeviceOffline
2667 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2668 * EnvConditions: N/A.
2669 * CaseDescription: 1. set pkgName not null
2670 * set Callback not null
2671 * 2. set checkMap null
2672 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2673 * 4. Get checkMap from DeviceManagerNotify
2674 * 5. check checkMap not null
2675 * 6. set testpkcName com.ohos.test1
2676 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2677 * 8. check if callback OnDeviceOffline called.
2678 */
2679 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Level0)
2680 {
2681 // 1. set pkgName not null
2682 std::string pkgName = "com.ohos.test";
2683 // set Callback not null
2684 int count = 0;
2685 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2686 // 2. set checkMap null
2687 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2688 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2689 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2690 // 4. Get checkMap from DeviceManagerNotify
2691 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2692 // 5. check checkMap not null
2693 ASSERT_NE(checkMap, nullptr);
2694 // 6. set testpkcName com.ohos.test1
2695 std::string testPkgName = "com.ohos.test1";
2696 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2697 DmDeviceInfo deviceInfo;
2698 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2699 // 8. check if callback OnDeviceOffline called
2700 ASSERT_EQ(count, 0);
2701 }
2702
2703 /*
2704 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2705 * Function: DeviceManagerNotifyTest
2706 * SubFunction: OnDeviceOffline
2707 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2708 * EnvConditions: N/A.
2709 * CaseDescription: 1. set pkgName not null
2710 * set Callback not null
2711 * 2. set checkMap null
2712 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2713 * 4. Get checkMap from DeviceManagerNotify
2714 * 5. check checkMap not null
2715 * 6. set testpkcName com.ohos.test1
2716 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2717 * 8. check if callback OnDeviceOffline called.
2718 */
2719 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_003, testing::ext::TestSize.Level0)
2720 {
2721 // 1. set pkgName not null
2722 std::string pkgName = "com.ohos.test";
2723 // set Callback not null
2724 int count = 0;
2725 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2726 // 2. set checkMap null
2727 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2728 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2729 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2730 // 4. Get checkMap from DeviceManagerNotify
2731 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2732 // 5. check checkMap not null
2733 ASSERT_NE(checkMap, nullptr);
2734 // 6. set testpkcName null
2735 std::string testPkgName = "";
2736 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2737 DmDeviceInfo deviceInfo;
2738 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2739 // 8. check if callback OnDeviceOffline called
2740 ASSERT_EQ(count, 0);
2741 }
2742
2743 /*
2744 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2745 * Function: DeviceManagerNotifyTest
2746 * SubFunction: OnDeviceOffline
2747 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2748 * EnvConditions: N/A.
2749 * CaseDescription: 1. set pkgName not null
2750 * set Callback not null
2751 * 2. set checkMap null
2752 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2753 * 4. Get checkMap from DeviceManagerNotify
2754 * 5. check checkMap not null
2755 * 6. set testpkcName com.ohos.test1
2756 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2757 * 8. check if callback OnDeviceOffline called.
2758 */
2759 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_004, testing::ext::TestSize.Level0)
2760 {
2761 // 1. set pkgName not null
2762 std::string pkgName = "com.ohos.test";
2763 // set Callback not null
2764 int count = 0;
2765 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2766 // 2. set checkMap null
2767 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2768 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2769 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2770 // 4. Get checkMap from DeviceManagerNotify
2771 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2772 // 5. check checkMap not null
2773 ASSERT_NE(checkMap, nullptr);
2774 // 6. set testpkcName null
2775 std::string testPkgName = "";
2776 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2777 DmDeviceInfo deviceInfo;
2778 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2779 // 8. check if callback OnDeviceOffline called
2780 ASSERT_NE(count, 1);
2781 }
2782
2783 /*
2784 * Feature: DeviceManagerNotifyTest OnDeviceOffline
2785 * Function: DeviceManagerNotifyTest
2786 * SubFunction: OnDeviceOffline
2787 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline
2788 * EnvConditions: N/A.
2789 * CaseDescription: 1. set pkgName not null
2790 * set Callback not null
2791 * 2. set checkMap null
2792 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2793 * 4. Get checkMap from DeviceManagerNotify
2794 * 5. check checkMap not null
2795 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2796 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2797 * 8. check if callback OnDeviceOffline called.
2798 */
2799 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_005, testing::ext::TestSize.Level0)
2800 {
2801 // 1. set pkgName not null
2802 std::string pkgName = "com.ohos.test";
2803 // set Callback not null
2804 int count = 0;
2805 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2806 // 2. set checkMap null
2807 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2808 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2809 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2810 // 4. Get checkMap from DeviceManagerNotify
2811 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2812 // 5. check checkMap not null
2813 ASSERT_NE(checkMap, nullptr);
2814 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
2815 std::string testPkgName = "";
2816 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
2817 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName
2818 DmDeviceInfo deviceInfo;
2819 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo);
2820 // 8. check if callback OnDeviceOffline called
2821 ASSERT_EQ(count, 0);
2822 }
2823
2824 /*
2825 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2826 * Function: DeviceManagerNotifyTest
2827 * SubFunction: OnDeviceChanged
2828 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2829 * EnvConditions: OnDeviceChanged success.
2830 * CaseDescription: 1. set pkgName not null
2831 * set Callback not null
2832 * 2. set checkMap null
2833 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2834 * 4. Get checkMap from DeviceManagerNotify
2835 * 5. check checkMap not null
2836 * 6. call DeviceManagerNotify OnDeviceChanged
2837 * 7. check if callback OnDeviceChanged called.
2838 */
2839 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_001, testing::ext::TestSize.Level0)
2840 {
2841 // 1. set pkgName not null
2842 std::string pkgName = "com.ohos.test";
2843 // set Callback not null
2844 int count = 0;
2845 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2846 // 2. set checkMap null
2847 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2848 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2849 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2850 // 4. Get checkMap from DeviceManagerNotify
2851 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2852 // 5. check checkMap not null
2853 ASSERT_NE(checkMap, nullptr);
2854 // 6. call DeviceManagerNotify OnDeviceChanged
2855 DmDeviceInfo deviceInfo;
2856 DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo);
2857 // 7. check if callback OnDeviceChanged called
2858 ASSERT_EQ(count, 1);
2859 }
2860
2861 /*
2862 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2863 * Function: DeviceManagerNotifyTest
2864 * SubFunction: OnDeviceChanged
2865 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2866 * EnvConditions: N/A.
2867 * CaseDescription: 1. set pkgName not null
2868 * set Callback not null
2869 * 2. set checkMap null
2870 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2871 * 4. Get checkMap from DeviceManagerNotify
2872 * 5. check checkMap not null
2873 * 6. set testpkcName com.ohos.test1
2874 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2875 * 8. check if callback OnDeviceChanged called.
2876 */
2877 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Level0)
2878 {
2879 // 1. set pkgName not null
2880 std::string pkgName = "com.ohos.test";
2881 // set Callback not null
2882 int count = 0;
2883 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2884 // 2. set checkMap null
2885 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2886 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2887 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2888 // 4. Get checkMap from DeviceManagerNotify
2889 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2890 // 5. check checkMap not null
2891 ASSERT_NE(checkMap, nullptr);
2892 // 6. set testpkcName com.ohos.test1
2893 std::string testPkgName = "com.ohos.test1";
2894 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2895 DmDeviceInfo deviceInfo;
2896 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2897 // 8. check if callback OnDeviceChanged called
2898 ASSERT_EQ(count, 0);
2899 }
2900
2901 /*
2902 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2903 * Function: DeviceManagerNotifyTest
2904 * SubFunction: OnDeviceChanged
2905 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2906 * EnvConditions: N/A.
2907 * CaseDescription: 1. set pkgName not null
2908 * set Callback not null
2909 * 2. set checkMap null
2910 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2911 * 4. Get checkMap from DeviceManagerNotify
2912 * 5. check checkMap not null
2913 * 6. set testpkcName com.ohos.test1
2914 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2915 * 8. check if callback OnDeviceChanged called.
2916 */
2917 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_003, testing::ext::TestSize.Level0)
2918 {
2919 // 1. set pkgName not null
2920 std::string pkgName = "com.ohos.test";
2921 // set Callback not null
2922 int count = 0;
2923 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2924 // 2. set checkMap null
2925 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2926 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2927 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2928 // 4. Get checkMap from DeviceManagerNotify
2929 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2930 // 5. check checkMap not null
2931 ASSERT_NE(checkMap, nullptr);
2932 // 6. set testpkcName com.ohos.test1
2933 std::string testPkgName = "";
2934 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2935 DmDeviceInfo deviceInfo;
2936 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2937 // 8. check if callback OnDeviceChanged called
2938 ASSERT_EQ(count, 0);
2939 }
2940
2941 /*
2942 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2943 * Function: DeviceManagerNotifyTest
2944 * SubFunction: OnDeviceChanged
2945 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2946 * EnvConditions: N/A.
2947 * CaseDescription: 1. set pkgName not null
2948 * set Callback not null
2949 * 2. set checkMap null
2950 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2951 * 4. Get checkMap from DeviceManagerNotify
2952 * 5. check checkMap not null
2953 * 6. set testpkcName com.ohos.test1
2954 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2955 * 8. check if callback OnDeviceChanged called.
2956 */
2957 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0)
2958 {
2959 // 1. set pkgName not null
2960 std::string pkgName = "com.ohos.test";
2961 // set Callback not null
2962 int count = 0;
2963 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
2964 // 2. set checkMap null
2965 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
2966 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2967 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
2968 // 4. Get checkMap from DeviceManagerNotify
2969 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
2970 // 5. check checkMap not null
2971 ASSERT_NE(checkMap, nullptr);
2972 // 6. set testpkcName com.ohos.test1
2973 std::string testPkgName = "";
2974 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2975 DmDeviceInfo deviceInfo;
2976 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
2977 // 8. check if callback OnDeviceChanged called
2978 ASSERT_NE(count, 1);
2979 }
2980
2981 /*
2982 * Feature: DeviceManagerNotifyTest OnDeviceChanged
2983 * Function: DeviceManagerNotifyTest
2984 * SubFunction: OnDeviceChanged
2985 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged
2986 * EnvConditions: N/A.
2987 * CaseDescription: 1. set pkgName not null
2988 * set Callback not null
2989 * 2. set checkMap null
2990 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
2991 * 4. Get checkMap from DeviceManagerNotify
2992 * 5. check checkMap not null
2993 * 6. set testpkcName com.ohos.test1
2994 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
2995 * 8. check if callback OnDeviceChanged called.
2996 */
2997 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_005, testing::ext::TestSize.Level0)
2998 {
2999 // 1. set pkgName not null
3000 std::string pkgName = "com.ohos.test";
3001 // set Callback not null
3002 int count = 0;
3003 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count);
3004 // 2. set checkMap null
3005 std::shared_ptr<DeviceStateCallback> checkMap = nullptr;
3006 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter
3007 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback);
3008 // 4. Get checkMap from DeviceManagerNotify
3009 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName];
3010 // 5. check checkMap not null
3011 ASSERT_NE(checkMap, nullptr);
3012 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName
3013 std::string testPkgName = "";
3014 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName);
3015 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName
3016 DmDeviceInfo deviceInfo;
3017 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo);
3018 // 8. check if callback OnDeviceChanged called
3019 ASSERT_EQ(count, 0);
3020 }
3021
3022 /*
3023 * Feature: DeviceManagerNotifyTest OnDeviceFound
3024 * Function: DeviceManagerNotifyTest
3025 * SubFunction: OnDeviceFound
3026 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3027 * EnvConditions: OnDeviceFound success.
3028 * CaseDescription: 1. set pkgName not null
3029 * set callback not null
3030 * set subscribeId not null
3031 * 2. set checkMap null
3032 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3033 * 4. Get checkMap from DeviceManagerNotify
3034 * 5. check checkMap not null
3035 * 6. call DeviceManagerNotify OnDeviceFound
3036 * 7. check if callback OnDeviceFound called.
3037 */
3038 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound1, testing::ext::TestSize.Level0)
3039 {
3040 // 1. set pkgName not null
3041 std::string pkgName = "com.ohos.test";
3042 // set callback not null
3043 int count = 0;
3044 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3045 // set subscribeId not null
3046 uint16_t subscribeId = 0;
3047 // 2. set checkMap null
3048 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3049 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3050 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3051 // 4. Get checkMap from DeviceManagerNotify
3052 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3053 // 5. check checkMap not null
3054 ASSERT_NE(checkMap, nullptr);
3055 DmDeviceInfo deviceInfo;
3056 // 6. call DeviceManagerNotify OnDeviceFound
3057 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo);
3058 // 7. check if callback OnDeviceFound called
3059 ASSERT_EQ(count, 1);
3060 }
3061
3062 /*
3063 * Feature: DeviceManagerNotifyTest OnDeviceFound
3064 * Function: DeviceManagerNotifyTest
3065 * SubFunction: OnDeviceFound
3066 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3067 * EnvConditions: N/A.
3068 * CaseDescription: 1. set pkgName not null
3069 * set callback not null
3070 * set subscribeId not null
3071 * 2. set checkMap null
3072 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3073 * 4. Get checkMap from DeviceManagerNotify
3074 * 5. check checkMap not null
3075 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3076 * 7. check if callback OnDeviceFound called.
3077 */
3078 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound2, testing::ext::TestSize.Level0)
3079 {
3080 // 1. set pkgName not null
3081 std::string pkgName = "com.ohos.test";
3082 // set callback not null
3083 int count = 0;
3084 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3085 // set subscribeId not null
3086 uint16_t subscribeId = 0;
3087 // 2. set checkMap null
3088 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3089 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3090 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3091 // 4. Get checkMap from DeviceManagerNotify
3092 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3093 // 5. check checkMap not null
3094 ASSERT_NE(checkMap, nullptr);
3095 DmDeviceInfo deviceInfo;
3096 std::string testPkgName = "com.ohos.test1";
3097 // 6. call DeviceManagerNotify OnDeviceFound
3098 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3099 // 7. check if callback OnDeviceFound called
3100 ASSERT_EQ(count, 0);
3101 }
3102
3103 /*
3104 * Feature: DeviceManagerNotifyTest OnDeviceFound
3105 * Function: DeviceManagerNotifyTest
3106 * SubFunction: OnDeviceFound
3107 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3108 * EnvConditions: N/A.
3109 * CaseDescription: 1. set pkgName not null
3110 * set callback not null
3111 * set subscribeId not null
3112 * 2. set checkMap null
3113 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3114 * 4. Get checkMap from DeviceManagerNotify
3115 * 5. check checkMap not null
3116 * 6. call DeviceManagerNotify OnDeviceFound With testsubscribeId
3117 * 7. check if callback OnDeviceFound called.
3118 */
3119 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound3, testing::ext::TestSize.Level0)
3120 {
3121 // 1. set pkgName not null
3122 std::string pkgName = "com.ohos.test";
3123 // set callback not null
3124 int count = 0;
3125 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3126 // set subscribeId not null
3127 uint16_t subscribeId = 0;
3128 // 2. set checkMap null
3129 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3130 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3131 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3132 // 4. Get checkMap from DeviceManagerNotify
3133 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3134 // 5. check checkMap not null
3135 ASSERT_NE(checkMap, nullptr);
3136 DmDeviceInfo deviceInfo;
3137 uint16_t testsubscribeId = 1;
3138 // 6. call DeviceManagerNotify OnDeviceFound
3139 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, testsubscribeId, deviceInfo);
3140 // 7. check if callback OnDeviceFound called
3141 ASSERT_EQ(count, 0);
3142 }
3143
3144 /*
3145 * Feature: DeviceManagerNotifyTest OnDeviceFound
3146 * Function: DeviceManagerNotifyTest
3147 * SubFunction: OnDeviceFound
3148 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3149 * EnvConditions: N/A.
3150 * CaseDescription: 1. set pkgName not null
3151 * set callback not null
3152 * set subscribeId not null
3153 * 2. set checkMap null
3154 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3155 * 4. Get checkMap from DeviceManagerNotify
3156 * 5. check checkMap not null
3157 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3158 * 7. check if callback OnDeviceFound called.
3159 */
3160 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound4, testing::ext::TestSize.Level0)
3161 {
3162 // 1. set pkgName not null
3163 std::string pkgName = "com.ohos.test";
3164 // set callback not null
3165 int count = 0;
3166 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3167 // set subscribeId not null
3168 uint16_t subscribeId = 0;
3169 // 2. set checkMap null
3170 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3171 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3172 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3173 // 4. Get checkMap from DeviceManagerNotify
3174 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3175 // 5. check checkMap not null
3176 ASSERT_NE(checkMap, nullptr);
3177 DmDeviceInfo deviceInfo;
3178 std::string testPkgName = "";
3179 // 6. call DeviceManagerNotify OnDeviceFound
3180 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3181 // 7. check if callback OnDeviceFound called
3182 ASSERT_EQ(count, 0);
3183 }
3184
3185 /*
3186 * Feature: DeviceManagerNotifyTest OnDeviceFound
3187 * Function: DeviceManagerNotifyTest
3188 * SubFunction: OnDeviceFound
3189 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound
3190 * EnvConditions: N/A.
3191 * CaseDescription: 1. set pkgName not null
3192 * set callback not null
3193 * set subscribeId not null
3194 * 2. set checkMap null
3195 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3196 * 4. Get checkMap from DeviceManagerNotify
3197 * 5. check checkMap not null
3198 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName
3199 * 7. check if callback OnDeviceFound called.
3200 */
3201 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound5, testing::ext::TestSize.Level0)
3202 {
3203 // 1. set pkgName not null
3204 std::string pkgName = "com.ohos.test";
3205 // set callback not null
3206 int count = 0;
3207 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3208 // set subscribeId not null
3209 uint16_t subscribeId = 0;
3210 // 2. set checkMap null
3211 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3212 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3213 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3214 // 4. Get checkMap from DeviceManagerNotify
3215 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3216 // 5. check checkMap not null
3217 ASSERT_NE(checkMap, nullptr);
3218 DmDeviceInfo deviceInfo;
3219 std::string testPkgName = "";
3220 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3221 // 6. call DeviceManagerNotify OnDeviceFound
3222 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo);
3223 // 7. check if callback OnDeviceFound called
3224 ASSERT_EQ(count, 0);
3225 }
3226
3227 /*
3228 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3229 * Function: DeviceManagerNotifyTest
3230 * SubFunction: OnDiscoverFailed
3231 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3232 * EnvConditions: OnDiscoverFailed success.
3233 * CaseDescription: 1. set pkgName not null
3234 * set callback not null
3235 * set subscribeId not null
3236 * 2. set checkMap null
3237 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3238 * 4. Get checkMap from DeviceManagerNotify
3239 * 5. check checkMap not null
3240 * 6. call DeviceManagerNotify OnDiscoverFailed
3241 * 7. check if callback OnDiscoverFailed called.
3242 */
3243 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed1, testing::ext::TestSize.Level0)
3244 {
3245 // 1. set pkgName not null
3246 std::string pkgName = "com.ohos.test";
3247 // set callback not null
3248 int count = 0;
3249 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3250 // set subscribeId not null
3251 uint16_t subscribeId = 0;
3252 // 2. set checkMap null
3253 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3254 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3255 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3256 // 4. Get checkMap from DeviceManagerNotify
3257 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3258 // 5. check checkMap not null
3259 ASSERT_NE(checkMap, nullptr);
3260 int32_t failedReason = 0;
3261 // 6. call DeviceManagerNotify OnDiscoverFailed
3262 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason);
3263 // 7. check if callback OnDiscoverFailed called
3264 ASSERT_EQ(count, 1);
3265 }
3266
3267 /*
3268 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3269 * Function: DeviceManagerNotifyTest
3270 * SubFunction: OnDiscoverFailed
3271 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3272 * EnvConditions: N/A.
3273 * CaseDescription: 1. set pkgName not null
3274 * set callback not null
3275 * set subscribeId not null
3276 * 2. set checkMap null
3277 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3278 * 4. Get checkMap from DeviceManagerNotify
3279 * 5. check checkMap not null
3280 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3281 * 7. check if callback OnDiscoverFailed called.
3282 */
3283 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed2, testing::ext::TestSize.Level0)
3284 {
3285 // 1. set pkgName not null
3286 std::string pkgName = "com.ohos.test";
3287 // set callback not null
3288 int count = 0;
3289 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3290 // set subscribeId not null
3291 uint16_t subscribeId = 0;
3292 // 2. set checkMap null
3293 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3294 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3295 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3296 // 4. Get checkMap from DeviceManagerNotify
3297 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3298 // 5. check checkMap not null
3299 ASSERT_NE(checkMap, nullptr);
3300 std::string testPkgName = "com.ohos.test1";
3301 int32_t failedReason = 0;
3302 // 6. call DeviceManagerNotify OnDiscoverFailed
3303 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3304 // 7. check if callback OnDiscoverFailed called
3305 ASSERT_EQ(count, 0);
3306 }
3307
3308 /*
3309 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3310 * Function: DeviceManagerNotifyTest
3311 * SubFunction: OnDiscoverFailed
3312 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3313 * EnvConditions: N/A.
3314 * CaseDescription: 1. set pkgName not null
3315 * set callback not null
3316 * set subscribeId not null
3317 * 2. set checkMap null
3318 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3319 * 4. Get checkMap from DeviceManagerNotify
3320 * 5. check checkMap not null
3321 * 6. call DeviceManagerNotify OnDiscoverFailed With testsubscribeId
3322 * 7. check if callback OnDiscoverFailed called.
3323 */
3324 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed3, testing::ext::TestSize.Level0)
3325 {
3326 // 1. set pkgName not null
3327 std::string pkgName = "com.ohos.test";
3328 // set callback not null
3329 int count = 0;
3330 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3331 // set subscribeId not null
3332 uint16_t subscribeId = 0;
3333 // 2. set checkMap null
3334 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3335 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3336 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3337 // 4. Get checkMap from DeviceManagerNotify
3338 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3339 // 5. check checkMap not null
3340 ASSERT_NE(checkMap, nullptr);
3341 int32_t failedReason = 0;
3342 uint16_t testsubscribeId = 1;
3343 // 6. call DeviceManagerNotify OnDiscoverFailed
3344 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason);
3345 // 7. check if callback OnDiscoverFailed called
3346 ASSERT_EQ(count, 0);
3347 }
3348
3349 /*
3350 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3351 * Function: DeviceManagerNotifyTest
3352 * SubFunction: OnDiscoverFailed
3353 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3354 * EnvConditions: N/A.
3355 * CaseDescription: 1. set pkgName not null
3356 * set callback not null
3357 * set subscribeId not null
3358 * 2. set checkMap null
3359 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3360 * 4. Get checkMap from DeviceManagerNotify
3361 * 5. check checkMap not null
3362 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3363 * 7. check if callback OnDiscoverFailed called.
3364 */
3365 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed4, testing::ext::TestSize.Level0)
3366 {
3367 // 1. set pkgName not null
3368 std::string pkgName = "com.ohos.test";
3369 // set callback not null
3370 int count = 0;
3371 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3372 // set subscribeId not null
3373 uint16_t subscribeId = 0;
3374 // 2. set checkMap null
3375 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3376 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3377 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3378 // 4. Get checkMap from DeviceManagerNotify
3379 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3380 // 5. check checkMap not null
3381 ASSERT_NE(checkMap, nullptr);
3382 std::string testPkgName = "";
3383 int32_t failedReason = 0;
3384 // 6. call DeviceManagerNotify OnDiscoverFailed
3385 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3386 // 7. check if callback OnDiscoverFailed called
3387 ASSERT_EQ(count, 0);
3388 }
3389
3390 /*
3391 * Feature: DeviceManagerNotifyTest OnDiscoverFailed
3392 * Function: DeviceManagerNotifyTest
3393 * SubFunction: OnDiscoverFailed
3394 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed
3395 * EnvConditions: N/A.
3396 * CaseDescription: 1. set pkgName not null
3397 * set callback not null
3398 * set subscribeId not null
3399 * 2. set checkMap null
3400 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3401 * 4. Get checkMap from DeviceManagerNotify
3402 * 5. check checkMap not null
3403 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName
3404 * 7. check if callback OnDiscoverFailed called.
3405 */
3406 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed5, testing::ext::TestSize.Level0)
3407 {
3408 // 1. set pkgName not null
3409 std::string pkgName = "com.ohos.test";
3410 // set callback not null
3411 int count = 0;
3412 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3413 // set subscribeId not null
3414 uint16_t subscribeId = 0;
3415 // 2. set checkMap null
3416 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3417 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3418 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3419 // 4. Get checkMap from DeviceManagerNotify
3420 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3421 // 5. check checkMap not null
3422 ASSERT_NE(checkMap, nullptr);
3423 std::string testPkgName = "";
3424 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3425 int32_t failedReason = 0;
3426 // 6. call DeviceManagerNotify OnDiscoverFailed
3427 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason);
3428 // 7. check if callback OnDiscoverFailed called
3429 ASSERT_EQ(count, 0);
3430 }
3431
3432 /*
3433 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3434 * Function: DeviceManagerNotifyTest
3435 * SubFunction: OnDiscoverySuccess
3436 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3437 * EnvConditions: OnDiscoverySuccess success.
3438 * CaseDescription: 1. set pkgName not null
3439 * set callback not null
3440 * set subscribeId not null
3441 * 2. set checkMap null
3442 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3443 * 4. Get checkMap from DeviceManagerNotify
3444 * 5. check checkMap not null
3445 * 6. call DeviceManagerNotify OnDiscoverySuccess
3446 * 7. check if callback OnDiscoverySuccess called.
3447 */
3448 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess1, testing::ext::TestSize.Level0)
3449 {
3450 // 1. set pkgName not null
3451 std::string pkgName = "com.ohos.test";
3452 // set callback not null
3453 int count = 0;
3454 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3455 // set subscribeId not null
3456 uint16_t subscribeId = 0;
3457 // 2. set checkMap null
3458 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3459 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3460 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3461 // 4. Get checkMap from DeviceManagerNotify
3462 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3463 // 5. check checkMap not null
3464 ASSERT_NE(checkMap, nullptr);
3465 // 6. call DeviceManagerNotify OnDiscoverySuccess
3466 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId);
3467 // 7. check if callback OnDiscoverySuccess called
3468 ASSERT_EQ(count, 1);
3469 }
3470
3471 /*
3472 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3473 * Function: DeviceManagerNotifyTest
3474 * SubFunction: OnDiscoverySuccess
3475 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3476 * EnvConditions: N/A.
3477 * CaseDescription: 1. set pkgName not null
3478 * set callback not null
3479 * set subscribeId not null
3480 * 2. set checkMap null
3481 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3482 * 4. Get checkMap from DeviceManagerNotify
3483 * 5. check checkMap not null
3484 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3485 * 7. check if callback OnDiscoverySuccess called.
3486 */
3487 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess2, testing::ext::TestSize.Level0)
3488 {
3489 // 1. set pkgName not null
3490 std::string pkgName = "com.ohos.test";
3491 // set callback not null
3492 int count = 0;
3493 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3494 // set subscribeId not null
3495 uint16_t subscribeId = 0;
3496 // 2. set checkMap null
3497 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3498 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3499 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3500 // 4. Get checkMap from DeviceManagerNotify
3501 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3502 // 5. check checkMap not null
3503 ASSERT_NE(checkMap, nullptr);
3504 std::string testPkgName = "com.ohos.test1";
3505 // 6. call DeviceManagerNotify OnDiscoverySuccess
3506 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3507 // 7. check if callback OnDiscoverySuccess called
3508 ASSERT_EQ(count, 0);
3509 }
3510
3511 /*
3512 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3513 * Function: DeviceManagerNotifyTest
3514 * SubFunction: OnDiscoverySuccess
3515 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3516 * EnvConditions: N/A.
3517 * CaseDescription: 1. set pkgName not null
3518 * set callback not null
3519 * set subscribeId not null
3520 * 2. set checkMap null
3521 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3522 * 4. Get checkMap from DeviceManagerNotify
3523 * 5. check checkMap not null
3524 * 6. call DeviceManagerNotify OnDiscoverySuccess With testsubscribeId
3525 * 7. check if callback OnDiscoverySuccess called.
3526 */
3527 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess3, testing::ext::TestSize.Level0)
3528 {
3529 // 1. set pkgName not null
3530 std::string pkgName = "com.ohos.test";
3531 // set callback not null
3532 int count = 0;
3533 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3534 // set subscribeId not null
3535 uint16_t subscribeId = 0;
3536 // 2. set checkMap null
3537 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3538 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3539 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3540 // 4. Get checkMap from DeviceManagerNotify
3541 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3542 // 5. check checkMap not null
3543 ASSERT_NE(checkMap, nullptr);
3544 uint16_t testsubscribeId = 1;
3545 // 6. call DeviceManagerNotify OnDiscoverySuccess
3546 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, testsubscribeId);
3547 // 7. check if callback OnDiscoverySuccess called
3548 ASSERT_EQ(count, 0);
3549 }
3550
3551 /*
3552 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3553 * Function: DeviceManagerNotifyTest
3554 * SubFunction: OnDiscoverySuccess
3555 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3556 * EnvConditions: N/A.
3557 * CaseDescription: 1. set pkgName not null
3558 * set callback not null
3559 * set subscribeId not null
3560 * 2. set checkMap null
3561 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3562 * 4. Get checkMap from DeviceManagerNotify
3563 * 5. check checkMap not null
3564 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3565 * 7. check if callback OnDiscoverySuccess called.
3566 */
3567 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess4, testing::ext::TestSize.Level0)
3568 {
3569 // 1. set pkgName not null
3570 std::string pkgName = "com.ohos.test";
3571 // set callback not null
3572 int count = 0;
3573 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3574 // set subscribeId not null
3575 uint16_t subscribeId = 0;
3576 // 2. set checkMap null
3577 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3578 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3579 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3580 // 4. Get checkMap from DeviceManagerNotify
3581 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3582 // 5. check checkMap not null
3583 ASSERT_NE(checkMap, nullptr);
3584 std::string testPkgName = "";
3585 // 6. call DeviceManagerNotify OnDiscoverySuccess
3586 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3587 // 7. check if callback OnDiscoverySuccess called
3588 ASSERT_EQ(count, 0);
3589 }
3590
3591 /*
3592 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess
3593 * Function: DeviceManagerNotifyTest
3594 * SubFunction: OnDiscoverySuccess
3595 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess
3596 * EnvConditions: N/A.
3597 * CaseDescription: 1. set pkgName not null
3598 * set callback not null
3599 * set subscribeId not null
3600 * 2. set checkMap null
3601 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3602 * 4. Get checkMap from DeviceManagerNotify
3603 * 5. check checkMap not null
3604 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName
3605 * 7. check if callback OnDiscoverySuccess called.
3606 */
3607 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess5, testing::ext::TestSize.Level0)
3608 {
3609 // 1. set pkgName not null
3610 std::string pkgName = "com.ohos.test";
3611 // set callback not null
3612 int count = 0;
3613 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count);
3614 // set subscribeId not null
3615 uint16_t subscribeId = 0;
3616 // 2. set checkMap null
3617 std::shared_ptr<DiscoveryCallback> checkMap = nullptr;
3618 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
3619 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback);
3620 // 4. Get checkMap from DeviceManagerNotify
3621 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId];
3622 // 5. check checkMap not null
3623 ASSERT_NE(checkMap, nullptr);
3624 std::string testPkgName = "";
3625 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId);
3626 // 6. call DeviceManagerNotify OnDiscoverySuccess
3627 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId);
3628 // 7. check if callback OnDiscoverySuccess called
3629 ASSERT_EQ(count, 0);
3630 }
3631
3632 /*
3633 * Feature: DeviceManagerNotifyTest OnPublishResult
3634 * Function: DeviceManagerNotifyTest
3635 * SubFunction: OnPublishResult Failed
3636 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3637 * EnvConditions: OnPublishResult.
3638 * CaseDescription: 1. set pkgName not null
3639 * set callback not null
3640 * set publishId not null
3641 * 2. set checkMap null
3642 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3643 * 4. Get checkMap from DeviceManagerNotify
3644 * 5. check checkMap not null
3645 * 6. call DeviceManagerNotify OnPublishResult
3646 * 7. check if callback OnPublishResult called.
3647 */
3648 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult1, testing::ext::TestSize.Level0)
3649 {
3650 // 1. set pkgName not null
3651 std::string pkgName = "com.ohos.test";
3652 // set callback not null
3653 int count = 0;
3654 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3655 // set publishId not null
3656 int32_t publishId = 0;
3657 // 2. set checkMap null
3658 std::shared_ptr<PublishCallback> checkMap = nullptr;
3659 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3660 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3661 // 4. Get checkMap from DeviceManagerNotify
3662 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3663 // 5. check checkMap not null
3664 ASSERT_NE(checkMap, nullptr);
3665 int32_t failedReason = 1;
3666 // 6. call DeviceManagerNotify OnPublishResult
3667 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, failedReason);
3668 // 7. check if callback OnPublishResult called
3669 ASSERT_EQ(count, 1);
3670 }
3671
3672 /*
3673 * Feature: DeviceManagerNotifyTest OnPublishResult
3674 * Function: DeviceManagerNotifyTest
3675 * SubFunction: OnPublishResult Failed
3676 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3677 * EnvConditions: N/A.
3678 * CaseDescription: 1. set pkgName not null
3679 * set callback not null
3680 * set publishId not null
3681 * 2. set checkMap null
3682 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3683 * 4. Get checkMap from DeviceManagerNotify
3684 * 5. check checkMap not null
3685 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3686 * 7. check if callback OnPublishResult called.
3687 */
3688 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult2, testing::ext::TestSize.Level0)
3689 {
3690 // 1. set pkgName not null
3691 std::string pkgName = "com.ohos.test";
3692 // set callback not null
3693 int count = 0;
3694 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3695 // set publishId not null
3696 int32_t publishId = 0;
3697 // 2. set checkMap null
3698 std::shared_ptr<PublishCallback> checkMap = nullptr;
3699 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3700 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3701 // 4. Get checkMap from DeviceManagerNotify
3702 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3703 // 5. check checkMap not null
3704 ASSERT_NE(checkMap, nullptr);
3705 std::string testPkgName = "com.ohos.test1";
3706 int32_t failedReason = 1;
3707 // 6. call DeviceManagerNotify OnPublishResult
3708 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3709 // 7. check if callback OnPublishResult called
3710 ASSERT_EQ(count, 0);
3711 }
3712
3713 /*
3714 * Feature: DeviceManagerNotifyTest OnPublishResult
3715 * Function: DeviceManagerNotifyTest
3716 * SubFunction: OnPublishResult Failed
3717 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3718 * EnvConditions: N/A.
3719 * CaseDescription: 1. set pkgName not null
3720 * set callback not null
3721 * set publishId not null
3722 * 2. set checkMap null
3723 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3724 * 4. Get checkMap from DeviceManagerNotify
3725 * 5. check checkMap not null
3726 * 6. call DeviceManagerNotify OnPublishFailed With testpublishId
3727 * 7. check if callback OnPublishResult called.
3728 */
3729 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult3, testing::ext::TestSize.Level0)
3730 {
3731 // 1. set pkgName not null
3732 std::string pkgName = "com.ohos.test";
3733 // set callback not null
3734 int count = 0;
3735 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3736 // set publishId not null
3737 int32_t publishId = 0;
3738 // 2. set checkMap null
3739 std::shared_ptr<PublishCallback> checkMap = nullptr;
3740 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3741 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3742 // 4. Get checkMap from DeviceManagerNotify
3743 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3744 // 5. check checkMap not null
3745 ASSERT_NE(checkMap, nullptr);
3746 int32_t failedReason = 1;
3747 int32_t testpublishId = 1;
3748 // 6. call DeviceManagerNotify OnPublishResult
3749 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, failedReason);
3750 // 7. check if callback OnPublishResult called
3751 ASSERT_EQ(count, 0);
3752 }
3753
3754 /*
3755 * Feature: DeviceManagerNotifyTest OnPublishResult
3756 * Function: DeviceManagerNotifyTest
3757 * SubFunction: OnPublishResult Failed
3758 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3759 * EnvConditions: N/A.
3760 * CaseDescription: 1. set pkgName not null
3761 * set callback not null
3762 * set publishId not null
3763 * 2. set checkMap null
3764 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3765 * 4. Get checkMap from DeviceManagerNotify
3766 * 5. check checkMap not null
3767 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3768 * 7. check if callback OnPublishResult called.
3769 */
3770 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed4, testing::ext::TestSize.Level0)
3771 {
3772 // 1. set pkgName not null
3773 std::string pkgName = "com.ohos.test";
3774 // set callback not null
3775 int count = 0;
3776 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3777 // set publishId not null
3778 int32_t publishId = 0;
3779 // 2. set checkMap null
3780 std::shared_ptr<PublishCallback> checkMap = nullptr;
3781 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3782 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3783 // 4. Get checkMap from DeviceManagerNotify
3784 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3785 // 5. check checkMap not null
3786 ASSERT_NE(checkMap, nullptr);
3787 std::string testPkgName = "";
3788 int32_t failedReason = 1;
3789 // 6. call DeviceManagerNotify OnPublishResult
3790 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3791 // 7. check if callback OnPublishResult called
3792 ASSERT_EQ(count, 0);
3793 }
3794
3795 /*
3796 * Feature: DeviceManagerNotifyTest OnPublishResult
3797 * Function: DeviceManagerNotifyTest
3798 * SubFunction: OnPublishResult Failed
3799 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3800 * EnvConditions: N/A.
3801 * CaseDescription: 1. set pkgName not null
3802 * set callback not null
3803 * set publishId not null
3804 * 2. set checkMap null
3805 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3806 * 4. Get checkMap from DeviceManagerNotify
3807 * 5. check checkMap not null
3808 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3809 * 7. check if callback OnPublishResult called.
3810 */
3811 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed5, testing::ext::TestSize.Level0)
3812 {
3813 // 1. set pkgName not null
3814 std::string pkgName = "com.ohos.test";
3815 // set callback not null
3816 int count = 0;
3817 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3818 // set publishId not null
3819 int32_t publishId = 2;
3820 // 2. set checkMap null
3821 std::shared_ptr<PublishCallback> checkMap = nullptr;
3822 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3823 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3824 // 4. Get checkMap from DeviceManagerNotify
3825 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3826 // 5. check checkMap not null
3827 ASSERT_NE(checkMap, nullptr);
3828 std::string testPkgName = "";
3829 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId);
3830 int32_t failedReason = 1;
3831 // 6. call DeviceManagerNotify OnPublishResult
3832 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason);
3833 // 7. check if callback OnPublishResult called
3834 ASSERT_EQ(count, 0);
3835 }
3836
3837 /*
3838 * Feature: DeviceManagerNotifyTest OnPublishResult
3839 * Function: DeviceManagerNotifyTest
3840 * SubFunction: OnPublishResult
3841 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3842 * EnvConditions: OnPublishResult success.
3843 * CaseDescription: 1. set pkgName not null
3844 * set callback not null
3845 * set publishId not null
3846 * 2. set checkMap null
3847 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3848 * 4. Get checkMap from DeviceManagerNotify
3849 * 5. check checkMap not null
3850 * 6. call DeviceManagerNotify OnPublishResult
3851 * 7. check if callback OnPublishResult called.
3852 */
3853 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess1, testing::ext::TestSize.Level0)
3854 {
3855 // 1. set pkgName not null
3856 std::string pkgName = "com.ohos.test";
3857 // set callback not null
3858 int count = 0;
3859 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3860 // set publishId not null
3861 int32_t publishId = 0;
3862 // 2. set checkMap null
3863 std::shared_ptr<PublishCallback> checkMap = nullptr;
3864 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3865 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3866 // 4. Get checkMap from DeviceManagerNotify
3867 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3868 // 5. check checkMap not null
3869 ASSERT_NE(checkMap, nullptr);
3870 // 6. call DeviceManagerNotify OnPublishResult
3871 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, 0);
3872 // 7. check if callback OnPublishResult called
3873 ASSERT_EQ(count, 1);
3874 }
3875
3876 /*
3877 * Feature: DeviceManagerNotifyTest OnPublishResult
3878 * Function: DeviceManagerNotifyTest
3879 * SubFunction: OnPublishResult
3880 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3881 * EnvConditions: N/A.
3882 * CaseDescription: 1. set pkgName not null
3883 * set callback not null
3884 * set publishId not null
3885 * 2. set checkMap null
3886 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3887 * 4. Get checkMap from DeviceManagerNotify
3888 * 5. check checkMap not null
3889 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3890 * 7. check if callback OnPublishResult called.
3891 */
3892 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess2, testing::ext::TestSize.Level0)
3893 {
3894 // 1. set pkgName not null
3895 std::string pkgName = "com.ohos.test";
3896 // set callback not null
3897 int count = 0;
3898 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3899 // set publishId not null
3900 int32_t publishId = 0;
3901 // 2. set checkMap null
3902 std::shared_ptr<PublishCallback> checkMap = nullptr;
3903 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3904 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3905 // 4. Get checkMap from DeviceManagerNotify
3906 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3907 // 5. check checkMap not null
3908 ASSERT_NE(checkMap, nullptr);
3909 std::string testPkgName = "com.ohos.test1";
3910 // 6. call DeviceManagerNotify OnPublishResult
3911 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
3912 // 7. check if callback OnPublishResult called
3913 ASSERT_EQ(count, 0);
3914 }
3915
3916 /*
3917 * Feature: DeviceManagerNotifyTest OnPublishResult
3918 * Function: DeviceManagerNotifyTest
3919 * SubFunction: OnPublishResult
3920 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3921 * EnvConditions: N/A.
3922 * CaseDescription: 1. set pkgName not null
3923 * set callback not null
3924 * set publishId not null
3925 * 2. set checkMap null
3926 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3927 * 4. Get checkMap from DeviceManagerNotify
3928 * 5. check checkMap not null
3929 * 6. call DeviceManagerNotify OnPublishResult With testpublishId
3930 * 7. check if callback OnPublishResult called.
3931 */
3932 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess3, testing::ext::TestSize.Level0)
3933 {
3934 // 1. set pkgName not null
3935 std::string pkgName = "com.ohos.test";
3936 // set callback not null
3937 int count = 0;
3938 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3939 // set publishId not null
3940 int32_t publishId = 0;
3941 // 2. set checkMap null
3942 std::shared_ptr<PublishCallback> checkMap = nullptr;
3943 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3944 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3945 // 4. Get checkMap from DeviceManagerNotify
3946 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3947 // 5. check checkMap not null
3948 ASSERT_NE(checkMap, nullptr);
3949 int32_t testpublishId = 1;
3950 // 6. call DeviceManagerNotify OnPublishResult
3951 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, 0);
3952 // 7. check if callback OnPublishResult called
3953 ASSERT_EQ(count, 0);
3954 }
3955
3956 /*
3957 * Feature: DeviceManagerNotifyTest OnPublishResult
3958 * Function: DeviceManagerNotifyTest
3959 * SubFunction: OnPublishResult Success
3960 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
3961 * EnvConditions: N/A.
3962 * CaseDescription: 1. set pkgName not null
3963 * set callback not null
3964 * set publishId not null
3965 * 2. set checkMap null
3966 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3967 * 4. Get checkMap from DeviceManagerNotify
3968 * 5. check checkMap not null
3969 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
3970 * 7. check if callback OnPublishResult called.
3971 */
3972 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess4, testing::ext::TestSize.Level0)
3973 {
3974 // 1. set pkgName not null
3975 std::string pkgName = "com.ohos.test";
3976 // set callback not null
3977 int count = 0;
3978 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
3979 // set publishId not null
3980 int32_t publishId = 0;
3981 // 2. set checkMap null
3982 std::shared_ptr<PublishCallback> checkMap = nullptr;
3983 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
3984 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
3985 // 4. Get checkMap from DeviceManagerNotify
3986 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
3987 // 5. check checkMap not null
3988 ASSERT_NE(checkMap, nullptr);
3989 std::string testPkgName = "";
3990 // 6. call DeviceManagerNotify OnPublishResult
3991 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
3992 // 7. check if callback OnPublishResult called
3993 ASSERT_EQ(count, 0);
3994 }
3995
3996 /*
3997 * Feature: DeviceManagerNotifyTest OnPublishResult
3998 * Function: DeviceManagerNotifyTest
3999 * SubFunction: OnPublishResult Success
4000 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult
4001 * EnvConditions: N/A.
4002 * CaseDescription: 1. set pkgName not null
4003 * set callback not null
4004 * set subscribeId not null
4005 * 2. set checkMap null
4006 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter
4007 * 4. Get checkMap from DeviceManagerNotify
4008 * 5. check checkMap not null
4009 * 6. call DeviceManagerNotify OnPublishResult With testPkgName
4010 * 7. check if callback OnPublishResult called.
4011 */
4012 HWTEST_F(DeviceManagerNotifyTest, OnPublishSuccess5, testing::ext::TestSize.Level0)
4013 {
4014 // 1. set pkgName not null
4015 std::string pkgName = "com.ohos.test";
4016 // set callback not null
4017 int count = 0;
4018 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count);
4019 // set publishId not null
4020 int32_t publishId = 0;
4021 // 2. set checkMap null
4022 std::shared_ptr<PublishCallback> checkMap = nullptr;
4023 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter
4024 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback);
4025 // 4. Get checkMap from DeviceManagerNotify
4026 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId];
4027 // 5. check checkMap not null
4028 ASSERT_NE(checkMap, nullptr);
4029 std::string testPkgName = "";
4030 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId);
4031 // 6. call DeviceManagerNotify OnPublishResult
4032 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, 0);
4033 // 7. check if callback OnPublishSuccess called
4034 ASSERT_EQ(count, 0);
4035 }
4036
4037 /*
4038 * Feature: DeviceManagerNotifyTest OnAuthResult
4039 * Function: OnAuthResult
4040 * SubFunction: RegisterAuthenticateCallback
4041 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4042 * EnvConditions: OnAuthResult success.
4043 * CaseDescription: 1. set pkgName not null
4044 * set Callback not null
4045 * set deviceId not null
4046 * 2. set checkMap null
4047 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4048 * 4. Get checkMap from DeviceManagerNotify
4049 * 5. check checkMap not null
4050 * 6. call DeviceManagerNotify OnAuthResult
4051 * 7. check if callback OnDiscoverySuccess called
4052 */
4053 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult1, testing::ext::TestSize.Level0)
4054 {
4055 // 1. set pkgName not null
4056 std::string pkgName = "com.ohos.test";
4057 // set callback not null
4058 int count = 0;
4059 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4060 // set subscribeId not null
4061 std::string deviceId = "1";
4062 // 2. set checkMap null
4063 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4064 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4065 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4066 // 4. Get checkMap from DeviceManagerNotify
4067 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4068 // 5. check checkMap not null
4069 ASSERT_NE(checkMap, nullptr);
4070 // 6. call DeviceManagerNotify OnAuthResult
4071 std::string token = "111";
4072 uint32_t status = 0;
4073 uint32_t reason = 0;
4074 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4075 // 7. check if callback OnDiscoverySuccess called
4076 ASSERT_EQ(count, 1);
4077 }
4078
4079 /*
4080 * Feature: DeviceManagerNotifyTest OnAuthResult
4081 * Function: OnAuthResult
4082 * SubFunction: RegisterAuthenticateCallback
4083 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4084 * EnvConditions: OnAuthResult success.
4085 * CaseDescription: 1. set pkgName not null
4086 * set Callback not null
4087 * set deviceId not null
4088 * 2. set checkMap null
4089 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4090 * 4. Get checkMap from DeviceManagerNotify
4091 * 5. check checkMap not null
4092 * 6. call DeviceManagerNotify OnAuthResult with testPkgName
4093 * 7. check if callback OnDiscoverySuccess called
4094 */
4095 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult2, testing::ext::TestSize.Level0)
4096 {
4097 // 1. set pkgName not null
4098 std::string pkgName = "com.ohos.test";
4099 // set callback not null
4100 int count = 0;
4101 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4102 // set subscribeId not null
4103 std::string deviceId = "1";
4104 // 2. set checkMap null
4105 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4106 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4107 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4108 // 4. Get checkMap from DeviceManagerNotify
4109 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4110 // 5. check checkMap not null
4111 ASSERT_NE(checkMap, nullptr);
4112 // 6. call DeviceManagerNotify OnAuthResult
4113 std::string testPkgName = "com.ohos.test1";
4114 std::string token = "111";
4115 uint32_t status = 0;
4116 uint32_t reason = 0;
4117 DeviceManagerNotify::GetInstance().OnAuthResult(testPkgName, deviceId, token, status, reason);
4118 // 7. check if callback OnDiscoverySuccess called
4119 ASSERT_EQ(count, 0);
4120 }
4121
4122 /*
4123 * Feature: DeviceManagerNotifyTest OnAuthResult
4124 * Function: OnAuthResult
4125 * SubFunction: RegisterAuthenticateCallback
4126 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4127 * EnvConditions: OnAuthResult success.
4128 * CaseDescription: 1. set pkgName not null
4129 * set Callback not null
4130 * set deviceId not null
4131 * 2. set checkMap null
4132 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4133 * 4. Get checkMap from DeviceManagerNotify
4134 * 5. check checkMap not null
4135 * 6. call DeviceManagerNotify OnAuthResult with testDeviceId
4136 * 7. check if callback OnDiscoverySuccess called
4137 */
4138 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult3, testing::ext::TestSize.Level0)
4139 {
4140 // 1. set pkgName not null
4141 std::string pkgName = "com.ohos.test";
4142 // set callback not null
4143 int count = 0;
4144 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4145 // set subscribeId not null
4146 std::string deviceId = "1";
4147 // 2. set checkMap null
4148 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4149 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4150 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4151 // 4. Get checkMap from DeviceManagerNotify
4152 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4153 // 5. check checkMap not null
4154 ASSERT_NE(checkMap, nullptr);
4155 // 6. call DeviceManagerNotify OnAuthResult
4156 std::string testDeviceId = "2";
4157 std::string token = "111";
4158 uint32_t status = 0;
4159 uint32_t reason = 0;
4160 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason);
4161 // 7. check if callback OnDiscoverySuccess called
4162 ASSERT_EQ(count, 0);
4163 }
4164
4165 /*
4166 * Feature: DeviceManagerNotifyTest OnAuthResult
4167 * Function: OnAuthResult
4168 * SubFunction: RegisterAuthenticateCallback
4169 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4170 * EnvConditions: OnAuthResult success.
4171 * CaseDescription: 1. set pkgName not null
4172 * set Callback not null
4173 * set deviceId not null
4174 * 2. set checkMap null
4175 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4176 * 4. Get checkMap from DeviceManagerNotify
4177 * 5. check checkMap not null
4178 * 6. call DeviceManagerNotify OnAuthResult
4179 * 7. check if callback OnDiscoverySuccess called
4180 */
4181 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult4, testing::ext::TestSize.Level0)
4182 {
4183 // 1. set pkgName not null
4184 std::string pkgName = "com.ohos.test";
4185 // set callback not null
4186 int count = 0;
4187 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4188 // set subscribeId not null
4189 std::string deviceId = "1";
4190 // 2. set checkMap null
4191 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4192 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4193 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4194 // 4. Get checkMap from DeviceManagerNotify
4195 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4196 // 5. check checkMap not null
4197 ASSERT_NE(checkMap, nullptr);
4198 // 6. call DeviceManagerNotify OnAuthResult
4199 std::string token = "111";
4200 uint32_t status = 0;
4201 uint32_t reason = 0;
4202 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4203 // 7. check if callback OnDiscoverySuccess called
4204 ASSERT_EQ(count, 1);
4205 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4206 ASSERT_EQ(checkMap, nullptr);
4207 }
4208
4209 /*
4210 * Feature: DeviceManagerNotifyTest OnAuthResult
4211 * Function: OnAuthResult
4212 * SubFunction: RegisterAuthenticateCallback
4213 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4214 * EnvConditions: OnAuthResult success.
4215 * CaseDescription: 1. set pkgName not null
4216 * set Callback not null
4217 * set deviceId not null
4218 * 2. set checkMap null
4219 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4220 * 4. Get checkMap from DeviceManagerNotify
4221 * 5. check checkMap not null
4222 * 6. call DeviceManagerNotify OnAuthResult
4223 * 7. check if callback OnDiscoverySuccess called
4224 */
4225 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult5, testing::ext::TestSize.Level0)
4226 {
4227 // 1. set pkgName not null
4228 std::string pkgName = "com.ohos.test";
4229 // set callback not null
4230 int count = 0;
4231 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4232 // set subscribeId not null
4233 std::string deviceId = "1";
4234 // 2. set checkMap null
4235 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4236 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4237 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4238 // 4. Get checkMap from DeviceManagerNotify
4239 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4240 // 5. check checkMap not null
4241 ASSERT_NE(checkMap, nullptr);
4242 // 6. call DeviceManagerNotify OnAuthResult
4243 std::string testPkaName = "com.ohos.test1";
4244 std::string token = "111";
4245 uint32_t status = 0;
4246 uint32_t reason = 0;
4247 DeviceManagerNotify::GetInstance().OnAuthResult(testPkaName, deviceId, token, status, reason);
4248 // 7. check if callback OnDiscoverySuccess called
4249 ASSERT_EQ(count, 0);
4250 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4251 ASSERT_NE(checkMap, nullptr);
4252 }
4253
4254 /*
4255 * Feature: DeviceManagerNotifyTest OnAuthResult
4256 * Function: OnAuthResult
4257 * SubFunction: RegisterAuthenticateCallback
4258 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4259 * EnvConditions: OnAuthResult success.
4260 * CaseDescription: 1. set pkgName not null
4261 * set Callback not null
4262 * set deviceId not null
4263 * 2. set checkMap null
4264 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4265 * 4. Get checkMap from DeviceManagerNotify
4266 * 5. check checkMap not null
4267 * 6. call DeviceManagerNotify OnAuthResult
4268 * 7. check if callback OnDiscoverySuccess called
4269 */
4270 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult6, testing::ext::TestSize.Level0)
4271 {
4272 // 1. set pkgName not null
4273 std::string pkgName = "com.ohos.test";
4274 // set callback not null
4275 int count = 0;
4276 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4277 // set subscribeId not null
4278 std::string deviceId = "1";
4279 // 2. set checkMap null
4280 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4281 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4282 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4283 // 4. Get checkMap from DeviceManagerNotify
4284 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4285 // 5. check checkMap not null
4286 ASSERT_NE(checkMap, nullptr);
4287 // 6. call DeviceManagerNotify OnAuthResult
4288 std::string testDeviceId = "2";
4289 std::string token = "111";
4290 uint32_t status = 0;
4291 uint32_t reason = 0;
4292 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, testDeviceId, token, status, reason);
4293 // 7. check if callback OnDiscoverySuccess called
4294 ASSERT_EQ(count, 0);
4295 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4296 ASSERT_NE(checkMap, nullptr);
4297 }
4298
4299 /*
4300 * Feature: DeviceManagerNotifyTest OnAuthResult
4301 * Function: OnAuthResult
4302 * SubFunction: RegisterAuthenticateCallback
4303 * FunctionPoints: DeviceManagerNotifyTest OnAuthResult
4304 * EnvConditions: OnAuthResult success.
4305 * CaseDescription: 1. set pkgName not null
4306 * set Callback not null
4307 * set deviceId not null
4308 * 2. set checkMap null
4309 * 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4310 * 4. Get checkMap from DeviceManagerNotify
4311 * 5. check checkMap not null
4312 * 6. call DeviceManagerNotify OnAuthResult
4313 * 7. check if callback OnDiscoverySuccess called
4314 */
4315 HWTEST_F(DeviceManagerNotifyTest, OnAuthResult7, testing::ext::TestSize.Level0)
4316 {
4317 // 1. set pkgName not null
4318 std::string pkgName = "com.ohos.test";
4319 // set callback not null
4320 int count = 0;
4321 std::shared_ptr<AuthenticateCallback> callback = std::make_shared<AuthenticateCallbackTest>(count);
4322 // set subscribeId not null
4323 std::string deviceId = "1";
4324 // 2. set checkMap null
4325 std::shared_ptr<AuthenticateCallback> checkMap = nullptr;
4326 // 3. call DeviceManagerNotifyTest RegisterAuthenticateCallback with parameter
4327 DeviceManagerNotify::GetInstance().RegisterAuthenticateCallback(pkgName, deviceId, callback);
4328 // 4. Get checkMap from DeviceManagerNotify
4329 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4330 // 5. check checkMap not null
4331 ASSERT_NE(checkMap, nullptr);
4332 // 6. call DeviceManagerNotify OnAuthResult
4333 std::string token = "111";
4334 uint32_t status = 0;
4335 uint32_t reason = 0;
4336 DeviceManagerNotify::GetInstance().OnAuthResult(pkgName, deviceId, token, status, reason);
4337 // 7. check if callback OnDiscoverySuccess called
4338 ASSERT_EQ(count, 1);
4339 checkMap = DeviceManagerNotify::GetInstance().authenticateCallback_[pkgName][deviceId];
4340 ASSERT_EQ(checkMap, nullptr);
4341 }
4342
4343 /*
4344 * Feature: DeviceManagerNotifyTest OnUiCall
4345 * Function: DeviceManagerNotifyTest
4346 * SubFunction: OnUiCall
4347 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4348 * EnvConditions: OnUiCall success.
4349 * CaseDescription: 1. set pkgName not null
4350 * set dmUiCallback_ not null
4351 * 2. set checkMap null
4352 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4353 * 4. Get checkMap from DeviceManagerNotify
4354 * 5. check checkMap not null
4355 * 6. call DeviceManagerNotify OnUiCall
4356 * 7. check if callback OnCheckAuthResult called
4357 */
4358 HWTEST_F(DeviceManagerNotifyTest, OnUiCall1, testing::ext::TestSize.Level0)
4359 {
4360 // 1. set pkgName not null
4361 std::string pkgName = "com.ohos.test";
4362 // set dmUiCallback_ not null
4363 int count = 0;
4364 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4365 // 2. set checkMap null
4366 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4367 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4368 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4369 // 4. Get checkMap from DeviceManagerNotify
4370 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4371 // 5. check checkMap not null
4372 ASSERT_NE(checkMap, nullptr);
4373 // 6. call DeviceManagerNotify OnUiCall
4374 std::string paramJson = "trstParamJson";
4375 DeviceManagerNotify::GetInstance().OnUiCall(pkgName, paramJson);
4376 // 7. check if callback OnCheckAuthResult called
4377 ASSERT_EQ(count, 1);
4378 }
4379
4380 /*
4381 * Feature: DeviceManagerNotifyTest OnUiCall
4382 * Function: DeviceManagerNotifyTest
4383 * SubFunction: OnUiCall
4384 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4385 * EnvConditions: OnUiCall success.
4386 * CaseDescription: 1. set pkgName not null
4387 * set dmUiCallback_ not null
4388 * 2. set checkMap null
4389 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4390 * 4. Get checkMap from DeviceManagerNotify
4391 * 5. check checkMap not null
4392 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4393 * 7. check if callback OnCheckAuthResult called
4394 */
4395 HWTEST_F(DeviceManagerNotifyTest, OnUiCall2, testing::ext::TestSize.Level0)
4396 {
4397 // 1. set pkgName not null
4398 std::string pkgName = "com.ohos.test";
4399 // set dmUiCallback_ not null
4400 int count = 0;
4401 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4402 // 2. set checkMap null
4403 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4404 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4405 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4406 // 4. Get checkMap from DeviceManagerNotify
4407 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4408 // 5. check checkMap not null
4409 ASSERT_NE(checkMap, nullptr);
4410 // 6. call DeviceManagerNotify OnUiCall
4411 std::string testPkgName = "com.ohos.test1";
4412 std::string paramJson = "trstParamJson";
4413 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4414 // 7. check if callback OnCheckAuthResult called
4415 ASSERT_EQ(count, 0);
4416 }
4417
4418 /*
4419 * Feature: DeviceManagerNotifyTest OnUiCall
4420 * Function: DeviceManagerNotifyTest
4421 * SubFunction: OnUiCall
4422 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4423 * EnvConditions: OnUiCall success.
4424 * CaseDescription: 1. set pkgName not null
4425 * set dmUiCallback_ not null
4426 * 2. set checkMap null
4427 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4428 * 4. Get checkMap from DeviceManagerNotify
4429 * 5. check checkMap not null
4430 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4431 * 7. check if callback OnCheckAuthResult called
4432 */
4433 HWTEST_F(DeviceManagerNotifyTest, OnUiCall3, testing::ext::TestSize.Level0)
4434 {
4435 // 1. set pkgName not null
4436 std::string pkgName = "com.ohos.test";
4437 // set dmUiCallback_ not null
4438 int count = 0;
4439 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4440 // 2. set checkMap null
4441 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4442 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4443 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4444 // 4. Get checkMap from DeviceManagerNotify
4445 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4446 // 5. check checkMap not null
4447 ASSERT_NE(checkMap, nullptr);
4448 // 6. call DeviceManagerNotify OnUiCall
4449 std::string testPkgName = "";
4450 std::string paramJson = "trstParamJson";
4451 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4452 // 7. check if callback OnCheckAuthResult called
4453 ASSERT_EQ(count, 0);
4454 }
4455
4456 /*
4457 * Feature: DeviceManagerNotifyTest OnUiCall
4458 * Function: DeviceManagerNotifyTest
4459 * SubFunction: OnUiCall
4460 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4461 * EnvConditions: OnUiCall success.
4462 * CaseDescription: 1. set pkgName not null
4463 * set dmUiCallback_ not null
4464 * 2. set checkMap null
4465 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4466 * 4. Get checkMap from DeviceManagerNotify
4467 * 5. check checkMap not null
4468 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4469 * 7. check if callback OnCheckAuthResult called
4470 */
4471 HWTEST_F(DeviceManagerNotifyTest, OnUiCall4, testing::ext::TestSize.Level0)
4472 {
4473 // 1. set pkgName not null
4474 std::string pkgName = "com.ohos.test";
4475 // set dmUiCallback_ not null
4476 int count = 0;
4477 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4478 // 2. set checkMap null
4479 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4480 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4481 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4482 // 4. Get checkMap from DeviceManagerNotify
4483 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4484 // 5. check checkMap not null
4485 ASSERT_NE(checkMap, nullptr);
4486 // 6. call DeviceManagerNotify OnUiCall
4487 std::string testPkgName = "com.ohos.test";
4488 std::string paramJson = "trstParamJson";
4489 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4490 // 7. check if callback OnCheckAuthResult called
4491 ASSERT_EQ(count, 1);
4492 }
4493
4494 /*
4495 * Feature: DeviceManagerNotifyTest OnUiCall
4496 * Function: DeviceManagerNotifyTest
4497 * SubFunction: OnUiCall
4498 * FunctionPoints: DeviceManagerNotifyTest OnUiCall
4499 * EnvConditions: OnUiCall success.
4500 * CaseDescription: 1. set pkgName not null
4501 * set dmUiCallback_ not null
4502 * 2. set checkMap null
4503 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4504 * 4. Get checkMap from DeviceManagerNotify
4505 * 5. check checkMap not null
4506 * 6. call DeviceManagerNotify OnUiCall with testPkgName
4507 * 7. check if callback OnCheckAuthResult called
4508 */
4509 HWTEST_F(DeviceManagerNotifyTest, OnUiCall5, testing::ext::TestSize.Level0)
4510 {
4511 // 1. set pkgName not null
4512 std::string pkgName = "";
4513 // set dmUiCallback_ not null
4514 int count = 0;
4515 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count);
4516 // 2. set checkMap null
4517 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr;
4518 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter
4519 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_);
4520 // 4. Get checkMap from DeviceManagerNotify
4521 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName];
4522 // 5. check checkMap not null
4523 ASSERT_NE(checkMap, nullptr);
4524 // 6. call DeviceManagerNotify OnUiCall
4525 std::string testPkgName = "";
4526 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName);
4527 std::string paramJson = "trstParamJson";
4528 DeviceManagerNotify::GetInstance().OnUiCall(testPkgName, paramJson);
4529 // 7. check if callback OnCheckAuthResult called
4530 ASSERT_EQ(count, 0);
4531 }
4532
4533 /**
4534 * @tc.name: OnCredentialResult1
4535 * @tc.type: FUNC
4536 */
4537 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult1, testing::ext::TestSize.Level0)
4538 {
4539 std::string pkgName = "";
4540 int32_t action = 1;
4541 std::string credentialResult = "failed";
4542 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4543 std::shared_ptr<CredentialCallback> tempCbk;
4544 tempCbk = DeviceManagerNotify::GetInstance().credentialCallback_[pkgName];
4545 EXPECT_EQ(tempCbk, nullptr);
4546 }
4547 /**
4548 * @tc.name: OnCredentialResult2
4549 * @tc.type: FUNC
4550 */
4551 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult2, testing::ext::TestSize.Level0)
4552 {
4553 std::string pkgName = "com.ohos.test";
4554 int32_t action = 1;
4555 std::string credentialResult = "failed";
4556 std::shared_ptr<CredentialCallback> tempCbk = std::make_shared<CredentialCallbackTest>();
4557 DeviceManagerNotify::GetInstance().credentialCallback_[pkgName] = tempCbk;
4558 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4559 int count = DeviceManagerNotify::GetInstance().credentialCallback_.count(pkgName);
4560 EXPECT_EQ(count, 1);
4561 }
4562
4563 /**
4564 * @tc.name: OnCredentialResult3
4565 * @tc.type: FUNC
4566 */
4567 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult3, testing::ext::TestSize.Level0)
4568 {
4569 std::string pkgName = "com.ohos.test3";
4570 int32_t action = 1;
4571 std::string credentialResult = "failed";
4572 DeviceManagerNotify::GetInstance().credentialCallback_[pkgName] = nullptr;
4573 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4574 int count = DeviceManagerNotify::GetInstance().credentialCallback_.count(pkgName);
4575 EXPECT_EQ(count, 1);
4576 }
4577
4578 /**
4579 * @tc.name: OnCredentialResult4
4580 * @tc.type: FUNC
4581 */
4582 HWTEST_F(DeviceManagerNotifyTest, OnCredentialResult4, testing::ext::TestSize.Level0)
4583 {
4584 std::string pkgName = "com.ohos.test4";
4585 int32_t action = 1;
4586 std::string credentialResult = "failed";
4587 DeviceManagerNotify::GetInstance().OnCredentialResult(pkgName, action, credentialResult);
4588 int count = DeviceManagerNotify::GetInstance().credentialCallback_.count(pkgName);
4589 EXPECT_EQ(count, 0);
4590 }
4591
4592 /**
4593 * @tc.name: OnVerifyAuthResult1
4594 * @tc.type: FUNC
4595 */
4596 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult1, testing::ext::TestSize.Level0)
4597 {
4598 std::string pkgName = "";
4599 std::string deviceId = "123";
4600 int32_t resultCode = 0;
4601 int32_t flag = 0;
4602 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4603 std::shared_ptr<VerifyAuthCallback> tempCbk;
4604 tempCbk = DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName];
4605 EXPECT_EQ(tempCbk, nullptr);
4606 }
4607
4608 /**
4609 * @tc.name: OnVerifyAuthResult2
4610 * @tc.type: FUNC
4611 */
4612 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult2, testing::ext::TestSize.Level0)
4613 {
4614 std::string pkgName = "com.ohos.test2";
4615 std::string deviceId = "12";
4616 int32_t resultCode = 0;
4617 int32_t flag = 0;
4618 std::shared_ptr<VerifyAuthCallback> tempCbk = std::make_shared<VerifyAuthCallbackTest>();
4619 DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName] = tempCbk;
4620 int count = DeviceManagerNotify::GetInstance().verifyAuthCallback_.count(pkgName);
4621 EXPECT_EQ(count, 1);
4622 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4623 count = DeviceManagerNotify::GetInstance().verifyAuthCallback_.count(pkgName);
4624 EXPECT_EQ(count, 0);
4625 }
4626
4627 /**
4628 * @tc.name: OnVerifyAuthResult3
4629 * @tc.type: FUNC
4630 */
4631 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult3, testing::ext::TestSize.Level0)
4632 {
4633 std::string pkgName = "com.ohos.test3";
4634 std::string deviceId = "123";
4635 int32_t resultCode = 0;
4636 int32_t flag = 0;
4637 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4638 int count = DeviceManagerNotify::GetInstance().verifyAuthCallback_.count(pkgName);
4639 EXPECT_EQ(count, 0);
4640 }
4641
4642 /**
4643 * @tc.name: OnVerifyAuthResult4
4644 * @tc.type: FUNC
4645 */
4646 HWTEST_F(DeviceManagerNotifyTest, OnVerifyAuthResult4, testing::ext::TestSize.Level0)
4647 {
4648 std::string pkgName = "com.ohos.test4";
4649 std::string deviceId = "1234";
4650 int32_t resultCode = 0;
4651 int32_t flag = 0;
4652 DeviceManagerNotify::GetInstance().verifyAuthCallback_[pkgName] = nullptr;
4653 DeviceManagerNotify::GetInstance().OnVerifyAuthResult(pkgName, deviceId, resultCode, flag);
4654 int count = DeviceManagerNotify::GetInstance().verifyAuthCallback_.count(pkgName);
4655 EXPECT_EQ(count, 1);
4656 }
4657
4658 /**
4659 * @tc.name: UnRegisterDeviceStatusCallback1
4660 * @tc.type: FUNC
4661 */
4662 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStatusCallback1, testing::ext::TestSize.Level0)
4663 {
4664 std::string pkgName = "com.ohos.test4";
4665 DeviceManagerNotify::GetInstance().UnRegisterDeviceStatusCallback(pkgName);
4666 EXPECT_EQ(DeviceManagerNotify::GetInstance().deviceStatusCallback_.empty(), true);
4667 }
4668
4669 /**
4670 * @tc.name: UnRegisterDeviceStatusCallback2
4671 * @tc.type: FUNC
4672 */
4673 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceStatusCallback2, testing::ext::TestSize.Level0)
4674 {
4675 std::string pkgName;
4676 DeviceManagerNotify::GetInstance().UnRegisterDeviceStatusCallback(pkgName);
4677 EXPECT_EQ(DeviceManagerNotify::GetInstance().deviceStatusCallback_.empty(), true);
4678 }
4679
4680 /**
4681 * @tc.name: RegisterDeviceStatusCallback1
4682 * @tc.type: FUNC
4683 */
4684 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStatusCallback1, testing::ext::TestSize.Level0)
4685 {
4686 std::string pkgName = "com.ohos.test4";
4687 std::shared_ptr<DeviceStatusCallback> callback = nullptr;
4688 DeviceManagerNotify::GetInstance().RegisterDeviceStatusCallback(pkgName, callback);
4689 EXPECT_EQ(DeviceManagerNotify::GetInstance().deviceStatusCallback_.empty(), false);
4690 }
4691
4692 /**
4693 * @tc.name: RegisterDeviceStatusCallback2
4694 * @tc.type: FUNC
4695 */
4696 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceStatusCallback2, testing::ext::TestSize.Level0)
4697 {
4698 std::string pkgName;
4699 std::shared_ptr<DeviceStatusCallback> callback = nullptr;
4700 DeviceManagerNotify::GetInstance().RegisterDeviceStatusCallback(pkgName, callback);
4701 EXPECT_EQ(DeviceManagerNotify::GetInstance().deviceStatusCallback_.empty(), false);
4702 }
4703
4704 /**
4705 * @tc.name: OnDeviceOnline1
4706 * @tc.type: FUNC
4707 */
4708 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline1, testing::ext::TestSize.Level0)
4709 {
4710 std::string pkgName = "com.ohos.test4";
4711 DmDeviceBasicInfo deviceBasicInfo;
4712 DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceBasicInfo);
4713 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4714 EXPECT_EQ(ptr, nullptr);
4715 }
4716
4717 /**
4718 * @tc.name: OnDeviceOnline2
4719 * @tc.type: FUNC
4720 */
4721 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline2, testing::ext::TestSize.Level0)
4722 {
4723 std::string pkgName;
4724 DmDeviceBasicInfo deviceBasicInfo;
4725 DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceBasicInfo);
4726 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4727 EXPECT_EQ(ptr, nullptr);
4728 }
4729
4730 /**
4731 * @tc.name: OnDeviceOffline1
4732 * @tc.type: FUNC
4733 */
4734 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline1, testing::ext::TestSize.Level0)
4735 {
4736 std::string pkgName = "com.ohos.test4";
4737 DmDeviceBasicInfo deviceBasicInfo;
4738 DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceBasicInfo);
4739 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4740 EXPECT_EQ(ptr, nullptr);
4741 }
4742
4743 /**
4744 * @tc.name: OnDeviceOffline2
4745 * @tc.type: FUNC
4746 */
4747 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline2, testing::ext::TestSize.Level0)
4748 {
4749 std::string pkgName;
4750 DmDeviceBasicInfo deviceBasicInfo;
4751 DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceBasicInfo);
4752 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4753 EXPECT_EQ(ptr, nullptr);
4754 }
4755
4756 /**
4757 * @tc.name: OnDeviceReady1
4758 * @tc.type: FUNC
4759 */
4760 HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady1, testing::ext::TestSize.Level0)
4761 {
4762 std::string pkgName = "com.ohos.test4";
4763 DmDeviceBasicInfo deviceBasicInfo;
4764 DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, deviceBasicInfo);
4765 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4766 EXPECT_EQ(ptr, nullptr);
4767 }
4768
4769 /**
4770 * @tc.name: OnDeviceReady2
4771 * @tc.type: FUNC
4772 */
4773 HWTEST_F(DeviceManagerNotifyTest, OnDeviceReady2, testing::ext::TestSize.Level0)
4774 {
4775 std::string pkgName;
4776 DmDeviceBasicInfo deviceBasicInfo;
4777 DeviceManagerNotify::GetInstance().OnDeviceReady(pkgName, deviceBasicInfo);
4778 auto ptr = DeviceManagerNotify::GetInstance().deviceStatusCallback_[pkgName];
4779 EXPECT_EQ(ptr, nullptr);
4780 }
4781
4782 /**
4783 * @tc.name: OnDeviceFound6
4784 * @tc.type: FUNC
4785 */
4786 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound6, testing::ext::TestSize.Level0)
4787 {
4788 std::string pkgName = "com.ohos.test4";
4789 uint16_t subscribeId = 0;
4790 DmDeviceBasicInfo deviceBasicInfo;
4791 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceBasicInfo);
4792 auto map = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName];
4793 EXPECT_EQ(map.empty(), true);
4794 }
4795
4796 /**
4797 * @tc.name: OnDeviceFound7
4798 * @tc.type: FUNC
4799 */
4800 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound7, testing::ext::TestSize.Level0)
4801 {
4802 std::string pkgName;
4803 uint16_t subscribeId = 0;
4804 DmDeviceBasicInfo deviceBasicInfo;
4805 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceBasicInfo);
4806 auto map = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName];
4807 EXPECT_EQ(map.empty(), false);
4808 }
4809 } // namespace
4810
DmInitCallbackTest(int & count)4811 DmInitCallbackTest::DmInitCallbackTest(int &count) : DmInitCallback()
4812 {
4813 count_ = &count;
4814 }
OnRemoteDied()4815 void DmInitCallbackTest::OnRemoteDied()
4816 {
4817 *count_ = *count_ + 1;
4818 }
4819
DeviceStateCallbackTest(int & count)4820 DeviceStateCallbackTest::DeviceStateCallbackTest(int &count) : DeviceStateCallback()
4821 {
4822 count_ = &count;
4823 }
4824
OnDeviceOnline(const DmDeviceInfo & deviceInfo)4825 void DeviceStateCallbackTest::OnDeviceOnline(const DmDeviceInfo &deviceInfo)
4826 {
4827 *count_ = *count_ + 1;
4828 }
4829
OnDeviceReady(const DmDeviceInfo & deviceInfo)4830 void DeviceStateCallbackTest::OnDeviceReady(const DmDeviceInfo &deviceInfo)
4831 {
4832 *count_ = *count_ + 1;
4833 }
4834
OnDeviceOffline(const DmDeviceInfo & deviceInfo)4835 void DeviceStateCallbackTest::OnDeviceOffline(const DmDeviceInfo &deviceInfo)
4836 {
4837 *count_ = *count_ + 1;
4838 }
4839
OnDeviceChanged(const DmDeviceInfo & deviceInfo)4840 void DeviceStateCallbackTest::OnDeviceChanged(const DmDeviceInfo &deviceInfo)
4841 {
4842 *count_ = *count_ + 1;
4843 }
4844
DiscoveryCallbackTest(int & count)4845 DiscoveryCallbackTest::DiscoveryCallbackTest(int &count) : DiscoveryCallback()
4846 {
4847 count_ = &count;
4848 }
4849
OnDeviceFound(uint16_t subscribeId,const DmDeviceInfo & deviceInfo)4850 void DiscoveryCallbackTest::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo)
4851 {
4852 *count_ = *count_ + 1;
4853 }
4854
OnDiscoveryFailed(uint16_t subscribeId,int32_t failedReason)4855 void DiscoveryCallbackTest::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason)
4856 {
4857 *count_ = *count_ + 1;
4858 }
4859
OnDiscoverySuccess(uint16_t subscribeId)4860 void DiscoveryCallbackTest::OnDiscoverySuccess(uint16_t subscribeId)
4861 {
4862 *count_ = *count_ + 1;
4863 }
4864
PublishCallbackTest(int & count)4865 PublishCallbackTest::PublishCallbackTest(int &count) : PublishCallback()
4866 {
4867 count_ = &count;
4868 }
4869
OnPublishResult(int32_t publishId,int32_t failedReason)4870 void PublishCallbackTest::OnPublishResult(int32_t publishId, int32_t failedReason)
4871 {
4872 *count_ = *count_ + 1;
4873 }
4874
AuthenticateCallbackTest(int & count)4875 AuthenticateCallbackTest::AuthenticateCallbackTest(int &count) : AuthenticateCallback()
4876 {
4877 count_ = &count;
4878 }
4879
OnAuthResult(const std::string & deviceId,const std::string & token,int32_t status,int32_t reason)4880 void AuthenticateCallbackTest::OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status,
4881 int32_t reason)
4882 {
4883 *count_ = *count_ + 1;
4884 }
4885
DeviceManagerFaCallbackTest(int & count)4886 DeviceManagerFaCallbackTest::DeviceManagerFaCallbackTest(int &count) : DeviceManagerUiCallback()
4887 {
4888 count_ = &count;
4889 }
4890
OnCall(const std::string & paramJson)4891 void DeviceManagerFaCallbackTest::OnCall(const std::string ¶mJson)
4892 {
4893 *count_ = *count_ + 1;
4894 }
4895 } // namespace DistributedHardware
4896 } // namespace OHOS
4897