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 // 8. call OnDeviceChanged,count != 0 846 ASSERT_NE(count, 0); 847 } 848 849 /* 850 * Feature: DeviceManagerNotifyTest OnDeviceChanged 851 * Function: DeviceManagerNotifyTest 852 * SubFunction: OnDeviceChanged 853 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 854 * EnvConditions: N/A. 855 * CaseDescription: 1. set pkgName not null 856 * set Callback not null 857 * 2. set checkMap null 858 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 859 * 4. Get checkMap from DeviceManagerNotify 860 * 5. check checkMap not null 861 * 6. set testpkcName com.ohos.test1 862 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 863 * 8. check if callback OnDeviceChanged called. 864 */ 865 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_002, testing::ext::TestSize.Level0) 866 { 867 // 1. set pkgName not null 868 std::string pkgName = "com.ohos.test"; 869 // set Callback not null 870 int count = 0; 871 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 872 // 2. set checkMap null 873 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 874 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 875 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 876 // 4. Get checkMap from DeviceManagerNotify 877 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 878 // 5. check checkMap not null 879 ASSERT_NE(checkMap, nullptr); 880 // 6. set testpkcName com.ohos.test1 881 std::string testPkgName = "com.ohos.test1"; 882 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 883 DmDeviceInfo deviceInfo; 884 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 885 // 8. check if callback OnDeviceChanged called 886 ASSERT_EQ(count, 0); 887 } 888 889 /* 890 * Feature: DeviceManagerNotifyTest OnDeviceChanged 891 * Function: DeviceManagerNotifyTest 892 * SubFunction: OnDeviceChanged 893 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 894 * EnvConditions: N/A. 895 * CaseDescription: 1. set pkgName not null 896 * set Callback not null 897 * 2. set checkMap null 898 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 899 * 4. Get checkMap from DeviceManagerNotify 900 * 5. check checkMap not null 901 * 6. set testpkcName com.ohos.test1 902 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 903 * 8. check if callback OnDeviceChanged called. 904 */ 905 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_003, testing::ext::TestSize.Level0) 906 { 907 // 1. set pkgName not null 908 std::string pkgName = "com.ohos.test"; 909 // set Callback not null 910 int count = 0; 911 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 912 // 2. set checkMap null 913 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 914 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 915 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 916 // 4. Get checkMap from DeviceManagerNotify 917 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 918 // 5. check checkMap not null 919 ASSERT_NE(checkMap, nullptr); 920 // 6. set testpkcName com.ohos.test1 921 std::string testPkgName = ""; 922 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 923 DmDeviceInfo deviceInfo; 924 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 925 // 8. check if callback OnDeviceChanged called 926 ASSERT_EQ(count, 0); 927 } 928 929 /* 930 * Feature: DeviceManagerNotifyTest OnDeviceChanged 931 * Function: DeviceManagerNotifyTest 932 * SubFunction: OnDeviceChanged 933 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 934 * EnvConditions: N/A. 935 * CaseDescription: 1. set pkgName not null 936 * set Callback not null 937 * 2. set checkMap null 938 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 939 * 4. Get checkMap from DeviceManagerNotify 940 * 5. check checkMap not null 941 * 6. set testpkcName com.ohos.test1 942 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 943 * 8. check if callback OnDeviceChanged called. 944 */ 945 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_004, testing::ext::TestSize.Level0) 946 { 947 // 1. set pkgName not null 948 std::string pkgName = "com.ohos.test"; 949 // set Callback not null 950 int count = 0; 951 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 952 // 2. set checkMap null 953 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 954 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 955 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 956 // 4. Get checkMap from DeviceManagerNotify 957 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 958 // 5. check checkMap not null 959 ASSERT_NE(checkMap, nullptr); 960 // 6. set testpkcName com.ohos.test1 961 std::string testPkgName = ""; 962 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 963 DmDeviceInfo deviceInfo; 964 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 965 // 8. check if callback OnDeviceChanged called 966 ASSERT_NE(count, 1); 967 } 968 969 /* 970 * Feature: DeviceManagerNotifyTest OnDeviceChanged 971 * Function: DeviceManagerNotifyTest 972 * SubFunction: OnDeviceChanged 973 * FunctionPoints: DeviceManagerNotifyTest OnDeviceChanged 974 * EnvConditions: N/A. 975 * CaseDescription: 1. set pkgName not null 976 * set Callback not null 977 * 2. set checkMap null 978 * 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 979 * 4. Get checkMap from DeviceManagerNotify 980 * 5. check checkMap not null 981 * 6. set testpkcName com.ohos.test1 982 * 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 983 * 8. check if callback OnDeviceChanged called. 984 */ 985 HWTEST_F(DeviceManagerNotifyTest, OnDeviceChanged_005, testing::ext::TestSize.Level0) 986 { 987 // 1. set pkgName not null 988 std::string pkgName = "com.ohos.test"; 989 // set Callback not null 990 int count = 0; 991 std::shared_ptr<DeviceStateCallback> callback = std::make_shared<DeviceStateCallbackTest>(count); 992 // 2. set checkMap null 993 std::shared_ptr<DeviceStateCallback> checkMap = nullptr; 994 // 3. call DeviceManagerNotifyTest RegisterDeviceStateCallback with parameter 995 DeviceManagerNotify::GetInstance().RegisterDeviceStateCallback(pkgName, callback); 996 // 4. Get checkMap from DeviceManagerNotify 997 checkMap = DeviceManagerNotify::GetInstance().deviceStateCallback_[pkgName]; 998 // 5. check checkMap not null 999 ASSERT_NE(checkMap, nullptr); 1000 // 6. call DeviceManagerNotify UnRegisterDeviceStateCallback withtestPkgName 1001 std::string testPkgName = ""; 1002 DeviceManagerNotify::GetInstance().UnRegisterDeviceStateCallback(testPkgName); 1003 // 7. call DeviceManagerNotify OnDeviceChanged with testpkcName 1004 DmDeviceInfo deviceInfo; 1005 DeviceManagerNotify::GetInstance().OnDeviceChanged(testPkgName, deviceInfo); 1006 // 8. check if callback OnDeviceChanged called 1007 ASSERT_EQ(count, 0); 1008 } 1009 1010 /* 1011 * Feature: DeviceManagerNotifyTest OnDeviceFound 1012 * Function: DeviceManagerNotifyTest 1013 * SubFunction: OnDeviceFound 1014 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1015 * EnvConditions: OnDeviceFound success. 1016 * CaseDescription: 1. set pkgName not null 1017 * set callback not null 1018 * set subscribeId not null 1019 * 2. set checkMap null 1020 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1021 * 4. Get checkMap from DeviceManagerNotify 1022 * 5. check checkMap not null 1023 * 6. call DeviceManagerNotify OnDeviceFound 1024 * 7. check if callback OnDeviceFound called. 1025 */ 1026 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound1, testing::ext::TestSize.Level0) 1027 { 1028 // 1. set pkgName not null 1029 std::string pkgName = "com.ohos.test"; 1030 // set callback not null 1031 int count = 0; 1032 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1033 // set subscribeId not null 1034 uint16_t subscribeId = 0; 1035 // 2. set checkMap null 1036 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1037 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1038 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1039 // 4. Get checkMap from DeviceManagerNotify 1040 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1041 // 5. check checkMap not null 1042 ASSERT_NE(checkMap, nullptr); 1043 DmDeviceInfo deviceInfo; 1044 // 6. call DeviceManagerNotify OnDeviceFound 1045 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, subscribeId, deviceInfo); 1046 // 7. check if callback OnDeviceFound called 1047 sleep(1); 1048 ASSERT_NE(count, 10); 1049 } 1050 1051 /* 1052 * Feature: DeviceManagerNotifyTest OnDeviceFound 1053 * Function: DeviceManagerNotifyTest 1054 * SubFunction: OnDeviceFound 1055 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1056 * EnvConditions: N/A. 1057 * CaseDescription: 1. set pkgName not null 1058 * set callback not null 1059 * set subscribeId not null 1060 * 2. set checkMap null 1061 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1062 * 4. Get checkMap from DeviceManagerNotify 1063 * 5. check checkMap not null 1064 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1065 * 7. check if callback OnDeviceFound called. 1066 */ 1067 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound2, testing::ext::TestSize.Level0) 1068 { 1069 // 1. set pkgName not null 1070 std::string pkgName = "com.ohos.test"; 1071 // set callback not null 1072 int count = 0; 1073 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1074 // set subscribeId not null 1075 uint16_t subscribeId = 0; 1076 // 2. set checkMap null 1077 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1078 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1079 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1080 // 4. Get checkMap from DeviceManagerNotify 1081 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1082 // 5. check checkMap not null 1083 ASSERT_NE(checkMap, nullptr); 1084 DmDeviceInfo deviceInfo; 1085 std::string testPkgName = "com.ohos.test1"; 1086 // 6. call DeviceManagerNotify OnDeviceFound 1087 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1088 // 7. check if callback OnDeviceFound called 1089 ASSERT_EQ(count, 0); 1090 } 1091 1092 /* 1093 * Feature: DeviceManagerNotifyTest OnDeviceFound 1094 * Function: DeviceManagerNotifyTest 1095 * SubFunction: OnDeviceFound 1096 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1097 * EnvConditions: N/A. 1098 * CaseDescription: 1. set pkgName not null 1099 * set callback not null 1100 * set subscribeId not null 1101 * 2. set checkMap null 1102 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1103 * 4. Get checkMap from DeviceManagerNotify 1104 * 5. check checkMap not null 1105 * 6. call DeviceManagerNotify OnDeviceFound With testsubscribeId 1106 * 7. check if callback OnDeviceFound called. 1107 */ 1108 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound3, testing::ext::TestSize.Level0) 1109 { 1110 // 1. set pkgName not null 1111 std::string pkgName = "com.ohos.test"; 1112 // set callback not null 1113 int count = 0; 1114 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1115 // set subscribeId not null 1116 uint16_t subscribeId = 0; 1117 // 2. set checkMap null 1118 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1119 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1120 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1121 // 4. Get checkMap from DeviceManagerNotify 1122 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1123 // 5. check checkMap not null 1124 ASSERT_NE(checkMap, nullptr); 1125 DmDeviceInfo deviceInfo; 1126 uint16_t testsubscribeId = 1; 1127 // 6. call DeviceManagerNotify OnDeviceFound 1128 DeviceManagerNotify::GetInstance().OnDeviceFound(pkgName, testsubscribeId, deviceInfo); 1129 // 7. check if callback OnDeviceFound called 1130 ASSERT_EQ(count, 0); 1131 } 1132 1133 /* 1134 * Feature: DeviceManagerNotifyTest OnDeviceFound 1135 * Function: DeviceManagerNotifyTest 1136 * SubFunction: OnDeviceFound 1137 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1138 * EnvConditions: N/A. 1139 * CaseDescription: 1. set pkgName not null 1140 * set callback not null 1141 * set subscribeId not null 1142 * 2. set checkMap null 1143 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1144 * 4. Get checkMap from DeviceManagerNotify 1145 * 5. check checkMap not null 1146 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1147 * 7. check if callback OnDeviceFound called. 1148 */ 1149 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound4, testing::ext::TestSize.Level0) 1150 { 1151 // 1. set pkgName not null 1152 std::string pkgName = "com.ohos.test"; 1153 // set callback not null 1154 int count = 0; 1155 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1156 // set subscribeId not null 1157 uint16_t subscribeId = 0; 1158 // 2. set checkMap null 1159 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1160 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1161 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1162 // 4. Get checkMap from DeviceManagerNotify 1163 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1164 // 5. check checkMap not null 1165 ASSERT_NE(checkMap, nullptr); 1166 DmDeviceInfo deviceInfo; 1167 std::string testPkgName = ""; 1168 // 6. call DeviceManagerNotify OnDeviceFound 1169 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1170 // 7. check if callback OnDeviceFound called 1171 ASSERT_EQ(count, 0); 1172 } 1173 1174 /* 1175 * Feature: DeviceManagerNotifyTest OnDeviceFound 1176 * Function: DeviceManagerNotifyTest 1177 * SubFunction: OnDeviceFound 1178 * FunctionPoints: DeviceManagerNotifyTest OnDeviceFound 1179 * EnvConditions: N/A. 1180 * CaseDescription: 1. set pkgName not null 1181 * set callback not null 1182 * set subscribeId not null 1183 * 2. set checkMap null 1184 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1185 * 4. Get checkMap from DeviceManagerNotify 1186 * 5. check checkMap not null 1187 * 6. call DeviceManagerNotify OnDeviceFound With testPkgName 1188 * 7. check if callback OnDeviceFound called. 1189 */ 1190 HWTEST_F(DeviceManagerNotifyTest, OnDeviceFound5, testing::ext::TestSize.Level0) 1191 { 1192 // 1. set pkgName not null 1193 std::string pkgName = "com.ohos.test"; 1194 // set callback not null 1195 int count = 0; 1196 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1197 // set subscribeId not null 1198 uint16_t subscribeId = 0; 1199 // 2. set checkMap null 1200 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1201 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1202 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1203 // 4. Get checkMap from DeviceManagerNotify 1204 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1205 // 5. check checkMap not null 1206 ASSERT_NE(checkMap, nullptr); 1207 DmDeviceInfo deviceInfo; 1208 std::string testPkgName = ""; 1209 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1210 // 6. call DeviceManagerNotify OnDeviceFound 1211 DeviceManagerNotify::GetInstance().OnDeviceFound(testPkgName, subscribeId, deviceInfo); 1212 // 7. check if callback OnDeviceFound called 1213 ASSERT_EQ(count, 0); 1214 } 1215 1216 /* 1217 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1218 * Function: DeviceManagerNotifyTest 1219 * SubFunction: OnDiscoverFailed 1220 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1221 * EnvConditions: OnDiscoverFailed success. 1222 * CaseDescription: 1. set pkgName not null 1223 * set callback not null 1224 * set subscribeId not null 1225 * 2. set checkMap null 1226 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1227 * 4. Get checkMap from DeviceManagerNotify 1228 * 5. check checkMap not null 1229 * 6. call DeviceManagerNotify OnDiscoverFailed 1230 * 7. check if callback OnDiscoverFailed called. 1231 */ 1232 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed1, testing::ext::TestSize.Level0) 1233 { 1234 // 1. set pkgName not null 1235 std::string pkgName = "com.ohos.test"; 1236 // set callback not null 1237 int count = 0; 1238 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1239 // set subscribeId not null 1240 uint16_t subscribeId = 0; 1241 // 2. set checkMap null 1242 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1243 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1244 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1245 // 4. Get checkMap from DeviceManagerNotify 1246 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1247 // 5. check checkMap not null 1248 ASSERT_NE(checkMap, nullptr); 1249 int32_t failedReason = 0; 1250 // 6. call DeviceManagerNotify OnDiscoverFailed 1251 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, subscribeId, failedReason); 1252 // 7. check if callback OnDiscoverFailed called 1253 ASSERT_NE(count, 10); 1254 } 1255 1256 /* 1257 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1258 * Function: DeviceManagerNotifyTest 1259 * SubFunction: OnDiscoverFailed 1260 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1261 * EnvConditions: N/A. 1262 * CaseDescription: 1. set pkgName not null 1263 * set callback not null 1264 * set subscribeId not null 1265 * 2. set checkMap null 1266 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1267 * 4. Get checkMap from DeviceManagerNotify 1268 * 5. check checkMap not null 1269 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1270 * 7. check if callback OnDiscoverFailed called. 1271 */ 1272 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed2, testing::ext::TestSize.Level0) 1273 { 1274 // 1. set pkgName not null 1275 std::string pkgName = "com.ohos.test"; 1276 // set callback not null 1277 int count = 0; 1278 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1279 // set subscribeId not null 1280 uint16_t subscribeId = 0; 1281 // 2. set checkMap null 1282 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1283 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1284 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1285 // 4. Get checkMap from DeviceManagerNotify 1286 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1287 // 5. check checkMap not null 1288 ASSERT_NE(checkMap, nullptr); 1289 std::string testPkgName = "com.ohos.test1"; 1290 int32_t failedReason = 0; 1291 // 6. call DeviceManagerNotify OnDiscoverFailed 1292 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1293 // 7. check if callback OnDiscoverFailed called 1294 ASSERT_EQ(count, 0); 1295 } 1296 1297 /* 1298 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1299 * Function: DeviceManagerNotifyTest 1300 * SubFunction: OnDiscoverFailed 1301 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1302 * EnvConditions: N/A. 1303 * CaseDescription: 1. set pkgName not null 1304 * set callback not null 1305 * set subscribeId not null 1306 * 2. set checkMap null 1307 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1308 * 4. Get checkMap from DeviceManagerNotify 1309 * 5. check checkMap not null 1310 * 6. call DeviceManagerNotify OnDiscoverFailed With testsubscribeId 1311 * 7. check if callback OnDiscoverFailed called. 1312 */ 1313 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed3, testing::ext::TestSize.Level0) 1314 { 1315 // 1. set pkgName not null 1316 std::string pkgName = "com.ohos.test"; 1317 // set callback not null 1318 int count = 0; 1319 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1320 // set subscribeId not null 1321 uint16_t subscribeId = 0; 1322 // 2. set checkMap null 1323 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1324 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1325 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1326 // 4. Get checkMap from DeviceManagerNotify 1327 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1328 // 5. check checkMap not null 1329 ASSERT_NE(checkMap, nullptr); 1330 int32_t failedReason = 0; 1331 uint16_t testsubscribeId = 1; 1332 // 6. call DeviceManagerNotify OnDiscoverFailed 1333 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(pkgName, testsubscribeId, failedReason); 1334 // 7. check if callback OnDiscoverFailed called 1335 ASSERT_EQ(count, 0); 1336 } 1337 1338 /* 1339 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1340 * Function: DeviceManagerNotifyTest 1341 * SubFunction: OnDiscoverFailed 1342 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1343 * EnvConditions: N/A. 1344 * CaseDescription: 1. set pkgName not null 1345 * set callback not null 1346 * set subscribeId not null 1347 * 2. set checkMap null 1348 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1349 * 4. Get checkMap from DeviceManagerNotify 1350 * 5. check checkMap not null 1351 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1352 * 7. check if callback OnDiscoverFailed called. 1353 */ 1354 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed4, testing::ext::TestSize.Level0) 1355 { 1356 // 1. set pkgName not null 1357 std::string pkgName = "com.ohos.test"; 1358 // set callback not null 1359 int count = 0; 1360 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1361 // set subscribeId not null 1362 uint16_t subscribeId = 0; 1363 // 2. set checkMap null 1364 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1365 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1366 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1367 // 4. Get checkMap from DeviceManagerNotify 1368 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1369 // 5. check checkMap not null 1370 ASSERT_NE(checkMap, nullptr); 1371 std::string testPkgName = ""; 1372 int32_t failedReason = 0; 1373 // 6. call DeviceManagerNotify OnDiscoverFailed 1374 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1375 // 7. check if callback OnDiscoverFailed called 1376 ASSERT_EQ(count, 0); 1377 } 1378 1379 /* 1380 * Feature: DeviceManagerNotifyTest OnDiscoverFailed 1381 * Function: DeviceManagerNotifyTest 1382 * SubFunction: OnDiscoverFailed 1383 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverFailed 1384 * EnvConditions: N/A. 1385 * CaseDescription: 1. set pkgName not null 1386 * set callback not null 1387 * set subscribeId not null 1388 * 2. set checkMap null 1389 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1390 * 4. Get checkMap from DeviceManagerNotify 1391 * 5. check checkMap not null 1392 * 6. call DeviceManagerNotify OnDiscoverFailed With testPkgName 1393 * 7. check if callback OnDiscoverFailed called. 1394 */ 1395 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverFailed5, testing::ext::TestSize.Level0) 1396 { 1397 // 1. set pkgName not null 1398 std::string pkgName = "com.ohos.test"; 1399 // set callback not null 1400 int count = 0; 1401 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1402 // set subscribeId not null 1403 uint16_t subscribeId = 0; 1404 // 2. set checkMap null 1405 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1406 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1407 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1408 // 4. Get checkMap from DeviceManagerNotify 1409 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1410 // 5. check checkMap not null 1411 ASSERT_NE(checkMap, nullptr); 1412 std::string testPkgName = ""; 1413 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1414 int32_t failedReason = 0; 1415 // 6. call DeviceManagerNotify OnDiscoverFailed 1416 DeviceManagerNotify::GetInstance().OnDiscoveryFailed(testPkgName, subscribeId, failedReason); 1417 // 7. check if callback OnDiscoverFailed called 1418 ASSERT_EQ(count, 0); 1419 } 1420 1421 /* 1422 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1423 * Function: DeviceManagerNotifyTest 1424 * SubFunction: OnDiscoverySuccess 1425 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1426 * EnvConditions: OnDiscoverySuccess success. 1427 * CaseDescription: 1. set pkgName not null 1428 * set callback not null 1429 * set subscribeId not null 1430 * 2. set checkMap null 1431 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1432 * 4. Get checkMap from DeviceManagerNotify 1433 * 5. check checkMap not null 1434 * 6. call DeviceManagerNotify OnDiscoverySuccess 1435 * 7. check if callback OnDiscoverySuccess called. 1436 */ 1437 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess1, testing::ext::TestSize.Level0) 1438 { 1439 // 1. set pkgName not null 1440 std::string pkgName = "com.ohos.test"; 1441 // set callback not null 1442 int count = 0; 1443 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1444 // set subscribeId not null 1445 uint16_t subscribeId = 0; 1446 // 2. set checkMap null 1447 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1448 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1449 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1450 // 4. Get checkMap from DeviceManagerNotify 1451 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1452 // 5. check checkMap not null 1453 ASSERT_NE(checkMap, nullptr); 1454 // 6. call DeviceManagerNotify OnDiscoverySuccess 1455 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, subscribeId); 1456 // 7. check if callback OnDiscoverySuccess called 1457 ASSERT_NE(count, 10); 1458 } 1459 1460 /* 1461 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1462 * Function: DeviceManagerNotifyTest 1463 * SubFunction: OnDiscoverySuccess 1464 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1465 * EnvConditions: N/A. 1466 * CaseDescription: 1. set pkgName not null 1467 * set callback not null 1468 * set subscribeId not null 1469 * 2. set checkMap null 1470 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1471 * 4. Get checkMap from DeviceManagerNotify 1472 * 5. check checkMap not null 1473 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1474 * 7. check if callback OnDiscoverySuccess called. 1475 */ 1476 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess2, testing::ext::TestSize.Level0) 1477 { 1478 // 1. set pkgName not null 1479 std::string pkgName = "com.ohos.test"; 1480 // set callback not null 1481 int count = 0; 1482 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1483 // set subscribeId not null 1484 uint16_t subscribeId = 0; 1485 // 2. set checkMap null 1486 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1487 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1488 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1489 // 4. Get checkMap from DeviceManagerNotify 1490 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1491 // 5. check checkMap not null 1492 ASSERT_NE(checkMap, nullptr); 1493 std::string testPkgName = "com.ohos.test1"; 1494 // 6. call DeviceManagerNotify OnDiscoverySuccess 1495 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1496 // 7. check if callback OnDiscoverySuccess called 1497 ASSERT_EQ(count, 0); 1498 } 1499 1500 /* 1501 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1502 * Function: DeviceManagerNotifyTest 1503 * SubFunction: OnDiscoverySuccess 1504 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1505 * EnvConditions: N/A. 1506 * CaseDescription: 1. set pkgName not null 1507 * set callback not null 1508 * set subscribeId not null 1509 * 2. set checkMap null 1510 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1511 * 4. Get checkMap from DeviceManagerNotify 1512 * 5. check checkMap not null 1513 * 6. call DeviceManagerNotify OnDiscoverySuccess With testsubscribeId 1514 * 7. check if callback OnDiscoverySuccess called. 1515 */ 1516 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess3, testing::ext::TestSize.Level0) 1517 { 1518 // 1. set pkgName not null 1519 std::string pkgName = "com.ohos.test"; 1520 // set callback not null 1521 int count = 0; 1522 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1523 // set subscribeId not null 1524 uint16_t subscribeId = 0; 1525 // 2. set checkMap null 1526 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1527 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1528 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1529 // 4. Get checkMap from DeviceManagerNotify 1530 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1531 // 5. check checkMap not null 1532 ASSERT_NE(checkMap, nullptr); 1533 uint16_t testsubscribeId = 1; 1534 // 6. call DeviceManagerNotify OnDiscoverySuccess 1535 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(pkgName, testsubscribeId); 1536 // 7. check if callback OnDiscoverySuccess called 1537 ASSERT_EQ(count, 0); 1538 } 1539 1540 /* 1541 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1542 * Function: DeviceManagerNotifyTest 1543 * SubFunction: OnDiscoverySuccess 1544 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1545 * EnvConditions: N/A. 1546 * CaseDescription: 1. set pkgName not null 1547 * set callback not null 1548 * set subscribeId not null 1549 * 2. set checkMap null 1550 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1551 * 4. Get checkMap from DeviceManagerNotify 1552 * 5. check checkMap not null 1553 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1554 * 7. check if callback OnDiscoverySuccess called. 1555 */ 1556 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess4, testing::ext::TestSize.Level0) 1557 { 1558 // 1. set pkgName not null 1559 std::string pkgName = "com.ohos.test"; 1560 // set callback not null 1561 int count = 0; 1562 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1563 // set subscribeId not null 1564 uint16_t subscribeId = 0; 1565 // 2. set checkMap null 1566 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1567 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1568 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1569 // 4. Get checkMap from DeviceManagerNotify 1570 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1571 // 5. check checkMap not null 1572 ASSERT_NE(checkMap, nullptr); 1573 std::string testPkgName = ""; 1574 // 6. call DeviceManagerNotify OnDiscoverySuccess 1575 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1576 // 7. check if callback OnDiscoverySuccess called 1577 ASSERT_EQ(count, 0); 1578 } 1579 1580 /* 1581 * Feature: DeviceManagerNotifyTest OnDiscoverySuccess 1582 * Function: DeviceManagerNotifyTest 1583 * SubFunction: OnDiscoverySuccess 1584 * FunctionPoints: DeviceManagerNotifyTest OnDiscoverySuccess 1585 * EnvConditions: N/A. 1586 * CaseDescription: 1. set pkgName not null 1587 * set callback not null 1588 * set subscribeId not null 1589 * 2. set checkMap null 1590 * 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1591 * 4. Get checkMap from DeviceManagerNotify 1592 * 5. check checkMap not null 1593 * 6. call DeviceManagerNotify OnDiscoverySuccess With testPkgName 1594 * 7. check if callback OnDiscoverySuccess called. 1595 */ 1596 HWTEST_F(DeviceManagerNotifyTest, OnDiscoverySuccess5, testing::ext::TestSize.Level0) 1597 { 1598 // 1. set pkgName not null 1599 std::string pkgName = "com.ohos.test"; 1600 // set callback not null 1601 int count = 0; 1602 std::shared_ptr<DiscoveryCallback> callback = std::make_shared<DiscoveryCallbackTest>(count); 1603 // set subscribeId not null 1604 uint16_t subscribeId = 0; 1605 // 2. set checkMap null 1606 std::shared_ptr<DiscoveryCallback> checkMap = nullptr; 1607 // 3. call DeviceManagerNotifyTest RegisterDiscoverCallback with parameter 1608 DeviceManagerNotify::GetInstance().RegisterDiscoveryCallback(pkgName, subscribeId, callback); 1609 // 4. Get checkMap from DeviceManagerNotify 1610 checkMap = DeviceManagerNotify::GetInstance().deviceDiscoveryCallbacks_[pkgName][subscribeId]; 1611 // 5. check checkMap not null 1612 ASSERT_NE(checkMap, nullptr); 1613 std::string testPkgName = ""; 1614 DeviceManagerNotify::GetInstance().UnRegisterDiscoveryCallback(testPkgName, subscribeId); 1615 // 6. call DeviceManagerNotify OnDiscoverySuccess 1616 DeviceManagerNotify::GetInstance().OnDiscoverySuccess(testPkgName, subscribeId); 1617 // 7. check if callback OnDiscoverySuccess called 1618 ASSERT_EQ(count, 0); 1619 } 1620 1621 /* 1622 * Feature: DeviceManagerNotifyTest OnPublishResult 1623 * Function: DeviceManagerNotifyTest 1624 * SubFunction: OnPublishResult Failed 1625 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1626 * EnvConditions: OnPublishResult. 1627 * CaseDescription: 1. set pkgName not null 1628 * set callback not null 1629 * set publishId not null 1630 * 2. set checkMap null 1631 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1632 * 4. Get checkMap from DeviceManagerNotify 1633 * 5. check checkMap not null 1634 * 6. call DeviceManagerNotify OnPublishResult 1635 * 7. check if callback OnPublishResult called. 1636 */ 1637 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult1, testing::ext::TestSize.Level0) 1638 { 1639 // 1. set pkgName not null 1640 std::string pkgName = "com.ohos.test"; 1641 // set callback not null 1642 int count = 0; 1643 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1644 // set publishId not null 1645 int32_t publishId = 0; 1646 // 2. set checkMap null 1647 std::shared_ptr<PublishCallback> checkMap = nullptr; 1648 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1649 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1650 // 4. Get checkMap from DeviceManagerNotify 1651 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1652 // 5. check checkMap not null 1653 ASSERT_NE(checkMap, nullptr); 1654 int32_t failedReason = 1; 1655 // 6. call DeviceManagerNotify OnPublishResult 1656 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, publishId, failedReason); 1657 // 7. check if callback OnPublishResult called 1658 ASSERT_EQ(count, 1); 1659 } 1660 1661 /* 1662 * Feature: DeviceManagerNotifyTest OnPublishResult 1663 * Function: DeviceManagerNotifyTest 1664 * SubFunction: OnPublishResult Failed 1665 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1666 * EnvConditions: N/A. 1667 * CaseDescription: 1. set pkgName not null 1668 * set callback not null 1669 * set publishId not null 1670 * 2. set checkMap null 1671 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1672 * 4. Get checkMap from DeviceManagerNotify 1673 * 5. check checkMap not null 1674 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1675 * 7. check if callback OnPublishResult called. 1676 */ 1677 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult2, testing::ext::TestSize.Level0) 1678 { 1679 // 1. set pkgName not null 1680 std::string pkgName = "com.ohos.test"; 1681 // set callback not null 1682 int count = 0; 1683 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1684 // set publishId not null 1685 int32_t publishId = 0; 1686 // 2. set checkMap null 1687 std::shared_ptr<PublishCallback> checkMap = nullptr; 1688 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1689 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1690 // 4. Get checkMap from DeviceManagerNotify 1691 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1692 // 5. check checkMap not null 1693 ASSERT_NE(checkMap, nullptr); 1694 std::string testPkgName = "com.ohos.test1"; 1695 int32_t failedReason = 1; 1696 // 6. call DeviceManagerNotify OnPublishResult 1697 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1698 // 7. check if callback OnPublishResult called 1699 ASSERT_EQ(count, 0); 1700 } 1701 1702 /* 1703 * Feature: DeviceManagerNotifyTest OnPublishResult 1704 * Function: DeviceManagerNotifyTest 1705 * SubFunction: OnPublishResult Failed 1706 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1707 * EnvConditions: N/A. 1708 * CaseDescription: 1. set pkgName not null 1709 * set callback not null 1710 * set publishId not null 1711 * 2. set checkMap null 1712 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1713 * 4. Get checkMap from DeviceManagerNotify 1714 * 5. check checkMap not null 1715 * 6. call DeviceManagerNotify OnPublishFailed With testpublishId 1716 * 7. check if callback OnPublishResult called. 1717 */ 1718 HWTEST_F(DeviceManagerNotifyTest, OnPublishResult3, testing::ext::TestSize.Level0) 1719 { 1720 // 1. set pkgName not null 1721 std::string pkgName = "com.ohos.test"; 1722 // set callback not null 1723 int count = 0; 1724 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1725 // set publishId not null 1726 int32_t publishId = 0; 1727 // 2. set checkMap null 1728 std::shared_ptr<PublishCallback> checkMap = nullptr; 1729 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1730 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1731 // 4. Get checkMap from DeviceManagerNotify 1732 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1733 // 5. check checkMap not null 1734 ASSERT_NE(checkMap, nullptr); 1735 int32_t failedReason = 1; 1736 int32_t testpublishId = 1; 1737 // 6. call DeviceManagerNotify OnPublishResult 1738 DeviceManagerNotify::GetInstance().OnPublishResult(pkgName, testpublishId, failedReason); 1739 // 7. check if callback OnPublishResult called 1740 ASSERT_EQ(count, 0); 1741 } 1742 1743 /* 1744 * Feature: DeviceManagerNotifyTest OnPublishResult 1745 * Function: DeviceManagerNotifyTest 1746 * SubFunction: OnPublishResult Failed 1747 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1748 * EnvConditions: N/A. 1749 * CaseDescription: 1. set pkgName not null 1750 * set callback not null 1751 * set publishId not null 1752 * 2. set checkMap null 1753 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1754 * 4. Get checkMap from DeviceManagerNotify 1755 * 5. check checkMap not null 1756 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1757 * 7. check if callback OnPublishResult called. 1758 */ 1759 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed4, testing::ext::TestSize.Level0) 1760 { 1761 // 1. set pkgName not null 1762 std::string pkgName = "com.ohos.test"; 1763 // set callback not null 1764 int count = 0; 1765 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1766 // set publishId not null 1767 int32_t publishId = 0; 1768 // 2. set checkMap null 1769 std::shared_ptr<PublishCallback> checkMap = nullptr; 1770 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1771 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1772 // 4. Get checkMap from DeviceManagerNotify 1773 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1774 // 5. check checkMap not null 1775 ASSERT_NE(checkMap, nullptr); 1776 std::string testPkgName = ""; 1777 int32_t failedReason = 1; 1778 // 6. call DeviceManagerNotify OnPublishResult 1779 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1780 // 7. check if callback OnPublishResult called 1781 ASSERT_EQ(count, 0); 1782 } 1783 1784 /* 1785 * Feature: DeviceManagerNotifyTest OnPublishResult 1786 * Function: DeviceManagerNotifyTest 1787 * SubFunction: OnPublishResult Failed 1788 * FunctionPoints: DeviceManagerNotifyTest OnPublishResult 1789 * EnvConditions: N/A. 1790 * CaseDescription: 1. set pkgName not null 1791 * set callback not null 1792 * set publishId not null 1793 * 2. set checkMap null 1794 * 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1795 * 4. Get checkMap from DeviceManagerNotify 1796 * 5. check checkMap not null 1797 * 6. call DeviceManagerNotify OnPublishResult With testPkgName 1798 * 7. check if callback OnPublishResult called. 1799 */ 1800 HWTEST_F(DeviceManagerNotifyTest, OnPublishFailed5, testing::ext::TestSize.Level0) 1801 { 1802 // 1. set pkgName not null 1803 std::string pkgName = "com.ohos.test"; 1804 // set callback not null 1805 int count = 0; 1806 std::shared_ptr<PublishCallback> callback = std::make_shared<PublishCallbackTest>(count); 1807 // set publishId not null 1808 int32_t publishId = 2; 1809 // 2. set checkMap null 1810 std::shared_ptr<PublishCallback> checkMap = nullptr; 1811 // 3. call DeviceManagerNotifyTest RegisterPublishCallback with parameter 1812 DeviceManagerNotify::GetInstance().RegisterPublishCallback(pkgName, publishId, callback); 1813 // 4. Get checkMap from DeviceManagerNotify 1814 checkMap = DeviceManagerNotify::GetInstance().devicePublishCallbacks_[pkgName][publishId]; 1815 // 5. check checkMap not null 1816 ASSERT_NE(checkMap, nullptr); 1817 std::string testPkgName = ""; 1818 DeviceManagerNotify::GetInstance().UnRegisterPublishCallback(testPkgName, publishId); 1819 int32_t failedReason = 1; 1820 // 6. call DeviceManagerNotify OnPublishResult 1821 DeviceManagerNotify::GetInstance().OnPublishResult(testPkgName, publishId, failedReason); 1822 // 7. check if callback OnPublishResult called 1823 ASSERT_EQ(count, 0); 1824 } 1825 } // namespace 1826 } // namespace DistributedHardware 1827 } // namespace OHOS 1828