1/* 2 * Copyright (c) 2022-2024 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_dm_discovery_manager.h" 17 18#include <iostream> 19#include <string> 20#include <unistd.h> 21 22#include "dm_log.h" 23#include "dm_constants.h" 24#include "dm_anonymous.h" 25#include "ipc_server_listener.h" 26#include "device_manager_service_listener.h" 27#include "softbus_bus_center.h" 28#include "device_manager_service_listener.h" 29#include "softbus_error_code.h" 30 31namespace OHOS { 32namespace DistributedHardware { 33void DmDiscoveryManagerTest::SetUp() 34{ 35} 36 37void DmDiscoveryManagerTest::TearDown() 38{ 39} 40 41void DmDiscoveryManagerTest::SetUpTestCase() 42{ 43} 44 45void DmDiscoveryManagerTest::TearDownTestCase() 46{ 47} 48 49namespace { 50std::shared_ptr<SoftbusConnector> softbusConnector_ = std::make_shared<SoftbusConnector>(); 51std::shared_ptr<DeviceManagerServiceListener> listener_ = std::make_shared<DeviceManagerServiceListener>(); 52std::shared_ptr<HiChainConnector> hiChainConnector_ = std::make_shared<HiChainConnector>(); 53std::shared_ptr<DmDiscoveryManager> discoveryMgr_ = 54 std::make_shared<DmDiscoveryManager>(softbusConnector_, listener_, hiChainConnector_); 55 56/** 57 * @tc.name: DmDiscoveryManager_001 58 * @tc.desc: Test whether the DmDiscoveryManager function can generate a new pointer 59 * @tc.type: FUNC 60 * @tc.require: AR000GHSJK 61 */ 62HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_001, testing::ext::TestSize.Level0) 63{ 64 std::shared_ptr<DmDiscoveryManager> Test = 65 std::make_shared<DmDiscoveryManager>(softbusConnector_, listener_, hiChainConnector_); 66 ASSERT_NE(Test, nullptr); 67} 68 69/** 70 * @tc.name: DmDiscoveryManager_002 71 * @tc.desc: Test whether the DmDiscoveryManager function can delete a new pointer 72 * @tc.type: FUNC 73 * @tc.require: AR000GHSJK 74 */ 75HWTEST_F(DmDiscoveryManagerTest, DmDiscoveryManager_002, testing::ext::TestSize.Level0) 76{ 77 std::shared_ptr<DmDiscoveryManager> Test = 78 std::make_shared<DmDiscoveryManager>(softbusConnector_, listener_, hiChainConnector_); 79 Test.reset(); 80 EXPECT_EQ(Test, nullptr); 81} 82 83/** 84 * @tc.name:StartDeviceDiscovery_001 85 * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, 86 * extra is not empty and return ERR_DM_INPUT_PARA_INVALID 87 * @tc.type: FUNC 88 * @tc.require: AR000GHSJK 89 */ 90HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_001, testing::ext::TestSize.Level0) 91{ 92 std::string pkgName = "com.ohos.helloworld"; 93 DmSubscribeInfo subscribeInfo; 94 subscribeInfo.subscribeId = 1; 95 const std::string extra = "com.ohos.test"; 96 int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); 97 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); 98 discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); 99} 100 101/** 102 * @tc.name:StartDeviceDiscovery_002 103 * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, 104 * extra is empty and return ERR_DM_DISCOVERY_REPEATED 105 * @tc.type: FUNC 106 * @tc.require: AR000GHSJK 107 */ 108HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_002, testing::ext::TestSize.Level0) 109{ 110 std::string pkgName = "com.ohos.helloworld"; 111 DmSubscribeInfo subscribeInfo; 112 subscribeInfo.subscribeId = 1; 113 std::string extra; 114 std::queue<std::string> emptyQueue; 115 discoveryMgr_->discoveryQueue_ = emptyQueue; 116 discoveryMgr_->discoveryQueue_.push(pkgName); 117 int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); 118 EXPECT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); 119 discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); 120} 121 122/** 123 * @tc.name:StartDeviceDiscovery_003 124 * @tc.desc: keeping pkgame unchanged, call StartDeviceDiscovery once, 125 * extra is empty, discoveryQueue_ is empty, and return SOFTBUS_INVALID_PARAM 126 * @tc.type: FUNC 127 * @tc.require: AR000GHSJK 128 */ 129HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_003, testing::ext::TestSize.Level0) 130{ 131 std::string pkgName = "com.ohos.helloworld"; 132 std::string extra; 133 DmSubscribeInfo subscribeInfo; 134 subscribeInfo.subscribeId = 1; 135 std::queue<std::string> emptyQueue; 136 discoveryMgr_->discoveryQueue_ = emptyQueue; 137 int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeInfo, extra); 138 ASSERT_TRUE(ret == SOFTBUS_INVALID_PARAM || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR); 139 discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeInfo.subscribeId); 140} 141 142/** 143 * @tc.name:StartDeviceDiscovery_004 144 * @tc.desc: pkgame changed, call StartDeviceDiscovery once, 145 * discoveryQueue is not empty and return ERR_DM_DISCOVERY_FAILED 146 * @tc.type: FUNC 147 * @tc.require: AR000GHSJK 148 */ 149HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_004, testing::ext::TestSize.Level0) 150{ 151 std::string pkgName = "com.ohos.helloworld"; 152 uint16_t subscribeId = 1; 153 std::string filterOptions; 154 std::queue<std::string> emptyQueue; 155 discoveryMgr_->discoveryQueue_ = emptyQueue; 156 discoveryMgr_->discoveryQueue_.push(pkgName); 157 int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); 158 ASSERT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); 159 discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); 160} 161 162/** 163 * @tc.name:StartDeviceDiscovery_005 164 * @tc.desc: pkgame changed, call StartDeviceDiscovery once, 165 * discoveryQueue is empty and return SOFTBUS_IPC_ERR 166 * @tc.type: FUNC 167 * @tc.require: AR000GHSJK 168 */ 169HWTEST_F(DmDiscoveryManagerTest, StartDeviceDiscovery_005, testing::ext::TestSize.Level0) 170{ 171 std::string pkgName = "com.ohos.helloworld"; 172 uint16_t subscribeId = 1; 173 std::string filterOptions; 174 std::queue<std::string> emptyQueue; 175 discoveryMgr_->discoveryQueue_ = emptyQueue; 176 int32_t ret = discoveryMgr_->StartDeviceDiscovery(pkgName, subscribeId, filterOptions); 177 ASSERT_TRUE(ret == SOFTBUS_IPC_ERR || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR); 178 discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); 179} 180 181/** 182 * @tc.name: StopDeviceDiscovery_001 183 * @tc.desc: return ERR_DM_INPUT_PARA_INVALID 184 * @tc.type: FUNC 185 * @tc.require: AR000GHSJK 186 */ 187HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_001, testing::ext::TestSize.Level0) 188{ 189 std::string pkgName; 190 uint16_t subscribeId = 1; 191 int32_t ret = discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); 192 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); 193} 194 195/** 196 * @tc.name: StopDeviceDiscovery_002 197 * @tc.desc: return SOFTBUS_IPC_ERR 198 * @tc.type: FUNC 199 * @tc.require: AR000GHSJK 200 */ 201HWTEST_F(DmDiscoveryManagerTest, StopDeviceDiscovery_002, testing::ext::TestSize.Level0) 202{ 203 std::string pkgName = "com.ohos.helloworld"; 204 uint16_t subscribeId = 1; 205 int32_t ret = discoveryMgr_->StopDeviceDiscovery(pkgName, subscribeId); 206 EXPECT_TRUE(ret == SOFTBUS_IPC_ERR || ret == SOFTBUS_NETWORK_NOT_INIT || ret == SOFTBUS_NETWORK_LOOPER_ERR); 207} 208 209/** 210 * @tc.name: OnDeviceFound_001 211 * @tc.desc: The OnDeviceFound function does the correct case and assigns pkgName 212 * @tc.type: FUNC 213 * @tc.require: AR000GHSJK 214 */ 215HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_001, testing::ext::TestSize.Level0) 216{ 217 std::string pkgName = "com.ohos.helloworld"; 218 std::string filterOptions = R"( 219 { 220 "filter_op": "OR", 221 "filters": 222 [ 223 { 224 "type" : "credible", 225 "value" : 0 226 } 227 ] 228 } 229 )"; 230 DmDeviceFilterOption dmFilter; 231 dmFilter.TransformToFilter(filterOptions); 232 uint16_t aaa = 11; 233 DmDiscoveryContext context { pkgName, filterOptions, aaa, dmFilter.filterOp_, dmFilter.filters_ }; 234 discoveryMgr_->discoveryContextMap_[pkgName] = context; 235 sleep(1); 236 DmDeviceInfo info; 237 info.deviceId[0] = '\0'; 238 info.deviceName[0] = '\0'; 239 bool isOnline = false; 240 discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); 241 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); 242} 243 244/** 245 * @tc.name: OnDeviceFound_002 246 * @tc.desc: set pkgName not null and discoveryContextMap_ null and return 247 * @tc.type: FUNC 248 * @tc.require: AR000GHSJK 249 */ 250HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_002, testing::ext::TestSize.Level0) 251{ 252 std::string pkgName = "com.ohos.helloworld"; 253 std::string filterOptions = R"( 254 { 255 "filter_op": "AND", 256 "filters": 257 [ 258 { 259 "type" : "credible", 260 "value" : 2 261 } 262 ] 263 } 264 )"; 265 DmDeviceFilterOption dmFilter; 266 dmFilter.TransformToFilter(filterOptions); 267 uint16_t aaa = 11; 268 DmDiscoveryContext context { pkgName, filterOptions, aaa, dmFilter.filterOp_, dmFilter.filters_ }; 269 discoveryMgr_->discoveryContextMap_[pkgName] = context; 270 DmDeviceInfo info; 271 bool isOnline = false; 272 discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); 273 int ret = discoveryMgr_->discoveryContextMap_.count(pkgName); 274 EXPECT_EQ(ret, 1); 275} 276 277/** 278 * @tc.name: OnDeviceFound_003 279 * @tc.desc: set pkgName not null 280 * @tc.type: FUNC 281 * @tc.require: AR000GHSJK 282 */ 283HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_003, testing::ext::TestSize.Level0) 284{ 285 std::string pkgName = "com.ohos.helloworld"; 286 DmDeviceInfo info; 287 bool isOnline = true; 288 discoveryMgr_->discoveryContextMap_.clear(); 289 discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); 290 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); 291} 292 293/** 294 * @tc.name: OnDeviceFound_004 295 * @tc.desc: set pkgName not null 296 * @tc.type: FUNC 297 * @tc.require: AR000GHSJK 298 */ 299HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_004, testing::ext::TestSize.Level0) 300{ 301 std::string pkgName = "com.ohos.helloworld"; 302 DmDeviceInfo info; 303 bool isOnline = true; 304 DmDiscoveryContext context; 305 discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); 306 discoveryMgr_->OnDeviceFound(pkgName, info, isOnline); 307 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); 308} 309 310/** 311 * @tc.name: OnDeviceFound_005 312 * @tc.desc: set pkgName not null 313 * @tc.type: FUNC 314 * @tc.require: AR000GHSJK 315 */ 316HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_005, testing::ext::TestSize.Level0) 317{ 318 std::string pkgName = "com.ohos.helloworld"; 319 DmDeviceBasicInfo info; 320 int32_t range = 0; 321 bool isOnline = true; 322 discoveryMgr_->discoveryContextMap_.clear(); 323 discoveryMgr_->OnDeviceFound(pkgName, info, range, isOnline); 324 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); 325} 326 327/** 328 * @tc.name: OnDeviceFound_006 329 * @tc.desc: set pkgName not null 330 * @tc.type: FUNC 331 * @tc.require: AR000GHSJK 332 */ 333HWTEST_F(DmDiscoveryManagerTest, OnDeviceFound_006, testing::ext::TestSize.Level0) 334{ 335 std::string pkgName = "com.ohos.helloworld"; 336 DmDeviceBasicInfo info; 337 int32_t range = 0; 338 bool isOnline = true; 339 DmDiscoveryContext context; 340 discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); 341 discoveryMgr_->OnDeviceFound(pkgName, info, range, isOnline); 342 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); 343} 344 345/** 346 * @tc.name: GetAuthForm_001 347 * @tc.desc: set localDeviceId null 348 * @tc.type: FUNC 349 * @tc.require: AR000GHSJK 350 */ 351HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_001, testing::ext::TestSize.Level0) 352{ 353 std::string localDeviceId; 354 std::string deviceId; 355 bool isTrusted = true; 356 DmAuthForm authForm; 357 int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); 358 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); 359} 360 361/** 362 * @tc.name: GetAuthForm_002 363 * @tc.desc: set localDeviceId not null 364 * @tc.type: FUNC 365 * @tc.require: AR000GHSJK 366 */ 367HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_002, testing::ext::TestSize.Level0) 368{ 369 std::string localDeviceId = "125462"; 370 std::string deviceId; 371 bool isTrusted = true; 372 DmAuthForm authForm; 373 int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); 374 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID); 375} 376 377/** 378 * @tc.name: GetAuthForm_003 379 * @tc.desc: set localDeviceId not null 380 * @tc.type: FUNC 381 * @tc.require: AR000GHSJK 382 */ 383HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_003, testing::ext::TestSize.Level0) 384{ 385 std::string localDeviceId = "125462"; 386 std::string deviceId = "236541"; 387 bool isTrusted = true; 388 DmAuthForm authForm; 389 discoveryMgr_->hiChainConnector_ = nullptr; 390 int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); 391 EXPECT_EQ(ret, ERR_DM_POINT_NULL); 392} 393 394/** 395 * @tc.name: GetAuthForm_004 396 * @tc.desc: set localDeviceId not null 397 * @tc.type: FUNC 398 * @tc.require: AR000GHSJK 399 */ 400HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_004, testing::ext::TestSize.Level0) 401{ 402 std::string localDeviceId = "125462"; 403 std::string deviceId = "236541"; 404 bool isTrusted = true; 405 DmAuthForm authForm; 406 discoveryMgr_->softbusConnector_ = nullptr; 407 int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); 408 EXPECT_EQ(ret, ERR_DM_POINT_NULL); 409} 410 411/** 412 * @tc.name: GetAuthForm_005 413 * @tc.desc: set localDeviceId not null 414 * @tc.type: FUNC 415 * @tc.require: AR000GHSJK 416 */ 417HWTEST_F(DmDiscoveryManagerTest, GetAuthForm_005, testing::ext::TestSize.Level0) 418{ 419 std::string localDeviceId = "125462"; 420 std::string deviceId = "236541"; 421 bool isTrusted = true; 422 DmAuthForm authForm; 423 discoveryMgr_->softbusConnector_ = std::make_shared<SoftbusConnector>(); 424 discoveryMgr_->hiChainConnector_ = std::make_shared<HiChainConnector>(); 425 int32_t ret = discoveryMgr_->GetAuthForm(localDeviceId, deviceId, isTrusted, authForm); 426 EXPECT_EQ(ret, DM_OK); 427} 428 429/** 430 * @tc.name: OnDiscoveryFailed_001 431 * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName 432 * @tc.type: FUNC 433 * @tc.require: AR000GHSJK 434 */ 435HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_001, testing::ext::TestSize.Level0) 436{ 437 std::string pkgName = "com.ohos.helloworld"; 438 int32_t subscribeId = 1; 439 int32_t failedReason = 3; 440 discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); 441 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); 442} 443 444/** 445 * @tc.name: OnDiscoveryFailed_002 446 * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName 447 * @tc.type: FUNC 448 * @tc.require: AR000GHSJK 449 */ 450HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_002, testing::ext::TestSize.Level0) 451{ 452 std::string pkgName; 453 int32_t subscribeId = 1; 454 int32_t failedReason = 3; 455 discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); 456 int ret1 = discoveryMgr_->discoveryContextMap_.count(pkgName); 457 EXPECT_EQ(ret1, 0); 458} 459 460/** 461 * @tc.name: OnDiscoveryFailed_003 462 * @tc.desc: The OnDeviceFound function takes the wrong case and emptying pkgName 463 * @tc.type: FUNC 464 * @tc.require: AR000GHSJK 465 */ 466HWTEST_F(DmDiscoveryManagerTest, OnDiscoveryFailed_003, testing::ext::TestSize.Level0) 467{ 468 std::string pkgName = "com.ohos.helloworld"; 469 int32_t subscribeId = 1; 470 int32_t failedReason = 3; 471 discoveryMgr_->discoveryQueue_.push(pkgName); 472 DmDiscoveryContext context; 473 discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); 474 discoveryMgr_->OnDiscoveryFailed(pkgName, subscribeId, failedReason); 475 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), true); 476} 477 478/** 479 * @tc.name: OnDiscoverySuccess_001 480 * @tc.desc: The OnDeviceFound function takes the wrong case and return pkgName 481 * @tc.type: FUNC 482 * @tc.require: AR000GHSJK 483 */ 484HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_001, testing::ext::TestSize.Level0) 485{ 486 std::string pkgName = "com.ohos.helloworld"; 487 int32_t subscribeId = 1; 488 discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId); 489 EXPECT_EQ(discoveryMgr_->discoveryContextMap_.empty(), false); 490} 491 492/** 493 * @tc.name: OnDiscoverySuccess_002 494 * @tc.desc: set pkgName null and return discoveryContextMap_ null and return pkgName(null) 495 * @tc.type: FUNC 496 * @tc.require: AR000GHSJK 497 */ 498HWTEST_F(DmDiscoveryManagerTest, OnDiscoverySuccess_002, testing::ext::TestSize.Level0) 499{ 500 std::string pkgName; 501 int32_t subscribeId = 1; 502 discoveryMgr_->OnDiscoverySuccess(pkgName, subscribeId); 503 int ret = discoveryMgr_->discoveryContextMap_.count(pkgName); 504 EXPECT_EQ(ret, 1); 505} 506 507HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_001, testing::ext::TestSize.Level0) 508{ 509 std::string pkgName; 510 std::queue<std::string> emptyQueue; 511 discoveryMgr_->discoveryQueue_ = emptyQueue; 512 discoveryMgr_->HandleDiscoveryTimeout(pkgName); 513 EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), true); 514} 515 516HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_002, testing::ext::TestSize.Level0) 517{ 518 std::string pkgName = "com.ohos.helloworld_new"; 519 discoveryMgr_->discoveryQueue_.push(pkgName); 520 discoveryMgr_->HandleDiscoveryTimeout(pkgName); 521 EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), false); 522} 523 524HWTEST_F(DmDiscoveryManagerTest, HandleDiscoveryTimeout_003, testing::ext::TestSize.Level0) 525{ 526 std::string pkgName = "com.ohos.helloworld_new"; 527 discoveryMgr_->discoveryQueue_.push(pkgName); 528 DmDiscoveryContext context; 529 discoveryMgr_->discoveryContextMap_.emplace(pkgName, context); 530 discoveryMgr_->HandleDiscoveryTimeout(pkgName); 531 EXPECT_EQ(discoveryMgr_->discoveryQueue_.empty(), false); 532} 533 534HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_001, testing::ext::TestSize.Level0) 535{ 536 std::string pkgName; 537 std::queue<std::string> emptyQueue; 538 discoveryMgr_->discoveryQueue_ = emptyQueue; 539 int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); 540 EXPECT_EQ(ret, DM_OK); 541} 542 543HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_002, testing::ext::TestSize.Level0) 544{ 545 std::string pkgName = "ohos_test"; 546 std::queue<std::string> emptyQueue; 547 discoveryMgr_->discoveryQueue_ = emptyQueue; 548 discoveryMgr_->discoveryQueue_.push(pkgName); 549 int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); 550 EXPECT_EQ(ret, ERR_DM_DISCOVERY_REPEATED); 551} 552 553HWTEST_F(DmDiscoveryManagerTest, CheckDiscoveryQueue_003, testing::ext::TestSize.Level0) 554{ 555 std::string pkgName = "pkgName"; 556 std::queue<std::string> emptyQueue; 557 discoveryMgr_->discoveryQueue_ = emptyQueue; 558 std::string frontPkgName = "ohos_test"; 559 discoveryMgr_->discoveryQueue_.push(frontPkgName); 560 int32_t ret = discoveryMgr_->CheckDiscoveryQueue(pkgName); 561 EXPECT_EQ(ret, DM_OK); 562} 563} // namespace 564} // namespace DistributedHardware 565} // namespace OHOS 566