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