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