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 { 32 namespace { 33 /* 34 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 35 * Function: DeviceManagerNotifyTest 36 * SubFunction: RegisterDeviceManagerFaCallback 37 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 38 * EnvConditions: RegisterDeviceManagerFaCallback success. 39 * CaseDescription: 1. set pkgName not null 40 * set dmUiCallback_ not null 41 * 2. set checkMap null 42 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 43 * 4. Get checkMap from DeviceManagerNotify 44 * 5. check checkMap not null 45 */ 46 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) 47 { 48 std::string pkgName = "com.ohos.test"; 49 int count = 0; 50 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 51 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 52 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 53 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 54 ASSERT_NE(checkMap, nullptr); 55 } 56 57 /* 58 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 59 * Function: DeviceManagerNotifyTest 60 * SubFunction: RegisterDeviceManagerFaCallback 61 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 62 * EnvConditions: N/A. 63 * CaseDescription: 1. set pkgName not null 64 * set dmUiCallback_ null 65 * 2. set checkMap null 66 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 67 * 4. Get checkMap from DeviceManagerNotify 68 * 5. check checkMap null 69 */ 70 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) 71 { 72 std::string pkgName = "com.ohos.test"; 73 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr; 74 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 75 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 76 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 77 ASSERT_EQ(checkMap, nullptr); 78 } 79 80 /* 81 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 82 * Function: DeviceManagerNotifyTest 83 * SubFunction: RegisterDeviceManagerFaCallback 84 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 85 * EnvConditions: N/A. 86 * CaseDescription: 1. set pkgName com.ohos.test 87 * set dmUiCallback_ not null 88 * 2. set checkMap null 89 * 3. set testpkcName com.ohos.test1 90 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 91 * 5. Get checkMap from DeviceManagerNotify with testpkcName 92 * 6. check checkMap null 93 */ 94 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) 95 { 96 std::string pkgName = "com.ohos.test"; 97 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = nullptr; 98 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 99 std::string testPkgName = "com.ohos.test1"; 100 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 101 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName]; 102 ASSERT_EQ(checkMap, nullptr); 103 } 104 105 /* 106 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 107 * Function: DeviceManagerNotifyTest 108 * SubFunction: RegisterDeviceManagerFaCallback 109 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 110 * EnvConditions: RegisterDeviceManagerFaCallback success. 111 * CaseDescription: 1. set pkgName not null 112 * set dmUiCallback_ not null 113 * 2. set checkMap null 114 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 115 * 4. Get checkMap from DeviceManagerNotify 116 * 5. check checkMap not null 117 */ 118 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) 119 { 120 std::string pkgName = "com.ohos.test"; 121 int count = 0; 122 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 123 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 124 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 125 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 126 ASSERT_NE(checkMap, nullptr); 127 std::string paramJson = "test"; 128 if (checkMap != nullptr) { 129 checkMap->OnCall(paramJson); 130 } 131 ASSERT_EQ(count, 1); 132 } 133 134 /* 135 * Feature: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 136 * Function: DeviceManagerNotifyTest 137 * SubFunction: RegisterDeviceManagerFaCallback 138 * FunctionPoints: DeviceManagerNotifyTest RegisterDeviceManagerFaCallback 139 * EnvConditions: N/A. 140 * CaseDescription: 1. set pkgName com.ohos.test 141 * set dmUiCallback_ not null 142 * 2. set checkMap null 143 * 3. set testpkcName com.ohos.test1 144 * 4. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 145 * 5. Get checkMap from DeviceManagerNotify with testpkcName 146 * 6. check checkMap null 147 */ 148 HWTEST_F(DeviceManagerNotifyTest, RegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) 149 { 150 std::string pkgName = "com.ohos.test"; 151 int count = 0; 152 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 153 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 154 std::string testPkgName = "com.ohos.test1"; 155 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 156 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[testPkgName]; 157 ASSERT_EQ(checkMap, nullptr); 158 } 159 160 /* 161 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 162 * Function: DeviceManagerNotifyTest 163 * SubFunction: UnRegisterDeviceManagerFaCallback 164 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 165 * EnvConditions: UnRegisterDeviceManagerFaCallback success. 166 * CaseDescription: 1. set pkgName not null 167 * set dmUiCallback_ not null 168 * 2. set checkMap null 169 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 170 * 4. Get checkMap from DeviceManagerNotify 171 * 5. check checkMap not null 172 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter 173 * 7. Get checkMap from DeviceManagerNotify 174 * 8. check checkMap null 175 */ 176 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_001, testing::ext::TestSize.Level0) 177 { 178 // 1. set pkgName not null 179 std::string pkgName = "com.ohos.test"; 180 // set dmInitCallback not null 181 int count = 0; 182 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 183 // 2. set checkMap null 184 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 185 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 186 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 187 // 4. Get checkMap from DeviceManagerNotify 188 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 189 // 5. check checkMap not null 190 ASSERT_NE(checkMap, nullptr); 191 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter 192 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); 193 // 7. Get checkMap from DeviceManagerNotify 194 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 195 // 8 check checkMap null 196 ASSERT_EQ(checkMap, nullptr); 197 } 198 199 /* 200 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 201 * Function: DeviceManagerNotifyTest 202 * SubFunction: UnRegisterDeviceManagerFaCallback 203 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 204 * EnvConditions: N/A. 205 * CaseDescription: 1. set pkgName com.ohos.test 206 * set dmInitCallback not null 207 * 2. set checkMap null 208 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 209 * 4. Get checkMap from DeviceManagerNotify 210 * 5. check checkMap not null 211 * 6. set testpkcName com.ohos.test1 212 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 213 * 8. Get checkMap from DeviceManagerNotify 214 * 9. check checkMap not null 215 */ 216 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_002, testing::ext::TestSize.Level0) 217 { 218 // 1. set pkgName not null 219 std::string pkgName = "com.ohos.test"; 220 // set dmUiCallback_ not null 221 int count = 0; 222 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 223 // 2. set checkMap null 224 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 225 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 226 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 227 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback 228 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 229 // 5. check checkMap not null 230 ASSERT_NE(checkMap, nullptr); 231 // 6. set testpkcName com.ohos.test1 232 std::string testPkgName = "com.ohos.test1"; 233 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 234 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); 235 // 8. Get checkMap from DeviceManagerNotify 236 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 237 // 8 check checkMap not null 238 ASSERT_NE(checkMap, nullptr); 239 } 240 241 /* 242 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_003 243 * Function: DeviceManagerNotifyTest 244 * SubFunction: UnRegisterDeviceManagerFaCallback 245 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 246 * EnvConditions: N/A. 247 * CaseDescription: 1. set pkgName com.ohos.test 248 * set dmInitCallback not null 249 * 2. set checkMap null 250 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 251 * 4. Get checkMap from DeviceManagerNotify 252 * 5. check checkMap not null 253 * 6. set testpkcName com.ohos.test1 254 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 255 * 8. Get checkMap from DeviceManagerNotify 256 * 9. check checkMap not null 257 */ 258 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_003, testing::ext::TestSize.Level0) 259 { 260 // 1. set pkgName not null 261 std::string pkgName = "com.ohos.test"; 262 // set dmUiCallback_ not null 263 int count = 0; 264 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 265 // 2. set checkMap null 266 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 267 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 268 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 269 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback 270 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 271 // 5. check checkMap not null 272 ASSERT_NE(checkMap, nullptr); 273 // 6. set testpkcName com.ohos.test1 274 std::string testPkgName = "com.ohos.test1"; 275 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 276 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); 277 // 8. Get checkMap from DeviceManagerNotify 278 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 279 // 9. check checkMap not null 280 ASSERT_NE(checkMap, nullptr); 281 // 10. call checkMap OnCall 282 std::string paramJson = "test"; 283 if (checkMap != nullptr) { 284 checkMap->OnCall(paramJson); 285 } 286 ASSERT_EQ(count, 1); 287 } 288 289 /* 290 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_004 291 * Function: DeviceManagerNotifyTest 292 * SubFunction: UnRegisterDeviceManagerFaCallback 293 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 294 * EnvConditions: UnRegisterDeviceManagerFaCallback success. 295 * CaseDescription: 1. set pkgName not null 296 * set dmUiCallback_ not null 297 * 2. set checkMap null 298 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 299 * 4. Get checkMap from DeviceManagerNotify 300 * 5. check checkMap not null 301 * 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter 302 * 7. Get checkMap from DeviceManagerNotify 303 * 8. check checkMap null 304 */ 305 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_004, testing::ext::TestSize.Level0) 306 { 307 // 1. set pkgName not null 308 std::string pkgName = "com.ohos.test"; 309 // set dmInitCallback not null 310 int count = 0; 311 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 312 // 2. set checkMap null 313 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 314 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 315 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 316 // 4. Get checkMap from DeviceManagerNotify 317 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 318 // 5. check checkMap not null 319 ASSERT_NE(checkMap, nullptr); 320 // 6. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with parameter 321 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(pkgName); 322 // 7. Get checkMap from DeviceManagerNotify 323 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 324 // 8 check checkMap null 325 ASSERT_EQ(checkMap, nullptr); 326 } 327 328 /* 329 * Feature: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback_005 330 * Function: DeviceManagerNotifyTest 331 * SubFunction: UnRegisterDeviceManagerFaCallback 332 * FunctionPoints: DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback 333 * EnvConditions: N/A. 334 * CaseDescription: 1. set pkgName com.ohos.test 335 * set dmInitCallback not null 336 * 2. set checkMap null 337 * 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 338 * 4. Get checkMap from DeviceManagerNotify 339 * 5. check checkMap not null 340 * 6. set testpkcName com.ohos.test1 341 * 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 342 * 8. Get checkMap from DeviceManagerNotify 343 * 9. check checkMap not null 344 */ 345 HWTEST_F(DeviceManagerNotifyTest, UnRegisterDeviceManagerFaCallback_005, testing::ext::TestSize.Level0) 346 { 347 // 1. set pkgName not null 348 std::string pkgName = "com.ohos.test"; 349 // set dmUiCallback_ not null 350 int count = 0; 351 std::shared_ptr<DeviceManagerUiCallback> dmUiCallback_ = std::make_shared<DeviceManagerFaCallbackTest>(count); 352 // 2. set checkMap null 353 std::shared_ptr<DeviceManagerUiCallback> checkMap = nullptr; 354 // 3. call DeviceManagerNotifyTest RegisterDeviceManagerFaCallback with parameter 355 DeviceManagerNotify::GetInstance().RegisterDeviceManagerFaCallback(pkgName, dmUiCallback_); 356 // 4. Get checkMap from DeviceManagerNotify RegisterDeathRecipientCallback 357 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 358 // 5. check checkMap not null 359 ASSERT_NE(checkMap, nullptr); 360 // 6. set testpkcName com.ohos.test1 361 std::string testPkgName = ""; 362 // 7. call DeviceManagerNotifyTest UnRegisterDeviceManagerFaCallback with testpkcName 363 DeviceManagerNotify::GetInstance().UnRegisterDeviceManagerFaCallback(testPkgName); 364 // 8. Get checkMap from DeviceManagerNotify 365 checkMap = DeviceManagerNotify::GetInstance().dmUiCallback_[pkgName]; 366 // 9. check checkMap not null 367 ASSERT_NE(checkMap, nullptr); 368 // 10. call checkMap OnCall 369 std::string paramJson = "test"; 370 if (checkMap != nullptr) { 371 checkMap->OnCall(paramJson); 372 } 373 ASSERT_EQ(count, 1); 374 } 375 376 /* 377 * Feature: DeviceManagerNotifyTest OnRemoteDied 378 * Function: DeviceManagerNotifyTest 379 * SubFunction: OnRemoteDied 380 * FunctionPoints: DeviceManagerNotifyTest OnRemoteDied 381 * EnvConditions: OnRemoteDied success. 382 * CaseDescription: 1. set pkgName not null 383 * set dmInitCallback not null 384 * 2. set checkMap null 385 * 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter 386 * 4. Get checkMap from DeviceManagerNotify 387 * 5. check checkMap not null 388 * 6. call DeviceManagerNotify OnRemoteDied 389 * 7. check if dmInitCallback OnRemoteDied called. 390 */ 391 HWTEST_F(DeviceManagerNotifyTest, OnRemoteDied1, testing::ext::TestSize.Level0) 392 { 393 // 1. set pkgName not null 394 std::string pkgName = "com.ohos.test"; 395 // set dmInitCallback not null 396 int count = 0; 397 std::shared_ptr<DmInitCallback> dmInitCallback = std::make_shared<DmInitCallbackTest>(count); 398 // 2. set checkMap null 399 std::shared_ptr<DmInitCallback> checkMap = nullptr; 400 // 3. call DeviceManagerNotifyTest RegisterDeathRecipientCallback with parameter 401 DeviceManagerNotify::GetInstance().RegisterDeathRecipientCallback(pkgName, dmInitCallback); 402 // 4. Get checkMap from DeviceManagerNotify 403 checkMap = DeviceManagerNotify::GetInstance().dmInitCallback_[pkgName]; 404 // 5. check checkMap not null 405 ASSERT_NE(checkMap, nullptr); 406 // 6. call DeviceManagerNotify OnRemoteDied 407 DeviceManagerNotify::GetInstance().OnRemoteDied(); 408 // 7. check if dmInitCallback OnRemoteDied called 409 ASSERT_EQ(count, 1); 410 } 411 412 /* 413 * Feature: DeviceManagerNotifyTest OnDeviceOnline 414 * Function: DeviceManagerNotifyTest 415 * SubFunction: OnDeviceOnline 416 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline 417 * EnvConditions: OnDeviceOnline success. 418 * CaseDescription: 1. set pkgName not null 419 * set Callback not null 420 * 2. set checkMap null 421 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 422 * 4. Get checkMap from DeviceManagerNotify 423 * 5. check checkMap not null 424 * 6. call DeviceManagerNotify OnDeviceOnline 425 * 7. check if callback OnDeviceOnline called. 426 */ 427 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_001, testing::ext::TestSize.Level0) 428 { 429 // 1. set pkgName not null 430 std::string pkgName = "com.ohos.test"; 431 // set Callback not null 432 int count = 0; 433 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 434 // 2. set checkMap null 435 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 436 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 437 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 438 // 4. Get checkMap from DeviceManagerNotify 439 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 440 // 5. check checkMap not null 441 ASSERT_NE(checkMap, nullptr); 442 // 6. call DeviceManagerNotify OnDeviceOnline 443 DmDeviceInfo deviceInfo; 444 DeviceManagerNotify::GetInstance().OnDeviceOnline(pkgName, deviceInfo); 445 // 7. check if callback OnDeviceOnline called 446 sleep(1); 447 ASSERT_EQ(count, 1); 448 } 449 450 /* 451 * Feature: DeviceManagerNotifyTest OnDeviceOnline 452 * Function: DeviceManagerNotifyTest 453 * SubFunction: OnDeviceOnline 454 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline 455 * EnvConditions: N/A. 456 * CaseDescription: 1. set pkgName not null 457 * set Callback not null 458 * 2. set checkMap null 459 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 460 * 4. Get checkMap from DeviceManagerNotify 461 * 5. check checkMap not null 462 * 6. set testpkcName com.ohos.test1 463 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 464 * 8. check if callback OnDeviceOnline called. 465 */ 466 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_002, testing::ext::TestSize.Level0) 467 { 468 // 1. set pkgName not null 469 std::string pkgName = "com.ohos.test"; 470 // set Callback not null 471 int count = 0; 472 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 473 // 2. set checkMap null 474 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 475 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 476 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 477 // 4. Get checkMap from DeviceManagerNotify 478 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 479 // 5. check checkMap not null 480 ASSERT_NE(checkMap, nullptr); 481 // 6. set testpkcName com.ohos.test1 482 std::string testPkgName = "com.ohos.test1"; 483 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 484 DmDeviceInfo deviceInfo; 485 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); 486 // 8. check if callback OnDeviceOnline called 487 ASSERT_EQ(count, 0); 488 } 489 490 /* 491 * Feature: DeviceManagerNotifyTest OnDeviceOnline 492 * Function: DeviceManagerNotifyTest 493 * SubFunction: OnDeviceOnline 494 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline 495 * EnvConditions: N/A. 496 * CaseDescription: 1. set pkgName not null 497 * set Callback not null 498 * 2. set checkMap null 499 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 500 * 4. Get checkMap from DeviceManagerNotify 501 * 5. check checkMap not null 502 * 6. set testpkcName com.ohos.test1 503 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 504 * 8. check if callback OnDeviceOnline called. 505 */ 506 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_003, testing::ext::TestSize.Level0) 507 { 508 // 1. set pkgName not null 509 std::string pkgName = "com.ohos.test"; 510 // set Callback not null 511 int count = 0; 512 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 513 // 2. set checkMap null 514 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 515 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 516 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 517 // 4. Get checkMap from DeviceManagerNotify 518 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 519 // 5. check checkMap not null 520 ASSERT_NE(checkMap, nullptr); 521 // 6. set testpkcName com.ohos.test1 522 std::string testPkgName = ""; 523 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 524 DmDeviceInfo deviceInfo; 525 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); 526 // 8. check if callback OnDeviceOnline called 527 ASSERT_EQ(count, 0); 528 } 529 530 /* 531 * Feature: DeviceManagerNotifyTest OnDeviceOnline 532 * Function: DeviceManagerNotifyTest 533 * SubFunction: OnDeviceOnline 534 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline 535 * EnvConditions: N/A. 536 * CaseDescription: 1. set pkgName not null 537 * set Callback not null 538 * 2. set checkMap null 539 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 540 * 4. Get checkMap from DeviceManagerNotify 541 * 5. check checkMap not null 542 * 6. set testpkcName com.ohos.test1 543 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 544 * 8. check if callback OnDeviceOnline called. 545 */ 546 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_004, testing::ext::TestSize.Level0) 547 { 548 // 1. set pkgName not null 549 std::string pkgName = "com.ohos.test"; 550 // set Callback not null 551 int count = 0; 552 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 553 // 2. set checkMap null 554 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 555 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 556 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 557 // 4. Get checkMap from DeviceManagerNotify 558 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 559 // 5. check checkMap not null 560 ASSERT_NE(checkMap, nullptr); 561 // 6. set testpkcName com.ohos.test1 562 std::string testPkgName = "111"; 563 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 564 DmDeviceInfo deviceInfo; 565 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); 566 // 8. check if callback OnDeviceOnline called 567 ASSERT_NE(count, 1); 568 } 569 570 /* 571 * Feature: DeviceManagerNotifyTest OnDeviceOnline 572 * Function: DeviceManagerNotifyTest 573 * SubFunction: OnDeviceOnline 574 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOnline 575 * EnvConditions: N/A. 576 * CaseDescription: 1. set pkgName not null 577 * set Callback not null 578 * 2. set checkMap null 579 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 580 * 4. Get checkMap from DeviceManagerNotify 581 * 5. check checkMap not null 582 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 583 * 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 584 * 8. check if callback OnDeviceOnline called 585 */ 586 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOnline_005, testing::ext::TestSize.Level0) 587 { 588 // 1. set pkgName not null 589 std::string pkgName = "com.ohos.test"; 590 // set Callback not null 591 int count = 0; 592 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 593 // 2. set checkMap null 594 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 595 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 596 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 597 // 4. Get checkMap from DeviceManagerNotify 598 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 599 // 5. check checkMap not null 600 ASSERT_NE(checkMap, nullptr); 601 std::string testPkgName = ""; 602 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 603 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); 604 // 7. call DeviceManagerNotify OnDeviceOnline with testpkcName 605 DmDeviceInfo deviceInfo; 606 DeviceManagerNotify::GetInstance().OnDeviceOnline(testPkgName, deviceInfo); 607 // 8. check if callback OnDeviceOnline called 608 ASSERT_EQ(count, 0); 609 } 610 611 /* 612 * Feature: DeviceManagerNotifyTest OnDeviceOffline 613 * Function: DeviceManagerNotifyTest 614 * SubFunction: OnDeviceOffline 615 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline 616 * EnvConditions: OnDeviceOffline success. 617 * CaseDescription: 1. set pkgName not null 618 * set Callback not null 619 * 2. set checkMap null 620 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 621 * 4. Get checkMap from DeviceManagerNotify 622 * 5. check checkMap not null 623 * 6. call DeviceManagerNotify OnDeviceOffline 624 * 7. check if callback OnDeviceOffline called. 625 */ 626 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_001, testing::ext::TestSize.Level0) 627 { 628 // 1. set pkgName not null 629 std::string pkgName = "com.ohos.test"; 630 // set Callback not null 631 int count = 0; 632 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 633 // 2. set checkMap null 634 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 635 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 636 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 637 // 4. Get checkMap from DeviceManagerNotify 638 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 639 // 5. check checkMap not null 640 ASSERT_NE(checkMap, nullptr); 641 // 6. call DeviceManagerNotify OnDeviceOffline 642 DmDeviceInfo deviceInfo; 643 DeviceManagerNotify::GetInstance().OnDeviceOffline(pkgName, deviceInfo); 644 // 7. check if callback OnDeviceOffline called 645 sleep(1); 646 ASSERT_EQ(count, 1); 647 } 648 649 /* 650 * Feature: DeviceManagerNotifyTest OnDeviceOffline 651 * Function: DeviceManagerNotifyTest 652 * SubFunction: OnDeviceOffline 653 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline 654 * EnvConditions: N/A. 655 * CaseDescription: 1. set pkgName not null 656 * set Callback not null 657 * 2. set checkMap null 658 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 659 * 4. Get checkMap from DeviceManagerNotify 660 * 5. check checkMap not null 661 * 6. set testpkcName com.ohos.test1 662 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 663 * 8. check if callback OnDeviceOffline called. 664 */ 665 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_002, testing::ext::TestSize.Level0) 666 { 667 // 1. set pkgName not null 668 std::string pkgName = "com.ohos.test"; 669 // set Callback not null 670 int count = 0; 671 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 672 // 2. set checkMap null 673 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 674 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 675 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 676 // 4. Get checkMap from DeviceManagerNotify 677 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 678 // 5. check checkMap not null 679 ASSERT_NE(checkMap, nullptr); 680 // 6. set testpkcName com.ohos.test1 681 std::string testPkgName = "com.ohos.test1"; 682 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 683 DmDeviceInfo deviceInfo; 684 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); 685 // 8. check if callback OnDeviceOffline called 686 ASSERT_EQ(count, 0); 687 } 688 689 /* 690 * Feature: DeviceManagerNotifyTest OnDeviceOffline 691 * Function: DeviceManagerNotifyTest 692 * SubFunction: OnDeviceOffline 693 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline 694 * EnvConditions: N/A. 695 * CaseDescription: 1. set pkgName not null 696 * set Callback not null 697 * 2. set checkMap null 698 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 699 * 4. Get checkMap from DeviceManagerNotify 700 * 5. check checkMap not null 701 * 6. set testpkcName com.ohos.test1 702 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 703 * 8. check if callback OnDeviceOffline called. 704 */ 705 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_003, testing::ext::TestSize.Level0) 706 { 707 // 1. set pkgName not null 708 std::string pkgName = "com.ohos.test"; 709 // set Callback not null 710 int count = 0; 711 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 712 // 2. set checkMap null 713 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 714 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 715 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 716 // 4. Get checkMap from DeviceManagerNotify 717 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 718 // 5. check checkMap not null 719 ASSERT_NE(checkMap, nullptr); 720 // 6. set testpkcName null 721 std::string testPkgName = ""; 722 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 723 DmDeviceInfo deviceInfo; 724 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); 725 // 8. check if callback OnDeviceOffline called 726 ASSERT_EQ(count, 0); 727 } 728 729 /* 730 * Feature: DeviceManagerNotifyTest OnDeviceOffline 731 * Function: DeviceManagerNotifyTest 732 * SubFunction: OnDeviceOffline 733 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline 734 * EnvConditions: N/A. 735 * CaseDescription: 1. set pkgName not null 736 * set Callback not null 737 * 2. set checkMap null 738 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 739 * 4. Get checkMap from DeviceManagerNotify 740 * 5. check checkMap not null 741 * 6. set testpkcName com.ohos.test1 742 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 743 * 8. check if callback OnDeviceOffline called. 744 */ 745 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_004, testing::ext::TestSize.Level0) 746 { 747 // 1. set pkgName not null 748 std::string pkgName = "com.ohos.test"; 749 // set Callback not null 750 int count = 0; 751 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 752 // 2. set checkMap null 753 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 754 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 755 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 756 // 4. Get checkMap from DeviceManagerNotify 757 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 758 // 5. check checkMap not null 759 ASSERT_NE(checkMap, nullptr); 760 // 6. set testpkcName null 761 std::string testPkgName = ""; 762 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 763 DmDeviceInfo deviceInfo; 764 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); 765 // 8. check if callback OnDeviceOffline called 766 ASSERT_NE(count, 1); 767 } 768 769 /* 770 * Feature: DeviceManagerNotifyTest OnDeviceOffline 771 * Function: DeviceManagerNotifyTest 772 * SubFunction: OnDeviceOffline 773 * FunctionPoints: DeviceManagerNotifyTest OnDeviceOffline 774 * EnvConditions: N/A. 775 * CaseDescription: 1. set pkgName not null 776 * set Callback not null 777 * 2. set checkMap null 778 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 779 * 4. Get checkMap from DeviceManagerNotify 780 * 5. check checkMap not null 781 * 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 782 * 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 783 * 8. check if callback OnDeviceOffline called. 784 */ 785 HWTEST_F(DeviceManagerNotifyTest, OnDeviceOffline_005, testing::ext::TestSize.Level0) 786 { 787 // 1. set pkgName not null 788 std::string pkgName = "com.ohos.test"; 789 // set Callback not null 790 int count = 0; 791 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 792 // 2. set checkMap null 793 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 794 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 795 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 796 // 4. Get checkMap from DeviceManagerNotify 797 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 798 // 5. check checkMap not null 799 ASSERT_NE(checkMap, nullptr); 800 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 801 std::string testPkgName = ""; 802 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); 803 // 7. call DeviceManagerNotify OnDeviceOffline with testpkcName 804 DmDeviceInfo deviceInfo; 805 DeviceManagerNotify::GetInstance().OnDeviceOffline(testPkgName, deviceInfo); 806 // 8. check if callback OnDeviceOffline called 807 ASSERT_EQ(count, 0); 808 } 809 810 /* 811 * Feature: DeviceManagerNotifyTest OnDeviceChanged 812 * Function: DeviceManagerNotifyTest 813 * SubFunction: OnDeviceChanged 814 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 815 * EnvConditions: OnDeviceChanged success. 816 * CaseDescription: 1. set pkgName not null 817 * set Callback not null 818 * 2. set checkMap null 819 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 820 * 4. Get checkMap from DeviceManagerNotify 821 * 5. check checkMap not null 822 * 6. call DeviceManagerNotify OnDeviceChanged 823 * 7. check if callback OnDeviceChanged called. 824 */ 825 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_001, testing::ext::TestSize.Level0) 826 { 827 // 1. set pkgName not null 828 std::string pkgName = "com.ohos.test"; 829 // set Callback not null 830 int count = 0; 831 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 832 // 2. set checkMap null 833 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 834 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 835 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 836 // 4. Get checkMap from DeviceManagerNotify 837 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 838 // 5. check checkMap not null 839 ASSERT_NE(checkMap, nullptr); 840 // 6. call DeviceManagerNotify OnDeviceChanged 841 DmDeviceInfo deviceInfo; 842 DeviceManagerNotify::GetInstance().OnDeviceChanged(pkgName, deviceInfo); 843 // 7. check if callback OnDeviceChanged called 844 sleep(1); 845 ASSERT_EQ(count, 1); 846 } 847 848 /* 849 * Feature: DeviceManagerNotifyTest OnDeviceChanged 850 * Function: DeviceManagerNotifyTest 851 * SubFunction: OnDeviceChanged 852 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 853 * EnvConditions: N/A. 854 * CaseDescription: 1. set pkgName not null 855 * set Callback not null 856 * 2. set checkMap null 857 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 858 * 4. Get checkMap from DeviceManagerNotify 859 * 5. check checkMap not null 860 * 6. set testpkcName com.ohos.test1 861 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 862 * 8. check if callback OnDeviceChanged called. 863 */ 864 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Level0) 865 { 866 // 1. set pkgName not null 867 std::string pkgName = "com.ohos.test"; 868 // set Callback not null 869 int count = 0; 870 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 871 // 2. set checkMap null 872 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 873 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 874 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 875 // 4. Get checkMap from DeviceManagerNotify 876 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 877 // 5. check checkMap not null 878 ASSERT_NE(checkMap, nullptr); 879 // 6. set testpkcName com.ohos.test1 880 std::string testPkgName = "com.ohos.test1"; 881 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 882 DmDeviceInfo deviceInfo; 883 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 884 // 8. check if callback OnDeviceChanged called 885 ASSERT_EQ(count, 0); 886 } 887 888 /* 889 * Feature: DeviceManagerNotifyTest OnDeviceChanged 890 * Function: DeviceManagerNotifyTest 891 * SubFunction: OnDeviceChanged 892 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 893 * EnvConditions: N/A. 894 * CaseDescription: 1. set pkgName not null 895 * set Callback not null 896 * 2. set checkMap null 897 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 898 * 4. Get checkMap from DeviceManagerNotify 899 * 5. check checkMap not null 900 * 6. set testpkcName com.ohos.test1 901 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 902 * 8. check if callback OnDeviceChanged called. 903 */ 904 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_003, testing::ext::TestSize.Level0) 905 { 906 // 1. set pkgName not null 907 std::string pkgName = "com.ohos.test"; 908 // set Callback not null 909 int count = 0; 910 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 911 // 2. set checkMap null 912 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 913 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 914 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 915 // 4. Get checkMap from DeviceManagerNotify 916 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 917 // 5. check checkMap not null 918 ASSERT_NE(checkMap, nullptr); 919 // 6. set testpkcName com.ohos.test1 920 std::string testPkgName = ""; 921 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 922 DmDeviceInfo deviceInfo; 923 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 924 // 8. check if callback OnDeviceChanged called 925 ASSERT_EQ(count, 0); 926 } 927 928 /* 929 * Feature: DeviceManagerNotifyTest OnDeviceChanged 930 * Function: DeviceManagerNotifyTest 931 * SubFunction: OnDeviceChanged 932 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 933 * EnvConditions: N/A. 934 * CaseDescription: 1. set pkgName not null 935 * set Callback not null 936 * 2. set checkMap null 937 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 938 * 4. Get checkMap from DeviceManagerNotify 939 * 5. check checkMap not null 940 * 6. set testpkcName com.ohos.test1 941 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 942 * 8. check if callback OnDeviceChanged called. 943 */ 944 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0) 945 { 946 // 1. set pkgName not null 947 std::string pkgName = "com.ohos.test"; 948 // set Callback not null 949 int count = 0; 950 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 951 // 2. set checkMap null 952 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 953 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 954 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 955 // 4. Get checkMap from DeviceManagerNotify 956 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 957 // 5. check checkMap not null 958 ASSERT_NE(checkMap, nullptr); 959 // 6. set testpkcName com.ohos.test1 960 std::string testPkgName = ""; 961 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 962 DmDeviceInfo deviceInfo; 963 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 964 // 8. check if callback OnDeviceChanged called 965 ASSERT_NE(count, 1); 966 } 967 968 /* 969 * Feature: DeviceManagerNotifyTest OnDeviceChanged 970 * Function: DeviceManagerNotifyTest 971 * SubFunction: OnDeviceChanged 972 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 973 * EnvConditions: N/A. 974 * CaseDescription: 1. set pkgName not null 975 * set Callback not null 976 * 2. set checkMap null 977 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 978 * 4. Get checkMap from DeviceManagerNotify 979 * 5. check checkMap not null 980 * 6. set testpkcName com.ohos.test1 981 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 982 * 8. check if callback OnDeviceChanged called. 983 */ 984 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_005, testing::ext::TestSize.Level0) 985 { 986 // 1. set pkgName not null 987 std::string pkgName = "com.ohos.test"; 988 // set Callback not null 989 int count = 0; 990 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 991 // 2. set checkMap null 992 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 993 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 994 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 995 // 4. Get checkMap from DeviceManagerNotify 996 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 997 // 5. check checkMap not null 998 ASSERT_NE(checkMap, nullptr); 999 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 1000 std::string testPkgName = ""; 1001 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); 1002 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 1003 DmDeviceInfo deviceInfo; 1004 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 1005 // 8. check if callback OnDeviceChanged called 1006 ASSERT_EQ(count, 0); 1007 } 1008 1009 /* 1010 * Feature: DeviceManagerNotifyTest OnDeviceFound 1011 * Function: DeviceManagerNotifyTest 1012 * SubFunction: OnDeviceFound 1013 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1014 * EnvConditions: OnDeviceFound success. 1015 * CaseDescription: 1. set pkgName not null 1016 * set callback not null 1017 * set subscribeId not null 1018 * 2. set checkMap null 1019 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1020 * 4. Get checkMap from DeviceManagerNotify 1021 * 5. check checkMap not null 1022 * 6. call DeviceManagerNotify OnDeviceFound 1023 * 7. check if callback OnDeviceFound called. 1024 */ 1025 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound1, testing::ext::TestSize.Level0) 1026 { 1027 // 1. set pkgName not null 1028 std::string pkgName = "com.ohos.test"; 1029 // set callback not null 1030 int count = 0; 1031 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1032 // set subscribeId not null 1033 uint16_t subscribeId = 0; 1034 // 2. set checkMap null 1035 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1036 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1037 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1038 // 4. Get checkMap from DeviceManagerNotify 1039 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1040 // 5. check checkMap not null 1041 ASSERT_NE(checkMap, nullptr); 1042 DmDeviceInfo deviceInfo; 1043 // 6. call DeviceManagerNotify OnDeviceFound 1044 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo); 1045 // 7. check if callback OnDeviceFound called 1046 sleep(1); 1047 ASSERT_NE(count, 10); 1048 } 1049 1050 /* 1051 * Feature: DeviceManagerNotifyTest OnDeviceFound 1052 * Function: DeviceManagerNotifyTest 1053 * SubFunction: OnDeviceFound 1054 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1055 * EnvConditions: N/A. 1056 * CaseDescription: 1. set pkgName not null 1057 * set callback not null 1058 * set subscribeId not null 1059 * 2. set checkMap null 1060 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1061 * 4. Get checkMap from DeviceManagerNotify 1062 * 5. check checkMap not null 1063 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1064 * 7. check if callback OnDeviceFound called. 1065 */ 1066 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound2, testing::ext::TestSize.Level0) 1067 { 1068 // 1. set pkgName not null 1069 std::string pkgName = "com.ohos.test"; 1070 // set callback not null 1071 int count = 0; 1072 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1073 // set subscribeId not null 1074 uint16_t subscribeId = 0; 1075 // 2. set checkMap null 1076 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1077 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1078 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1079 // 4. Get checkMap from DeviceManagerNotify 1080 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1081 // 5. check checkMap not null 1082 ASSERT_NE(checkMap, nullptr); 1083 DmDeviceInfo deviceInfo; 1084 std::string testPkgName = "com.ohos.test1"; 1085 // 6. call DeviceManagerNotify OnDeviceFound 1086 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1087 // 7. check if callback OnDeviceFound called 1088 ASSERT_EQ(count, 0); 1089 } 1090 1091 /* 1092 * Feature: DeviceManagerNotifyTest OnDeviceFound 1093 * Function: DeviceManagerNotifyTest 1094 * SubFunction: OnDeviceFound 1095 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1096 * EnvConditions: N/A. 1097 * CaseDescription: 1. set pkgName not null 1098 * set callback not null 1099 * set subscribeId not null 1100 * 2. set checkMap null 1101 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1102 * 4. Get checkMap from DeviceManagerNotify 1103 * 5. check checkMap not null 1104 * 6. call DeviceManagerNotify OnDeviceFound With testsubscribeId 1105 * 7. check if callback OnDeviceFound called. 1106 */ 1107 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound3, testing::ext::TestSize.Level0) 1108 { 1109 // 1. set pkgName not null 1110 std::string pkgName = "com.ohos.test"; 1111 // set callback not null 1112 int count = 0; 1113 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1114 // set subscribeId not null 1115 uint16_t subscribeId = 0; 1116 // 2. set checkMap null 1117 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1118 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1119 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1120 // 4. Get checkMap from DeviceManagerNotify 1121 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1122 // 5. check checkMap not null 1123 ASSERT_NE(checkMap, nullptr); 1124 DmDeviceInfo deviceInfo; 1125 uint16_t testsubscribeId = 1; 1126 // 6. call DeviceManagerNotify OnDeviceFound 1127 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, testsubscribeId, deviceInfo); 1128 // 7. check if callback OnDeviceFound called 1129 ASSERT_EQ(count, 0); 1130 } 1131 1132 /* 1133 * Feature: DeviceManagerNotifyTest OnDeviceFound 1134 * Function: DeviceManagerNotifyTest 1135 * SubFunction: OnDeviceFound 1136 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1137 * EnvConditions: N/A. 1138 * CaseDescription: 1. set pkgName not null 1139 * set callback not null 1140 * set subscribeId not null 1141 * 2. set checkMap null 1142 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1143 * 4. Get checkMap from DeviceManagerNotify 1144 * 5. check checkMap not null 1145 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1146 * 7. check if callback OnDeviceFound called. 1147 */ 1148 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound4, testing::ext::TestSize.Level0) 1149 { 1150 // 1. set pkgName not null 1151 std::string pkgName = "com.ohos.test"; 1152 // set callback not null 1153 int count = 0; 1154 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1155 // set subscribeId not null 1156 uint16_t subscribeId = 0; 1157 // 2. set checkMap null 1158 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1159 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1160 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1161 // 4. Get checkMap from DeviceManagerNotify 1162 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1163 // 5. check checkMap not null 1164 ASSERT_NE(checkMap, nullptr); 1165 DmDeviceInfo deviceInfo; 1166 std::string testPkgName = ""; 1167 // 6. call DeviceManagerNotify OnDeviceFound 1168 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1169 // 7. check if callback OnDeviceFound called 1170 ASSERT_EQ(count, 0); 1171 } 1172 1173 /* 1174 * Feature: DeviceManagerNotifyTest OnDeviceFound 1175 * Function: DeviceManagerNotifyTest 1176 * SubFunction: OnDeviceFound 1177 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1178 * EnvConditions: N/A. 1179 * CaseDescription: 1. set pkgName not null 1180 * set callback not null 1181 * set subscribeId not null 1182 * 2. set checkMap null 1183 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1184 * 4. Get checkMap from DeviceManagerNotify 1185 * 5. check checkMap not null 1186 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1187 * 7. check if callback OnDeviceFound called. 1188 */ 1189 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound5, testing::ext::TestSize.Level0) 1190 { 1191 // 1. set pkgName not null 1192 std::string pkgName = "com.ohos.test"; 1193 // set callback not null 1194 int count = 0; 1195 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1196 // set subscribeId not null 1197 uint16_t subscribeId = 0; 1198 // 2. set checkMap null 1199 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1200 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1201 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1202 // 4. Get checkMap from DeviceManagerNotify 1203 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1204 // 5. check checkMap not null 1205 ASSERT_NE(checkMap, nullptr); 1206 DmDeviceInfo deviceInfo; 1207 std::string testPkgName = ""; 1208 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1209 // 6. call DeviceManagerNotify OnDeviceFound 1210 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1211 // 7. check if callback OnDeviceFound called 1212 ASSERT_EQ(count, 0); 1213 } 1214 1215 /* 1216 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1217 * Function: DeviceManagerNotifyTest 1218 * SubFunction: OnDiscoverFailed 1219 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1220 * EnvConditions: OnDiscoverFailed success. 1221 * CaseDescription: 1. set pkgName not null 1222 * set callback not null 1223 * set subscribeId not null 1224 * 2. set checkMap null 1225 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1226 * 4. Get checkMap from DeviceManagerNotify 1227 * 5. check checkMap not null 1228 * 6. call DeviceManagerNotify OnDiscoverFailed 1229 * 7. check if callback OnDiscoverFailed called. 1230 */ 1231 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed1, testing::ext::TestSize.Level0) 1232 { 1233 // 1. set pkgName not null 1234 std::string pkgName = "com.ohos.test"; 1235 // set callback not null 1236 int count = 0; 1237 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1238 // set subscribeId not null 1239 uint16_t subscribeId = 0; 1240 // 2. set checkMap null 1241 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1242 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1243 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1244 // 4. Get checkMap from DeviceManagerNotify 1245 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1246 // 5. check checkMap not null 1247 ASSERT_NE(checkMap, nullptr); 1248 int32_t failedReason = 0; 1249 // 6. call DeviceManagerNotify OnDiscoverFailed 1250 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); 1251 // 7. check if callback OnDiscoverFailed called 1252 ASSERT_NE(count, 10); 1253 } 1254 1255 /* 1256 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1257 * Function: DeviceManagerNotifyTest 1258 * SubFunction: OnDiscoverFailed 1259 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1260 * EnvConditions: N/A. 1261 * CaseDescription: 1. set pkgName not null 1262 * set callback not null 1263 * set subscribeId not null 1264 * 2. set checkMap null 1265 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1266 * 4. Get checkMap from DeviceManagerNotify 1267 * 5. check checkMap not null 1268 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1269 * 7. check if callback OnDiscoverFailed called. 1270 */ 1271 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed2, testing::ext::TestSize.Level0) 1272 { 1273 // 1. set pkgName not null 1274 std::string pkgName = "com.ohos.test"; 1275 // set callback not null 1276 int count = 0; 1277 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1278 // set subscribeId not null 1279 uint16_t subscribeId = 0; 1280 // 2. set checkMap null 1281 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1282 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1283 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1284 // 4. Get checkMap from DeviceManagerNotify 1285 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1286 // 5. check checkMap not null 1287 ASSERT_NE(checkMap, nullptr); 1288 std::string testPkgName = "com.ohos.test1"; 1289 int32_t failedReason = 0; 1290 // 6. call DeviceManagerNotify OnDiscoverFailed 1291 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1292 // 7. check if callback OnDiscoverFailed called 1293 ASSERT_EQ(count, 0); 1294 } 1295 1296 /* 1297 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1298 * Function: DeviceManagerNotifyTest 1299 * SubFunction: OnDiscoverFailed 1300 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1301 * EnvConditions: N/A. 1302 * CaseDescription: 1. set pkgName not null 1303 * set callback not null 1304 * set subscribeId not null 1305 * 2. set checkMap null 1306 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1307 * 4. Get checkMap from DeviceManagerNotify 1308 * 5. check checkMap not null 1309 * 6. call DeviceManagerNotify OnDiscoverFailed With testsubscribeId 1310 * 7. check if callback OnDiscoverFailed called. 1311 */ 1312 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed3, testing::ext::TestSize.Level0) 1313 { 1314 // 1. set pkgName not null 1315 std::string pkgName = "com.ohos.test"; 1316 // set callback not null 1317 int count = 0; 1318 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1319 // set subscribeId not null 1320 uint16_t subscribeId = 0; 1321 // 2. set checkMap null 1322 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1323 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1324 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1325 // 4. Get checkMap from DeviceManagerNotify 1326 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1327 // 5. check checkMap not null 1328 ASSERT_NE(checkMap, nullptr); 1329 int32_t failedReason = 0; 1330 uint16_t testsubscribeId = 1; 1331 // 6. call DeviceManagerNotify OnDiscoverFailed 1332 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason); 1333 // 7. check if callback OnDiscoverFailed called 1334 ASSERT_EQ(count, 0); 1335 } 1336 1337 /* 1338 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1339 * Function: DeviceManagerNotifyTest 1340 * SubFunction: OnDiscoverFailed 1341 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1342 * EnvConditions: N/A. 1343 * CaseDescription: 1. set pkgName not null 1344 * set callback not null 1345 * set subscribeId not null 1346 * 2. set checkMap null 1347 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1348 * 4. Get checkMap from DeviceManagerNotify 1349 * 5. check checkMap not null 1350 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1351 * 7. check if callback OnDiscoverFailed called. 1352 */ 1353 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed4, testing::ext::TestSize.Level0) 1354 { 1355 // 1. set pkgName not null 1356 std::string pkgName = "com.ohos.test"; 1357 // set callback not null 1358 int count = 0; 1359 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1360 // set subscribeId not null 1361 uint16_t subscribeId = 0; 1362 // 2. set checkMap null 1363 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1364 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1365 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1366 // 4. Get checkMap from DeviceManagerNotify 1367 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1368 // 5. check checkMap not null 1369 ASSERT_NE(checkMap, nullptr); 1370 std::string testPkgName = ""; 1371 int32_t failedReason = 0; 1372 // 6. call DeviceManagerNotify OnDiscoverFailed 1373 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1374 // 7. check if callback OnDiscoverFailed called 1375 ASSERT_EQ(count, 0); 1376 } 1377 1378 /* 1379 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1380 * Function: DeviceManagerNotifyTest 1381 * SubFunction: OnDiscoverFailed 1382 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1383 * EnvConditions: N/A. 1384 * CaseDescription: 1. set pkgName not null 1385 * set callback not null 1386 * set subscribeId not null 1387 * 2. set checkMap null 1388 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1389 * 4. Get checkMap from DeviceManagerNotify 1390 * 5. check checkMap not null 1391 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1392 * 7. check if callback OnDiscoverFailed called. 1393 */ 1394 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed5, testing::ext::TestSize.Level0) 1395 { 1396 // 1. set pkgName not null 1397 std::string pkgName = "com.ohos.test"; 1398 // set callback not null 1399 int count = 0; 1400 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1401 // set subscribeId not null 1402 uint16_t subscribeId = 0; 1403 // 2. set checkMap null 1404 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1405 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1406 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1407 // 4. Get checkMap from DeviceManagerNotify 1408 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1409 // 5. check checkMap not null 1410 ASSERT_NE(checkMap, nullptr); 1411 std::string testPkgName = ""; 1412 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1413 int32_t failedReason = 0; 1414 // 6. call DeviceManagerNotify OnDiscoverFailed 1415 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1416 // 7. check if callback OnDiscoverFailed called 1417 ASSERT_EQ(count, 0); 1418 } 1419 1420 /* 1421 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1422 * Function: DeviceManagerNotifyTest 1423 * SubFunction: OnDiscoverySuccess 1424 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1425 * EnvConditions: OnDiscoverySuccess success. 1426 * CaseDescription: 1. set pkgName not null 1427 * set callback not null 1428 * set subscribeId not null 1429 * 2. set checkMap null 1430 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1431 * 4. Get checkMap from DeviceManagerNotify 1432 * 5. check checkMap not null 1433 * 6. call DeviceManagerNotify OnDiscoverySuccess 1434 * 7. check if callback OnDiscoverySuccess called. 1435 */ 1436 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess1, testing::ext::TestSize.Level0) 1437 { 1438 // 1. set pkgName not null 1439 std::string pkgName = "com.ohos.test"; 1440 // set callback not null 1441 int count = 0; 1442 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1443 // set subscribeId not null 1444 uint16_t subscribeId = 0; 1445 // 2. set checkMap null 1446 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1447 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1448 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1449 // 4. Get checkMap from DeviceManagerNotify 1450 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1451 // 5. check checkMap not null 1452 ASSERT_NE(checkMap, nullptr); 1453 // 6. call DeviceManagerNotify OnDiscoverySuccess 1454 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); 1455 // 7. check if callback OnDiscoverySuccess called 1456 ASSERT_NE(count, 10); 1457 } 1458 1459 /* 1460 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1461 * Function: DeviceManagerNotifyTest 1462 * SubFunction: OnDiscoverySuccess 1463 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1464 * EnvConditions: N/A. 1465 * CaseDescription: 1. set pkgName not null 1466 * set callback not null 1467 * set subscribeId not null 1468 * 2. set checkMap null 1469 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1470 * 4. Get checkMap from DeviceManagerNotify 1471 * 5. check checkMap not null 1472 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1473 * 7. check if callback OnDiscoverySuccess called. 1474 */ 1475 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess2, testing::ext::TestSize.Level0) 1476 { 1477 // 1. set pkgName not null 1478 std::string pkgName = "com.ohos.test"; 1479 // set callback not null 1480 int count = 0; 1481 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1482 // set subscribeId not null 1483 uint16_t subscribeId = 0; 1484 // 2. set checkMap null 1485 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1486 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1487 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1488 // 4. Get checkMap from DeviceManagerNotify 1489 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1490 // 5. check checkMap not null 1491 ASSERT_NE(checkMap, nullptr); 1492 std::string testPkgName = "com.ohos.test1"; 1493 // 6. call DeviceManagerNotify OnDiscoverySuccess 1494 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1495 // 7. check if callback OnDiscoverySuccess called 1496 ASSERT_EQ(count, 0); 1497 } 1498 1499 /* 1500 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1501 * Function: DeviceManagerNotifyTest 1502 * SubFunction: OnDiscoverySuccess 1503 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1504 * EnvConditions: N/A. 1505 * CaseDescription: 1. set pkgName not null 1506 * set callback not null 1507 * set subscribeId not null 1508 * 2. set checkMap null 1509 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1510 * 4. Get checkMap from DeviceManagerNotify 1511 * 5. check checkMap not null 1512 * 6. call DeviceManagerNotify OnDiscoverySuccess With testsubscribeId 1513 * 7. check if callback OnDiscoverySuccess called. 1514 */ 1515 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess3, testing::ext::TestSize.Level0) 1516 { 1517 // 1. set pkgName not null 1518 std::string pkgName = "com.ohos.test"; 1519 // set callback not null 1520 int count = 0; 1521 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1522 // set subscribeId not null 1523 uint16_t subscribeId = 0; 1524 // 2. set checkMap null 1525 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1526 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1527 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1528 // 4. Get checkMap from DeviceManagerNotify 1529 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1530 // 5. check checkMap not null 1531 ASSERT_NE(checkMap, nullptr); 1532 uint16_t testsubscribeId = 1; 1533 // 6. call DeviceManagerNotify OnDiscoverySuccess 1534 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, testsubscribeId); 1535 // 7. check if callback OnDiscoverySuccess called 1536 ASSERT_EQ(count, 0); 1537 } 1538 1539 /* 1540 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1541 * Function: DeviceManagerNotifyTest 1542 * SubFunction: OnDiscoverySuccess 1543 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1544 * EnvConditions: N/A. 1545 * CaseDescription: 1. set pkgName not null 1546 * set callback not null 1547 * set subscribeId not null 1548 * 2. set checkMap null 1549 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1550 * 4. Get checkMap from DeviceManagerNotify 1551 * 5. check checkMap not null 1552 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1553 * 7. check if callback OnDiscoverySuccess called. 1554 */ 1555 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess4, testing::ext::TestSize.Level0) 1556 { 1557 // 1. set pkgName not null 1558 std::string pkgName = "com.ohos.test"; 1559 // set callback not null 1560 int count = 0; 1561 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1562 // set subscribeId not null 1563 uint16_t subscribeId = 0; 1564 // 2. set checkMap null 1565 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1566 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1567 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1568 // 4. Get checkMap from DeviceManagerNotify 1569 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1570 // 5. check checkMap not null 1571 ASSERT_NE(checkMap, nullptr); 1572 std::string testPkgName = ""; 1573 // 6. call DeviceManagerNotify OnDiscoverySuccess 1574 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1575 // 7. check if callback OnDiscoverySuccess called 1576 ASSERT_EQ(count, 0); 1577 } 1578 1579 /* 1580 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1581 * Function: DeviceManagerNotifyTest 1582 * SubFunction: OnDiscoverySuccess 1583 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1584 * EnvConditions: N/A. 1585 * CaseDescription: 1. set pkgName not null 1586 * set callback not null 1587 * set subscribeId not null 1588 * 2. set checkMap null 1589 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1590 * 4. Get checkMap from DeviceManagerNotify 1591 * 5. check checkMap not null 1592 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1593 * 7. check if callback OnDiscoverySuccess called. 1594 */ 1595 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess5, testing::ext::TestSize.Level0) 1596 { 1597 // 1. set pkgName not null 1598 std::string pkgName = "com.ohos.test"; 1599 // set callback not null 1600 int count = 0; 1601 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1602 // set subscribeId not null 1603 uint16_t subscribeId = 0; 1604 // 2. set checkMap null 1605 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1606 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1607 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1608 // 4. Get checkMap from DeviceManagerNotify 1609 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1610 // 5. check checkMap not null 1611 ASSERT_NE(checkMap, nullptr); 1612 std::string testPkgName = ""; 1613 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1614 // 6. call DeviceManagerNotify OnDiscoverySuccess 1615 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1616 // 7. check if callback OnDiscoverySuccess called 1617 ASSERT_EQ(count, 0); 1618 } 1619 1620 /* 1621 * Feature: DeviceManagerNotifyTest OnPublishResult 1622 * Function: DeviceManagerNotifyTest 1623 * SubFunction: OnPublishResult Failed 1624 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1625 * EnvConditions: OnPublishResult. 1626 * CaseDescription: 1. set pkgName not null 1627 * set callback not null 1628 * set publishId not null 1629 * 2. set checkMap null 1630 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1631 * 4. Get checkMap from DeviceManagerNotify 1632 * 5. check checkMap not null 1633 * 6. call DeviceManagerNotify OnPublishResult 1634 * 7. check if callback OnPublishResult called. 1635 */ 1636 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult1, testing::ext::TestSize.Level0) 1637 { 1638 // 1. set pkgName not null 1639 std::string pkgName = "com.ohos.test"; 1640 // set callback not null 1641 int count = 0; 1642 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1643 // set publishId not null 1644 int32_t publishId = 0; 1645 // 2. set checkMap null 1646 std::shared_ptr<PublishCallback> checkMap = nullptr; 1647 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1648 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1649 // 4. Get checkMap from DeviceManagerNotify 1650 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1651 // 5. check checkMap not null 1652 ASSERT_NE(checkMap, nullptr); 1653 int32_t failedReason = 1; 1654 // 6. call DeviceManagerNotify OnPublishResult 1655 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, failedReason); 1656 // 7. check if callback OnPublishResult called 1657 ASSERT_EQ(count, 1); 1658 } 1659 1660 /* 1661 * Feature: DeviceManagerNotifyTest OnPublishResult 1662 * Function: DeviceManagerNotifyTest 1663 * SubFunction: OnPublishResult Failed 1664 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1665 * EnvConditions: N/A. 1666 * CaseDescription: 1. set pkgName not null 1667 * set callback not null 1668 * set publishId not null 1669 * 2. set checkMap null 1670 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1671 * 4. Get checkMap from DeviceManagerNotify 1672 * 5. check checkMap not null 1673 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1674 * 7. check if callback OnPublishResult called. 1675 */ 1676 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult2, testing::ext::TestSize.Level0) 1677 { 1678 // 1. set pkgName not null 1679 std::string pkgName = "com.ohos.test"; 1680 // set callback not null 1681 int count = 0; 1682 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1683 // set publishId not null 1684 int32_t publishId = 0; 1685 // 2. set checkMap null 1686 std::shared_ptr<PublishCallback> checkMap = nullptr; 1687 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1688 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1689 // 4. Get checkMap from DeviceManagerNotify 1690 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1691 // 5. check checkMap not null 1692 ASSERT_NE(checkMap, nullptr); 1693 std::string testPkgName = "com.ohos.test1"; 1694 int32_t failedReason = 1; 1695 // 6. call DeviceManagerNotify OnPublishResult 1696 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1697 // 7. check if callback OnPublishResult called 1698 ASSERT_EQ(count, 0); 1699 } 1700 1701 /* 1702 * Feature: DeviceManagerNotifyTest OnPublishResult 1703 * Function: DeviceManagerNotifyTest 1704 * SubFunction: OnPublishResult Failed 1705 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1706 * EnvConditions: N/A. 1707 * CaseDescription: 1. set pkgName not null 1708 * set callback not null 1709 * set publishId not null 1710 * 2. set checkMap null 1711 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1712 * 4. Get checkMap from DeviceManagerNotify 1713 * 5. check checkMap not null 1714 * 6. call DeviceManagerNotify OnPublishFailed With testpublishId 1715 * 7. check if callback OnPublishResult called. 1716 */ 1717 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult3, testing::ext::TestSize.Level0) 1718 { 1719 // 1. set pkgName not null 1720 std::string pkgName = "com.ohos.test"; 1721 // set callback not null 1722 int count = 0; 1723 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1724 // set publishId not null 1725 int32_t publishId = 0; 1726 // 2. set checkMap null 1727 std::shared_ptr<PublishCallback> checkMap = nullptr; 1728 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1729 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1730 // 4. Get checkMap from DeviceManagerNotify 1731 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1732 // 5. check checkMap not null 1733 ASSERT_NE(checkMap, nullptr); 1734 int32_t failedReason = 1; 1735 int32_t testpublishId = 1; 1736 // 6. call DeviceManagerNotify OnPublishResult 1737 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, failedReason); 1738 // 7. check if callback OnPublishResult called 1739 ASSERT_EQ(count, 0); 1740 } 1741 1742 /* 1743 * Feature: DeviceManagerNotifyTest OnPublishResult 1744 * Function: DeviceManagerNotifyTest 1745 * SubFunction: OnPublishResult Failed 1746 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1747 * EnvConditions: N/A. 1748 * CaseDescription: 1. set pkgName not null 1749 * set callback not null 1750 * set publishId not null 1751 * 2. set checkMap null 1752 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1753 * 4. Get checkMap from DeviceManagerNotify 1754 * 5. check checkMap not null 1755 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1756 * 7. check if callback OnPublishResult called. 1757 */ 1758 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed4, testing::ext::TestSize.Level0) 1759 { 1760 // 1. set pkgName not null 1761 std::string pkgName = "com.ohos.test"; 1762 // set callback not null 1763 int count = 0; 1764 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1765 // set publishId not null 1766 int32_t publishId = 0; 1767 // 2. set checkMap null 1768 std::shared_ptr<PublishCallback> checkMap = nullptr; 1769 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1770 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1771 // 4. Get checkMap from DeviceManagerNotify 1772 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1773 // 5. check checkMap not null 1774 ASSERT_NE(checkMap, nullptr); 1775 std::string testPkgName = ""; 1776 int32_t failedReason = 1; 1777 // 6. call DeviceManagerNotify OnPublishResult 1778 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1779 // 7. check if callback OnPublishResult called 1780 ASSERT_EQ(count, 0); 1781 } 1782 1783 /* 1784 * Feature: DeviceManagerNotifyTest OnPublishResult 1785 * Function: DeviceManagerNotifyTest 1786 * SubFunction: OnPublishResult Failed 1787 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1788 * EnvConditions: N/A. 1789 * CaseDescription: 1. set pkgName not null 1790 * set callback not null 1791 * set publishId not null 1792 * 2. set checkMap null 1793 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1794 * 4. Get checkMap from DeviceManagerNotify 1795 * 5. check checkMap not null 1796 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1797 * 7. check if callback OnPublishResult called. 1798 */ 1799 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed5, testing::ext::TestSize.Level0) 1800 { 1801 // 1. set pkgName not null 1802 std::string pkgName = "com.ohos.test"; 1803 // set callback not null 1804 int count = 0; 1805 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1806 // set publishId not null 1807 int32_t publishId = 2; 1808 // 2. set checkMap null 1809 std::shared_ptr<PublishCallback> checkMap = nullptr; 1810 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1811 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1812 // 4. Get checkMap from DeviceManagerNotify 1813 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1814 // 5. check checkMap not null 1815 ASSERT_NE(checkMap, nullptr); 1816 std::string testPkgName = ""; 1817 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId); 1818 int32_t failedReason = 1; 1819 // 6. call DeviceManagerNotify OnPublishResult 1820 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1821 // 7. check if callback OnPublishResult called 1822 ASSERT_EQ(count, 0); 1823 } 1824 } // namespace 1825 } // namespace DistributedHardware 1826 } // namespace OHOS 1827