1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <cstdio>
17 #include <ctime>
18 #include <gtest/gtest.h>
19 #include <sys/time.h>
20 #include <unistd.h>
21
22 #include "discovery_service.h"
23
24 using namespace testing::ext;
25
26 #define TEST_ERRO_MOUDULE ((MODULE_LNN) + 3)
27
28 namespace OHOS {
29 static int g_subscribeId = 0;
30 static int g_publishId = 0;
31 static const char *g_pkgName = "Softbus_Kits";
32 static const char *g_pkgName1 = "Softbus_Kits_1";
33 static const char *g_erroPkgName = "Softbus_Erro_Kits";
34
35 class DiscSdkTestBle : public testing::Test {
36 public:
DiscSdkTestBle()37 DiscSdkTestBle()
38 {}
~DiscSdkTestBle()39 ~DiscSdkTestBle()
40 {}
41 static void SetUpTestCase(void);
42 static void TearDownTestCase(void);
SetUp()43 void SetUp() override
44 {}
TearDown()45 void TearDown() override
46 {}
47 };
48
SetUpTestCase(void)49 void DiscSdkTestBle::SetUpTestCase(void)
50 {}
51
TearDownTestCase(void)52 void DiscSdkTestBle::TearDownTestCase(void)
53 {}
54
GetSubscribeId(void)55 static int GetSubscribeId(void)
56 {
57 g_subscribeId++;
58 return g_subscribeId;
59 }
60
GetPublishId(void)61 static int GetPublishId(void)
62 {
63 g_publishId++;
64 return g_publishId;
65 }
66
67 static SubscribeInfo g_sInfo = {
68 .subscribeId = 1,
69 .mode = DISCOVER_MODE_ACTIVE,
70 .medium = COAP,
71 .freq = MID,
72 .isSameAccount = true,
73 .isWakeRemote = false,
74 .capability = "dvKit",
75 .capabilityData = (unsigned char *)"capdata3",
76 .dataLen = sizeof("capdata3")
77 };
78
79 static PublishInfo g_pInfo = {
80 .publishId = 1,
81 .mode = DISCOVER_MODE_ACTIVE,
82 .medium = COAP,
83 .freq = MID,
84 .capability = "dvKit",
85 .capabilityData = (unsigned char *)"capdata4",
86 .dataLen = sizeof("capdata4")
87 };
88
89 static PublishInfo g_pInfo1 = {
90 .publishId = 1,
91 .mode = DISCOVER_MODE_ACTIVE,
92 .medium = COAP,
93 .freq = MID,
94 .capability = "dvKit",
95 .capabilityData = NULL,
96 .dataLen = 0
97 };
98
99 static SubscribeInfo g_sInfo1 = {
100 .subscribeId = 1,
101 .mode = DISCOVER_MODE_ACTIVE,
102 .medium = COAP,
103 .freq = MID,
104 .isSameAccount = true,
105 .isWakeRemote = false,
106 .capability = "hicall",
107 .capabilityData = NULL,
108 .dataLen = 0
109 };
110
TestDeviceFound(const DeviceInfo * device)111 static void TestDeviceFound(const DeviceInfo *device)
112 {
113 printf("[client]TestDeviceFound\n");
114 }
115
TestDiscoverFailed(int subscribeId,DiscoveryFailReason failReason)116 static void TestDiscoverFailed(int subscribeId, DiscoveryFailReason failReason)
117 {
118 printf("[client]TestDiscoverFailed\n");
119 }
120
TestDiscoverySuccess(int subscribeId)121 static void TestDiscoverySuccess(int subscribeId)
122 {
123 printf("[client]TestDiscoverySuccess\n");
124 }
125
TestPublishSuccess(int publishId)126 static void TestPublishSuccess(int publishId)
127 {
128 printf("[client]TestPublishSuccess\n");
129 }
130
TestPublishFail(int publishId,PublishFailReason reason)131 static void TestPublishFail(int publishId, PublishFailReason reason)
132 {
133 printf("[client]TestPublishFail\n");
134 }
135
136 static IDiscoveryCallback g_subscribeCb = {
137 .OnDeviceFound = TestDeviceFound,
138 .OnDiscoverFailed = TestDiscoverFailed,
139 .OnDiscoverySuccess = TestDiscoverySuccess
140 };
141
142 static IPublishCallback g_publishCb = {
143 .OnPublishSuccess = TestPublishSuccess,
144 .OnPublishFail = TestPublishFail
145 };
146
147 /**
148 * @tc.name: PublishServiceTest001
149 * @tc.desc: Test active publish, verify correct parameter with passive mode and "BLE" medium.
150 * @tc.in: Test module, Test number, Test levels.
151 * @tc.out: Zero
152 * @tc.type: FUNC
153 * @tc.require: The PublishService and UnPublishService operates normally.
154 */
155 HWTEST_F(DiscSdkTestBle, PublishServiceTest001, TestSize.Level1)
156 {
157 int ret;
158 PublishInfo testInfo = {
159 .publishId = GetPublishId(),
160 .mode = DISCOVER_MODE_PASSIVE,
161 .medium = BLE,
162 .freq = LOW,
163 .capability = "dvKit",
164 .capabilityData = (unsigned char *)"capdata2",
165 .dataLen = sizeof("capdata2")
166 };
167
168 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
169 EXPECT_TRUE(ret == 0);
170 ret = UnPublishService(g_pkgName, testInfo.publishId);
171 EXPECT_TRUE(ret == 0);
172
173 testInfo.freq = MID;
174 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
175 EXPECT_TRUE(ret == 0);
176 ret = UnPublishService(g_pkgName, testInfo.publishId);
177 EXPECT_TRUE(ret == 0);
178
179 testInfo.freq = HIGH;
180 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
181 EXPECT_TRUE(ret == 0);
182 ret = UnPublishService(g_pkgName, testInfo.publishId);
183 EXPECT_TRUE(ret == 0);
184
185 testInfo.freq = SUPER_HIGH;
186 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
187 EXPECT_TRUE(ret == 0);
188 ret = UnPublishService(g_pkgName, testInfo.publishId);
189 EXPECT_TRUE(ret == 0);
190 }
191
192 /**
193 * @tc.name: PublishServiceTest002
194 * @tc.desc: Test active publish, verify correct parameter with active mode and "BLE" medium.
195 * @tc.in: Test module, Test number, Test levels.
196 * @tc.out: Zero
197 * @tc.type: FUNC
198 * @tc.require: The PublishService and UnPublishService operates normally.
199 */
200 HWTEST_F(DiscSdkTestBle, PublishServiceTest002, TestSize.Level1)
201 {
202 int ret;
203 PublishInfo testInfo = {
204 .publishId = GetPublishId(),
205 .mode = DISCOVER_MODE_ACTIVE,
206 .medium = BLE,
207 .freq = LOW,
208 .capability = "dvKit",
209 .capabilityData = (unsigned char *)"capdata2",
210 .dataLen = sizeof("capdata2")
211 };
212
213 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
214 EXPECT_TRUE(ret == 0);
215 ret = UnPublishService(g_pkgName, testInfo.publishId);
216 EXPECT_TRUE(ret == 0);
217
218 testInfo.freq = MID;
219 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
220 EXPECT_TRUE(ret == 0);
221 ret = UnPublishService(g_pkgName, testInfo.publishId);
222 EXPECT_TRUE(ret == 0);
223
224 testInfo.freq = HIGH;
225 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
226 EXPECT_TRUE(ret == 0);
227 ret = UnPublishService(g_pkgName, testInfo.publishId);
228 EXPECT_TRUE(ret == 0);
229
230 testInfo.freq = SUPER_HIGH;
231 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
232 EXPECT_TRUE(ret == 0);
233 ret = UnPublishService(g_pkgName, testInfo.publishId);
234 EXPECT_TRUE(ret == 0);
235 }
236
237 /**
238 * @tc.name: PublishServiceTest003
239 * @tc.desc: Extern module publishuse the same parameter again, perform two subscriptions.
240 * @tc.in: test module, test number, Test Levels.
241 * @tc.out: Nonzero
242 * @tc.type: FUNC
243 * @tc.require: The PublishService operates normally.
244 */
245 HWTEST_F(DiscSdkTestBle, PublishServiceTest003, TestSize.Level1)
246 {
247 int ret;
248
249 g_pInfo.publishId = GetPublishId();
250 ret = PublishService(g_pkgName, &g_pInfo, &g_publishCb);
251 ret = PublishService(g_pkgName, &g_pInfo, &g_publishCb);
252 EXPECT_TRUE(ret != 0);
253 }
254
255 /**
256 * @tc.name: PublishServiceTest004
257 * @tc.desc: Test active publish, use the wrong Medium and Freq Under the BLE.
258 * @tc.in: Test module, Test number, Test levels.
259 * @tc.out: Nonzero
260 * @tc.type: FUNC
261 * @tc.require: The PublishService and UnPublishService operates normally.
262 */
263 HWTEST_F(DiscSdkTestBle, PublishServiceTest004, TestSize.Level1)
264 {
265 int ret;
266 PublishInfo testInfo = {
267 .publishId = GetPublishId(),
268 .mode = DISCOVER_MODE_ACTIVE,
269 .medium = BLE,
270 .freq = MID,
271 .capability = "dvKit",
272 .capabilityData = (unsigned char *)"capdata2",
273 .dataLen = sizeof("capdata2")
274 };
275
276 testInfo.medium = (ExchangeMedium)(AUTO - 1);
277 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
278 EXPECT_TRUE(ret != 0);
279 testInfo.medium = COAP;
280
281 testInfo.freq = (ExchangeFreq)(LOW - 1);
282 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
283 EXPECT_TRUE(ret != 0);
284 testInfo.freq = LOW;
285 }
286
287 /**
288 * @tc.name: PublishServiceTest005
289 * @tc.desc: Test active publish, verify correct parameter with passive mode and "BLE" medium.
290 * @tc.in: Test module, Test number, Test levels.
291 * @tc.out: Zero
292 * @tc.type: FUNC
293 * @tc.require: The PublishService and UnPublishService operates normally.
294 */
295 HWTEST_F(DiscSdkTestBle, PublishServiceTest005, TestSize.Level1)
296 {
297 int ret;
298 PublishInfo testInfo = {
299 .publishId = GetPublishId(),
300 .mode = DISCOVER_MODE_PASSIVE,
301 .medium = BLE,
302 .freq = LOW,
303 .capability = "dvKit",
304 .capabilityData = (unsigned char *)"capdata2",
305 .dataLen = sizeof("capdata2")
306 };
307
308 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
309 EXPECT_TRUE(ret == 0);
310 ret = UnPublishService(g_pkgName, testInfo.publishId);
311 EXPECT_TRUE(ret == 0);
312
313 testInfo.freq = MID;
314 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
315 EXPECT_TRUE(ret == 0);
316 ret = UnPublishService(g_pkgName, testInfo.publishId);
317 EXPECT_TRUE(ret == 0);
318
319 testInfo.freq = HIGH;
320 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
321 EXPECT_TRUE(ret == 0);
322 ret = UnPublishService(g_pkgName, testInfo.publishId);
323 EXPECT_TRUE(ret == 0);
324
325 testInfo.freq = SUPER_HIGH;
326 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
327 EXPECT_TRUE(ret == 0);
328 ret = UnPublishService(g_pkgName, testInfo.publishId);
329 EXPECT_TRUE(ret == 0);
330 }
331
332 /**
333 * @tc.name: PublishServiceTest006
334 * @tc.desc: Test active publish, verify correct parameter with active mode and "BLE" medium.
335 * @tc.in: Test module, Test number, Test levels.
336 * @tc.out: Zero
337 * @tc.type: FUNC
338 * @tc.require: The PublishService and UnPublishService operates normally.
339 */
340 HWTEST_F(DiscSdkTestBle, PublishServiceTest006, TestSize.Level1)
341 {
342 int ret;
343 PublishInfo testInfo = {
344 .publishId = GetPublishId(),
345 .mode = DISCOVER_MODE_ACTIVE,
346 .medium = BLE,
347 .freq = LOW,
348 .capability = "dvKit",
349 .capabilityData = (unsigned char *)"capdata2",
350 .dataLen = sizeof("capdata2")
351 };
352
353 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
354 EXPECT_TRUE(ret == 0);
355 ret = UnPublishService(g_pkgName, testInfo.publishId);
356 EXPECT_TRUE(ret == 0);
357
358 testInfo.freq = MID;
359 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
360 EXPECT_TRUE(ret == 0);
361 ret = UnPublishService(g_pkgName, testInfo.publishId);
362 EXPECT_TRUE(ret == 0);
363
364 testInfo.freq = HIGH;
365 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
366 EXPECT_TRUE(ret == 0);
367 ret = UnPublishService(g_pkgName, testInfo.publishId);
368 EXPECT_TRUE(ret == 0);
369
370 testInfo.freq = SUPER_HIGH;
371 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
372 EXPECT_TRUE(ret == 0);
373 ret = UnPublishService(g_pkgName, testInfo.publishId);
374 EXPECT_TRUE(ret == 0);
375 }
376
377 /**
378 * @tc.name: PublishServiceTest007
379 * @tc.desc: Verify wrong parameter.
380 * @tc.in: Test module, Test number, Test levels.
381 * @tc.out: Nonzero
382 * @tc.type: FUNC
383 * @tc.require: The PublishService and UnPublishService operates normally.
384 */
385 HWTEST_F(DiscSdkTestBle, PublishServiceTest007, TestSize.Level1)
386 {
387 int ret;
388 g_pInfo.publishId = GetPublishId();
389 ret = PublishService(g_erroPkgName, &g_pInfo, &g_publishCb);
390 EXPECT_TRUE(ret != 0);
391 }
392
393 /**
394 * @tc.name: PublishServiceTest008
395 * @tc.desc: Test passive publish, use the wrong Medium and Freq Under the BLE.
396 * @tc.in: Test module, Test number, Test levels.
397 * @tc.out: Nonzero
398 * @tc.type: FUNC
399 * @tc.require: The PublishService and UnPublishService operates normally.
400 */
401 HWTEST_F(DiscSdkTestBle, PublishServiceTest008, TestSize.Level1)
402 {
403 int ret;
404 PublishInfo testInfo = {
405 .publishId = GetPublishId(),
406 .mode = DISCOVER_MODE_PASSIVE,
407 .medium = BLE,
408 .freq = MID,
409 .capability = "dvKit",
410 .capabilityData = (unsigned char *)"capdata2",
411 .dataLen = sizeof("capdata2")
412 };
413
414 testInfo.medium = (ExchangeMedium)(AUTO - 1);
415 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
416 EXPECT_TRUE(ret != 0);
417 testInfo.medium = COAP;
418
419 testInfo.freq = (ExchangeFreq)(LOW - 1);
420 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
421 EXPECT_TRUE(ret != 0);
422 testInfo.freq = LOW;
423 }
424
425 /**
426 * @tc.name: PublishServiceTest009
427 * @tc.desc: Test active publish, verify correct parameter with passive mode,"BLE" medium and diff capability.
428 * @tc.in: Test module, Test number, Test levels.
429 * @tc.out: Zero
430 * @tc.type: FUNC
431 * @tc.require: The PublishService and UnPublishService operates normally.
432 */
433 HWTEST_F(DiscSdkTestBle, PublishServiceTest009, TestSize.Level1)
434 {
435 int ret;
436 PublishInfo testInfo = {
437 .publishId = GetPublishId(),
438 .mode = DISCOVER_MODE_PASSIVE,
439 .medium = BLE,
440 .freq = LOW,
441 .capability = "dvKit",
442 .capabilityData = (unsigned char *)"capdata2",
443 .dataLen = sizeof("capdata2")
444 };
445
446 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
447 EXPECT_TRUE(ret == 0);
448 ret = UnPublishService(g_pkgName, testInfo.publishId);
449
450 testInfo.capability = "hicall";
451 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
452 EXPECT_TRUE(ret == 0);
453 ret = UnPublishService(g_pkgName, testInfo.publishId);
454
455 testInfo.capability = "profile";
456 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
457 EXPECT_TRUE(ret == 0);
458 ret = UnPublishService(g_pkgName, testInfo.publishId);
459
460 testInfo.capability = "homevisionPic";
461 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
462 EXPECT_TRUE(ret == 0);
463 ret = UnPublishService(g_pkgName, testInfo.publishId);
464
465 testInfo.capability = "castPlus";
466 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
467 EXPECT_TRUE(ret == 0);
468 ret = UnPublishService(g_pkgName, testInfo.publishId);
469
470 testInfo.capability = "aaCapability";
471 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
472 EXPECT_TRUE(ret == 0);
473 ret = UnPublishService(g_pkgName, testInfo.publishId);
474
475 testInfo.capability = "ddmpCapability";
476 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
477 EXPECT_TRUE(ret == 0);
478 ret = UnPublishService(g_pkgName, testInfo.publishId);
479
480 testInfo.capability = "osdCapability";
481 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
482 EXPECT_TRUE(ret == 0);
483 ret = UnPublishService(g_pkgName, testInfo.publishId);
484 }
485
486 /**
487 * @tc.name: PublishServiceTest010
488 * @tc.desc: Test active publish, verify correct parameter with active mode,"BLE" medium and diff capability.
489 * @tc.in: Test module, Test number, Test levels.
490 * @tc.out: Zero
491 * @tc.type: FUNC
492 * @tc.require: The PublishService and UnPublishService operates normally.
493 */
494 HWTEST_F(DiscSdkTestBle, PublishServiceTest010, TestSize.Level1)
495 {
496 int ret;
497 PublishInfo testInfo = {
498 .publishId = GetPublishId(),
499 .mode = DISCOVER_MODE_ACTIVE,
500 .medium = BLE,
501 .freq = LOW,
502 .capability = "dvKit",
503 .capabilityData = (unsigned char *)"capdata2",
504 .dataLen = sizeof("capdata2")
505 };
506
507 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
508 EXPECT_TRUE(ret == 0);
509 ret = UnPublishService(g_pkgName, testInfo.publishId);
510
511 testInfo.capability = "hicall";
512 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
513 EXPECT_TRUE(ret == 0);
514 ret = UnPublishService(g_pkgName, testInfo.publishId);
515
516 testInfo.capability = "profile";
517 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
518 EXPECT_TRUE(ret == 0);
519 ret = UnPublishService(g_pkgName, testInfo.publishId);
520
521 testInfo.capability = "homevisionPic";
522 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
523 EXPECT_TRUE(ret == 0);
524 ret = UnPublishService(g_pkgName, testInfo.publishId);
525
526 testInfo.capability = "castPlus";
527 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
528 EXPECT_TRUE(ret == 0);
529 ret = UnPublishService(g_pkgName, testInfo.publishId);
530
531 testInfo.capability = "aaCapability";
532 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
533 EXPECT_TRUE(ret == 0);
534 ret = UnPublishService(g_pkgName, testInfo.publishId);
535
536 testInfo.capability = "ddmpCapability";
537 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
538 EXPECT_TRUE(ret == 0);
539 ret = UnPublishService(g_pkgName, testInfo.publishId);
540
541 testInfo.capability = "osdCapability";
542 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
543 EXPECT_TRUE(ret == 0);
544 ret = UnPublishService(g_pkgName, testInfo.publishId);
545 }
546
547 /**
548 * @tc.name: StartDiscoveryTest001
549 * @tc.desc: Test active discover, verify correct parameter with active mode and "BLE" medium.
550 * @tc.in: Test module, Test number, Test levels.
551 * @tc.out: Zero
552 * @tc.type: FUNC
553 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
554 */
555 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest001, TestSize.Level1)
556 {
557 int ret;
558 SubscribeInfo testInfo = {
559 .subscribeId = GetSubscribeId(),
560 .mode = DISCOVER_MODE_ACTIVE,
561 .medium = BLE,
562 .freq = LOW,
563 .isSameAccount = true,
564 .isWakeRemote = false,
565 .capability = "dvKit",
566 .capabilityData = (unsigned char *)"capdata3",
567 .dataLen = sizeof("capdata3")
568 };
569
570 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
571 EXPECT_TRUE(ret == 0);
572 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
573 EXPECT_TRUE(ret == 0);
574
575 testInfo.freq = MID;
576 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
577 EXPECT_TRUE(ret == 0);
578 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
579 EXPECT_TRUE(ret == 0);
580
581 testInfo.freq = HIGH;
582 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
583 EXPECT_TRUE(ret == 0);
584 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
585 EXPECT_TRUE(ret == 0);
586
587 testInfo.freq = SUPER_HIGH;
588 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
589 EXPECT_TRUE(ret == 0);
590 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
591 EXPECT_TRUE(ret == 0);
592 }
593
594 /**
595 * @tc.name: StartDiscoveryTest002
596 * @tc.desc: Test active discover, verify correct parameter with active mode and "BLE" medium.
597 * @tc.in: Test module, Test number, Test levels.
598 * @tc.out: Zero
599 * @tc.type: FUNC
600 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
601 */
602 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest002, TestSize.Level1)
603 {
604 int ret;
605 SubscribeInfo testInfo = {
606 .subscribeId = GetSubscribeId(),
607 .mode = DISCOVER_MODE_ACTIVE,
608 .medium = BLE,
609 .freq = LOW,
610 .isSameAccount = true,
611 .isWakeRemote = false,
612 .capability = "dvKit",
613 .capabilityData = (unsigned char *)"capdata3",
614 .dataLen = sizeof("capdata3")
615 };
616
617 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
618 EXPECT_TRUE(ret == 0);
619 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
620 EXPECT_TRUE(ret == 0);
621
622 testInfo.freq = MID;
623 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
624 EXPECT_TRUE(ret == 0);
625 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
626 EXPECT_TRUE(ret == 0);
627
628 testInfo.freq = HIGH;
629 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
630 EXPECT_TRUE(ret == 0);
631 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
632 EXPECT_TRUE(ret == 0);
633
634 testInfo.freq = SUPER_HIGH;
635 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
636 EXPECT_TRUE(ret == 0);
637 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
638 EXPECT_TRUE(ret == 0);
639 }
640
641 /**
642 * @tc.name: StartDiscoveryTest003
643 * @tc.desc: Test passive discover verify correct parameter with passive mode and "BLE" medium.
644 * @tc.in: Test module, Test number, Test levels.
645 * @tc.out: Zero
646 * @tc.type: FUNC
647 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
648 */
649 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest003, TestSize.Level1)
650 {
651 int ret;
652 SubscribeInfo testInfo = {
653 .subscribeId = GetSubscribeId(),
654 .mode = DISCOVER_MODE_PASSIVE,
655 .medium = BLE,
656 .freq = LOW,
657 .isSameAccount = true,
658 .isWakeRemote = false,
659 .capability = "dvKit",
660 .capabilityData = (unsigned char *)"capdata3",
661 .dataLen = sizeof("capdata3")
662 };
663
664 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
665 EXPECT_TRUE(ret == 0);
666 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
667 EXPECT_TRUE(ret == 0);
668
669 testInfo.freq = MID;
670 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
671 EXPECT_TRUE(ret == 0);
672 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
673 EXPECT_TRUE(ret == 0);
674
675 testInfo.freq = HIGH;
676 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
677 EXPECT_TRUE(ret == 0);
678 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
679 EXPECT_TRUE(ret == 0);
680
681 testInfo.freq = SUPER_HIGH;
682 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
683 EXPECT_TRUE(ret == 0);
684 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
685 EXPECT_TRUE(ret == 0);
686 }
687
688 /**
689 * @tc.name: StartDiscoveryTest004
690 * @tc.desc:Test extern module active discoveruse wrong Medium and Freq Under the BLE.
691 * @tc.in: Test module, Test number, Test levels.
692 * @tc.out: Nonzero
693 * @tc.type: FUNC
694 * @tc.require: The StartDiscovery operates normally.
695 */
696 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest004, TestSize.Level1)
697 {
698 int ret;
699 SubscribeInfo testInfo = {
700 .subscribeId = GetSubscribeId(),
701 .mode = DISCOVER_MODE_ACTIVE,
702 .medium = BLE,
703 .freq = LOW,
704 .isSameAccount = true,
705 .isWakeRemote = false,
706 .capability = "dvKit",
707 .capabilityData = (unsigned char *)"capdata3",
708 .dataLen = sizeof("capdata3")
709 };
710
711 testInfo.medium = (ExchangeMedium)(AUTO - 1);
712 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
713 EXPECT_TRUE(ret != 0);
714 testInfo.medium = COAP;
715
716 testInfo.freq = (ExchangeFreq)(LOW - 1);
717 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
718 EXPECT_TRUE(ret != 0);
719 testInfo.freq = LOW;
720 }
721
722 /**
723 * @tc.name: StartDiscoveryTest005
724 * @tc.desc:Test extern module active discoveruse Diff Freq Under the BLE.
725 * @tc.in: Test module, Test number, Test levels.
726 * @tc.out: Zero
727 * @tc.type: FUNC
728 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
729 */
730 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest005, TestSize.Level1)
731 {
732 int ret;
733 SubscribeInfo testInfo = {
734 .subscribeId = GetSubscribeId(),
735 .mode = DISCOVER_MODE_ACTIVE,
736 .medium = BLE,
737 .freq = LOW,
738 .isSameAccount = true,
739 .isWakeRemote = false,
740 .capability = "dvKit",
741 .capabilityData = (unsigned char *)"capdata3",
742 .dataLen = sizeof("capdata3")
743 };
744
745 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
746 EXPECT_TRUE(ret == 0);
747 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
748 EXPECT_TRUE(ret == 0);
749
750 testInfo.freq = MID;
751 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
752 EXPECT_TRUE(ret == 0);
753 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
754 EXPECT_TRUE(ret == 0);
755
756 testInfo.freq = HIGH;
757 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
758 EXPECT_TRUE(ret == 0);
759 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
760 EXPECT_TRUE(ret == 0);
761
762 testInfo.freq = SUPER_HIGH;
763 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
764 EXPECT_TRUE(ret == 0);
765 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
766 EXPECT_TRUE(ret == 0);
767 }
768
769 /**
770 * @tc.name: StartDiscoveryTest006
771 * @tc.desc:Test extern module passive discoveruse Diff Freq Under the BLE.
772 * @tc.in: Test module, Test number, Test levels.
773 * @tc.out: Zero
774 * @tc.type: FUNC
775 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
776 */
777 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest006, TestSize.Level1)
778 {
779 int ret;
780 SubscribeInfo testInfo = {
781 .subscribeId = GetSubscribeId(),
782 .mode = DISCOVER_MODE_PASSIVE,
783 .medium = BLE,
784 .freq = LOW,
785 .isSameAccount = true,
786 .isWakeRemote = false,
787 .capability = "dvKit",
788 .capabilityData = (unsigned char *)"capdata3",
789 .dataLen = sizeof("capdata3")
790 };
791
792 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
793 EXPECT_TRUE(ret == 0);
794 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
795 EXPECT_TRUE(ret == 0);
796
797 testInfo.freq = MID;
798 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
799 EXPECT_TRUE(ret == 0);
800 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
801 EXPECT_TRUE(ret == 0);
802
803 testInfo.freq = HIGH;
804 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
805 EXPECT_TRUE(ret == 0);
806 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
807 EXPECT_TRUE(ret == 0);
808
809 testInfo.freq = SUPER_HIGH;
810 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
811 EXPECT_TRUE(ret == 0);
812 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
813 EXPECT_TRUE(ret == 0);
814 }
815
816 /**
817 * @tc.name: StartDiscoveryTest007
818 * @tc.desc: Test active publish, verify correct parameter with passive mode,"BLE" medium and diff capability.
819 * @tc.in: Test module, Test number, Test levels.
820 * @tc.out: Zero
821 * @tc.type: FUNC
822 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
823 */
824 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest007, TestSize.Level1)
825 {
826 int ret;
827 SubscribeInfo testInfo = {
828 .subscribeId = GetSubscribeId(),
829 .mode = DISCOVER_MODE_PASSIVE,
830 .medium = BLE,
831 .freq = LOW,
832 .isSameAccount = true,
833 .isWakeRemote = false,
834 .capability = "dvKit",
835 .capabilityData = (unsigned char *)"capdata3",
836 .dataLen = sizeof("capdata3")
837 };
838
839 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
840 EXPECT_TRUE(ret == 0);
841 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
842
843 testInfo.capability = "hicall";
844 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
845 EXPECT_TRUE(ret == 0);
846 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
847
848 testInfo.capability = "profile";
849 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
850 EXPECT_TRUE(ret == 0);
851 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
852
853 testInfo.capability = "homevisionPic";
854 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
855 EXPECT_TRUE(ret == 0);
856 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
857
858 testInfo.capability = "castPlus";
859 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
860 EXPECT_TRUE(ret == 0);
861 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
862
863 testInfo.capability = "aaCapability";
864 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
865 EXPECT_TRUE(ret == 0);
866 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
867
868 testInfo.capability = "ddmpCapability";
869 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
870 EXPECT_TRUE(ret == 0);
871 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
872
873 testInfo.capability = "osdCapability";
874 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
875 EXPECT_TRUE(ret == 0);
876 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
877 }
878
879 /**
880 * @tc.name: StartDiscoveryTest008
881 * @tc.desc: Test active publish, verify correct parameter with active mode,"BLE" medium and diff capability.
882 * @tc.in: Test module, Test number, Test levels.
883 * @tc.out: Zero
884 * @tc.type: FUNC
885 * @tc.require: The StartDiscovery and StopDiscovery operates normally.
886 */
887 HWTEST_F(DiscSdkTestBle, StartDiscoveryTest008, TestSize.Level1)
888 {
889 int ret;
890 SubscribeInfo testInfo = {
891 .subscribeId = GetSubscribeId(),
892 .mode = DISCOVER_MODE_ACTIVE,
893 .medium = BLE,
894 .freq = LOW,
895 .isSameAccount = true,
896 .isWakeRemote = false,
897 .capability = "dvKit",
898 .capabilityData = (unsigned char *)"capdata3",
899 .dataLen = sizeof("capdata3")
900 };
901
902 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
903 EXPECT_TRUE(ret == 0);
904 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
905
906 testInfo.capability = "hicall";
907 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
908 EXPECT_TRUE(ret == 0);
909 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
910
911 testInfo.capability = "profile";
912 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
913 EXPECT_TRUE(ret == 0);
914 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
915
916 testInfo.capability = "homevisionPic";
917 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
918 EXPECT_TRUE(ret == 0);
919 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
920
921 testInfo.capability = "castPlus";
922 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
923 EXPECT_TRUE(ret == 0);
924 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
925
926 testInfo.capability = "aaCapability";
927 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
928 EXPECT_TRUE(ret == 0);
929 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
930
931 testInfo.capability = "ddmpCapability";
932 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
933 EXPECT_TRUE(ret == 0);
934 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
935
936 testInfo.capability = "osdCapability";
937 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
938 EXPECT_TRUE(ret == 0);
939 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
940 }
941
942 /**
943 * @tc.name: UnpublishServiceTest001
944 * @tc.desc: Extern module stop publishuse the wrong parameter.
945 * @tc.in: Test module, Test number, Test levels.
946 * @tc.out: Nonzero
947 * @tc.type: FUNC
948 * @tc.require: The UnPublishService operates normally.
949 */
950 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest001, TestSize.Level1)
951 {
952 int ret;
953 int tmpId = GetPublishId();
954
955 g_pInfo.publishId = tmpId;
956 PublishService(g_pkgName, &g_pInfo, &g_publishCb);
957
958 ret = UnPublishService(NULL, tmpId);
959 EXPECT_TRUE(ret != 0);
960
961 ret = UnPublishService(g_erroPkgName, tmpId);
962 EXPECT_TRUE(ret != 0);
963
964 ret = UnPublishService(g_pkgName1, tmpId);
965 EXPECT_TRUE(ret != 0);
966 }
967
968 /**
969 * @tc.name: UnpublishServiceTest002
970 * @tc.desc: Extern module stop publishuse the normal parameter.
971 * @tc.in: Test module, Test number, Test levels.
972 * @tc.out: Zero
973 * @tc.type: FUNC
974 * @tc.require: The UnPublishService operates normally.
975 */
976 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest002, TestSize.Level1)
977 {
978 int ret;
979 int tmpId1 = GetPublishId();
980 int tmpId2 = GetPublishId();
981 g_pInfo.publishId = tmpId1;
982 PublishService(g_pkgName, &g_pInfo, &g_publishCb);
983 g_pInfo1.publishId = tmpId2;
984 PublishService(g_pkgName, &g_pInfo1, &g_publishCb);
985
986 ret = UnPublishService(g_pkgName, tmpId1);
987 EXPECT_TRUE(ret == 0);
988
989 ret = UnPublishService(g_pkgName, tmpId2);
990 EXPECT_TRUE(ret == 0);
991 }
992
993 /**
994 * @tc.name: UnpublishServiceTest003
995 * @tc.desc: Extern module stop publishrelease the same parameter again, perform two subscriptions.
996 * @tc.in: Test module, Test number, Test levels.
997 * @tc.out: Nonzero
998 * @tc.type: FUNC
999 * @tc.require: The UnPublishService operates normally.
1000 */
1001 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest003, TestSize.Level1)
1002 {
1003 int ret;
1004 int tmpId = GetPublishId();
1005
1006 g_pInfo.publishId = tmpId;
1007 PublishService(g_pkgName, &g_pInfo, &g_publishCb);
1008
1009 ret = UnPublishService(g_pkgName, tmpId);
1010 ret = UnPublishService(g_pkgName, tmpId);
1011 EXPECT_TRUE(ret != 0);
1012 }
1013
1014 /**
1015 * @tc.name: UnpublishServiceTest004
1016 * @tc.desc: Extern module stop publish, use the normal parameter and different frequencies under active BLE.
1017 * @tc.in: Test module, Test number, Test levels.
1018 * @tc.out: Zero
1019 * @tc.type: FUNC
1020 * @tc.require: The UnPublishService operates normally.
1021 */
1022 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest004, TestSize.Level1)
1023 {
1024 int ret;
1025 PublishInfo testInfo = {
1026 .publishId = GetPublishId(),
1027 .mode = DISCOVER_MODE_ACTIVE,
1028 .medium = BLE,
1029 .freq = LOW,
1030 .capability = "dvKit",
1031 .capabilityData = (unsigned char *)"capdata2",
1032 .dataLen = sizeof("capdata2")
1033 };
1034
1035 PublishService(g_pkgName, &testInfo, &g_publishCb);
1036 ret = UnPublishService(g_pkgName, testInfo.publishId);
1037 EXPECT_TRUE(ret == 0);
1038
1039 testInfo.freq = MID;
1040 PublishService(g_pkgName, &testInfo, &g_publishCb);
1041 ret = UnPublishService(g_pkgName, testInfo.publishId);
1042 EXPECT_TRUE(ret == 0);
1043
1044 testInfo.freq = HIGH;
1045 PublishService(g_pkgName, &testInfo, &g_publishCb);
1046 ret = UnPublishService(g_pkgName, testInfo.publishId);
1047 EXPECT_TRUE(ret == 0);
1048
1049 testInfo.freq = SUPER_HIGH;
1050 PublishService(g_pkgName, &testInfo, &g_publishCb);
1051 ret = UnPublishService(g_pkgName, testInfo.publishId);
1052 EXPECT_TRUE(ret == 0);
1053 }
1054
1055 /**
1056 * @tc.name: UnpublishServiceTest005
1057 * @tc.desc: Extern module stop publish, use the normal parameter and different frequencies under passive BLE.
1058 * @tc.in: Test module, Test number, Test levels.
1059 * @tc.out: Zero
1060 * @tc.type: FUNC
1061 * @tc.require: The UnPublishService operates normally.
1062 */
1063 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest005, TestSize.Level1)
1064 {
1065 int ret;
1066 PublishInfo testInfo = {
1067 .publishId = GetPublishId(),
1068 .mode = DISCOVER_MODE_PASSIVE,
1069 .medium = BLE,
1070 .freq = LOW,
1071 .capability = "dvKit",
1072 .capabilityData = (unsigned char *)"capdata2",
1073 .dataLen = sizeof("capdata2")
1074 };
1075
1076 PublishService(g_pkgName, &testInfo, &g_publishCb);
1077 ret = UnPublishService(g_pkgName, testInfo.publishId);
1078 EXPECT_TRUE(ret == 0);
1079
1080 testInfo.freq = MID;
1081 PublishService(g_pkgName, &testInfo, &g_publishCb);
1082 ret = UnPublishService(g_pkgName, testInfo.publishId);
1083 EXPECT_TRUE(ret == 0);
1084
1085 testInfo.freq = HIGH;
1086 PublishService(g_pkgName, &testInfo, &g_publishCb);
1087 ret = UnPublishService(g_pkgName, testInfo.publishId);
1088 EXPECT_TRUE(ret == 0);
1089
1090 testInfo.freq = SUPER_HIGH;
1091 PublishService(g_pkgName, &testInfo, &g_publishCb);
1092 ret = UnPublishService(g_pkgName, testInfo.publishId);
1093 EXPECT_TRUE(ret == 0);
1094 }
1095
1096 /**
1097 * @tc.name: UnpublishServiceTest006
1098 * @tc.desc: Test active publish, verify correct parameter with passive mode,"BLE" medium and diff capability.
1099 * @tc.in: Test module, Test number, Test levels.
1100 * @tc.out: Zero
1101 * @tc.type: FUNC
1102 * @tc.require: The UnPublishService operates normally.
1103 */
1104 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest006, TestSize.Level1)
1105 {
1106 int ret;
1107 PublishInfo testInfo = {
1108 .publishId = GetPublishId(),
1109 .mode = DISCOVER_MODE_PASSIVE,
1110 .medium = BLE,
1111 .freq = LOW,
1112 .capability = "dvKit",
1113 .capabilityData = (unsigned char *)"capdata2",
1114 .dataLen = sizeof("capdata2")
1115 };
1116
1117 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1118 EXPECT_TRUE(ret == 0);
1119 ret = UnPublishService(g_pkgName, testInfo.publishId);
1120
1121 testInfo.capability = "hicall";
1122 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1123 EXPECT_TRUE(ret == 0);
1124 ret = UnPublishService(g_pkgName, testInfo.publishId);
1125
1126 testInfo.capability = "profile";
1127 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1128 EXPECT_TRUE(ret == 0);
1129 ret = UnPublishService(g_pkgName, testInfo.publishId);
1130
1131 testInfo.capability = "homevisionPic";
1132 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1133 EXPECT_TRUE(ret == 0);
1134 ret = UnPublishService(g_pkgName, testInfo.publishId);
1135
1136 testInfo.capability = "castPlus";
1137 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1138 EXPECT_TRUE(ret == 0);
1139 ret = UnPublishService(g_pkgName, testInfo.publishId);
1140
1141 testInfo.capability = "aaCapability";
1142 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1143 EXPECT_TRUE(ret == 0);
1144 ret = UnPublishService(g_pkgName, testInfo.publishId);
1145
1146 testInfo.capability = "ddmpCapability";
1147 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1148 EXPECT_TRUE(ret == 0);
1149 ret = UnPublishService(g_pkgName, testInfo.publishId);
1150
1151 testInfo.capability = "osdCapability";
1152 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1153 EXPECT_TRUE(ret == 0);
1154 ret = UnPublishService(g_pkgName, testInfo.publishId);
1155 }
1156
1157 /**
1158 * @tc.name: UnpublishServiceTest007
1159 * @tc.desc: Test active publish, verify correct parameter with active mode,"BLE" medium and diff capability.
1160 * @tc.in: Test module, Test number, Test levels.
1161 * @tc.out: Zero
1162 * @tc.type: FUNC
1163 * @tc.require: The UnPublishService operates normally.
1164 */
1165 HWTEST_F(DiscSdkTestBle, UnpublishServiceTest007, TestSize.Level1)
1166 {
1167 int ret;
1168 PublishInfo testInfo = {
1169 .publishId = GetPublishId(),
1170 .mode = DISCOVER_MODE_ACTIVE,
1171 .medium = BLE,
1172 .freq = LOW,
1173 .capability = "dvKit",
1174 .capabilityData = (unsigned char *)"capdata2",
1175 .dataLen = sizeof("capdata2")
1176 };
1177
1178 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1179 EXPECT_TRUE(ret == 0);
1180 ret = UnPublishService(g_pkgName, testInfo.publishId);
1181
1182 testInfo.capability = "hicall";
1183 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1184 EXPECT_TRUE(ret == 0);
1185 ret = UnPublishService(g_pkgName, testInfo.publishId);
1186
1187 testInfo.capability = "profile";
1188 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1189 EXPECT_TRUE(ret == 0);
1190 ret = UnPublishService(g_pkgName, testInfo.publishId);
1191
1192 testInfo.capability = "homevisionPic";
1193 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1194 EXPECT_TRUE(ret == 0);
1195 ret = UnPublishService(g_pkgName, testInfo.publishId);
1196
1197 testInfo.capability = "castPlus";
1198 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1199 EXPECT_TRUE(ret == 0);
1200 ret = UnPublishService(g_pkgName, testInfo.publishId);
1201
1202 testInfo.capability = "aaCapability";
1203 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1204 EXPECT_TRUE(ret == 0);
1205 ret = UnPublishService(g_pkgName, testInfo.publishId);
1206
1207 testInfo.capability = "ddmpCapability";
1208 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1209 EXPECT_TRUE(ret == 0);
1210 ret = UnPublishService(g_pkgName, testInfo.publishId);
1211
1212 testInfo.capability = "osdCapability";
1213 ret = PublishService(g_pkgName, &testInfo, &g_publishCb);
1214 EXPECT_TRUE(ret == 0);
1215 ret = UnPublishService(g_pkgName, testInfo.publishId);
1216 }
1217
1218 /**
1219 * @tc.name: StopDiscoveryTest001
1220 * @tc.desc: Extern module stop discoveruse the wrong parameter.
1221 * @tc.in: test module, test number, Test Levels.
1222 * @tc.out: Nonzero
1223 * @tc.type: FUNC
1224 * @tc.require: The StopDiscovery operates normally
1225 */
1226 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest001, TestSize.Level1)
1227 {
1228 int ret;
1229 int tmpId = GetSubscribeId();
1230
1231 g_sInfo.subscribeId = tmpId;
1232 StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
1233
1234 ret = StopDiscovery(NULL, tmpId);
1235 EXPECT_TRUE(ret != 0);
1236
1237 ret = StopDiscovery(g_erroPkgName, tmpId);
1238 EXPECT_TRUE(ret != 0);
1239
1240 ret = StopDiscovery(g_pkgName1, tmpId);
1241 EXPECT_TRUE(ret != 0);
1242 }
1243
1244 /**
1245 * @tc.name: StopDiscoveryTest002
1246 * @tc.desc: Extern module stop discoveruse the normal parameter.
1247 * @tc.in: test module, test number, Test Levels.
1248 * @tc.out: Zero
1249 * @tc.type: FUNC
1250 * @tc.require: The StopDiscovery operates normally
1251 */
1252 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest002, TestSize.Level1)
1253 {
1254 int ret;
1255 int tmpId1 = GetSubscribeId();
1256 int tmpId2 = GetSubscribeId();
1257
1258 g_sInfo.subscribeId = tmpId1;
1259 StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
1260 g_sInfo1.subscribeId = tmpId2;
1261 StartDiscovery(g_pkgName, &g_sInfo1, &g_subscribeCb);
1262
1263 ret = StopDiscovery(g_pkgName, tmpId1);
1264 EXPECT_TRUE(ret == 0);
1265
1266 ret = StopDiscovery(g_pkgName, tmpId2);
1267 EXPECT_TRUE(ret == 0);
1268 }
1269
1270 /**
1271 * @tc.name: StopDiscoveryTest003
1272 * @tc.desc: Extern module stop discoverrelease the same parameter again, perform two subscriptions.
1273 * @tc.in: test module, test number, Test Levels.
1274 * @tc.out: Zero
1275 * @tc.type: FUNC
1276 * @tc.require: The StopDiscovery operates normally
1277 */
1278 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest003, TestSize.Level1)
1279 {
1280 int ret;
1281 int tmpId = GetSubscribeId();
1282
1283 g_sInfo.subscribeId = tmpId;
1284 StartDiscovery(g_pkgName, &g_sInfo, &g_subscribeCb);
1285
1286 ret = StopDiscovery(g_pkgName, tmpId);
1287 ret = StopDiscovery(g_pkgName, tmpId);
1288 EXPECT_TRUE(ret != 0);
1289 }
1290
1291 /**
1292 * @tc.name: StopDiscoveryTest004
1293 * @tc.desc:Test extern module stop active discover, use Diff Freq Under the BLE.
1294 * @tc.in: test module, test number, Test Levels.
1295 * @tc.out: Nonzero
1296 * @tc.type: FUNC
1297 * @tc.require: The StopDiscovery operates normally
1298 */
1299 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest004, TestSize.Level1)
1300 {
1301 int ret;
1302 SubscribeInfo testInfo = {
1303 .subscribeId = GetSubscribeId(),
1304 .mode = DISCOVER_MODE_ACTIVE,
1305 .medium = BLE,
1306 .freq = LOW,
1307 .isSameAccount = true,
1308 .isWakeRemote = false,
1309 .capability = "dvKit",
1310 .capabilityData = (unsigned char *)"capdata3",
1311 .dataLen = sizeof("capdata3")
1312 };
1313 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1314 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1315 EXPECT_TRUE(ret == 0);
1316
1317 testInfo.freq = MID;
1318 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1319 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1320 EXPECT_TRUE(ret == 0);
1321
1322 testInfo.freq = HIGH;
1323 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1324 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1325 EXPECT_TRUE(ret == 0);
1326
1327 testInfo.freq = SUPER_HIGH;
1328 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1329 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1330 EXPECT_TRUE(ret == 0);
1331 }
1332
1333 /**
1334 * @tc.name: StopDiscoveryTest005
1335 * @tc.desc:Test extern module stop passive discover, use Diff Freq Under the BLE.
1336 * @tc.in: test module, test number, Test Levels.
1337 * @tc.out: Zero
1338 * @tc.type: FUNC
1339 * @tc.require: The StopDiscovery operates normally
1340 */
1341 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest005, TestSize.Level1)
1342 {
1343 int ret;
1344 SubscribeInfo testInfo = {
1345 .subscribeId = GetSubscribeId(),
1346 .mode = DISCOVER_MODE_PASSIVE,
1347 .medium = BLE,
1348 .freq = LOW,
1349 .isSameAccount = true,
1350 .isWakeRemote = false,
1351 .capability = "dvKit",
1352 .capabilityData = (unsigned char *)"capdata3",
1353 .dataLen = sizeof("capdata3")
1354 };
1355 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1356 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1357 EXPECT_TRUE(ret == 0);
1358
1359 testInfo.freq = MID;
1360 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1361 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1362 EXPECT_TRUE(ret == 0);
1363
1364 testInfo.freq = HIGH;
1365 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1366 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1367 EXPECT_TRUE(ret == 0);
1368
1369 testInfo.freq = SUPER_HIGH;
1370 StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1371 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1372 EXPECT_TRUE(ret == 0);
1373 }
1374
1375 /**
1376 * @tc.name: StopDiscoveryTest006
1377 * @tc.desc: Test active publish, verify correct parameter with passive mode,"BLE" medium and diff capability.
1378 * @tc.in: Test module, Test number, Test levels.
1379 * @tc.out: Zero
1380 * @tc.type: FUNC
1381 * @tc.require:The StopDiscovery operates normally
1382 */
1383 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest006, TestSize.Level1)
1384 {
1385 int ret;
1386 SubscribeInfo testInfo = {
1387 .subscribeId = GetSubscribeId(),
1388 .mode = DISCOVER_MODE_PASSIVE,
1389 .medium = BLE,
1390 .freq = LOW,
1391 .isSameAccount = true,
1392 .isWakeRemote = false,
1393 .capability = "dvKit",
1394 .capabilityData = (unsigned char *)"capdata3",
1395 .dataLen = sizeof("capdata3")
1396 };
1397
1398 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1399 EXPECT_TRUE(ret == 0);
1400 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1401
1402 testInfo.capability = "hicall";
1403 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1404 EXPECT_TRUE(ret == 0);
1405 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1406
1407 testInfo.capability = "profile";
1408 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1409 EXPECT_TRUE(ret == 0);
1410 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1411
1412 testInfo.capability = "homevisionPic";
1413 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1414 EXPECT_TRUE(ret == 0);
1415 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1416
1417 testInfo.capability = "castPlus";
1418 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1419 EXPECT_TRUE(ret == 0);
1420 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1421
1422 testInfo.capability = "aaCapability";
1423 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1424 EXPECT_TRUE(ret == 0);
1425 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1426
1427 testInfo.capability = "ddmpCapability";
1428 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1429 EXPECT_TRUE(ret == 0);
1430 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1431
1432 testInfo.capability = "osdCapability";
1433 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1434 EXPECT_TRUE(ret == 0);
1435 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1436 }
1437
1438 /**
1439 * @tc.name:StopDiscoveryTest007
1440 * @tc.desc: Test active publish, verify correct parameter with active mode,"BLE" medium and diff capability.
1441 * @tc.in: Test module, Test number, Test levels.
1442 * @tc.out: Zero
1443 * @tc.type: FUNC
1444 * @tc.require:The StopDiscovery operates normally
1445 */
1446 HWTEST_F(DiscSdkTestBle, StopDiscoveryTest007, TestSize.Level1)
1447 {
1448 int ret;
1449 SubscribeInfo testInfo = {
1450 .subscribeId = GetSubscribeId(),
1451 .mode = DISCOVER_MODE_ACTIVE,
1452 .medium = BLE,
1453 .freq = LOW,
1454 .isSameAccount = true,
1455 .isWakeRemote = false,
1456 .capability = "dvKit",
1457 .capabilityData = (unsigned char *)"capdata3",
1458 .dataLen = sizeof("capdata3")
1459 };
1460
1461 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1462 EXPECT_TRUE(ret == 0);
1463 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1464
1465 testInfo.capability = "hicall";
1466 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1467 EXPECT_TRUE(ret == 0);
1468 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1469
1470 testInfo.capability = "profile";
1471 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1472 EXPECT_TRUE(ret == 0);
1473 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1474
1475 testInfo.capability = "homevisionPic";
1476 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1477 EXPECT_TRUE(ret == 0);
1478 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1479
1480 testInfo.capability = "castPlus";
1481 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1482 EXPECT_TRUE(ret == 0);
1483 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1484
1485 testInfo.capability = "aaCapability";
1486 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1487 EXPECT_TRUE(ret == 0);
1488 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1489
1490 testInfo.capability = "ddmpCapability";
1491 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1492 EXPECT_TRUE(ret == 0);
1493 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1494
1495 testInfo.capability = "osdCapability";
1496 ret = StartDiscovery(g_pkgName, &testInfo, &g_subscribeCb);
1497 EXPECT_TRUE(ret == 0);
1498 ret = StopDiscovery(g_pkgName, testInfo.subscribeId);
1499 }
1500 } // namespace OHOS
1501