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