• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <gtest/gtest.h>
17 #include <unistd.h>
18 
19 #include "disc_ble_dispatcher.h"
20 #include "disc_interface.h"
21 #include "disc_log.h"
22 #include "softbus_error_code.h"
23 
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 typedef struct {
28     int32_t publishCntA;
29     int32_t startScanCntA;
30     int32_t unpublishCntA;
31     int32_t stopScanCntA;
32     int32_t startAdvertiseCntA;
33     int32_t subscribeCntA;
34     int32_t unsubscribeCntA;
35     int32_t stopAdvertiseCntA;
36     int32_t linkStatusChangedCntA;
37     int32_t updateLocalDeviceInfoCntA;
38 } InterfaceFunCntA;
39 
40 typedef struct {
41     int32_t publishCntB;
42     int32_t startScanCntB;
43     int32_t unpublishCntB;
44     int32_t stopScanCntB;
45     int32_t startAdvertiseCntB;
46     int32_t subscribeCntB;
47     int32_t stopAdvertiseCntB;
48     int32_t unsubscribeCntB;
49 } InterfaceFunCntB;
50 
51 #define IS_CONCERNA 1
52 #define IS_CONCERNB 2
53 InterfaceFunCntA g_interfaceFunCntA = { .publishCntA = 0,
54     .startScanCntA = 0,
55     .unpublishCntA = 0,
56     .stopScanCntA = 0,
57     .startAdvertiseCntA = 0,
58     .subscribeCntA = 0,
59     .unsubscribeCntA = 0,
60     .stopAdvertiseCntA = 0,
61     .linkStatusChangedCntA = 0,
62     .updateLocalDeviceInfoCntA = 0 };
63 
64 InterfaceFunCntB g_interfaceFunCntB = {
65     .publishCntB = 0,
66     .startScanCntB = 0,
67     .unpublishCntB = 0,
68     .stopScanCntB = 0,
69     .startAdvertiseCntB = 0,
70     .subscribeCntB = 0,
71     .stopAdvertiseCntB = 0,
72     .unsubscribeCntB = 0,
73 };
IsConcernA(uint32_t capability)74 static bool IsConcernA(uint32_t capability)
75 {
76     if (capability == IS_CONCERNA) {
77         return true;
78     }
79     return false;
80 }
81 
IsConcernB(uint32_t capability)82 static bool IsConcernB(uint32_t capability)
83 {
84     if (capability == IS_CONCERNB) {
85         return true;
86     }
87     return false;
88 }
89 
PublishA(const PublishOption * option)90 static int32_t PublishA(const PublishOption *option)
91 {
92     if (IsConcernA(option->capabilityBitmap[0])) {
93         g_interfaceFunCntA.publishCntA = 1;
94         return SOFTBUS_OK;
95     }
96     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
97 }
98 
StartScanA(const PublishOption * option)99 static int32_t StartScanA(const PublishOption *option)
100 {
101     if (IsConcernA(option->capabilityBitmap[0])) {
102         g_interfaceFunCntA.startScanCntA = 1;
103         return SOFTBUS_OK;
104     }
105     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
106 }
107 
UnpublishA(const PublishOption * option)108 static int32_t UnpublishA(const PublishOption *option)
109 {
110     if (IsConcernA(option->capabilityBitmap[0])) {
111         g_interfaceFunCntA.unpublishCntA = 1;
112         return SOFTBUS_OK;
113     }
114     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
115 }
116 
StopScanA(const PublishOption * option)117 static int32_t StopScanA(const PublishOption *option)
118 {
119     if (IsConcernA(option->capabilityBitmap[0])) {
120         g_interfaceFunCntA.stopScanCntA = 1;
121         return SOFTBUS_OK;
122     }
123     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
124 }
125 
StartAdvertiseA(const SubscribeOption * option)126 static int32_t StartAdvertiseA(const SubscribeOption *option)
127 {
128     if (IsConcernA(option->capabilityBitmap[0])) {
129         g_interfaceFunCntA.startAdvertiseCntA = 1;
130         return SOFTBUS_OK;
131     }
132     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
133 }
134 
SubscribeA(const SubscribeOption * option)135 static int32_t SubscribeA(const SubscribeOption *option)
136 {
137     if (IsConcernA(option->capabilityBitmap[0])) {
138         g_interfaceFunCntA.subscribeCntA = 1;
139         return SOFTBUS_OK;
140     }
141     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
142 }
143 
UnsubscribeA(const SubscribeOption * option)144 static int32_t UnsubscribeA(const SubscribeOption *option)
145 {
146     if (IsConcernA(option->capabilityBitmap[0])) {
147         g_interfaceFunCntA.unsubscribeCntA = 1;
148         return SOFTBUS_OK;
149     }
150     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
151 }
152 
StopAdvertiseA(const SubscribeOption * option)153 static int32_t StopAdvertiseA(const SubscribeOption *option)
154 {
155     if (IsConcernA(option->capabilityBitmap[0])) {
156         g_interfaceFunCntA.stopAdvertiseCntA = 1;
157         return SOFTBUS_OK;
158     }
159     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
160 }
161 
LinkStatusChangedA(LinkStatus status)162 static void LinkStatusChangedA(LinkStatus status)
163 {
164     g_interfaceFunCntA.linkStatusChangedCntA = 1;
165 }
166 
UpdateLocalDeviceInfoA(InfoTypeChanged type)167 static void UpdateLocalDeviceInfoA(InfoTypeChanged type)
168 {
169     (void)type;
170     g_interfaceFunCntA.updateLocalDeviceInfoCntA = 1;
171 }
172 
PublishB(const PublishOption * option)173 static int32_t PublishB(const PublishOption *option)
174 {
175     if (IsConcernB(option->capabilityBitmap[0])) {
176         g_interfaceFunCntB.publishCntB = 1;
177         return SOFTBUS_OK;
178     }
179     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
180 }
181 
StartScanB(const PublishOption * option)182 static int32_t StartScanB(const PublishOption *option)
183 {
184     if (IsConcernB(option->capabilityBitmap[0])) {
185         g_interfaceFunCntB.startScanCntB = 1;
186         return SOFTBUS_OK;
187     }
188     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
189 }
190 
UnpublishB(const PublishOption * option)191 static int32_t UnpublishB(const PublishOption *option)
192 {
193     if (IsConcernB(option->capabilityBitmap[0])) {
194         g_interfaceFunCntB.unpublishCntB = 1;
195         return SOFTBUS_OK;
196     }
197     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
198 }
199 
StopScanB(const PublishOption * option)200 static int32_t StopScanB(const PublishOption *option)
201 {
202     if (IsConcernB(option->capabilityBitmap[0])) {
203         g_interfaceFunCntB.stopScanCntB = 1;
204         return SOFTBUS_OK;
205     }
206     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
207 }
208 
StartAdvertiseB(const SubscribeOption * option)209 static int32_t StartAdvertiseB(const SubscribeOption *option)
210 {
211     if (IsConcernB(option->capabilityBitmap[0])) {
212         g_interfaceFunCntB.startAdvertiseCntB = 1;
213         return SOFTBUS_OK;
214     }
215     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
216 }
217 
SubscribeB(const SubscribeOption * option)218 static int32_t SubscribeB(const SubscribeOption *option)
219 {
220     if (IsConcernB(option->capabilityBitmap[0])) {
221         g_interfaceFunCntB.subscribeCntB = 1;
222         return SOFTBUS_OK;
223     }
224     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
225 }
226 
UnsubscribeB(const SubscribeOption * option)227 static int32_t UnsubscribeB(const SubscribeOption *option)
228 {
229     if (IsConcernB(option->capabilityBitmap[0])) {
230         g_interfaceFunCntB.unsubscribeCntB = 1;
231         return SOFTBUS_OK;
232     }
233     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
234 }
235 
StopAdvertiseB(const SubscribeOption * option)236 static int32_t StopAdvertiseB(const SubscribeOption *option)
237 {
238     if (IsConcernB(option->capabilityBitmap[0])) {
239         g_interfaceFunCntB.stopAdvertiseCntB = 1;
240         return SOFTBUS_OK;
241     }
242     return SOFTBUS_DISCOVER_TEST_CASE_ERRCODE;
243 }
244 
245 static PublishOption g_pOption0 = {
246     .freq = 1,
247     .capabilityBitmap = {0},
248     .capabilityData = nullptr,
249     .dataLen = 0,
250     .ranging = true
251 };
252 
253 static SubscribeOption g_sOption0 = { .freq = 1,
254     .isSameAccount = true,
255     .isWakeRemote = false,
256     .capabilityBitmap = { 0 },
257     .capabilityData = nullptr,
258     .dataLen = 0 };
259 
260 static PublishOption g_pOption1 = {
261     .freq = 1,
262     .capabilityBitmap = {1},
263     .capabilityData = nullptr,
264     .dataLen = 0,
265     .ranging = true
266 };
267 
268 static SubscribeOption g_sOption1 = { .freq = 1,
269     .isSameAccount = true,
270     .isWakeRemote = false,
271     .capabilityBitmap = { 1 },
272     .capabilityData = nullptr,
273     .dataLen = 0 };
274 
275 static PublishOption g_pOption2 = {
276     .freq = 1,
277     .capabilityBitmap = {2},
278     .capabilityData = nullptr,
279     .dataLen = 0,
280     .ranging = true
281 };
282 
283 static SubscribeOption g_sOption2 = { .freq = 1,
284     .isSameAccount = true,
285     .isWakeRemote = false,
286     .capabilityBitmap = { 2 },
287     .capabilityData = nullptr,
288     .dataLen = 0 };
289 
290 static PublishOption g_pOption3 = {
291     .freq = 1,
292     .capabilityBitmap = {3},
293     .capabilityData = nullptr,
294     .dataLen = 0,
295     .ranging = true
296 };
297 
298 static SubscribeOption g_sOption3 = { .freq = 1,
299     .isSameAccount = true,
300     .isWakeRemote = false,
301     .capabilityBitmap = { 3 },
302     .capabilityData = nullptr,
303     .dataLen = 0 };
304 
305 class DiscBleDispatcherTest : public testing::Test {
306 public:
DiscBleDispatcherTest()307     DiscBleDispatcherTest() { }
~DiscBleDispatcherTest()308     ~DiscBleDispatcherTest() { }
309     static void SetUpTestCase(void);
310     static void TearDownTestCase(void);
311     void SetUp();
312     void TearDown();
313 };
314 
315 static DiscoveryFuncInterface g_discoveryFuncA = {
316     .Publish = PublishA,
317     .StartScan = StartScanA,
318     .Unpublish = UnpublishA,
319     .StopScan = StopScanA,
320     .StartAdvertise = StartAdvertiseA,
321     .Subscribe = SubscribeA,
322     .Unsubscribe = UnsubscribeA,
323     .StopAdvertise = StopAdvertiseA,
324     .LinkStatusChanged = LinkStatusChangedA,
325     .UpdateLocalDeviceInfo = UpdateLocalDeviceInfoA,
326 };
327 
328 static DiscoveryBleDispatcherInterface g_interfaceA = {
329     .IsConcern = IsConcernA,
330     .mediumInterface = &g_discoveryFuncA,
331 };
332 
333 static DiscoveryFuncInterface g_discoveryFuncB = {
334     .Publish = PublishB,
335     .StartScan = StartScanB,
336     .Unpublish = UnpublishB,
337     .StopScan = StopScanB,
338     .StartAdvertise = StartAdvertiseB,
339     .Subscribe = SubscribeB,
340     .Unsubscribe = UnsubscribeB,
341     .StopAdvertise = StopAdvertiseB,
342     .LinkStatusChanged = LinkStatusChangedA,
343     .UpdateLocalDeviceInfo = UpdateLocalDeviceInfoA,
344 };
345 
346 static DiscoveryBleDispatcherInterface g_interfaceB = {
347     .IsConcern = IsConcernB,
348     .mediumInterface = &g_discoveryFuncB,
349 };
350 
SetUpTestCase(void)351 void DiscBleDispatcherTest::SetUpTestCase(void) { }
352 
TearDownTestCase(void)353 void DiscBleDispatcherTest::TearDownTestCase(void) { }
354 
SetUp(void)355 void DiscBleDispatcherTest::SetUp(void) { }
356 
TearDown(void)357 void DiscBleDispatcherTest::TearDown(void) { }
358 
359 /*
360  * @tc.name: testDiscPublish001
361  * @tc.desc: test dispatcher
362  * @tc.type: FUNC
363  * @tc.require:
364  */
365 HWTEST_F(DiscBleDispatcherTest, testDiscPublish001, TestSize.Level1)
366 {
367     printf("testDiscPublish001\r\n");
368     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
369     int32_t ret;
370     int32_t beforeFunCntA;
371     int32_t beforeFunCntB;
372     int32_t afterFunCntA;
373     int32_t afterFunCntB;
374 
375     beforeFunCntA = g_interfaceFunCntA.publishCntA;
376     beforeFunCntB = g_interfaceFunCntB.publishCntB;
377     ret = interface->Publish(&g_pOption1);
378     afterFunCntA = g_interfaceFunCntA.publishCntA;
379     afterFunCntB = g_interfaceFunCntB.publishCntB;
380     EXPECT_EQ(SOFTBUS_OK, ret);
381     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
382     EXPECT_EQ(beforeFunCntB, afterFunCntB);
383 
384     beforeFunCntA = g_interfaceFunCntA.startScanCntA;
385     beforeFunCntB = g_interfaceFunCntB.startScanCntB;
386     ret = interface->StartScan(&g_pOption1);
387     afterFunCntA = g_interfaceFunCntA.startScanCntA;
388     afterFunCntB = g_interfaceFunCntB.startScanCntB;
389     EXPECT_EQ(SOFTBUS_OK, ret);
390     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
391     EXPECT_EQ(beforeFunCntB, afterFunCntB);
392 
393     beforeFunCntA = g_interfaceFunCntA.unpublishCntA;
394     beforeFunCntB = g_interfaceFunCntB.unpublishCntB;
395     ret = interface->Unpublish(&g_pOption1);
396     afterFunCntA = g_interfaceFunCntA.unpublishCntA;
397     afterFunCntB = g_interfaceFunCntB.unpublishCntB;
398     EXPECT_EQ(SOFTBUS_OK, ret);
399     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
400     EXPECT_EQ(beforeFunCntB, afterFunCntB);
401 
402     beforeFunCntA = g_interfaceFunCntA.stopScanCntA;
403     beforeFunCntB = g_interfaceFunCntB.stopScanCntB;
404     ret = interface->StopScan(&g_pOption1);
405     afterFunCntA = g_interfaceFunCntA.stopScanCntA;
406     afterFunCntB = g_interfaceFunCntB.stopScanCntB;
407     EXPECT_EQ(SOFTBUS_OK, ret);
408     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
409     EXPECT_EQ(beforeFunCntB, afterFunCntB);
410 };
411 
412 /*
413  * @tc.name: testDiscovery001
414  * @tc.desc: test dispatcher
415  * @tc.type: FUNC
416  * @tc.require:
417  */
418 HWTEST_F(DiscBleDispatcherTest, testDiscovery001, TestSize.Level1)
419 {
420     printf("testDiscovery001\r\n");
421     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
422     int32_t ret;
423     int32_t beforeFunCntA;
424     int32_t beforeFunCntB;
425     int32_t afterFunCntA;
426     int32_t afterFunCntB;
427 
428     beforeFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
429     beforeFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
430     ret = interface->StartAdvertise(&g_sOption1);
431     afterFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
432     afterFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
433     EXPECT_EQ(SOFTBUS_OK, ret);
434     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
435     EXPECT_EQ(beforeFunCntB, afterFunCntB);
436 
437     beforeFunCntA = g_interfaceFunCntA.subscribeCntA;
438     beforeFunCntB = g_interfaceFunCntB.subscribeCntB;
439     ret = interface->Subscribe(&g_sOption1);
440     afterFunCntA = g_interfaceFunCntA.subscribeCntA;
441     afterFunCntB = g_interfaceFunCntB.subscribeCntB;
442     EXPECT_EQ(SOFTBUS_OK, ret);
443     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
444     EXPECT_EQ(beforeFunCntB, afterFunCntB);
445 
446     beforeFunCntA = g_interfaceFunCntA.unsubscribeCntA;
447     beforeFunCntB = g_interfaceFunCntB.unsubscribeCntB;
448     ret = interface->Unsubscribe(&g_sOption1);
449     afterFunCntA = g_interfaceFunCntA.unsubscribeCntA;
450     afterFunCntB = g_interfaceFunCntB.unsubscribeCntB;
451     EXPECT_EQ(SOFTBUS_OK, ret);
452     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
453     EXPECT_EQ(beforeFunCntB, afterFunCntB);
454 
455     beforeFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
456     beforeFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
457     ret = interface->StopAdvertise(&g_sOption1);
458     afterFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
459     afterFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
460     EXPECT_EQ(SOFTBUS_OK, ret);
461     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
462     EXPECT_EQ(beforeFunCntB, afterFunCntB);
463 };
464 
465 /*
466  * @tc.name: testDiscPublish002
467  * @tc.desc: test dispatcher
468  * @tc.type: FUNC
469  * @tc.require:
470  */
471 HWTEST_F(DiscBleDispatcherTest, testDiscPublish002, TestSize.Level1)
472 {
473     printf("testDiscPublish002\r\n");
474     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
475     int32_t ret;
476     int32_t beforeFunCntA;
477     int32_t beforeFunCntB;
478     int32_t afterFunCntA;
479     int32_t afterFunCntB;
480 
481     beforeFunCntA = g_interfaceFunCntA.publishCntA;
482     beforeFunCntB = g_interfaceFunCntB.publishCntB;
483     ret = interface->Publish(&g_pOption2);
484     afterFunCntA = g_interfaceFunCntA.publishCntA;
485     afterFunCntB = g_interfaceFunCntB.publishCntB;
486     EXPECT_EQ(SOFTBUS_OK, ret);
487     EXPECT_EQ(beforeFunCntA, afterFunCntA);
488     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
489 
490     beforeFunCntA = g_interfaceFunCntA.startScanCntA;
491     beforeFunCntB = g_interfaceFunCntB.startScanCntB;
492     ret = interface->StartScan(&g_pOption2);
493     afterFunCntA = g_interfaceFunCntA.startScanCntA;
494     afterFunCntB = g_interfaceFunCntB.startScanCntB;
495     EXPECT_EQ(SOFTBUS_OK, ret);
496     EXPECT_EQ(beforeFunCntA, afterFunCntA);
497     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
498 
499     beforeFunCntA = g_interfaceFunCntA.unpublishCntA;
500     beforeFunCntB = g_interfaceFunCntB.unpublishCntB;
501     ret = interface->Unpublish(&g_pOption2);
502     afterFunCntA = g_interfaceFunCntA.unpublishCntA;
503     afterFunCntB = g_interfaceFunCntB.unpublishCntB;
504     EXPECT_EQ(SOFTBUS_OK, ret);
505     EXPECT_EQ(beforeFunCntA, afterFunCntA);
506     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
507 
508     beforeFunCntA = g_interfaceFunCntA.stopScanCntA;
509     beforeFunCntB = g_interfaceFunCntB.stopScanCntB;
510     ret = interface->StopScan(&g_pOption2);
511     afterFunCntA = g_interfaceFunCntA.stopScanCntA;
512     afterFunCntB = g_interfaceFunCntB.stopScanCntB;
513     EXPECT_EQ(SOFTBUS_OK, ret);
514     EXPECT_EQ(beforeFunCntA, afterFunCntA);
515     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
516 };
517 
518 /*
519  * @tc.name: testDiscovery002
520  * @tc.desc: test dispatcher
521  * @tc.type: FUNC
522  * @tc.require:
523  */
524 HWTEST_F(DiscBleDispatcherTest, testDiscovery002, TestSize.Level1)
525 {
526     printf("testDiscovery002\r\n");
527     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
528     int32_t ret;
529     int32_t beforeFunCntA;
530     int32_t beforeFunCntB;
531     int32_t afterFunCntA;
532     int32_t afterFunCntB;
533 
534     beforeFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
535     beforeFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
536     ret = interface->StartAdvertise(&g_sOption2);
537     afterFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
538     afterFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
539     EXPECT_EQ(SOFTBUS_OK, ret);
540     EXPECT_EQ(beforeFunCntA, afterFunCntA);
541     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
542 
543     beforeFunCntA = g_interfaceFunCntA.subscribeCntA;
544     beforeFunCntB = g_interfaceFunCntB.subscribeCntB;
545     ret = interface->Subscribe(&g_sOption2);
546     afterFunCntA = g_interfaceFunCntA.subscribeCntA;
547     afterFunCntB = g_interfaceFunCntB.subscribeCntB;
548     EXPECT_EQ(SOFTBUS_OK, ret);
549     EXPECT_EQ(beforeFunCntA, afterFunCntA);
550     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
551 
552     beforeFunCntA = g_interfaceFunCntA.unsubscribeCntA;
553     beforeFunCntB = g_interfaceFunCntB.unsubscribeCntB;
554     ret = interface->Unsubscribe(&g_sOption2);
555     afterFunCntA = g_interfaceFunCntA.unsubscribeCntA;
556     afterFunCntB = g_interfaceFunCntB.unsubscribeCntB;
557     EXPECT_EQ(SOFTBUS_OK, ret);
558     EXPECT_EQ(beforeFunCntA, afterFunCntA);
559     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
560 
561     beforeFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
562     beforeFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
563     ret = interface->StopAdvertise(&g_sOption2);
564     afterFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
565     afterFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
566     EXPECT_EQ(SOFTBUS_OK, ret);
567     EXPECT_EQ(beforeFunCntA, afterFunCntA);
568     EXPECT_EQ(beforeFunCntB + 1, afterFunCntB);
569 };
570 
571 /*
572  * @tc.name: testDiscPublish003
573  * @tc.desc: test dispatcher
574  * @tc.type: FUNC
575  * @tc.require:
576  */
577 HWTEST_F(DiscBleDispatcherTest, testDiscPublish003, TestSize.Level1)
578 {
579     printf("testDiscDispatcher003\r\n");
580     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
581     int32_t ret;
582     int32_t beforeFunCntA;
583     int32_t beforeFunCntB;
584     int32_t afterFunCntA;
585     int32_t afterFunCntB;
586 
587     beforeFunCntA = g_interfaceFunCntA.publishCntA;
588     beforeFunCntB = g_interfaceFunCntB.publishCntB;
589     ret = interface->Publish(&g_pOption3);
590     afterFunCntA = g_interfaceFunCntA.publishCntA;
591     afterFunCntB = g_interfaceFunCntB.publishCntB;
592     EXPECT_NE(SOFTBUS_OK, ret);
593     EXPECT_EQ(beforeFunCntA, afterFunCntA);
594     EXPECT_EQ(beforeFunCntB, afterFunCntB);
595 
596     beforeFunCntA = g_interfaceFunCntA.startScanCntA;
597     beforeFunCntB = g_interfaceFunCntB.startScanCntB;
598     ret = interface->StartScan(&g_pOption3);
599     afterFunCntA = g_interfaceFunCntA.startScanCntA;
600     afterFunCntB = g_interfaceFunCntB.startScanCntB;
601     EXPECT_NE(SOFTBUS_OK, ret);
602     EXPECT_EQ(beforeFunCntA, afterFunCntA);
603     EXPECT_EQ(beforeFunCntB, afterFunCntB);
604 
605     beforeFunCntA = g_interfaceFunCntA.unpublishCntA;
606     beforeFunCntB = g_interfaceFunCntB.unpublishCntB;
607     ret = interface->Unpublish(&g_pOption3);
608     afterFunCntA = g_interfaceFunCntA.unpublishCntA;
609     afterFunCntB = g_interfaceFunCntB.unpublishCntB;
610     EXPECT_NE(SOFTBUS_OK, ret);
611     EXPECT_EQ(beforeFunCntA, afterFunCntA);
612     EXPECT_EQ(beforeFunCntB, afterFunCntB);
613 
614     beforeFunCntA = g_interfaceFunCntA.stopScanCntA;
615     beforeFunCntB = g_interfaceFunCntB.stopScanCntB;
616     ret = interface->StopScan(&g_pOption3);
617     afterFunCntA = g_interfaceFunCntA.stopScanCntA;
618     afterFunCntB = g_interfaceFunCntB.stopScanCntB;
619     EXPECT_NE(SOFTBUS_OK, ret);
620     EXPECT_EQ(beforeFunCntA, afterFunCntA);
621     EXPECT_EQ(beforeFunCntB, afterFunCntB);
622 };
623 
624 /*
625  * @tc.name: testDiscovery003
626  * @tc.desc: test dispatcher
627  * @tc.type: FUNC
628  * @tc.require:
629  */
630 HWTEST_F(DiscBleDispatcherTest, testDiscovery003, TestSize.Level1)
631 {
632     printf("testDiscovery003\r\n");
633     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
634     int32_t ret;
635     int32_t beforeFunCntA;
636     int32_t beforeFunCntB;
637     int32_t afterFunCntA;
638     int32_t afterFunCntB;
639 
640     beforeFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
641     beforeFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
642     ret = interface->StartAdvertise(&g_sOption3);
643     afterFunCntA = g_interfaceFunCntA.startAdvertiseCntA;
644     afterFunCntB = g_interfaceFunCntB.startAdvertiseCntB;
645     EXPECT_NE(SOFTBUS_OK, ret);
646     EXPECT_EQ(beforeFunCntA, afterFunCntA);
647     EXPECT_EQ(beforeFunCntB, afterFunCntB);
648 
649     beforeFunCntA = g_interfaceFunCntA.subscribeCntA;
650     beforeFunCntB = g_interfaceFunCntB.subscribeCntB;
651     ret = interface->Subscribe(&g_sOption3);
652     afterFunCntA = g_interfaceFunCntA.subscribeCntA;
653     afterFunCntB = g_interfaceFunCntB.subscribeCntB;
654     EXPECT_NE(SOFTBUS_OK, ret);
655     EXPECT_EQ(beforeFunCntA, afterFunCntA);
656     EXPECT_EQ(beforeFunCntB, afterFunCntB);
657 
658     beforeFunCntA = g_interfaceFunCntA.unsubscribeCntA;
659     beforeFunCntB = g_interfaceFunCntB.unsubscribeCntB;
660     ret = interface->Unsubscribe(&g_sOption3);
661     afterFunCntA = g_interfaceFunCntA.unsubscribeCntA;
662     afterFunCntB = g_interfaceFunCntB.unsubscribeCntB;
663     EXPECT_NE(SOFTBUS_OK, ret);
664     EXPECT_EQ(beforeFunCntA, afterFunCntA);
665     EXPECT_EQ(beforeFunCntB, afterFunCntB);
666 
667     beforeFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
668     beforeFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
669     ret = interface->StopAdvertise(&g_sOption3);
670     afterFunCntA = g_interfaceFunCntA.stopAdvertiseCntA;
671     afterFunCntB = g_interfaceFunCntB.stopAdvertiseCntB;
672     EXPECT_NE(SOFTBUS_OK, ret);
673     EXPECT_EQ(beforeFunCntA, afterFunCntA);
674     EXPECT_EQ(beforeFunCntB, afterFunCntB);
675 };
676 
677 /*
678  * @tc.name: testLinkStatusChanged001
679  * @tc.desc: test dispatcher
680  * @tc.type: FUNC
681  * @tc.require:
682  */
683 HWTEST_F(DiscBleDispatcherTest, testLinkStatusChanged001, TestSize.Level1)
684 {
685     printf("testLinkStatusChanged001\r\n");
686     static LinkStatus status = LINK_STATUS_UP;
687     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
688     int32_t beforeFunCntA;
689     int32_t afterFunCntA;
690     beforeFunCntA = g_interfaceFunCntA.linkStatusChangedCntA;
691     interface->LinkStatusChanged(status);
692     afterFunCntA = g_interfaceFunCntA.linkStatusChangedCntA;
693     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
694 };
695 
696 /*
697  * @tc.name: testUpdateLocalDeviceInfo001
698  * @tc.desc: test dispatcher
699  * @tc.type: FUNC
700  * @tc.require:
701  */
702 HWTEST_F(DiscBleDispatcherTest, testUpdateLocalDeviceInfo001, TestSize.Level1)
703 {
704     printf("testUpdateLocalDeviceInfo001\r\n");
705     static InfoTypeChanged type = TYPE_LOCAL_DEVICE_NAME;
706     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
707     int32_t beforeFunCntA;
708     int32_t afterFunCntA;
709     beforeFunCntA = g_interfaceFunCntA.updateLocalDeviceInfoCntA;
710     interface->UpdateLocalDeviceInfo(type);
711     afterFunCntA = g_interfaceFunCntA.updateLocalDeviceInfoCntA;
712     EXPECT_EQ(beforeFunCntA + 1, afterFunCntA);
713 }
714 
715 /*
716  * @tc.name: BleDispatchPublishOption001
717  * @tc.desc: test dispatcher
718  * @tc.type: FUNC
719  * @tc.require:
720  */
721 HWTEST_F(DiscBleDispatcherTest, BleDispatchPublishOption001, TestSize.Level1)
722 {
723     DISC_LOGI(DISC_TEST, "BleDispatchPublishOption001");
724     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
725     int32_t ret = interface->Publish(&g_pOption0);
726     EXPECT_EQ(SOFTBUS_DISCOVER_BLE_DISPATCHER_FAIL, ret);
727 }
728 
729 /*
730  * @tc.name: BleDispatchSubscribeOption001
731  * @tc.desc: test dispatcher
732  * @tc.type: FUNC
733  * @tc.require:
734  */
735 HWTEST_F(DiscBleDispatcherTest, BleDispatchSubscribeOption001, TestSize.Level1)
736 {
737     DISC_LOGI(DISC_TEST, "BleDispatchSubscribeOption001");
738     DiscoveryFuncInterface *interface = DiscBleInitForTest(&g_interfaceA, &g_interfaceB);
739     int32_t ret = interface->StartAdvertise(&g_sOption0);
740     EXPECT_EQ(SOFTBUS_DISCOVER_BLE_DISPATCHER_FAIL, ret);
741 }
742 
743 /*
744  * @tc.name: DiscBleInit001
745  * @tc.desc: test dispatcher
746  * @tc.type: FUNC
747  * @tc.require:
748  */
749 HWTEST_F(DiscBleDispatcherTest, DiscBleInit001, TestSize.Level1)
750 {
751     DISC_LOGI(DISC_TEST, "DiscBleInit001");
752     DiscoveryFuncInterface *interface = DiscBleInit(nullptr);
753     EXPECT_EQ(interface, nullptr);
754 }
755 
756 /*
757  * @tc.name: DiscBleInit002
758  * @tc.desc: test dispatcher
759  * @tc.type: FUNC
760  * @tc.require:
761  */
762 HWTEST_F(DiscBleDispatcherTest, DiscBleInit002, TestSize.Level1)
763 {
764     DISC_LOGI(DISC_TEST, "DiscBleInit002");
765     DiscInnerCallback g_discMgrMediumCb;
766     g_discMgrMediumCb.OnDeviceFound = nullptr;
767     DiscoveryFuncInterface *interface = DiscBleInit(&g_discMgrMediumCb);
768     EXPECT_EQ(interface, nullptr);
769 }
770 } // namespace OHOS