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