1 /*
2  * Copyright (c) 2021-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 <cstdio>
17 #include <ctime>
18 #include <gtest/gtest.h>
19 #include <sys/time.h>
20 #include <unistd.h>
21 #include <securec.h>
22 #include <cstdint>
23 
24 #include "disc_log.h"
25 #include "disc_manager.h"
26 #include "nstackx.h"
27 #include "disc_coap.h"
28 #include "softbus_errcode.h"
29 
30 #define TEST_ERRO_MOUDULE1      ((MODULE_LNN) - 1)
31 #define TEST_ERRO_MOUDULE2      ((MODULE_LNN) - 2)
32 #define TEST_ERRO_MOUDULE       ((MODULE_LNN) + 3)
33 #define ERRO_CAPDATA_LEN        (MAX_CAPABILITYDATA_LEN + 1)
34 #define TEST_ASSERT_TRUE(ret)  \
35     if (ret) {                 \
36         DISC_LOGI(DISC_TEST, "[succ]\n");    \
37         g_succTestCount++;       \
38     } else {                   \
39         DISC_LOGI(DISC_TEST, "[error]\n");    \
40         g_failTestCount++;       \
41     }
42 
43 using namespace testing::ext;
44 
45 namespace OHOS {
46 static int32_t g_succTestCount = 0;
47 static int32_t g_failTestCount = 0;
48 static int32_t g_devieceFoundCount = 0;
49 static const char *g_corrPkgName = "CorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorrCorr";
50 static const char *g_erroPkgName = "ErroErroErroErroErroErroErroErroErroErroErroErroErroErroErroErroE";
51 static DiscoveryFuncInterface *g_coapDiscFunc = NULL;
52 static PublishOption g_publishOption = {.freq = 0, .capabilityBitmap = {1}, .capabilityData = NULL, .dataLen = 0};
53 static SubscribeOption g_subscribeOption = {.freq = 1,
54     .isSameAccount = true,
55     .isWakeRemote = false,
56     .capabilityBitmap = {2},
57     .capabilityData = NULL,
58     .dataLen = 0
59 };
60 
61 const int32_t TEST_PUBLISHINNER_ID = 1;
62 const int32_t TEST_PUBLISH_ID = 2;
63 const int32_t TEST_SUBSCRIBEINNER_ID = 3;
64 const int32_t TEST_SUBSCRIBE_ID = 4;
65 const int32_t TEST_PUBLISHINNER_ID1 = 5;
66 const int32_t TEST_PUBLISH_ID1 = 6;
67 const int32_t TEST_SUBSCRIBEINNER_ID1 = 7;
68 const int32_t TEST_SUBSCRIBE_ID1 = 8;
69 const int32_t TEST_BITMAP_CAP = 127;
70 const uint32_t PUB_CAP_BITMAP_2 = 6;
71 const uint32_t PUBLISH_MODE_2 = 5;
72 const uint32_t FILTER_CAP_BITMAP_2 = 4;
73 const uint32_t DISC_MODE_2 = 8;
74 
75 class DiscManagerTest : public testing::Test {
76 public:
DiscManagerTest()77     DiscManagerTest()
78     {}
~DiscManagerTest()79     ~DiscManagerTest()
80     {}
81     static void SetUpTestCase(void);
82     static void TearDownTestCase(void);
SetUp()83     void SetUp() override
84     {}
TearDown()85     void TearDown() override
86     {}
87 };
88 
SetUpTestCase(void)89 void DiscManagerTest::SetUpTestCase(void)
90 {}
91 
TearDownTestCase(void)92 void DiscManagerTest::TearDownTestCase(void)
93 {}
94 
TestDeviceFound(const char * packageName,const DeviceInfo * device,const InnerDeviceInfoAddtions * additions)95 static int32_t TestDeviceFound(const char *packageName, const DeviceInfo *device,
96     const InnerDeviceInfoAddtions *additions)
97 {
98     (void)additions;
99     g_devieceFoundCount++;
100     DISC_LOGI(DISC_TEST, "[device found]success!\n");
101     return 0;
102 }
103 
TestInnerDeviceFound(const DeviceInfo * device,const InnerDeviceInfoAddtions * additions)104 static void TestInnerDeviceFound(const DeviceInfo *device, const InnerDeviceInfoAddtions *additions)
105 {
106     (void)device;
107     (void)additions;
108     g_devieceFoundCount++;
109     DISC_LOGI(DISC_TEST, "[inner device found]success!\n");
110 }
111 
112 static DiscInnerCallback g_innerCallback = {
113     .OnDeviceFound = TestInnerDeviceFound
114 };
115 
DiscCoapStartDiscovery(uint32_t filterCapBitmap,uint32_t discMode)116 static int32_t DiscCoapStartDiscovery(uint32_t filterCapBitmap, uint32_t discMode)
117 {
118     if (g_coapDiscFunc == NULL) {
119         printf("g_coapDiscFunc is NULL.\n");
120         return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
121     }
122 
123     g_subscribeOption.capabilityBitmap[0] = filterCapBitmap;
124     switch (discMode) {
125         case 0:
126             if (g_coapDiscFunc->Subscribe(&g_subscribeOption) != 0) {
127                 printf("passivce start discvoery failed.\n");
128                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
129             }
130             break;
131         case 1:
132             if (g_coapDiscFunc->StartAdvertise(&g_subscribeOption) != 0) {
133                 printf("active start discvoery failed.\n");
134                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
135             }
136             break;
137         default:
138             printf("unsupport mode.\n");
139             return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
140     }
141     return SOFTBUS_OK;
142 }
143 
DiscCoapStopDiscovery(uint32_t filterCapBitmap,uint32_t discMode)144 static int32_t DiscCoapStopDiscovery(uint32_t filterCapBitmap, uint32_t discMode)
145 {
146     if (g_coapDiscFunc == NULL) {
147         return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
148     }
149 
150     g_subscribeOption.capabilityBitmap[0] = filterCapBitmap;
151     switch (discMode) {
152         case 0:
153             if (g_coapDiscFunc->Unsubscribe(&g_subscribeOption) != 0) {
154                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
155             }
156             break;
157         case 1:
158             if (g_coapDiscFunc->StopAdvertise(&g_subscribeOption) != 0) {
159                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
160             }
161             break;
162         default:
163             return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
164     }
165     return SOFTBUS_OK;
166 }
167 
DiscCoapUnpulbishService(uint32_t pubCapBitmap,uint32_t publishMode)168 static int32_t DiscCoapUnpulbishService(uint32_t pubCapBitmap, uint32_t publishMode)
169 {
170     if (g_coapDiscFunc == NULL) {
171         printf("g_coapDiscFunc is NULL.\n");
172         return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
173     }
174 
175     g_publishOption.capabilityBitmap[0] = pubCapBitmap;
176     switch (publishMode) {
177         case 0:
178             if (g_coapDiscFunc->StopScan(&g_publishOption) != 0) {
179                 printf("passive unpublish failed.\n");
180                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
181             }
182             break;
183         case 1:
184             if (g_coapDiscFunc->Unpublish(&g_publishOption) != 0) {
185                 printf("active unpublish failed.\n");
186                 return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
187             }
188             break;
189         default:
190             printf("unsupport mode.\n");
191             return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
192     }
193     return SOFTBUS_OK;
194 }
195 
196 static DiscInnerCallback g_discInnerCb = {
197     .OnDeviceFound = NULL
198 };
199 
200 static IServerDiscInnerCallback g_subscribeCb = {
201     .OnServerDeviceFound = TestDeviceFound
202 };
203 
204 static PublishInfo g_pInnerInfo = {
205     .publishId = TEST_PUBLISHINNER_ID,
206     .mode = DISCOVER_MODE_PASSIVE,
207     .medium = COAP,
208     .freq = LOW,
209     .capability = "hicall",
210     .capabilityData = (unsigned char *)"capdata1",
211     .dataLen = sizeof("capdata1")
212 };
213 
214 static PublishInfo g_pInfo = {
215     .publishId = TEST_PUBLISH_ID,
216     .mode = DISCOVER_MODE_ACTIVE,
217     .medium = COAP,
218     .freq = MID,
219     .capability = "dvKit",
220     .capabilityData = (unsigned char *)"capdata2",
221     .dataLen = sizeof("capdata2")
222 };
223 
224 static SubscribeInfo g_sInnerInfo = {
225     .subscribeId = TEST_SUBSCRIBEINNER_ID,
226     .mode = DISCOVER_MODE_ACTIVE,
227     .medium = COAP,
228     .freq = MID,
229     .isSameAccount = true,
230     .isWakeRemote = false,
231     .capability = "dvKit",
232     .capabilityData = (unsigned char *)"capdata3",
233     .dataLen = sizeof("capdata3")
234 };
235 
236 static SubscribeInfo g_sInfo = {
237     .subscribeId = TEST_SUBSCRIBE_ID,
238     .mode = DISCOVER_MODE_ACTIVE,
239     .medium = COAP,
240     .freq = MID,
241     .isSameAccount = true,
242     .isWakeRemote = false,
243     .capability = "hicall",
244     .capabilityData = (unsigned char *)"capdata4",
245     .dataLen = sizeof("capdata4")
246 };
247 
248 static PublishInfo g_pInnerInfo1 = {
249     .publishId = TEST_PUBLISHINNER_ID1,
250     .mode = DISCOVER_MODE_ACTIVE,
251     .medium = COAP,
252     .freq = LOW,
253     .capability = "hicall",
254     .capabilityData = NULL,
255     .dataLen = 0
256 };
257 
258 static PublishInfo g_pInfo1 = {
259     .publishId = TEST_PUBLISH_ID1,
260     .mode = DISCOVER_MODE_ACTIVE,
261     .medium = COAP,
262     .freq = MID,
263     .capability = "dvKit",
264     .capabilityData = NULL,
265     .dataLen = 0
266 };
267 
268 static SubscribeInfo g_sInnerInfo1 = {
269     .subscribeId = TEST_SUBSCRIBEINNER_ID1,
270     .mode = DISCOVER_MODE_PASSIVE,
271     .medium = COAP,
272     .freq = MID,
273     .isSameAccount = true,
274     .isWakeRemote = false,
275     .capability = "dvKit",
276     .capabilityData = NULL,
277     .dataLen = 0
278 };
279 
280 static SubscribeInfo g_sInfo1 = {
281     .subscribeId = TEST_SUBSCRIBE_ID1,
282     .mode = DISCOVER_MODE_ACTIVE,
283     .medium = COAP,
284     .freq = MID,
285     .isSameAccount = true,
286     .isWakeRemote = false,
287     .capability = "hicall",
288     .capabilityData = NULL,
289     .dataLen = 0
290 };
291 
292 /**
293  * @tc.name: DiscPublishTest001
294  * @tc.desc: Test inner module active publish, but softbus discover manager is not init.
295  * @tc.type: FUNC
296  * @tc.require: The DiscPublish operates normally.
297  */
298 HWTEST_F(DiscManagerTest, DiscPublishTest001, TestSize.Level1)
299 {
300     int32_t ret = DiscPublish(MODULE_CONN, &g_pInnerInfo);
301     TEST_ASSERT_TRUE(ret != 0);
302 }
303 
304 /**
305  * @tc.name: DiscPublishTest002
306  * @tc.desc: Test inner module active publish, use wrong Medium and Freq Under the COAP of MODULE_LNN.
307  * @tc.type: FUNC
308  * @tc.require: The DiscPublish operates normally.
309  */
310 HWTEST_F(DiscManagerTest, DiscPublishTest002, TestSize.Level1)
311 {
312     PublishInfo testInfo = {
313         .publishId = TEST_PUBLISHINNER_ID,
314         .mode = DISCOVER_MODE_ACTIVE,
315         .medium = COAP,
316         .freq = LOW,
317         .capability = "hicall",
318         .capabilityData = (unsigned char *)"capdata1",
319         .dataLen = sizeof("capdata1")
320     };
321 
322     DiscMgrInit();
323 
324     int32_t ret = DiscPublish((DiscModule)TEST_ERRO_MOUDULE, &testInfo);
325     TEST_ASSERT_TRUE(ret != 0);
326 
327     testInfo.medium = (ExchangeMedium)(COAP + 1);
328     ret = DiscPublish(MODULE_LNN, &testInfo);
329     TEST_ASSERT_TRUE(ret != 0);
330     testInfo.medium = COAP;
331 
332     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
333     ret = DiscPublish(MODULE_LNN, &testInfo);
334     TEST_ASSERT_TRUE(ret != 0);
335     testInfo.freq = LOW;
336 
337     testInfo.capability = "hicall";
338     testInfo.capabilityData = NULL;
339     ret = DiscPublish(MODULE_LNN, &testInfo);
340     TEST_ASSERT_TRUE(ret != 0);
341     testInfo.capabilityData = (unsigned char *)"capdata1";
342 
343     testInfo.dataLen = ERRO_CAPDATA_LEN;
344     ret = DiscPublish(MODULE_LNN, &testInfo);
345     TEST_ASSERT_TRUE(ret != 0);
346     testInfo.dataLen = sizeof("capdata1");
347 
348     DiscMgrDeinit();
349 }
350 
351 /**
352  * @tc.name: DiscPublishTest003
353  * @tc.desc: Inner LNN module active publish, use the normal parameter.
354  * @tc.type: FUNC
355  * @tc.require: The DiscPublish operates normally.
356  */
357 HWTEST_F(DiscManagerTest, DiscPublishTest003, TestSize.Level1)
358 {
359     DiscMgrInit();
360 
361     int32_t ret = DiscPublish(MODULE_LNN, &g_pInnerInfo);
362     TEST_ASSERT_TRUE(ret != 0);
363 
364     ret = DiscPublish(MODULE_LNN, &g_pInnerInfo1);
365     TEST_ASSERT_TRUE(ret == 0);
366 
367     DiscMgrDeinit();
368 }
369 
370 /**
371  * @tc.name: DiscPublishTest004
372  * @tc.desc: Inner module active publish, use the wrong parameter.
373  * @tc.type: FUNC
374  * @tc.require: The DiscPublish operates normally.
375  */
376 HWTEST_F(DiscManagerTest, DiscPublishTest004, TestSize.Level1)
377 {
378     DiscMgrInit();
379 
380     int32_t ret = DiscPublish(MODULE_LNN, &g_pInnerInfo1);
381     TEST_ASSERT_TRUE(ret == 0);
382 
383     ret = DiscPublish(MODULE_LNN, &g_pInnerInfo1);
384     TEST_ASSERT_TRUE(ret != 0);
385 
386     DiscMgrDeinit();
387 }
388 
389 /**
390  * @tc.name: DiscPublishTest005
391  * @tc.desc: Test inner module active publish, but softbus discover manager is not init.
392  * @tc.type: FUNC
393  * @tc.require: The DiscPublish operates normally.
394  */
395 HWTEST_F(DiscManagerTest, DiscPublishTest005, TestSize.Level1)
396 {
397     PublishInfo testInfo = {
398         .publishId = TEST_PUBLISHINNER_ID,
399         .mode = DISCOVER_MODE_ACTIVE,
400         .medium = COAP,
401         .freq = LOW,
402         .capability = "hicall",
403         .capabilityData = (unsigned char*)"capdata1",
404         .dataLen = sizeof("capdata1")
405     };
406 
407     int32_t ret = DiscPublish(MODULE_LNN, &testInfo);
408     TEST_ASSERT_TRUE(ret != 0);
409 }
410 
411 PublishInfo discPublishTestAbstractInfo001 = {
412     .publishId = TEST_PUBLISHINNER_ID,
413     .mode = DISCOVER_MODE_ACTIVE,
414     .medium = AUTO,
415     .freq = LOW,
416     .capability = "hicall",
417     .capabilityData = (unsigned char *)"capdata1",
418     .dataLen = sizeof("capdata1")
419 };
420 
DiscPublishTestAbstract001(DiscModule module,PublishInfo * info)421 void DiscPublishTestAbstract001(DiscModule module, PublishInfo *info)
422 {
423     DiscMgrInit();
424 
425     int32_t ret = DiscPublish(module, info);
426     TEST_ASSERT_TRUE(ret == 0);
427     DiscUnpublish(module, info->publishId);
428 
429     info->freq = MID;
430     ret = DiscPublish(module, info);
431     TEST_ASSERT_TRUE(ret == 0);
432     DiscUnpublish(module, info->publishId);
433 
434     info->freq = HIGH;
435     ret = DiscPublish(module, info);
436     TEST_ASSERT_TRUE(ret == 0);
437     DiscUnpublish(module, info->publishId);
438 
439     info->freq = SUPER_HIGH;
440     ret = DiscPublish(module, info);
441     TEST_ASSERT_TRUE(ret == 0);
442     DiscUnpublish(module, info->publishId);
443 
444     info->freq = EXTREME_HIGH;
445     ret = DiscPublish(module, info);
446     TEST_ASSERT_TRUE(ret == 0);
447     DiscUnpublish(module, info->publishId);
448 
449     info->freq = LOW;
450     DiscMgrDeinit();
451 }
452 
453 /**
454  * @tc.name: DiscPublishTest006
455  * @tc.desc: Test inner module active publish, use Diff Freq Under the AUTO of MODULE_LNN.
456  *           Test inner module active publish, use Diff Freq Under the AUTO of MODULE_CONN.
457  *           Test inner module active publish, use Diff Freq Under the BLE of MODULE_LNN.
458  *           Test inner module active publish, use Diff Freq Under the BLE of MODULE_CONN.
459  *           Test inner module active publish, use Diff Freq Under the COAP of MODULE_LNN.
460  *           Test inner module active publish, use Diff Freq Under the COAP of MODULE_LNN.
461  *           Test inner module active publish, use Diff Freq Under the COAP of MODULE_CONN.
462  * @tc.type: FUNC
463  * @tc.require: The DiscPublish operates normally.
464  */
465 HWTEST_F(DiscManagerTest, DiscPublishTest006, TestSize.Level1)
466 {
467     DiscPublishTestAbstract001(MODULE_LNN, &discPublishTestAbstractInfo001);
468     DiscPublishTestAbstract001(MODULE_CONN, &discPublishTestAbstractInfo001);
469 
470     discPublishTestAbstractInfo001.medium = BLE;
471     DiscPublishTestAbstract001(MODULE_LNN, &discPublishTestAbstractInfo001);
472     DiscPublishTestAbstract001(MODULE_CONN, &discPublishTestAbstractInfo001);
473 
474     discPublishTestAbstractInfo001.medium = COAP;
475     DiscPublishTestAbstract001(MODULE_LNN, &discPublishTestAbstractInfo001);
476     DiscPublishTestAbstract001(MODULE_CONN, &discPublishTestAbstractInfo001);
477 }
478 
479 PublishInfo discPublishTestAbstractInfo002 = {
480     .publishId = TEST_PUBLISHINNER_ID,
481     .mode = DISCOVER_MODE_ACTIVE,
482     .medium = COAP,
483     .freq = LOW,
484     .capability = "hicall",
485     .capabilityData = (unsigned char*)"capdata1",
486     .dataLen = sizeof("capdata1")
487 };
488 
DiscPublishTestAbstract002(DiscModule module,PublishInfo * info)489 void DiscPublishTestAbstract002(DiscModule module, PublishInfo *info)
490 {
491     DiscMgrInit();
492 
493     int32_t ret = DiscPublish((DiscModule)TEST_ERRO_MOUDULE2, info);
494     TEST_ASSERT_TRUE(ret != 0);
495 
496     info->medium = (ExchangeMedium)(AUTO - 1);
497     ret = DiscPublish(module, info);
498     TEST_ASSERT_TRUE(ret != 0);
499     info->medium = COAP;
500 
501     info->freq = (ExchangeFreq)(LOW - 1);
502     ret = DiscPublish(module, info);
503     TEST_ASSERT_TRUE(ret != 0);
504     info->freq = LOW;
505 
506     ret = DiscPublish(module, NULL);
507     TEST_ASSERT_TRUE(ret != 0);
508 
509     DiscMgrDeinit();
510 }
511 
512 /**
513  * @tc.name: DiscPublishTest007
514  * @tc.desc: Test inner module active publish, use wrong Medium and Freq Under the COAP of MODULE_LNN.
515  *           Test inner module active publish, use wrong Medium and Freq Under the BLE of MODULE_LNN.
516  *           Test inner module active publish, use wrong Medium and Freq Under the AUTO of MODULE_LNN.
517  * @tc.type: FUNC
518  * @tc.require: The DiscPublish operates normally.
519  */
520 HWTEST_F(DiscManagerTest, DiscPublishTest007, TestSize.Level1)
521 {
522     DiscPublishTestAbstract002(MODULE_LNN, &discPublishTestAbstractInfo002);
523 
524     discPublishTestAbstractInfo002.medium = BLE;
525     DiscPublishTestAbstract002(MODULE_LNN, &discPublishTestAbstractInfo002);
526 
527     discPublishTestAbstractInfo002.medium = AUTO;
528     DiscPublishTestAbstract002(MODULE_LNN, &discPublishTestAbstractInfo002);
529 }
530 
531 /**
532  * @tc.name: DiscStartScanTest001
533  * @tc.desc: Inner CONN module passive publish, the module is not initialized.
534  * @tc.type: FUNC
535  * @tc.require: The DiscStartScan operates normally.
536  */
537 HWTEST_F(DiscManagerTest, DiscStartScanTest001, TestSize.Level1)
538 {
539     int32_t ret = DiscStartScan(MODULE_CONN, &g_pInnerInfo);
540     TEST_ASSERT_TRUE(ret != 0);
541 }
542 
543 /**
544  * @tc.name: DiscStartScanTest002
545  * @tc.desc: Inner LNN module passive publish, use the wrong parameter.
546  * @tc.type: FUNC
547  * @tc.require: The DiscStartScan operates normally.
548  */
549 HWTEST_F(DiscManagerTest, DiscStartScanTest002, TestSize.Level1)
550 {
551     PublishInfo testInfo = {.publishId = TEST_PUBLISHINNER_ID,
552         .mode = DISCOVER_MODE_PASSIVE,
553         .medium = COAP,
554         .freq = LOW,
555         .capability = "hicall",
556         .capabilityData = (unsigned char *)"capdata1",
557         .dataLen = sizeof("capdata1")};
558 
559     DiscMgrInit();
560 
561     int32_t ret = DiscStartScan((DiscModule)TEST_ERRO_MOUDULE, &testInfo);
562     TEST_ASSERT_TRUE(ret != 0);
563 
564     testInfo.medium = (ExchangeMedium)(COAP + 1);
565     ret = DiscStartScan(MODULE_LNN, &testInfo);
566     TEST_ASSERT_TRUE(ret != 0);
567     testInfo.medium = COAP;
568 
569     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
570     ret = DiscStartScan(MODULE_LNN, &testInfo);
571     TEST_ASSERT_TRUE(ret != 0);
572     testInfo.freq = LOW;
573 
574     testInfo.capability = "hicall";
575     testInfo.capabilityData = NULL;
576     ret = DiscStartScan(MODULE_LNN, &testInfo);
577     TEST_ASSERT_TRUE(ret != 0);
578     testInfo.capabilityData = (unsigned char *)"capdata1";
579 
580     testInfo.dataLen = ERRO_CAPDATA_LEN;
581     ret = DiscStartScan(MODULE_LNN, &testInfo);
582     TEST_ASSERT_TRUE(ret != 0);
583     testInfo.dataLen = sizeof("capdata1");
584 
585     DiscMgrDeinit();
586 }
587 
588 /**
589  * @tc.name: DiscStartScanTest003
590  * @tc.desc: Inner LNN module passive publish, use the normal parameter.
591  * @tc.type: FUNC
592  * @tc.require: The DiscStartScan operates normally.
593  */
594 HWTEST_F(DiscManagerTest, DiscStartScanTest003, TestSize.Level1)
595 {
596     DiscMgrInit();
597 
598     int32_t ret = DiscStartScan(MODULE_LNN, &g_pInnerInfo);
599     TEST_ASSERT_TRUE(ret == 0);
600 
601     DiscMgrDeinit();
602 }
603 
604 /**
605  * @tc.name: DiscStartScanTest004
606  * @tc.desc: Inner LNN module passive publish, use the wrong parameter.
607  * @tc.type: FUNC
608  * @tc.require: The DiscStartScan operates normally.
609  */
610 HWTEST_F(DiscManagerTest, DiscStartScanTest004, TestSize.Level1)
611 {
612     DiscMgrInit();
613 
614     int32_t ret = DiscStartScan(MODULE_LNN, &g_pInnerInfo1);
615     TEST_ASSERT_TRUE(ret != 0);
616 
617     DiscMgrDeinit();
618 }
619 
620 /**
621  * @tc.name: DiscStartScanTest005
622  * @tc.desc: Test passive discover, but softbus discover manager is not initialized.
623  * @tc.type: FUNC
624  * @tc.require:The DiscStartScan operates normally.
625  */
626 HWTEST_F(DiscManagerTest, DiscStartScanTest005, TestSize.Level1)
627 {
628     PublishInfo testInfo = {
629         .publishId = TEST_PUBLISHINNER_ID,
630         .mode = DISCOVER_MODE_PASSIVE,
631         .medium = COAP,
632         .freq = LOW,
633         .capability = "hicall",
634         .capabilityData = (unsigned char *)"capdata1",
635         .dataLen = sizeof("capdata1")
636     };
637 
638     int32_t ret = DiscStartScan(MODULE_LNN, &testInfo);
639     TEST_ASSERT_TRUE(ret != 0);
640 }
641 
642 PublishInfo discStartScanTestAbstractInfo001 = {
643     .publishId = TEST_PUBLISHINNER_ID,
644     .mode = DISCOVER_MODE_PASSIVE,
645     .medium = COAP,
646     .freq = LOW,
647     .capability = "hicall",
648     .capabilityData = (unsigned char*)"capdata1",
649     .dataLen = sizeof("capdata1")
650 };
651 
DiscStartScanTestAbstract001(DiscModule module,PublishInfo * info,DiscModule erroModule)652 void DiscStartScanTestAbstract001(DiscModule module, PublishInfo *info, DiscModule erroModule)
653 {
654     DiscMgrInit();
655 
656     int32_t ret = DiscStartScan(erroModule, info);
657     TEST_ASSERT_TRUE(ret != 0);
658 
659     info->medium = (ExchangeMedium)(AUTO - 1);
660     ret = DiscStartScan(module, info);
661     TEST_ASSERT_TRUE(ret != 0);
662     info->medium = COAP;
663 
664     info->freq = (ExchangeFreq)(LOW - 1);
665     ret = DiscStartScan(module, info);
666     TEST_ASSERT_TRUE(ret != 0);
667     info->freq = LOW;
668 
669     ret = DiscStartScan(module, NULL);
670     TEST_ASSERT_TRUE(ret != 0);
671 
672     DiscMgrDeinit();
673 }
674 
675 /**
676  * @tc.name: DiscStartScanTest006
677  * @tc.desc: Test passive discover,use wrong Medium and Freq Under the COAP of MODULE_LNN.
678  *           Test passive discover,use wrong Medium and Freq Under the AUTO of MODULE_LNN.
679  *           Test passive discover,use wrong Medium and Freq Under the BLE of MODULE_LNN.
680  * @tc.type: FUNC
681  * @tc.require:The DiscStartScan operates normally.
682  */
683 HWTEST_F(DiscManagerTest, DiscStartScanTest006, TestSize.Level1)
684 {
685     DiscStartScanTestAbstract001(MODULE_LNN, &discStartScanTestAbstractInfo001, (DiscModule)TEST_ERRO_MOUDULE2);
686 
687     discStartScanTestAbstractInfo001.medium = AUTO;
688     DiscStartScanTestAbstract001(MODULE_LNN, &discStartScanTestAbstractInfo001, (DiscModule)TEST_ERRO_MOUDULE1);
689 
690     discStartScanTestAbstractInfo001.medium = BLE;
691     DiscStartScanTestAbstract001(MODULE_LNN, &discStartScanTestAbstractInfo001, (DiscModule)TEST_ERRO_MOUDULE2);
692 }
693 
694 /**
695  * @tc.name: DiscStartAdvertiseTest001
696  * @tc.desc: Inner CONN module active discover, the module is not initialized.
697  * @tc.type: FUNC
698  * @tc.require: The DiscStartAdvertise operates normally.
699  */
700 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest001, TestSize.Level1)
701 {
702     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
703     TEST_ASSERT_TRUE(ret != 0);
704 }
705 
706 /**
707  * @tc.name: DiscStartAdvertiseTest002
708  * @tc.desc: Inner LNN module active discover, use the wrong parameter.
709  * @tc.type: FUNC
710  * @tc.require: The DiscStartAdvertise operates normally.
711  */
712 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest002, TestSize.Level1)
713 {
714     SubscribeInfo testInfo = {
715         .subscribeId = TEST_SUBSCRIBEINNER_ID,
716         .mode = DISCOVER_MODE_ACTIVE,
717         .medium = COAP,
718         .freq = MID,
719         .isSameAccount = true,
720         .isWakeRemote = false,
721         .capability = "dvKit",
722         .capabilityData = (unsigned char *)"capdata3",
723         .dataLen = sizeof("capdata3")
724     };
725 
726     DiscMgrInit();
727 
728     int32_t ret = DiscStartAdvertise((DiscModule)TEST_ERRO_MOUDULE, &testInfo);
729     TEST_ASSERT_TRUE(ret != 0);
730 
731     testInfo.medium = (ExchangeMedium)(COAP + 1);
732     ret = DiscStartAdvertise(MODULE_LNN, &testInfo);
733     TEST_ASSERT_TRUE(ret != 0);
734     testInfo.medium = COAP;
735 
736     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
737     ret = DiscStartAdvertise(MODULE_LNN, &testInfo);
738     TEST_ASSERT_TRUE(ret != 0);
739     testInfo.freq = LOW;
740 
741     testInfo.capability = "hicall";
742     testInfo.capabilityData = NULL;
743     ret = DiscStartAdvertise(MODULE_LNN, &testInfo);
744     TEST_ASSERT_TRUE(ret != 0);
745     testInfo.capabilityData = (unsigned char *)"capdata1";
746 
747     testInfo.dataLen = ERRO_CAPDATA_LEN;
748     ret = DiscStartAdvertise(MODULE_LNN, &testInfo);
749     TEST_ASSERT_TRUE(ret != 0);
750     testInfo.dataLen = sizeof("capdata1");
751 
752     DiscMgrDeinit();
753 }
754 
755 /**
756  * @tc.name: DiscStartAdvertiseTest003
757  * @tc.desc: Inner CONN module active discover, use the normal parameter.
758  * @tc.type: FUNC
759  * @tc.require: The DiscStartAdvertise operates normally.
760  */
761 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest003, TestSize.Level1)
762 {
763     DiscMgrInit();
764 
765     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
766     TEST_ASSERT_TRUE(ret == 0);
767 
768     DiscMgrDeinit();
769 }
770 
771 /**
772  * @tc.name: DiscStartAdvertiseTest004
773  * @tc.desc: Inner CONN module active discover, use the wrong parameter.
774  * @tc.type: FUNC
775  * @tc.require: The DiscStartAdvertise operates normally.
776  */
777 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest004, TestSize.Level1)
778 {
779     DiscMgrInit();
780 
781     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo1);
782     TEST_ASSERT_TRUE(ret != 0);
783 
784     DiscMgrDeinit();
785 }
786 
787 SubscribeInfo discStartAdvertiseTestAbstractInfo001 = {
788     .subscribeId = TEST_SUBSCRIBEINNER_ID,
789     .mode = DISCOVER_MODE_ACTIVE,
790     .medium = COAP,
791     .freq = MID,
792     .isSameAccount = true,
793     .isWakeRemote = false,
794     .capability = "dvKit",
795     .capabilityData = (unsigned char *)"capdata3",
796     .dataLen = sizeof("capdata3")
797 };
798 
DiscStartAdvertiseTestAbstract001(DiscModule module,SubscribeInfo * info)799 void DiscStartAdvertiseTestAbstract001(DiscModule module, SubscribeInfo *info)
800 {
801     DiscMgrInit();
802 
803     int32_t ret = DiscStartAdvertise((DiscModule)TEST_ERRO_MOUDULE1, info);
804     TEST_ASSERT_TRUE(ret != 0);
805 
806     info->medium = (ExchangeMedium)(AUTO - 1);
807     ret = DiscStartAdvertise(module, info);
808     TEST_ASSERT_TRUE(ret != 0);
809     info->medium = COAP;
810 
811     info->freq = (ExchangeFreq)(LOW - 1);
812     ret = DiscStartAdvertise(module, info);
813     TEST_ASSERT_TRUE(ret != 0);
814     info->freq = LOW;
815 
816     ret = DiscStartAdvertise(module, NULL);
817     TEST_ASSERT_TRUE(ret != 0);
818 
819     info->freq = MID;
820     DiscMgrDeinit();
821 }
822 
823 /**
824  * @tc.name: DiscStartAdvertiseTest005
825  * @tc.desc: Test inner start discover, use wrong Medium and Freq Under the COAP of MODULE_LNN.
826  *           Test inner start discover, use wrong Medium and Freq Under the BLE of MODULE_LNN.
827  *           Test inner start discover, use wrong Medium and Freq Under the AUTO of MODULE_LNN.
828  *           Test inner module active discover, but softbus discover manager is not init.
829  * @tc.type: FUNC
830  * @tc.require: The DiscStartAdvertise operates normally.
831  */
832 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest005, TestSize.Level1)
833 {
834     DiscStartAdvertiseTestAbstract001(MODULE_LNN, &discStartAdvertiseTestAbstractInfo001);
835 
836     discStartAdvertiseTestAbstractInfo001.medium = BLE;
837     DiscStartAdvertiseTestAbstract001(MODULE_LNN, &discStartAdvertiseTestAbstractInfo001);
838 
839     discStartAdvertiseTestAbstractInfo001.medium = AUTO;
840     DiscStartAdvertiseTestAbstract001(MODULE_LNN, &discStartAdvertiseTestAbstractInfo001);
841 
842     discStartAdvertiseTestAbstractInfo001.medium = COAP;
843     int32_t ret = DiscStartAdvertise(MODULE_CONN, &discStartAdvertiseTestAbstractInfo001);
844     TEST_ASSERT_TRUE(ret == 0);
845 }
846 
847 SubscribeInfo discStartAdvertiseTestAbstractInfo002 = {
848     .subscribeId = TEST_SUBSCRIBEINNER_ID,
849     .mode = DISCOVER_MODE_ACTIVE,
850     .medium = AUTO,
851     .freq = LOW,
852     .isSameAccount = true,
853     .isWakeRemote = false,
854     .capability = "dvKit",
855     .capabilityData = (unsigned char *)"capdata3",
856     .dataLen = sizeof("capdata3")
857 };
858 
DiscStartAdvertiseTestAbstract002(DiscModule module,SubscribeInfo * info)859 void DiscStartAdvertiseTestAbstract002(DiscModule module, SubscribeInfo *info)
860 {
861     DiscMgrInit();
862 
863     int32_t ret = DiscStartAdvertise(MODULE_LNN, info);
864     TEST_ASSERT_TRUE(ret == 0);
865     DiscStopAdvertise(MODULE_LNN, info->subscribeId);
866 
867     info->freq = MID;
868     ret = DiscStartAdvertise(MODULE_LNN, info);
869     TEST_ASSERT_TRUE(ret == 0);
870     DiscStopAdvertise(MODULE_LNN, info->subscribeId);
871 
872     info->freq = HIGH;
873     ret = DiscStartAdvertise(MODULE_LNN, info);
874     TEST_ASSERT_TRUE(ret == 0);
875     DiscStopAdvertise(MODULE_LNN, info->subscribeId);
876 
877     info->freq = SUPER_HIGH;
878     ret = DiscStartAdvertise(MODULE_LNN, info);
879     TEST_ASSERT_TRUE(ret == 0);
880     DiscStopAdvertise(MODULE_LNN, info->subscribeId);
881 
882     info->freq = EXTREME_HIGH;
883     ret = DiscStartAdvertise(MODULE_LNN, info);
884     TEST_ASSERT_TRUE(ret == 0);
885     DiscStopAdvertise(MODULE_LNN, info->subscribeId);
886 
887     info->freq = LOW;
888     DiscMgrDeinit();
889 }
890 
891 /**
892  * @tc.name: DiscStartAdvertiseTest006
893  * @tc.desc: Test inner module active discover, use Diff Freq Under the AUTO of MODULE_LNN.
894  *           Test inner module active discover, use Diff Freq Under the AUTO of MODULE_CONN.
895  *           Test inner module active discover, use Diff Freq Under the BLE of MODULE_LNN.
896  *           Test inner module active discover, use Diff Freq Under the BLE of MODULE_CONN.
897  *           Test inner module active discover, use Diff Freq Under the COAP of MODULE_LNN.
898  *           Test inner module active discover, use use Diff Freq Under the COAP of MODULE_CONN.
899  * @tc.type: FUNC
900  * @tc.require: The DiscStartAdvertise operates normally.
901  */
902 HWTEST_F(DiscManagerTest, DiscStartAdvertiseTest006, TestSize.Level1)
903 {
904     DiscStartAdvertiseTestAbstract002(MODULE_LNN, &discStartAdvertiseTestAbstractInfo002);
905     DiscStartAdvertiseTestAbstract002(MODULE_CONN, &discStartAdvertiseTestAbstractInfo002);
906 
907     discStartAdvertiseTestAbstractInfo002.medium = BLE;
908     DiscStartAdvertiseTestAbstract002(MODULE_LNN, &discStartAdvertiseTestAbstractInfo002);
909     DiscStartAdvertiseTestAbstract002(MODULE_CONN, &discStartAdvertiseTestAbstractInfo002);
910 
911     discStartAdvertiseTestAbstractInfo002.medium = COAP;
912     DiscStartAdvertiseTestAbstract002(MODULE_LNN, &discStartAdvertiseTestAbstractInfo002);
913     DiscStartAdvertiseTestAbstract002(MODULE_CONN, &discStartAdvertiseTestAbstractInfo002);
914 }
915 
916 /**
917  * @tc.name: DiscSubscribeTest001
918  * @tc.desc: Inner CONN module passive discover, the module is not initialized.
919  * @tc.type: FUNC
920  * @tc.require: The DiscSubscribe operates normally.
921  */
922 HWTEST_F(DiscManagerTest, DiscSubscribeTest001, TestSize.Level1)
923 {
924     int32_t ret = DiscSubscribe(MODULE_CONN, &g_sInnerInfo);
925     TEST_ASSERT_TRUE(ret != 0);
926 }
927 
928 /**
929  * @tc.name: DiscSubscribeTest002
930  * @tc.desc: Inner LNN module passive discover, use the wrong parameter.
931  * @tc.type: FUNC
932  * @tc.require: The DiscSubscribe operates normally.
933  */
934 HWTEST_F(DiscManagerTest, DiscSubscribeTest002, TestSize.Level1)
935 {
936     SubscribeInfo testInfo = {.subscribeId = TEST_SUBSCRIBEINNER_ID,
937         .mode = DISCOVER_MODE_PASSIVE,
938         .medium = COAP,
939         .freq = MID,
940         .isSameAccount = true,
941         .isWakeRemote = false,
942         .capability = "dvKit",
943         .capabilityData = (unsigned char *)"capdata3",
944         .dataLen = sizeof("capdata3")};
945 
946     DiscMgrInit();
947 
948     int32_t ret = DiscSubscribe((DiscModule)TEST_ERRO_MOUDULE, &testInfo);
949     TEST_ASSERT_TRUE(ret != 0);
950 
951     testInfo.medium = (ExchangeMedium)(COAP + 1);
952     ret = DiscSubscribe(MODULE_LNN, &testInfo);
953     TEST_ASSERT_TRUE(ret != 0);
954     testInfo.medium = COAP;
955 
956     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
957     ret = DiscSubscribe(MODULE_LNN, &testInfo);
958     TEST_ASSERT_TRUE(ret != 0);
959     testInfo.freq = LOW;
960 
961     testInfo.capability = "hicall";
962     testInfo.capabilityData = NULL;
963     ret = DiscSubscribe(MODULE_LNN, &testInfo);
964     TEST_ASSERT_TRUE(ret != 0);
965     testInfo.capabilityData = (unsigned char *)"capdata1";
966 
967     testInfo.dataLen = ERRO_CAPDATA_LEN;
968     ret = DiscSubscribe(MODULE_LNN, &testInfo);
969     TEST_ASSERT_TRUE(ret != 0);
970     testInfo.dataLen = sizeof("capdata1");
971 
972     DiscMgrDeinit();
973 }
974 
975 /**
976  * @tc.name: DiscSubscribeTest003
977  * @tc.desc: Inner CONN module passive discover, use the wrong parameter.
978  * @tc.type: FUNC
979  * @tc.require: The DiscSubscribe operates normally.
980  */
981 HWTEST_F(DiscManagerTest, DiscSubscribeTest003, TestSize.Level1)
982 {
983     DiscMgrInit();
984 
985     int32_t ret = DiscSubscribe(MODULE_CONN, &g_sInnerInfo);
986     TEST_ASSERT_TRUE(ret != 0);
987 
988     DiscMgrDeinit();
989 }
990 
991 /**
992  * @tc.name: DiscSubscribeTest004
993  * @tc.desc: Inner CONN module passive discover, use the normal parameter.
994  * @tc.type: FUNC
995  * @tc.require: The DiscSubscribe operates normally.
996  */
997 HWTEST_F(DiscManagerTest, DiscSubscribeTest004, TestSize.Level1)
998 {
999     DiscMgrInit();
1000 
1001     int32_t ret = DiscSubscribe(MODULE_CONN, &g_sInnerInfo1);
1002     TEST_ASSERT_TRUE(ret == 0);
1003 
1004     DiscMgrDeinit();
1005 }
1006 
1007 /**
1008  * @tc.name: DiscSubscribeTest005
1009  * @tc.desc: Inner CONN module passive discover, use the same parameter again, Perform two subscriptions.
1010  * @tc.type: FUNC
1011  * @tc.require:The DiscSubscribe operates normally.
1012  */
1013 HWTEST_F(DiscManagerTest, DiscSubscribeTest005, TestSize.Level1)
1014 {
1015     DiscMgrInit();
1016 
1017     int32_t ret = DiscSubscribe(MODULE_CONN, &g_sInnerInfo1);
1018     ret = DiscSubscribe(MODULE_CONN, &g_sInnerInfo1);
1019     TEST_ASSERT_TRUE(ret != 0);
1020 
1021     DiscMgrDeinit();
1022 }
1023 
1024 SubscribeInfo discSubscribeTestAbstractInfo001 = {
1025     .subscribeId = TEST_SUBSCRIBEINNER_ID,
1026     .mode = DISCOVER_MODE_PASSIVE,
1027     .medium = BLE,
1028     .freq = MID,
1029     .isSameAccount = true,
1030     .isWakeRemote = false,
1031     .capability = "dvKit",
1032     .capabilityData = (unsigned char*)"capdata3",
1033     .dataLen = sizeof("capdata3")
1034 };
1035 
DiscSubscribeTestAbstract001(DiscModule module,SubscribeInfo * info)1036 void DiscSubscribeTestAbstract001(DiscModule module, SubscribeInfo *info)
1037 {
1038     DiscMgrInit();
1039 
1040     int32_t ret = DiscSubscribe((DiscModule)TEST_ERRO_MOUDULE1, info);
1041     TEST_ASSERT_TRUE(ret != 0);
1042 
1043     info->medium = (ExchangeMedium)(AUTO - 1);
1044     ret = DiscSubscribe(module, info);
1045     TEST_ASSERT_TRUE(ret != 0);
1046     info->medium = COAP;
1047 
1048     info->freq = (ExchangeFreq)(LOW - 1);
1049     ret = DiscSubscribe(module, info);
1050     TEST_ASSERT_TRUE(ret != 0);
1051     info->freq = LOW;
1052 
1053     ret = DiscSubscribe(module, NULL);
1054     TEST_ASSERT_TRUE(ret != 0);
1055 
1056     info->medium = BLE,
1057     info->freq = MID,
1058     DiscMgrDeinit();
1059 }
1060 
1061 /**
1062  * @tc.name: DiscSubscribeTest006
1063  * @tc.desc: Inner LNN module passive discover, use wrong parameter.
1064  *           Inner LNN module passive discover, use the wrong parameter.
1065  *           Softbus discovery manager is not init.
1066  * @tc.type: FUNC
1067  * @tc.require: The DiscSubscribe operates normally.
1068  */
1069 HWTEST_F(DiscManagerTest, DiscSubscribeTest006, TestSize.Level1)
1070 {
1071     DiscSubscribeTestAbstract001(MODULE_LNN, &discSubscribeTestAbstractInfo001);
1072 
1073     discSubscribeTestAbstractInfo001.medium = AUTO;
1074     DiscSubscribeTestAbstract001(MODULE_LNN, &discSubscribeTestAbstractInfo001);
1075 
1076     discSubscribeTestAbstractInfo001.medium = COAP;
1077     int32_t ret = DiscSubscribe(MODULE_CONN, &discSubscribeTestAbstractInfo001);
1078     TEST_ASSERT_TRUE(ret != 0);
1079 }
1080 
1081 /**
1082  * @tc.name: DiscUnpublishTest001
1083  * @tc.desc: Inner CONN module stop publish, the module is not initialized.
1084  * @tc.type: FUNC
1085  * @tc.require: The DiscUnpublish operates normally.
1086  */
1087 HWTEST_F(DiscManagerTest, DiscUnpublishTest001, TestSize.Level1)
1088 {
1089     int32_t ret = DiscUnpublish(MODULE_CONN, TEST_PUBLISHINNER_ID);
1090     TEST_ASSERT_TRUE(ret != 0);
1091 }
1092 
1093 /**
1094  * @tc.name: DiscUnpublishTest002
1095  * @tc.desc: Inner LNN module stop publish, use the wrong parameter.
1096  * @tc.type: FUNC
1097  * @tc.require: The DiscUnpublish operates normally.
1098  */
1099 HWTEST_F(DiscManagerTest, DiscUnpublishTest002, TestSize.Level1)
1100 {
1101     DiscMgrInit();
1102     DiscPublish(MODULE_LNN, &g_pInnerInfo1);
1103 
1104     int32_t ret = DiscUnpublish((DiscModule)TEST_ERRO_MOUDULE, TEST_PUBLISHINNER_ID);
1105     TEST_ASSERT_TRUE(ret != 0);
1106 
1107     DiscMgrDeinit();
1108 }
1109 
1110 /**
1111  * @tc.name: DiscUnpublishTest003
1112  * @tc.desc: Inner LNN module stop publish, use the normal parameter.
1113  * @tc.type: FUNC
1114  * @tc.require: The DiscUnpublish operates normally
1115  */
1116 HWTEST_F(DiscManagerTest, DiscUnpublishTest003, TestSize.Level1)
1117 {
1118     DiscMgrInit();
1119     DiscPublish(MODULE_LNN, &g_pInnerInfo1);
1120 
1121     int32_t ret = DiscUnpublish(MODULE_LNN, TEST_PUBLISHINNER_ID1);
1122     TEST_ASSERT_TRUE(ret == 0);
1123 
1124     DiscMgrDeinit();
1125 }
1126 
1127 /**
1128  * @tc.name: DiscUnpublishTest004
1129  * @tc.desc: Inner LNN module stop publish, release the same parameter again, perform two subscriptions.
1130  * @tc.type: FUNC
1131  * @tc.require: The DiscUnpublish operates normally.
1132  */
1133 HWTEST_F(DiscManagerTest, DiscUnpublishTest004, TestSize.Level1)
1134 {
1135     DiscMgrInit();
1136     DiscPublish(MODULE_LNN, &g_pInnerInfo1);
1137 
1138     int32_t ret = DiscUnpublish(MODULE_LNN, TEST_PUBLISHINNER_ID1);
1139 
1140     ret = DiscUnpublish(MODULE_LNN, TEST_PUBLISHINNER_ID1);
1141     TEST_ASSERT_TRUE(ret != 0);
1142 
1143     DiscMgrDeinit();
1144 }
1145 
1146 /**
1147  * @tc.name: DiscUnpublishTest005
1148  * @tc.desc: Inner LNN module stop publish, use the wrong parameter.
1149  * @tc.type: FUNC
1150  * @tc.require: The DiscUppublish operates normally.
1151  */
1152 HWTEST_F(DiscManagerTest, DiscUnpublishTest005, TestSize.Level1)
1153 {
1154     DiscMgrInit();
1155     DiscPublish(MODULE_LNN, &g_pInnerInfo1);
1156 
1157     int32_t ret = DiscUnpublish((DiscModule)TEST_ERRO_MOUDULE1, TEST_PUBLISHINNER_ID);
1158     TEST_ASSERT_TRUE(ret != 0);
1159 
1160     DiscMgrDeinit();
1161 }
1162 
1163 /**
1164  * @tc.name: DiscUnpublishTest006
1165  * @tc.desc: Inner CONN module stop publish, the module initialized, Directly to unpubish.
1166  * @tc.type: FUNC
1167  * @tc.require: The DiscUnpublish operates normally.
1168  */
1169 HWTEST_F(DiscManagerTest, DiscUnpublishTest006, TestSize.Level1)
1170 {
1171     DiscMgrInit();
1172     int32_t ret = DiscUnpublish(MODULE_CONN, TEST_PUBLISHINNER_ID);
1173     TEST_ASSERT_TRUE(ret != 0);
1174     DiscMgrDeinit();
1175 }
1176 
1177 PublishInfo discUnpublishTestAbstractInfo001 = {
1178     .publishId = TEST_PUBLISHINNER_ID,
1179     .mode = DISCOVER_MODE_ACTIVE,
1180     .medium = AUTO,
1181     .freq = LOW,
1182     .capability = "hicall",
1183     .capabilityData = (unsigned char *)"capdata1",
1184     .dataLen = sizeof("capdata1")
1185 };
1186 
DiscUnpublishTestAbstract001(DiscModule module,PublishInfo * info)1187 void DiscUnpublishTestAbstract001(DiscModule module, PublishInfo *info)
1188 {
1189     DiscMgrInit();
1190 
1191     DiscPublish(module, info);
1192     int32_t ret = DiscUnpublish(module, info->publishId);
1193     TEST_ASSERT_TRUE(ret == 0);
1194 
1195     info->freq = MID;
1196     DiscPublish(module, info);
1197     ret = DiscUnpublish(module, info->publishId);
1198     TEST_ASSERT_TRUE(ret == 0);
1199 
1200     info->freq = HIGH;
1201     DiscPublish(module, info);
1202     ret = DiscUnpublish(module, info->publishId);
1203     TEST_ASSERT_TRUE(ret == 0);
1204 
1205     info->freq = SUPER_HIGH;
1206     DiscPublish(module, info);
1207     ret = DiscUnpublish(module, info->publishId);
1208     TEST_ASSERT_TRUE(ret == 0);
1209 
1210     info->freq = EXTREME_HIGH;
1211     DiscPublish(module, info);
1212     ret = DiscUnpublish(module, info->publishId);
1213     TEST_ASSERT_TRUE(ret == 0);
1214 
1215     info->freq = LOW;
1216     DiscMgrDeinit();
1217 }
1218 
1219 /**
1220  * @tc.name: DiscUnpublishTest007
1221  * @tc.desc: Inner LNN module active publish, use the normal parameter and different frequencies under AUTO.
1222  *           Inner CONN module active publish, use the normal parameter and different frequencies under AUTO.
1223  *           Inner LNN module active publish, use the normal parameter and different frequencies under BLE.
1224  *           Inner CONN module active publish, use the normal parameter and different frequencies under BLE.
1225  *           inner LNN module active publish, use the normal parameter and different frequencies under COAP.
1226  *           inner CONN module active publish, use the normal parameter and different frequencies under COAP.
1227  * @tc.type: FUNC
1228  * @tc.require: The DiscUnpublish operates normally.
1229  */
1230 HWTEST_F(DiscManagerTest, DiscUnpublishTest007, TestSize.Level1)
1231 {
1232     DiscUnpublishTestAbstract001(MODULE_LNN, &discUnpublishTestAbstractInfo001);
1233     DiscUnpublishTestAbstract001(MODULE_CONN, &discUnpublishTestAbstractInfo001);
1234 
1235     discUnpublishTestAbstractInfo001.medium = BLE;
1236     DiscUnpublishTestAbstract001(MODULE_LNN, &discUnpublishTestAbstractInfo001);
1237     DiscUnpublishTestAbstract001(MODULE_CONN, &discUnpublishTestAbstractInfo001);
1238 
1239     discUnpublishTestAbstractInfo001.medium = COAP;
1240     DiscUnpublishTestAbstract001(MODULE_LNN, &discUnpublishTestAbstractInfo001);
1241     DiscUnpublishTestAbstract001(MODULE_LNN, &discUnpublishTestAbstractInfo001);
1242 }
1243 
1244 /**
1245  * @tc.name: DiscStopAdvertiseTest001
1246  * @tc.desc: Inner CONN module stop discover, the module is not initialized.
1247  * @tc.type: FUNC
1248  * @tc.require: The DiscStopAdvertise operates normally.
1249  */
1250 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest001, TestSize.Level1)
1251 {
1252     int32_t ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
1253     TEST_ASSERT_TRUE(ret != 0);
1254 }
1255 
1256 /**
1257  * @tc.name: DiscStopAdvertiseTest002
1258  * @tc.desc: Inner module stop discover, use the wrong parameter.
1259  * @tc.type: FUNC
1260  * @tc.require: The DiscStopAdvertise operates normally.
1261  */
1262 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest002, TestSize.Level1)
1263 {
1264     DiscMgrInit();
1265     DiscStartAdvertise(MODULE_LNN, &g_sInnerInfo);
1266 
1267     int32_t ret = DiscStopAdvertise((DiscModule)TEST_ERRO_MOUDULE, TEST_SUBSCRIBEINNER_ID);
1268     TEST_ASSERT_TRUE(ret != 0);
1269 
1270     DiscMgrDeinit();
1271 }
1272 
1273 /**
1274  * @tc.name: DiscStopAdvertiseTest003
1275  * @tc.desc: Inner LNN module stop discover, use the normal parameter.
1276  * @tc.type: FUNC
1277  * @tc.require: The DiscStopAdvertise operates normally.
1278  */
1279 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest003, TestSize.Level1)
1280 {
1281     DiscMgrInit();
1282     DiscStartAdvertise(MODULE_LNN, &g_sInnerInfo);
1283 
1284     int32_t ret = DiscStopAdvertise(MODULE_LNN, TEST_SUBSCRIBEINNER_ID);
1285     TEST_ASSERT_TRUE(ret == 0);
1286 
1287     DiscMgrDeinit();
1288 }
1289 
1290 /**
1291  * @tc.name: DiscStopAdvertiseTest004
1292  * @tc.desc: Inner LNN module stop discover, use the same parameter again, perform two subscriptions.
1293  * @tc.type: FUNC
1294  * @tc.require: The DiscStopAdvertise operates normally.
1295  */
1296 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest004, TestSize.Level1)
1297 {
1298     DiscMgrInit();
1299     DiscStartAdvertise(MODULE_LNN, &g_sInnerInfo);
1300 
1301     int32_t ret = DiscStopAdvertise(MODULE_LNN, TEST_SUBSCRIBEINNER_ID);
1302     ret = DiscStopAdvertise(MODULE_LNN, TEST_SUBSCRIBEINNER_ID);
1303     TEST_ASSERT_TRUE(ret != 0);
1304 
1305     DiscMgrDeinit();
1306 }
1307 
1308 /**
1309  * @tc.name: DiscStopAdvertiseTest005
1310  * @tc.desc: Test inner module stop discover, use the wrong parameter.
1311 
1312 
1313  * @tc.type: FUNC
1314  * @tc.require:The DiscStopAdvertise operates normally.
1315  */
1316 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest005, TestSize.Level1)
1317 {
1318     DiscMgrInit();
1319     DiscStartAdvertise(MODULE_LNN, &g_sInnerInfo);
1320 
1321     int32_t ret = DiscStopAdvertise((DiscModule)TEST_ERRO_MOUDULE1, TEST_SUBSCRIBEINNER_ID);
1322     TEST_ASSERT_TRUE(ret != 0);
1323 
1324     DiscMgrDeinit();
1325 }
1326 
1327 /**
1328  * @tc.name: DiscStopAdvertiseTest006
1329  * @tc.desc: Test inner module stop discover, bur module is not start discover.
1330  * @tc.type: FUNC
1331  * @tc.require:The DiscStopAdvertise operates normally.
1332  */
1333 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest006, TestSize.Level1)
1334 {
1335     DiscMgrInit();
1336     int32_t ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
1337     TEST_ASSERT_TRUE(ret != 0);
1338     DiscMgrDeinit();
1339 }
1340 
1341 SubscribeInfo discStopAdvertiseTestAbstractInfo001 = {
1342     .subscribeId = TEST_SUBSCRIBEINNER_ID,
1343     .mode = DISCOVER_MODE_ACTIVE,
1344     .medium = AUTO,
1345     .freq = LOW,
1346     .isSameAccount = true,
1347     .isWakeRemote = false,
1348     .capability = "dvKit",
1349     .capabilityData = (unsigned char *)"capdata3",
1350     .dataLen = sizeof("capdata3")
1351 };
1352 
DiscStopAdvertiseTestAbstract001(DiscModule module,SubscribeInfo * info)1353 void DiscStopAdvertiseTestAbstract001(DiscModule module, SubscribeInfo *info)
1354 {
1355     DiscMgrInit();
1356 
1357     DiscStartAdvertise(module, info);
1358     int32_t ret = DiscStopAdvertise(module, info->subscribeId);
1359     TEST_ASSERT_TRUE(ret == 0);
1360 
1361     info->freq = MID;
1362     DiscStartAdvertise(module, info);
1363     ret = DiscStopAdvertise(module, info->subscribeId);
1364     TEST_ASSERT_TRUE(ret == 0);
1365 
1366     info->freq = HIGH;
1367     DiscStartAdvertise(module, info);
1368     ret = DiscStopAdvertise(module, info->subscribeId);
1369     TEST_ASSERT_TRUE(ret == 0);
1370 
1371     info->freq = SUPER_HIGH;
1372     DiscStartAdvertise(module, info);
1373     ret = DiscStopAdvertise(module, info->subscribeId);
1374     TEST_ASSERT_TRUE(ret == 0);
1375 
1376     info->freq = EXTREME_HIGH;
1377     DiscStartAdvertise(module, info);
1378     ret = DiscStopAdvertise(module, info->subscribeId);
1379     TEST_ASSERT_TRUE(ret == 0);
1380 
1381     info->freq = LOW;
1382     DiscMgrDeinit();
1383 }
1384 
1385 /**
1386  * @tc.name: DiscStopAdvertiseTest007
1387  * @tc.desc: Test inner module active discover, use Diff Freq Under the AUTO of MODULE_LNN.
1388  *           Test inner module active discover, use Diff Freq Under the AUTO of MODULE_CONN.
1389  *           Test inner module active discover, use Diff Freq Under the BLE of MODULE_LNN.
1390  *           Test inner module active discover, use Diff Freq Under the BLE of MODULE_CONN.
1391  *           Test inner module active discover, use Diff Freq Under the COAP of MODULE_LNN.
1392  *           Test inner module active discover, use Diff Freq Under the COAP of MODULE_CONN.
1393  * @tc.type: FUNC
1394  * @tc.require:The DiscStopAdvertise operates normally.
1395  */
1396 HWTEST_F(DiscManagerTest, DiscStopAdvertiseTest007, TestSize.Level1)
1397 {
1398     DiscStopAdvertiseTestAbstract001(MODULE_LNN, &discStopAdvertiseTestAbstractInfo001);
1399     DiscStopAdvertiseTestAbstract001(MODULE_CONN, &discStopAdvertiseTestAbstractInfo001);
1400 
1401     discStopAdvertiseTestAbstractInfo001.medium = BLE;
1402     DiscStopAdvertiseTestAbstract001(MODULE_LNN, &discStopAdvertiseTestAbstractInfo001);
1403     DiscStopAdvertiseTestAbstract001(MODULE_CONN, &discStopAdvertiseTestAbstractInfo001);
1404 
1405     discStopAdvertiseTestAbstractInfo001.medium = COAP;
1406     DiscStopAdvertiseTestAbstract001(MODULE_LNN, &discStopAdvertiseTestAbstractInfo001);
1407     DiscStopAdvertiseTestAbstract001(MODULE_CONN, &discStopAdvertiseTestAbstractInfo001);
1408 }
1409 
1410 /**
1411  * @tc.name: PublishServiceTest001
1412  * @tc.desc: Extern module publish, the module is not initialized.
1413  * @tc.type: FUNC
1414  * @tc.require: The DiscPublishService operates normally.
1415  */
1416 HWTEST_F(DiscManagerTest, PublishServiceTest001, TestSize.Level1)
1417 {
1418     int32_t ret = DiscPublishService("pkgname1", &g_pInfo);
1419     TEST_ASSERT_TRUE(ret != 0);
1420 }
1421 
1422 /**
1423  * @tc.name: PublishServiceTest002
1424  * @tc.desc: Extern module active publish, use the wrong parameter.
1425  * @tc.type: FUNC
1426  * @tc.require: The DiscPublishService operates normally.
1427  */
1428 HWTEST_F(DiscManagerTest, PublishServiceTest002, TestSize.Level1)
1429 {
1430     PublishInfo testInfo = {
1431         .publishId = TEST_PUBLISH_ID,
1432         .mode = DISCOVER_MODE_ACTIVE,
1433         .medium = COAP,
1434         .freq = MID,
1435         .capability = "dvKit",
1436         .capabilityData = (unsigned char *)"capdata2",
1437         .dataLen = sizeof("capdata2")
1438     };
1439 
1440     DiscMgrInit();
1441 
1442     int32_t ret = DiscPublishService(NULL, &testInfo);
1443     TEST_ASSERT_TRUE(ret != 0);
1444 
1445     ret = DiscPublishService(g_erroPkgName, &testInfo);
1446     TEST_ASSERT_TRUE(ret != 0);
1447 
1448     ret = DiscPublishService("pkgname1", NULL);
1449     TEST_ASSERT_TRUE(ret != 0);
1450 
1451     ret = DiscPublishService("pkgname1", &testInfo);
1452     TEST_ASSERT_TRUE(ret != 0);
1453 
1454     testInfo.medium = (ExchangeMedium)(COAP + 1);
1455     ret = DiscPublishService("pkgname1", &testInfo);
1456     TEST_ASSERT_TRUE(ret != 0);
1457     testInfo.medium = COAP;
1458 
1459     testInfo.mode = (DiscoverMode)(DISCOVER_MODE_ACTIVE + 1);
1460     ret = DiscPublishService("pkgname1", &testInfo);
1461     TEST_ASSERT_TRUE(ret != 0);
1462     testInfo.mode = DISCOVER_MODE_ACTIVE;
1463 
1464     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
1465     ret = DiscPublishService("pkgname1", &testInfo);
1466     TEST_ASSERT_TRUE(ret != 0);
1467     testInfo.freq = LOW;
1468 
1469     testInfo.capability = "dvKit";
1470     testInfo.capabilityData = NULL;
1471     ret = DiscPublishService("pkgname1", &testInfo);
1472     TEST_ASSERT_TRUE(ret != 0);
1473     testInfo.capabilityData = (unsigned char *)"capdata1";
1474 
1475     testInfo.dataLen = ERRO_CAPDATA_LEN;
1476     ret = DiscPublishService("pkgname1", &testInfo);
1477     TEST_ASSERT_TRUE(ret != 0);
1478     testInfo.dataLen = sizeof("capdata1");
1479 
1480     DiscMgrDeinit();
1481 }
1482 
1483 /**
1484  * @tc.name: PublishServiceTest003
1485  * @tc.desc: Extern module publish, use the normal parameter.
1486  * @tc.type: FUNC
1487  * @tc.require: The DiscPublishService operates normally
1488  */
1489 HWTEST_F(DiscManagerTest, PublishServiceTest003, TestSize.Level1)
1490 {
1491     DiscMgrInit();
1492 
1493     int32_t ret = DiscPublishService("pkgname1", &g_pInfo);
1494     TEST_ASSERT_TRUE(ret == 0);
1495 
1496     ret = DiscPublishService("pkgname1", &g_pInfo1);
1497     TEST_ASSERT_TRUE(ret == 0);
1498 
1499     ret = DiscPublishService(g_corrPkgName, &g_pInfo);
1500     TEST_ASSERT_TRUE(ret == 0);
1501 
1502     DiscMgrDeinit();
1503 }
1504 
1505 /**
1506  * @tc.name: PublishServiceTest004
1507  * @tc.desc: Extern module publish, use the same parameter again, perform two subscriptions.
1508  * @tc.type: FUNC
1509  * @tc.require: The DiscPublishService operates normally.
1510  */
1511 HWTEST_F(DiscManagerTest, PublishServiceTest004, TestSize.Level1)
1512 {
1513     DiscMgrInit();
1514 
1515     int32_t ret = DiscPublishService("pkgname1", &g_pInfo);
1516     ret = DiscPublishService("pkgname1", &g_pInfo);
1517     TEST_ASSERT_TRUE(ret != 0);
1518 
1519     DiscMgrDeinit();
1520 }
1521 
1522 /**
1523  * @tc.name: PublishServiceTest005
1524  * @tc.desc: Test extern module active publish, use the wrong Medium and Freq Under the COAP.
1525  * @tc.type: FUNC
1526  * @tc.require: The DiscPublishService operates normally.
1527  */
1528 HWTEST_F(DiscManagerTest, PublishServiceTest005, TestSize.Level1)
1529 {
1530     PublishInfo testInfo = {
1531         .publishId = TEST_PUBLISH_ID,
1532         .mode = DISCOVER_MODE_ACTIVE,
1533         .medium = COAP,
1534         .freq = MID,
1535         .capability = "dvKit",
1536         .capabilityData = (unsigned char *)"capdata2",
1537         .dataLen = sizeof("capdata2")
1538     };
1539 
1540     DiscMgrInit();
1541 
1542     testInfo.medium = (ExchangeMedium)(AUTO - 1);
1543     int32_t ret = DiscPublishService("pkgname1", &testInfo);
1544     TEST_ASSERT_TRUE(ret != 0);
1545     testInfo.medium = COAP;
1546 
1547     testInfo.freq = (ExchangeFreq)(LOW - 1);
1548     ret = DiscPublishService("pkgname1", &testInfo);
1549     TEST_ASSERT_TRUE(ret != 0);
1550     testInfo.freq = LOW;
1551 
1552     DiscMgrDeinit();
1553 }
1554 
1555 /**
1556  * @tc.name: PublishServiceTest006
1557  * @tc.desc: Test extern module active publish, use wrong Medium and Freq Under the BLE.
1558  * @tc.type: FUNC
1559  * @tc.require: The DiscPublishService operates normally.
1560  */
1561 HWTEST_F(DiscManagerTest, PublishServiceTest006, TestSize.Level1)
1562 {
1563     PublishInfo testInfo = {
1564         .publishId = TEST_PUBLISH_ID,
1565         .mode = DISCOVER_MODE_ACTIVE,
1566         .medium = BLE,
1567         .freq = MID,
1568         .capability = "dvKit",
1569         .capabilityData = (unsigned char *)"capdata2",
1570         .dataLen = sizeof("capdata2")
1571     };
1572 
1573     DiscMgrInit();
1574 
1575     testInfo.medium = (ExchangeMedium)(AUTO - 1);
1576     int32_t ret = DiscPublishService("pkgname1", &testInfo);
1577     TEST_ASSERT_TRUE(ret != 0);
1578     testInfo.medium = COAP;
1579 
1580     testInfo.freq = (ExchangeFreq)(LOW - 1);
1581     ret = DiscPublishService("pkgname1", &testInfo);
1582     TEST_ASSERT_TRUE(ret != 0);
1583     testInfo.freq = LOW;
1584 
1585     DiscMgrDeinit();
1586 }
1587 
1588 /**
1589  * @tc.name: PublishServiceTest007
1590  * @tc.desc: Test extern module active publish, use wrong Medium and Freq Under the AUTO.
1591  * @tc.type: FUNC
1592  * @tc.require: The DiscPublishService operates normally.
1593  */
1594 HWTEST_F(DiscManagerTest, PublishServiceTest007, TestSize.Level1)
1595 {
1596     PublishInfo testInfo = {
1597         .publishId = TEST_PUBLISH_ID,
1598         .mode = DISCOVER_MODE_ACTIVE,
1599         .medium = AUTO,
1600         .freq = MID,
1601         .capability = "dvKit",
1602         .capabilityData = (unsigned char *)"capdata2",
1603         .dataLen = sizeof("capdata2")
1604     };
1605 
1606     DiscMgrInit();
1607 
1608     testInfo.medium = (ExchangeMedium)(AUTO - 1);
1609     int32_t ret = DiscPublishService("pkgname1", &testInfo);
1610     TEST_ASSERT_TRUE(ret != 0);
1611     testInfo.medium = COAP;
1612 
1613     testInfo.freq = (ExchangeFreq)(LOW - 1);
1614     ret = DiscPublishService("pkgname1", &testInfo);
1615     TEST_ASSERT_TRUE(ret != 0);
1616     testInfo.freq = LOW;
1617 
1618     DiscMgrDeinit();
1619 }
1620 
1621 PublishInfo publishServiceTestAbstractInfo = {
1622     .publishId = TEST_PUBLISH_ID,
1623     .mode = DISCOVER_MODE_ACTIVE,
1624     .medium = AUTO,
1625     .freq = LOW,
1626     .capability = "dvKit",
1627     .capabilityData = (unsigned char *)"capdata2",
1628     .dataLen = sizeof("capdata2")
1629 };
1630 
PublishServiceTestAbstract001(PublishInfo * info)1631 void PublishServiceTestAbstract001(PublishInfo *info)
1632 {
1633     DiscMgrInit();
1634 
1635     int32_t ret = DiscPublishService("pkgname1", info);
1636     TEST_ASSERT_TRUE(ret == 0);
1637     DiscUnPublishService("pkgname1", info->publishId);
1638 
1639     info->freq = MID;
1640     ret = DiscPublishService("pkgname1", info);
1641     TEST_ASSERT_TRUE(ret == 0);
1642     DiscUnPublishService("pkgname1", info->publishId);
1643 
1644     info->freq = HIGH;
1645     ret = DiscPublishService("pkgname1", info);
1646     TEST_ASSERT_TRUE(ret == 0);
1647     DiscUnPublishService("pkgname1", info->publishId);
1648 
1649     info->freq = SUPER_HIGH;
1650     ret = DiscPublishService("pkgname1", info);
1651     TEST_ASSERT_TRUE(ret == 0);
1652     DiscUnPublishService("pkgname1", info->publishId);
1653 
1654     info->freq = EXTREME_HIGH;
1655     ret = DiscPublishService("pkgname1", info);
1656     TEST_ASSERT_TRUE(ret == 0);
1657     DiscUnPublishService("pkgname1", info->publishId);
1658 
1659     info->freq = LOW;
1660     DiscMgrDeinit();
1661 }
1662 
1663 /**
1664  * @tc.name: PublishServiceTest008
1665  * @tc.desc: Test extern module active publish, use Diff Freq Under the AUTO.
1666  *           Test extern module passive publish, use Diff Freq Under the AUTO.
1667  *           Test extern module active publish, use Diff Freq Under the BLE.
1668  *           Test extern module passive publish, use Diff Freq Under the BLE.
1669  *           Test extern module active publish, use Diff Freq Under the COAP.
1670  *           Test extern module passive publish, use Diff Freq Under the COAP.
1671  * @tc.type: FUNC
1672  * @tc.require: The DiscPublishService operates normally.
1673  */
1674 HWTEST_F(DiscManagerTest, PublishServiceTest008, TestSize.Level1)
1675 {
1676     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1677 
1678     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_PASSIVE;
1679     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1680 
1681     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_ACTIVE;
1682     publishServiceTestAbstractInfo.medium = BLE;
1683     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1684 
1685     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_PASSIVE;
1686     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1687 
1688     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_ACTIVE;
1689     publishServiceTestAbstractInfo.medium = COAP;
1690     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1691 
1692     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_ACTIVE;
1693     PublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
1694 }
1695 
1696 /**
1697  * @tc.name: StartDiscoveryTest001
1698  * @tc.desc: Extern module discover, the module is not initialized.
1699  * @tc.type: FUNC
1700  * @tc.require: The DiscStartDiscovery operates normally.
1701  */
1702 HWTEST_F(DiscManagerTest, StartDiscoveryTest001, TestSize.Level1)
1703 {
1704     int32_t ret = DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
1705     TEST_ASSERT_TRUE(ret != 0);
1706 }
1707 
1708 /**
1709  * @tc.name: StartDiscoveryTest002
1710  * @tc.desc: Extern module active discover, use the wrong parameter.
1711  * @tc.type: FUNC
1712  * @tc.require: The DiscStartDiscovery operates normally
1713  */
1714 HWTEST_F(DiscManagerTest, StartDiscoveryTest002, TestSize.Level1)
1715 {
1716     SubscribeInfo testInfo = {
1717         .subscribeId = TEST_SUBSCRIBEINNER_ID,
1718         .mode = DISCOVER_MODE_ACTIVE,
1719         .medium = COAP,
1720         .freq = MID,
1721         .isSameAccount = true,
1722         .isWakeRemote = false,
1723         .capability = "dvKit",
1724         .capabilityData = (unsigned char *)"capdata3",
1725         .dataLen = sizeof("capdata3")
1726     };
1727 
1728     DiscMgrInit();
1729 
1730     int32_t ret = DiscStartDiscovery(NULL, &testInfo, &g_subscribeCb);
1731     TEST_ASSERT_TRUE(ret != 0);
1732 
1733     ret = DiscStartDiscovery(g_erroPkgName, &testInfo, &g_subscribeCb);
1734     TEST_ASSERT_TRUE(ret != 0);
1735 
1736     ret = DiscStartDiscovery("pkgname1", NULL, &g_subscribeCb);
1737     TEST_ASSERT_TRUE(ret != 0);
1738 
1739     ret = DiscStartDiscovery("pkgname1", &testInfo, NULL);
1740     TEST_ASSERT_TRUE(ret != 0);
1741 
1742     testInfo.medium = (ExchangeMedium)(COAP + 1);
1743     ret = DiscStartDiscovery("pkgname1", &testInfo, &g_subscribeCb);
1744     TEST_ASSERT_TRUE(ret != 0);
1745     testInfo.medium = COAP;
1746 
1747     testInfo.mode = (DiscoverMode)(DISCOVER_MODE_ACTIVE + 1);
1748     ret = DiscStartDiscovery("pkgname1", &testInfo, &g_subscribeCb);
1749     TEST_ASSERT_TRUE(ret != 0);
1750     testInfo.mode = DISCOVER_MODE_ACTIVE;
1751 
1752     testInfo.freq = (ExchangeFreq)(FREQ_BUTT);
1753     ret = DiscStartDiscovery("pkgname1", &testInfo, &g_subscribeCb);
1754     TEST_ASSERT_TRUE(ret != 0);
1755     testInfo.freq = LOW;
1756 
1757     testInfo.capability = "dvKit";
1758     testInfo.capabilityData = NULL;
1759     ret = DiscStartDiscovery("pkgname1", &testInfo, &g_subscribeCb);
1760     TEST_ASSERT_TRUE(ret != 0);
1761     testInfo.capabilityData = (unsigned char *)"capdata1";
1762 
1763     testInfo.dataLen = ERRO_CAPDATA_LEN;
1764     ret = DiscStartDiscovery("pkgname1", &testInfo, &g_subscribeCb);
1765     TEST_ASSERT_TRUE(ret != 0);
1766     testInfo.dataLen = sizeof("capdata1");
1767 
1768     DiscMgrDeinit();
1769 }
1770 
1771 /**
1772  * @tc.name: StartDiscoveryTest003
1773  * @tc.desc: Extern module discover, use the normal parameter.
1774  * @tc.type: FUNC
1775  * @tc.require: The DiscStartDiscovery operates normally.
1776  */
1777 HWTEST_F(DiscManagerTest, StartDiscoveryTest003, TestSize.Level1)
1778 {
1779     DiscMgrInit();
1780 
1781     int32_t ret = DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
1782     TEST_ASSERT_TRUE(ret == 0);
1783 
1784     ret = DiscStartDiscovery("pkgname1", &g_sInfo1, &g_subscribeCb);
1785     TEST_ASSERT_TRUE(ret == 0);
1786 
1787     ret = DiscStartDiscovery(g_corrPkgName, &g_sInfo, &g_subscribeCb);
1788     TEST_ASSERT_TRUE(ret == 0);
1789 
1790     DiscMgrDeinit();
1791 }
1792 
1793 /**
1794  * @tc.name: StartDiscoveryTest004
1795  * @tc.desc: Extern module discover, use the same parameter again, perform two subscriptions.
1796  * @tc.type: FUNC
1797  * @tc.require: The DiscStartDiscovery operates normally.
1798  */
1799 HWTEST_F(DiscManagerTest, StartDiscoveryTest004, TestSize.Level1)
1800 {
1801     DiscMgrInit();
1802 
1803     int32_t ret = DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
1804     ret = DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
1805     TEST_ASSERT_TRUE(ret != 0);
1806 
1807     DiscMgrDeinit();
1808 }
1809 
1810 SubscribeInfo startDiscoveryTestAbstractInfo002 = {
1811     .subscribeId = TEST_SUBSCRIBEINNER_ID,
1812     .mode = DISCOVER_MODE_ACTIVE,
1813     .medium = COAP,
1814     .freq = MID,
1815     .isSameAccount = true,
1816     .isWakeRemote = false,
1817     .capability = "dvKit",
1818     .capabilityData = (unsigned char*)"capdata3",
1819     .dataLen = sizeof("capdata3")
1820 };
1821 
StartDiscoveryTestAbstract002(SubscribeInfo * info)1822 void StartDiscoveryTestAbstract002(SubscribeInfo *info)
1823 {
1824     DiscMgrInit();
1825 
1826     info->medium = (ExchangeMedium)(AUTO - 1);
1827     int32_t ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1828     TEST_ASSERT_TRUE(ret != 0);
1829     info->medium = COAP;
1830 
1831     info->freq = (ExchangeFreq)(LOW - 1);
1832     ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1833     TEST_ASSERT_TRUE(ret != 0);
1834     info->freq = LOW;
1835 
1836     info->medium = COAP;
1837     info->freq = MID;
1838     DiscMgrDeinit();
1839 }
1840 
1841 /**
1842  * @tc.name: StartDiscoveryTest005
1843  * @tc.desc: Test extern module active discover, use wrong Medium and Freq Under the COAP.
1844  *           Test extern module active discover, use wrong Medium and Freq Under the BLE.
1845  *           Test extern module active discover, use wrong Medium and Freq Under the AUTO.
1846  * @tc.type: FUNC
1847  * @tc.require: The DiscStartDiscovery operates normally.
1848  */
1849 HWTEST_F(DiscManagerTest, StartDiscoveryTest005, TestSize.Level1)
1850 {
1851     StartDiscoveryTestAbstract002(&startDiscoveryTestAbstractInfo002);
1852 
1853     startDiscoveryTestAbstractInfo002.medium = BLE;
1854     StartDiscoveryTestAbstract002(&startDiscoveryTestAbstractInfo002);
1855 
1856     startDiscoveryTestAbstractInfo002.medium = AUTO;
1857     StartDiscoveryTestAbstract002(&startDiscoveryTestAbstractInfo002);
1858 }
1859 
1860 SubscribeInfo startDiscoveryTestAbstractInfo001 = {
1861     .subscribeId = TEST_SUBSCRIBE_ID,
1862     .mode = DISCOVER_MODE_ACTIVE,
1863     .medium = AUTO,
1864     .freq = LOW,
1865     .isSameAccount = true,
1866     .isWakeRemote = false,
1867     .capability = "dvKit",
1868     .capabilityData = (unsigned char *)"capdata3",
1869     .dataLen = sizeof("capdata3")
1870 };
1871 
StartDiscoveryTestAbstract001(SubscribeInfo * info)1872 void StartDiscoveryTestAbstract001(SubscribeInfo *info)
1873 {
1874     DiscMgrInit();
1875 
1876     int32_t ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1877     TEST_ASSERT_TRUE(ret == 0);
1878     DiscStopDiscovery("pkgname1", info->subscribeId);
1879 
1880     info->freq = MID;
1881     ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1882     TEST_ASSERT_TRUE(ret == 0);
1883     DiscStopDiscovery("pkgname1", info->subscribeId);
1884 
1885     info->freq = HIGH;
1886     ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1887     TEST_ASSERT_TRUE(ret == 0);
1888     DiscStopDiscovery("pkgname1", info->subscribeId);
1889 
1890     info->freq = SUPER_HIGH;
1891     ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1892     TEST_ASSERT_TRUE(ret == 0);
1893     DiscStopDiscovery("pkgname1", info->subscribeId);
1894 
1895     info->freq = EXTREME_HIGH;
1896     ret = DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
1897     TEST_ASSERT_TRUE(ret == 0);
1898     DiscStopDiscovery("pkgname1", info->subscribeId);
1899 
1900     DiscMgrDeinit();
1901 }
1902 
1903 /**
1904  * @tc.name: StartDiscoveryTest006
1905  * @tc.desc: Test extern module active discover, use Diff Freq Under the AUTO.
1906  *           Test extern module passive discover, use Diff Freq Under the AUTO.
1907  *           Test extern module active discover, use Diff Freq Under the BLE.
1908  *           Test extern module discover, use the normal parameter and different frequencies under passive COAP.
1909  *           Test extern module discover, use the normal parameter and different frequencies under passive BLE.
1910  *           Test extern module discover, use the normal parameter and different frequencies under active COAP.
1911  * @tc.type: FUNC
1912  * @tc.require: The DiscStartDiscovery operates normally.
1913  */
1914 HWTEST_F(DiscManagerTest, StartDiscoveryTest006, TestSize.Level1)
1915 {
1916     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1917 
1918     startDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_PASSIVE;
1919     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1920 
1921     startDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_ACTIVE;
1922     startDiscoveryTestAbstractInfo001.medium = BLE;
1923     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1924 
1925     startDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_PASSIVE;
1926     startDiscoveryTestAbstractInfo001.medium = COAP;
1927     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1928 
1929     startDiscoveryTestAbstractInfo001.medium = BLE;
1930     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1931 
1932     startDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_ACTIVE;
1933     startDiscoveryTestAbstractInfo001.medium = COAP;
1934     StartDiscoveryTestAbstract001(&startDiscoveryTestAbstractInfo001);
1935 }
1936 
1937 /**
1938  * @tc.name: UnPublishServiceTest001
1939  * @tc.desc: Extern module stop publish, the module is not initialized.
1940  * @tc.type: FUNC
1941  * @tc.require: The DiscUnPublishService operates normally.
1942  */
1943 HWTEST_F(DiscManagerTest, UnPublishServiceTest001, TestSize.Level1)
1944 {
1945     int32_t ret = DiscUnPublishService("pkgname1", TEST_PUBLISH_ID);
1946     TEST_ASSERT_TRUE(ret != 0);
1947 }
1948 
1949 /**
1950  * @tc.name: UnPublishServiceTest002
1951  * @tc.desc: Extern module stop publish, use the wrong parameter.
1952  * @tc.type: FUNC
1953  * @tc.require: The DiscUnPublishService operates normally.
1954  */
1955 HWTEST_F(DiscManagerTest, UnPublishServiceTest002, TestSize.Level1)
1956 {
1957     DiscMgrInit();
1958     DiscPublishService("pkgname1", &g_pInfo);
1959 
1960     int32_t ret = DiscUnPublishService(NULL, TEST_PUBLISH_ID);
1961     TEST_ASSERT_TRUE(ret != 0);
1962 
1963     ret = DiscUnPublishService(g_erroPkgName, TEST_PUBLISH_ID);
1964     TEST_ASSERT_TRUE(ret != 0);
1965 
1966     ret = DiscUnPublishService("pkgname2", TEST_PUBLISH_ID);
1967     TEST_ASSERT_TRUE(ret != 0);
1968 
1969     DiscMgrDeinit();
1970 }
1971 
1972 /**
1973  * @tc.name: UnPublishServiceTest003
1974  * @tc.desc: Extern module stop publish, use the normal parameter.
1975  * @tc.type: FUNC
1976  * @tc.require: The DiscUnPublishService operates normally.
1977  */
1978 HWTEST_F(DiscManagerTest, UnPublishServiceTest003, TestSize.Level1)
1979 {
1980     DiscMgrInit();
1981     DiscPublishService("pkgname1", &g_pInfo);
1982     DiscPublishService("pkgname1", &g_pInfo1);
1983     DiscPublishService(g_corrPkgName, &g_pInfo);
1984 
1985     int32_t ret = DiscUnPublishService("pkgname1", TEST_PUBLISH_ID);
1986     TEST_ASSERT_TRUE(ret == 0);
1987 
1988     ret = DiscUnPublishService("pkgname1", TEST_PUBLISH_ID1);
1989     TEST_ASSERT_TRUE(ret == 0);
1990 
1991     ret = DiscUnPublishService(g_corrPkgName, TEST_PUBLISH_ID);
1992     TEST_ASSERT_TRUE(ret == 0);
1993 
1994     DiscMgrDeinit();
1995 }
1996 
1997 /**
1998  * @tc.name: UnPublishServiceTest004
1999  * @tc.desc: Extern module stop publish, release the same parameter again, perform two subscriptions.
2000  * @tc.type: FUNC
2001  * @tc.require: The DiscUnPublishService operates normally.
2002  */
2003 HWTEST_F(DiscManagerTest, UnPublishServiceTest004, TestSize.Level1)
2004 {
2005     DiscMgrInit();
2006     DiscPublishService("pkgname1", &g_pInfo);
2007 
2008     int32_t ret = DiscUnPublishService("pkgname1", TEST_PUBLISH_ID);
2009     ret = DiscUnPublishService("pkgname1", TEST_PUBLISH_ID);
2010     TEST_ASSERT_TRUE(ret != 0);
2011 
2012     DiscMgrDeinit();
2013 }
2014 
UnPublishServiceTestAbstract001(PublishInfo * info)2015 void UnPublishServiceTestAbstract001(PublishInfo *info)
2016 {
2017     DiscMgrInit();
2018 
2019     DiscPublishService("pkgname1", info);
2020     int32_t ret = DiscUnPublishService("pkgname1", info->publishId);
2021     TEST_ASSERT_TRUE(ret == 0);
2022 
2023     info->freq = MID;
2024     DiscPublishService("pkgname1", info);
2025     ret = DiscUnPublishService("pkgname1", info->publishId);
2026     TEST_ASSERT_TRUE(ret == 0);
2027 
2028     info->freq = HIGH;
2029     DiscPublishService("pkgname1", info);
2030     ret = DiscUnPublishService("pkgname1", info->publishId);
2031     TEST_ASSERT_TRUE(ret == 0);
2032 
2033     info->freq = SUPER_HIGH;
2034     DiscPublishService("pkgname1", info);
2035     ret = DiscUnPublishService("pkgname1", info->publishId);
2036     TEST_ASSERT_TRUE(ret == 0);
2037 
2038     info->freq = EXTREME_HIGH;
2039     DiscPublishService("pkgname1", info);
2040     ret = DiscUnPublishService("pkgname1", info->publishId);
2041     TEST_ASSERT_TRUE(ret == 0);
2042 
2043     DiscMgrDeinit();
2044 }
2045 
2046 /**
2047  * @tc.name: UnPublishServiceTest005
2048  * @tc.desc: Extern module stop publish, use the normal parameter and different frequencies under active COAP.
2049  *           Extern module stop publish, use the normal parameter and different frequencies under passive COAP.
2050  *           Extern module stop publish, use the normal parameter and different frequencies under active BLE.
2051  *           Extern module stop publish, use the normal parameter and different frequencies under passive BLE.
2052  *           Extern module stop publish, use the normal parameter and different frequencies under active AUTO.
2053  *           Extern module stop publish, use the normal parameter and different frequencies under passive AUTO.
2054  * @tc.type: FUNC
2055  * @tc.require: The DiscUnPublishService operates normally.
2056  */
2057 HWTEST_F(DiscManagerTest, UnPublishServiceTest005, TestSize.Level1)
2058 {
2059     publishServiceTestAbstractInfo.medium = AUTO;
2060     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2061 
2062     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_PASSIVE;
2063     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2064 
2065     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_ACTIVE;
2066     publishServiceTestAbstractInfo.medium = BLE;
2067     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2068 
2069     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_PASSIVE;
2070     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2071 
2072     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_ACTIVE;
2073     publishServiceTestAbstractInfo.medium = AUTO;
2074     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2075 
2076     publishServiceTestAbstractInfo.mode = DISCOVER_MODE_PASSIVE;
2077     UnPublishServiceTestAbstract001(&publishServiceTestAbstractInfo);
2078 }
2079 
2080 /**
2081  * @tc.name: StopDiscoveryTest001
2082  * @tc.desc: Extern module stop discover, the module is not initialized.
2083  * @tc.type: FUNC
2084  * @tc.require: The DiscStopDiscovery operates normally
2085  */
2086 HWTEST_F(DiscManagerTest, StopDiscoveryTest001, TestSize.Level1)
2087 {
2088     int32_t ret = DiscStopDiscovery("pkgname1", TEST_SUBSCRIBE_ID);
2089     TEST_ASSERT_TRUE(ret != 0);
2090 }
2091 
2092 /**
2093  * @tc.name: StopDiscoveryTest002
2094  * @tc.desc: Extern module stop discover, use the wrong parameter.
2095  * @tc.type: FUNC
2096  * @tc.require: The DiscStopDiscovery operates normally
2097  */
2098 HWTEST_F(DiscManagerTest, StopDiscoveryTest002, TestSize.Level1)
2099 {
2100     DiscMgrInit();
2101     DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
2102 
2103     int32_t ret = DiscStopDiscovery(NULL, TEST_SUBSCRIBE_ID);
2104     TEST_ASSERT_TRUE(ret != 0);
2105 
2106     ret = DiscStopDiscovery(g_erroPkgName, TEST_SUBSCRIBE_ID);
2107     TEST_ASSERT_TRUE(ret != 0);
2108 
2109     ret = DiscStopDiscovery("pkgname2", TEST_SUBSCRIBE_ID);
2110     TEST_ASSERT_TRUE(ret != 0);
2111 
2112     DiscMgrDeinit();
2113 }
2114 
2115 /**
2116  * @tc.name: StopDiscoveryTest003
2117  * @tc.desc: Extern module stop discover, use the normal parameter.
2118  * @tc.type: FUNC
2119  * @tc.require: The DiscStopDiscovery operates normally
2120  */
2121 HWTEST_F(DiscManagerTest, StopDiscoveryTest003, TestSize.Level1)
2122 {
2123     DiscMgrInit();
2124     DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
2125     DiscStartDiscovery("pkgname1", &g_sInfo1, &g_subscribeCb);
2126     DiscStartDiscovery(g_corrPkgName, &g_sInfo, &g_subscribeCb);
2127 
2128     int32_t ret = DiscStopDiscovery("pkgname1", TEST_SUBSCRIBE_ID);
2129     TEST_ASSERT_TRUE(ret == 0);
2130 
2131     ret = DiscStopDiscovery("pkgname1", TEST_SUBSCRIBE_ID1);
2132     TEST_ASSERT_TRUE(ret == 0);
2133 
2134     ret = DiscStopDiscovery(g_corrPkgName, TEST_SUBSCRIBE_ID);
2135     TEST_ASSERT_TRUE(ret == 0);
2136 
2137     DiscMgrDeinit();
2138 }
2139 
2140 /**
2141  * @tc.name: StopDiscoveryTest004
2142  * @tc.desc: Extern module stop discover, release the same parameter again, perform two subscriptions.
2143  * @tc.type: FUNC
2144  * @tc.require: The DiscStopDiscovery operates normally
2145  */
2146 HWTEST_F(DiscManagerTest, StopDiscoveryTest004, TestSize.Level1)
2147 {
2148     DiscMgrInit();
2149     DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
2150 
2151     int32_t ret = DiscStopDiscovery("pkgname1", TEST_SUBSCRIBE_ID);
2152     ret = DiscStopDiscovery("pkgname1", TEST_SUBSCRIBE_ID);
2153     TEST_ASSERT_TRUE(ret != 0);
2154 
2155     DiscMgrDeinit();
2156 }
2157 
2158 SubscribeInfo stopDiscoveryTestAbstractInfo001 = {
2159     .subscribeId = TEST_SUBSCRIBE_ID,
2160     .mode = DISCOVER_MODE_ACTIVE,
2161     .medium = COAP,
2162     .freq = LOW,
2163     .isSameAccount = true,
2164     .isWakeRemote = false,
2165     .capability = "dvKit",
2166     .capabilityData = (unsigned char *)"capdata3",
2167     .dataLen = sizeof("capdata3")
2168 };
2169 
StopDiscoveryTestAbstract001(SubscribeInfo * info)2170 void StopDiscoveryTestAbstract001(SubscribeInfo *info)
2171 {
2172     DiscMgrInit();
2173 
2174     DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
2175     int32_t ret = DiscStopDiscovery("pkgname1", info->subscribeId);
2176     TEST_ASSERT_TRUE(ret == 0);
2177 
2178     info->freq = MID;
2179     DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
2180     ret = DiscStopDiscovery("pkgname1", info->subscribeId);
2181     TEST_ASSERT_TRUE(ret == 0);
2182 
2183     info->freq = HIGH;
2184     DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
2185     ret = DiscStopDiscovery("pkgname1", info->subscribeId);
2186     TEST_ASSERT_TRUE(ret == 0);
2187 
2188     info->freq = SUPER_HIGH;
2189     DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
2190     ret = DiscStopDiscovery("pkgname1", info->subscribeId);
2191     TEST_ASSERT_TRUE(ret == 0);
2192 
2193     info->freq = EXTREME_HIGH;
2194     DiscStartDiscovery("pkgname1", info, &g_subscribeCb);
2195     ret = DiscStopDiscovery("pkgname1", info->subscribeId);
2196     TEST_ASSERT_TRUE(ret == 0);
2197 
2198     DiscMgrDeinit();
2199 }
2200 
2201 /**
2202  * @tc.name: StopDiscoveryTest005
2203  * @tc.desc: Test extern module stop active discover, use Diff Freq Under the COAP.
2204  *           Test extern module stop passive discover, use Diff Freq Under the COAP.
2205  *           Test extern module stop active discover, use Diff Freq Under the BLE.
2206  *           Test extern module stop passive discover, use Diff Freq Under the BLE.
2207  *           Test extern module stop active discover, use Diff Freq Under the AUTO.
2208  *           Test extern module stop passive discover, use Diff Freq Under the AUTO.
2209  * @tc.type: FUNC
2210  * @tc.require: The DiscStopDiscovery operates normally.
2211  */
2212 HWTEST_F(DiscManagerTest, StopDiscoveryTest005, TestSize.Level1)
2213 {
2214     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2215 
2216     stopDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_PASSIVE;
2217     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2218 
2219     stopDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_ACTIVE;
2220     stopDiscoveryTestAbstractInfo001.medium = BLE;
2221     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2222 
2223     stopDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_PASSIVE;
2224     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2225 
2226     stopDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_ACTIVE;
2227     stopDiscoveryTestAbstractInfo001.medium = AUTO;
2228     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2229 
2230     stopDiscoveryTestAbstractInfo001.mode = DISCOVER_MODE_PASSIVE;
2231     StopDiscoveryTestAbstract001(&stopDiscoveryTestAbstractInfo001);
2232 }
2233 
2234 /**
2235  * @tc.name: DiscSetDiscoverCallbackTest001
2236  * @tc.desc: Callback set process.
2237  * @tc.type: FUNC
2238  * @tc.require: DiscSetDiscoverCallback and DiscStartAdvertise and DiscStopAdvertise operates normally.
2239  */
2240 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest001, TestSize.Level1)
2241 {
2242     DiscMgrInit();
2243 
2244     int32_t ret = DiscSetDiscoverCallback(MODULE_CONN, &g_innerCallback);
2245     TEST_ASSERT_TRUE(ret == 0);
2246 
2247     ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
2248     TEST_ASSERT_TRUE(ret == 0);
2249 
2250     ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
2251     TEST_ASSERT_TRUE(ret == 0);
2252 
2253     DiscMgrDeinit();
2254 }
2255 
2256 /**
2257  * @tc.name: DiscSetDiscoverCallbackTest002
2258  * @tc.desc: Callback set process.
2259  * @tc.type: FUNC
2260  * @tc.require: DiscStartAdvertise and DiscSetDiscoverCallback and DiscStopAdvertise operates normally.
2261  */
2262 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest002, TestSize.Level1)
2263 {
2264     DiscMgrInit();
2265 
2266     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
2267     TEST_ASSERT_TRUE(ret == 0);
2268 
2269     ret = DiscSetDiscoverCallback(MODULE_CONN, &g_innerCallback);
2270     TEST_ASSERT_TRUE(ret == 0);
2271 
2272     ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
2273     TEST_ASSERT_TRUE(ret == 0);
2274 
2275     DiscMgrDeinit();
2276 }
2277 
2278 /**
2279  * @tc.name: DiscSetDiscoverCallbackTest003
2280  * @tc.desc: Extern onDeviceFound test.
2281  * @tc.type: FUNC
2282  * @tc.require: The DiscStartDiscovery operates normally.
2283  */
2284 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest003, TestSize.Level1)
2285 {
2286     DeviceInfo devInfo;
2287     DiscMgrInit();
2288     int32_t ret = DiscStartDiscovery("pkgname1", &g_sInfo, &g_subscribeCb);
2289     TEST_ASSERT_TRUE(ret == 0);
2290 
2291     devInfo.capabilityBitmap[0] = TEST_BITMAP_CAP;
2292     TestInnerDeviceFound(&devInfo, NULL);
2293     DiscMgrDeinit();
2294 }
2295 
2296 /**
2297  * @tc.name: DiscSetDiscoverCallbackTest004
2298  * @tc.desc: Inner onDeviceFound test.
2299  * @tc.type: FUNC
2300  * @tc.require: DiscStartAdvertise and DiscSetDiscoverCallback and DiscStopAdvertise operates normally
2301  */
2302 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest004, TestSize.Level1)
2303 {
2304     DeviceInfo devInfo;
2305     DiscMgrInit();
2306 
2307     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
2308     TEST_ASSERT_TRUE(ret == 0);
2309 
2310     ret = DiscSetDiscoverCallback(MODULE_CONN, &g_innerCallback);
2311     TEST_ASSERT_TRUE(ret == 0);
2312 
2313     devInfo.capabilityBitmap[0] = TEST_BITMAP_CAP;
2314     TestInnerDeviceFound(&devInfo, NULL);
2315 
2316     ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
2317     TEST_ASSERT_TRUE(ret == 0);
2318 
2319     DiscMgrDeinit();
2320 }
2321 
2322 /**
2323  * @tc.name: DiscSetDiscoverCallbackTest005
2324  * @tc.desc: Inner onDeviceFound test with no callback.
2325  * @tc.type: FUNC
2326  * @tc.require: DiscStartAdvertise and DiscStopAdvertise operates normally
2327  */
2328 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest005, TestSize.Level1)
2329 {
2330     DeviceInfo devInfo;
2331     DiscMgrInit();
2332 
2333     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
2334     TEST_ASSERT_TRUE(ret == 0);
2335 
2336     devInfo.capabilityBitmap[0] = TEST_BITMAP_CAP;
2337     TestInnerDeviceFound(&devInfo, NULL);
2338 
2339     ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
2340     TEST_ASSERT_TRUE(ret == 0);
2341 
2342     DiscMgrDeinit();
2343 }
2344 
2345 /**
2346  * @tc.name: DiscSetDiscoverCallbackTest006
2347  * @tc.desc: Callback use the wrong parameter.
2348  * @tc.type: FUNC
2349  * @tc.require: DiscStartAdvertise and DiscSetDiscoverCallback and DiscStopAdvertise operates normally.
2350  */
2351 HWTEST_F(DiscManagerTest, DiscSetDiscoverCallbackTest006, TestSize.Level1)
2352 {
2353     DiscMgrInit();
2354 
2355     int32_t ret = DiscStartAdvertise(MODULE_CONN, &g_sInnerInfo);
2356     TEST_ASSERT_TRUE(ret == 0);
2357 
2358     ret = DiscSetDiscoverCallback(MODULE_CONN, NULL);
2359     TEST_ASSERT_TRUE(ret != 0);
2360 
2361     ret = DiscStopAdvertise(MODULE_CONN, TEST_SUBSCRIBEINNER_ID);
2362     TEST_ASSERT_TRUE(ret == 0);
2363 
2364     DiscMgrDeinit();
2365 }
2366 
2367 /**
2368  * @tc.name: DiscCoapStopDiscoveryTest001
2369  * @tc.desc: Active stop discovery, use the normal parameter.
2370  * @tc.type: FUNC
2371  * @tc.require: The DiscCoapStopDiscovery operates normally.
2372  */
2373 HWTEST_F(DiscManagerTest, DiscCoapStopDiscoveryTest001, TestSize.Level1)
2374 {
2375     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2376     DiscCoapStartDiscovery(1, 1);
2377 
2378     int32_t ret = DiscCoapStopDiscovery(1, 1);
2379     TEST_ASSERT_TRUE(ret == 0);
2380 }
2381 
2382 /**
2383  * @tc.name: DiscCoapStopDiscoveryTest002
2384  * @tc.desc: Passive stop discovery, the module is not initialized.
2385  * @tc.type: FUNC
2386  * @tc.require: The DiscCoapStopDiscovery operates normally.
2387  */
2388 HWTEST_F(DiscManagerTest, DiscCoapStopDiscoveryTest002, TestSize.Level1)
2389 {
2390     DiscCoapStartDiscovery(1, 1);
2391     int32_t ret = DiscCoapStopDiscovery(1, 1);
2392     TEST_ASSERT_TRUE(ret != 0);
2393 }
2394 
2395 /**
2396  * @tc.name: DiscCoapStopDiscoveryTest003
2397  * @tc.desc: Active stop discovery, the module is not initialized.
2398  * @tc.type: FUNC
2399  * @tc.require: The DiscCoapStopDiscovery operates normally.
2400  */
2401 HWTEST_F(DiscManagerTest, DiscCoapStopDiscoveryTest003, TestSize.Level1)
2402 {
2403     int32_t ret = DiscCoapStopDiscovery(1, 1);
2404     TEST_ASSERT_TRUE(ret != 0);
2405 }
2406 
2407 /**
2408  * @tc.name: DiscCoapPulbishServiceTest001
2409  * @tc.desc: Inner module publishing, use wrong parameters.
2410  * @tc.type: FUNC
2411  * @tc.require: The DiscCoapUnpulbishService operates normally.
2412  */
2413 HWTEST_F(DiscManagerTest, DiscCoapPulbishServiceTest001, TestSize.Level1)
2414 {
2415     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2416 
2417     int32_t ret = DiscCoapUnpulbishService(PUB_CAP_BITMAP_2, PUBLISH_MODE_2);
2418     TEST_ASSERT_TRUE(ret != 0);
2419     DiscCoapDeinit();
2420 }
2421 
2422 /**
2423  * @tc.name: DiscCoapPulbishServiceTest002
2424  * @tc.desc: Inner module publishing, use normal parameters.
2425  * @tc.type: FUNC
2426  * @tc.require: The DiscCoapUnpulbishService operates normally.
2427  */
2428 HWTEST_F(DiscManagerTest, DiscCoapPulbishServiceTest002, TestSize.Level1)
2429 {
2430     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2431 
2432     int32_t ret = DiscCoapUnpulbishService(1, 0);
2433     TEST_ASSERT_TRUE(ret == 0);
2434     DiscCoapDeinit();
2435 }
2436 
2437 /**
2438  * @tc.name: DiscCoapStartDiscoveryTest001
2439  * @tc.desc: Inner module Discovery, use wrong parameters.
2440  * @tc.type: FUNC
2441  * @tc.require: The DiscCoapStartDiscovery operates normally.
2442  */
2443 HWTEST_F(DiscManagerTest, DiscCoapStartDiscoveryTest001, TestSize.Level1)
2444 {
2445     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2446 
2447     int32_t ret = DiscCoapStartDiscovery(FILTER_CAP_BITMAP_2, DISC_MODE_2);
2448     TEST_ASSERT_TRUE(ret != 0);
2449     DiscCoapDeinit();
2450 }
2451 
2452 /**
2453  * @tc.name: DiscCoapStartDiscoveryTest002
2454  * @tc.desc: Test coap discovery, use normal parameters.
2455  * @tc.type: FUNC
2456  * @tc.require: The DiscCoapStartDiscovery operates normally.
2457  */
2458 HWTEST_F(DiscManagerTest, DiscCoapStartDiscoveryTest002, TestSize.Level1)
2459 {
2460     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2461 
2462     int32_t ret = DiscCoapStartDiscovery(1, 1);
2463     TEST_ASSERT_TRUE(ret == 0);
2464     DiscCoapDeinit();
2465 }
2466 
2467 /**
2468  * @tc.name: DiscCoapUnpulbishServiceTest001
2469  * @tc.desc: Inner modules stop publishing, using wrong parameters.
2470  * @tc.type: FUNC
2471  * @tc.require: The DiscCoapUnpulbishService operates normally.
2472  */
2473 HWTEST_F(DiscManagerTest, DiscCoapUnpulbishServiceTest001, TestSize.Level1)
2474 {
2475     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2476 
2477     int32_t ret = DiscCoapUnpulbishService(PUB_CAP_BITMAP_2, PUBLISH_MODE_2);
2478     TEST_ASSERT_TRUE(ret != 0);
2479     DiscCoapDeinit();
2480 }
2481 
2482 /**
2483  * @tc.name: DiscCoapUnpulbishServiceTest002
2484  * @tc.desc: Test stop publishing, using the normal parameters.
2485  * @tc.type: FUNC
2486  * @tc.require: The DiscCoapUnpulbishService operates normally.
2487  */
2488 HWTEST_F(DiscManagerTest, DiscCoapUnpulbishServiceTest002, TestSize.Level1)
2489 {
2490     g_coapDiscFunc = DiscCoapInit(&g_discInnerCb);
2491 
2492     int32_t ret = DiscCoapUnpulbishService(1, 0);
2493     TEST_ASSERT_TRUE(ret == 0);
2494     DiscCoapDeinit();
2495 }
2496 } // namespace OHOS
2497