1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include "gmock/gmock.h"
17060ff233Sopenharmony_ci#include "gtest/gtest.h"
18060ff233Sopenharmony_ci
19060ff233Sopenharmony_ci#include "softbus_ble_gatt.h"
20060ff233Sopenharmony_ci#include "softbus_broadcast_type.h"
21060ff233Sopenharmony_ci#include "disc_log.h"
22060ff233Sopenharmony_ci#include "c_header/ohos_bt_gatt.h"
23060ff233Sopenharmony_ci#include "softbus_adapter_mem.h"
24060ff233Sopenharmony_ci#include "softbus_errcode.h"
25060ff233Sopenharmony_ci#include "assert_helper.h"
26060ff233Sopenharmony_ci#include "bluetooth_mock.h"
27060ff233Sopenharmony_ci
28060ff233Sopenharmony_ci#define GATT_ADV_MAX_NUM 16
29060ff233Sopenharmony_ci#define GATT_SCAN_MAX_NUM 2
30060ff233Sopenharmony_ci
31060ff233Sopenharmony_ciusing namespace testing::ext;
32060ff233Sopenharmony_ciusing ::testing::AtMost;
33060ff233Sopenharmony_ciusing ::testing::Return;
34060ff233Sopenharmony_ci
35060ff233Sopenharmony_cinamespace OHOS {
36060ff233Sopenharmony_ci
37060ff233Sopenharmony_ciclass ScanResultCtx : public RecordCtx {
38060ff233Sopenharmony_cipublic:
39060ff233Sopenharmony_ci    explicit ScanResultCtx(const char *identifier);
40060ff233Sopenharmony_ci    ~ScanResultCtx();
41060ff233Sopenharmony_ci    bool Update(int32_t scannerId, const SoftBusBcScanResult *reportData);
42060ff233Sopenharmony_ci    testing::AssertionResult Expect(int32_t scannerId, const SoftBusBcScanResult *reportData);
43060ff233Sopenharmony_ciprivate:
44060ff233Sopenharmony_ci    SoftBusBcScanResult scanResult;
45060ff233Sopenharmony_ci    void Reset();
46060ff233Sopenharmony_ci};
47060ff233Sopenharmony_ci
48060ff233Sopenharmony_ciclass SoftbusBleGattTest : public testing::Test {
49060ff233Sopenharmony_cipublic:
50060ff233Sopenharmony_ci    static ScanResultCtx scanResultCtx;
51060ff233Sopenharmony_ci
52060ff233Sopenharmony_ci    static StRecordCtx advEnableCtx;
53060ff233Sopenharmony_ci    static StRecordCtx advDisableCtx;
54060ff233Sopenharmony_ci    static StRecordCtx advDataCtx;
55060ff233Sopenharmony_ci    static StRecordCtx advUpdateCtx;
56060ff233Sopenharmony_ci    static int32_t btInnerAdvId;
57060ff233Sopenharmony_ci
58060ff233Sopenharmony_ci    static void SetUpTestCase(void);
59060ff233Sopenharmony_ci};
60060ff233Sopenharmony_ci
61060ff233Sopenharmony_ciScanResultCtx SoftbusBleGattTest::scanResultCtx("OnReportScanDataCallback");
62060ff233Sopenharmony_ci
63060ff233Sopenharmony_ciStRecordCtx SoftbusBleGattTest::advEnableCtx("AdvEnableCallback");
64060ff233Sopenharmony_ciStRecordCtx SoftbusBleGattTest::advDisableCtx("AdvDisableCallback");
65060ff233Sopenharmony_ciStRecordCtx SoftbusBleGattTest::advDataCtx("AdvDataCallback");
66060ff233Sopenharmony_ciStRecordCtx SoftbusBleGattTest::advUpdateCtx("AdvUpdateCallback");
67060ff233Sopenharmony_ciint32_t SoftbusBleGattTest::btInnerAdvId = -1;
68060ff233Sopenharmony_ci
69060ff233Sopenharmony_civoid SoftbusBleGattTest::SetUpTestCase()
70060ff233Sopenharmony_ci{
71060ff233Sopenharmony_ci    MockBluetooth mocker;
72060ff233Sopenharmony_ci    SoftbusBleAdapterInit();
73060ff233Sopenharmony_ci    MockBluetooth::interface->Init();
74060ff233Sopenharmony_ci}
75060ff233Sopenharmony_ci
76060ff233Sopenharmony_cistatic void StubOnScanResult(int32_t scannerId, const SoftBusBcScanResult *reportData)
77060ff233Sopenharmony_ci{
78060ff233Sopenharmony_ci    SoftbusBleGattTest::scanResultCtx.Update(scannerId, reportData);
79060ff233Sopenharmony_ci}
80060ff233Sopenharmony_ci
81060ff233Sopenharmony_cistatic SoftbusScanCallback *GetStubScanListener()
82060ff233Sopenharmony_ci{
83060ff233Sopenharmony_ci    static SoftbusScanCallback listener = {
84060ff233Sopenharmony_ci        .OnStartScanCallback = nullptr,
85060ff233Sopenharmony_ci        .OnStopScanCallback = nullptr,
86060ff233Sopenharmony_ci        .OnReportScanDataCallback = StubOnScanResult,
87060ff233Sopenharmony_ci        .OnScanStateChanged = nullptr
88060ff233Sopenharmony_ci    };
89060ff233Sopenharmony_ci    return &listener;
90060ff233Sopenharmony_ci}
91060ff233Sopenharmony_ci
92060ff233Sopenharmony_cistatic void StubAdvEnableCallback(int32_t advId, int32_t status)
93060ff233Sopenharmony_ci{
94060ff233Sopenharmony_ci    SoftbusBleGattTest::advEnableCtx.Update(advId, status);
95060ff233Sopenharmony_ci}
96060ff233Sopenharmony_ci
97060ff233Sopenharmony_cistatic void StubAdvDisableCallback(int32_t advId, int32_t status)
98060ff233Sopenharmony_ci{
99060ff233Sopenharmony_ci    SoftbusBleGattTest::advDisableCtx.Update(advId, status);
100060ff233Sopenharmony_ci}
101060ff233Sopenharmony_ci
102060ff233Sopenharmony_cistatic void StubAdvUpdateCallback(int32_t advId, int32_t status)
103060ff233Sopenharmony_ci{
104060ff233Sopenharmony_ci    SoftbusBleGattTest::advUpdateCtx.Update(advId, status);
105060ff233Sopenharmony_ci}
106060ff233Sopenharmony_ci
107060ff233Sopenharmony_cistatic void StubAdvDataCallback(int32_t advId, int32_t status)
108060ff233Sopenharmony_ci{
109060ff233Sopenharmony_ci    SoftbusBleGattTest::advDataCtx.Update(advId, status);
110060ff233Sopenharmony_ci}
111060ff233Sopenharmony_ci
112060ff233Sopenharmony_ciSoftbusBroadcastCallback *GetStubAdvCallback()
113060ff233Sopenharmony_ci{
114060ff233Sopenharmony_ci    static SoftbusBroadcastCallback callback = {
115060ff233Sopenharmony_ci        .OnStartBroadcastingCallback = StubAdvEnableCallback,
116060ff233Sopenharmony_ci        .OnStopBroadcastingCallback = StubAdvDisableCallback,
117060ff233Sopenharmony_ci        .OnUpdateBroadcastingCallback = StubAdvUpdateCallback,
118060ff233Sopenharmony_ci        .OnSetBroadcastingCallback = StubAdvDataCallback,
119060ff233Sopenharmony_ci    };
120060ff233Sopenharmony_ci    return &callback;
121060ff233Sopenharmony_ci}
122060ff233Sopenharmony_ci
123060ff233Sopenharmony_cistatic testing::AssertionResult PrepareScanListener(int32_t *scannerId)
124060ff233Sopenharmony_ci{
125060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->RegisterScanListener(scannerId, GetStubScanListener());
126060ff233Sopenharmony_ci    if (ret != SOFTBUS_OK) {
127060ff233Sopenharmony_ci        return testing::AssertionFailure() << "RegisterScanListener failed";
128060ff233Sopenharmony_ci    }
129060ff233Sopenharmony_ci    if (MockBluetooth::bleScanCallback == nullptr) {
130060ff233Sopenharmony_ci        return testing::AssertionFailure() << "RegisterScanListener is not invoke";
131060ff233Sopenharmony_ci    }
132060ff233Sopenharmony_ci    return testing::AssertionSuccess();
133060ff233Sopenharmony_ci}
134060ff233Sopenharmony_ci
135060ff233Sopenharmony_cistatic SoftBusBcScanFilter *CreateScanFilter()
136060ff233Sopenharmony_ci{
137060ff233Sopenharmony_ci    unsigned char serviceData[] = {0xE, 0xE, 0xF, 0xF, 0x04, 0x05};
138060ff233Sopenharmony_ci    int32_t len = sizeof(serviceData);
139060ff233Sopenharmony_ci
140060ff233Sopenharmony_ci    SoftBusBcScanFilter *filter = static_cast<SoftBusBcScanFilter *>(SoftBusCalloc(sizeof(SoftBusBcScanFilter)));
141060ff233Sopenharmony_ci    unsigned char *serviceDataPtr = static_cast<unsigned char *>(SoftBusCalloc(len));
142060ff233Sopenharmony_ci    unsigned char *serviceDataMaskPtr = static_cast<unsigned char *>(SoftBusCalloc(len));
143060ff233Sopenharmony_ci    if (filter == nullptr || serviceDataPtr == nullptr || serviceDataMaskPtr == nullptr) {
144060ff233Sopenharmony_ci        goto EXIT;
145060ff233Sopenharmony_ci    }
146060ff233Sopenharmony_ci    if (memcpy_s(serviceDataPtr, len, serviceData, len) != EOK) {
147060ff233Sopenharmony_ci        goto EXIT;
148060ff233Sopenharmony_ci    }
149060ff233Sopenharmony_ci    if (memset_s(serviceDataMaskPtr, len, 0xFF, len) != EOK) {
150060ff233Sopenharmony_ci        goto EXIT;
151060ff233Sopenharmony_ci    }
152060ff233Sopenharmony_ci    filter->serviceData = serviceDataPtr;
153060ff233Sopenharmony_ci    filter->serviceDataMask = serviceDataMaskPtr;
154060ff233Sopenharmony_ci    filter->serviceDataLength = len;
155060ff233Sopenharmony_ci    return filter;
156060ff233Sopenharmony_ciEXIT:
157060ff233Sopenharmony_ci    SoftBusFree(filter);
158060ff233Sopenharmony_ci    SoftBusFree(serviceDataPtr);
159060ff233Sopenharmony_ci    SoftBusFree(serviceDataMaskPtr);
160060ff233Sopenharmony_ci    return nullptr;
161060ff233Sopenharmony_ci}
162060ff233Sopenharmony_ci
163060ff233Sopenharmony_ci/**
164060ff233Sopenharmony_ci * @tc.name: TestSoftbusGattInit
165060ff233Sopenharmony_ci * @tc.desc: Test lnit will return SOFTBUS_OK when called more than once
166060ff233Sopenharmony_ci * @tc.type: FUNC
167060ff233Sopenharmony_ci * @tc.require: NONE
168060ff233Sopenharmony_ci */
169060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusGattInit001, TestSize.Level1)
170060ff233Sopenharmony_ci{
171060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
172060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
173060ff233Sopenharmony_ci
174060ff233Sopenharmony_ci    ret = MockBluetooth::interface->Init();
175060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
176060ff233Sopenharmony_ci}
177060ff233Sopenharmony_ci
178060ff233Sopenharmony_ci/**
179060ff233Sopenharmony_ci * @tc.name: TestSoftbusGattDeInit
180060ff233Sopenharmony_ci * @tc.desc: Test DeInit will return SOFTBUS_OK when called more than once
181060ff233Sopenharmony_ci * @tc.type: FUNC
182060ff233Sopenharmony_ci * @tc.require: NONE
183060ff233Sopenharmony_ci */
184060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusGattDeInit001, TestSize.Level1)
185060ff233Sopenharmony_ci{
186060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->DeInit();
187060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
188060ff233Sopenharmony_ci
189060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
190060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
191060ff233Sopenharmony_ci}
192060ff233Sopenharmony_ci
193060ff233Sopenharmony_ci/**
194060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterAdvCb
195060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterAdvCb will return SOFTBUS_INVALID_PARAM when called more than once
196060ff233Sopenharmony_ci * @tc.type: FUNC
197060ff233Sopenharmony_ci * @tc.require: NONE
198060ff233Sopenharmony_ci */
199060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterAdvCb001, TestSize.Level1)
200060ff233Sopenharmony_ci{
201060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->RegisterBroadcaster(nullptr, nullptr);
202060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
203060ff233Sopenharmony_ci}
204060ff233Sopenharmony_ci
205060ff233Sopenharmony_ci//充当参数
206060ff233Sopenharmony_cistatic void FakeBcBleCallback(int32_t adapterBcld, int32_t status)
207060ff233Sopenharmony_ci{
208060ff233Sopenharmony_ci    (void)adapterBcld;
209060ff233Sopenharmony_ci    (void)status;
210060ff233Sopenharmony_ci}
211060ff233Sopenharmony_ci
212060ff233Sopenharmony_cistatic SoftbusBroadcastCallback g_softbusBcBleCbTest = {
213060ff233Sopenharmony_ci    .OnStartBroadcastingCallback = FakeBcBleCallback,
214060ff233Sopenharmony_ci    .OnStopBroadcastingCallback = FakeBcBleCallback,
215060ff233Sopenharmony_ci    .OnUpdateBroadcastingCallback = FakeBcBleCallback,
216060ff233Sopenharmony_ci    .OnSetBroadcastingCallback = FakeBcBleCallback,
217060ff233Sopenharmony_ci};
218060ff233Sopenharmony_ci
219060ff233Sopenharmony_ci/**
220060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterAdvCb002
221060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterAdvCb will return SOFTBUS_LOCK_ERR when called more than once
222060ff233Sopenharmony_ci * @tc.type: FUNC
223060ff233Sopenharmony_ci * @tc.require: NONE
224060ff233Sopenharmony_ci */
225060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterAdvCb002, TestSize.Level1)
226060ff233Sopenharmony_ci{
227060ff233Sopenharmony_ci    int32_t advld = 0;
228060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
229060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
230060ff233Sopenharmony_ci}
231060ff233Sopenharmony_ci
232060ff233Sopenharmony_ci/**
233060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterAdvCb003
234060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterAdvCb will return OHOS_BT_STATUS_FAIL
235060ff233Sopenharmony_ci * @tc.type: FUNC
236060ff233Sopenharmony_ci * @tc.require: NONE
237060ff233Sopenharmony_ci */
238060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterAdvCb003, TestSize.Level1)
239060ff233Sopenharmony_ci{
240060ff233Sopenharmony_ci    MockBluetooth mocker;
241060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
242060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
243060ff233Sopenharmony_ci
244060ff233Sopenharmony_ci    int32_t advld = 0;
245060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleGattRegisterCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_FAIL));
246060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
247060ff233Sopenharmony_ci    EXPECT_EQ(ret, OHOS_BT_STATUS_FAIL);
248060ff233Sopenharmony_ci
249060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
250060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
251060ff233Sopenharmony_ci}
252060ff233Sopenharmony_ci
253060ff233Sopenharmony_ci/**
254060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterAdvCb004
255060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterAdvCb will return SOFTBUS_OK when BleGattRegisterCallbacks
256060ff233Sopenharmony_ci * @tc.type: FUNC
257060ff233Sopenharmony_ci * @tc.require: NONE
258060ff233Sopenharmony_ci */
259060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterAdvCb004, TestSize.Level1)
260060ff233Sopenharmony_ci{
261060ff233Sopenharmony_ci    MockBluetooth mocker;
262060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
263060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
264060ff233Sopenharmony_ci
265060ff233Sopenharmony_ci    int32_t advld = 0;
266060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
267060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
268060ff233Sopenharmony_ci
269060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
270060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
271060ff233Sopenharmony_ci}
272060ff233Sopenharmony_ci
273060ff233Sopenharmony_ci/**
274060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterAdvCb001
275060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterAdvCb will return SOFTBUS_INVALID_PARAM when given invalid param
276060ff233Sopenharmony_ci * @tc.type: FUNC
277060ff233Sopenharmony_ci * @tc.require: NONE
278060ff233Sopenharmony_ci */
279060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterAdvCb001, TestSize.Level1)
280060ff233Sopenharmony_ci{
281060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->UnRegisterBroadcaster(GATT_ADV_MAX_NUM);
282060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
283060ff233Sopenharmony_ci
284060ff233Sopenharmony_ci    int32_t advld = -1;
285060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterBroadcaster(advld);
286060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
287060ff233Sopenharmony_ci}
288060ff233Sopenharmony_ci
289060ff233Sopenharmony_ci/**
290060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterAdvCb002
291060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterAdvCb will return SOFTBUS_LOCK_ERR when never called init
292060ff233Sopenharmony_ci * @tc.type: FUNC
293060ff233Sopenharmony_ci * @tc.require: NONE
294060ff233Sopenharmony_ci */
295060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterAdvCb002, TestSize.Level1)
296060ff233Sopenharmony_ci{
297060ff233Sopenharmony_ci    int32_t advld = 0;
298060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->UnRegisterBroadcaster(advld);
299060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
300060ff233Sopenharmony_ci}
301060ff233Sopenharmony_ci
302060ff233Sopenharmony_ci/**
303060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterAdvCb003
304060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterAdvCb will return SOFTBUS_OK when given vaild param
305060ff233Sopenharmony_ci * @tc.type: FUNC
306060ff233Sopenharmony_ci * @tc.require: NONE
307060ff233Sopenharmony_ci */
308060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterAdvCb003, TestSize.Level1)
309060ff233Sopenharmony_ci{
310060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
311060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
312060ff233Sopenharmony_ci
313060ff233Sopenharmony_ci    int32_t advld = 0;
314060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterBroadcaster(advld);
315060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
316060ff233Sopenharmony_ci
317060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterBroadcaster(advld);
318060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
319060ff233Sopenharmony_ci
320060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
321060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
322060ff233Sopenharmony_ci}
323060ff233Sopenharmony_ci
324060ff233Sopenharmony_ci/**
325060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterScanCb001
326060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterScanCb will return SOFTBUS_INVALID_PARAM when given invalid param
327060ff233Sopenharmony_ci * @tc.type: FUNC
328060ff233Sopenharmony_ci * @tc.require: NONE
329060ff233Sopenharmony_ci */
330060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterScanCb001, TestSize.Level1)
331060ff233Sopenharmony_ci{
332060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->RegisterScanListener(nullptr, nullptr);
333060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
334060ff233Sopenharmony_ci}
335060ff233Sopenharmony_ci
336060ff233Sopenharmony_ci//充当参数
337060ff233Sopenharmony_cistatic void FakeScanCallback(int32_t adapterScanld, int32_t status)
338060ff233Sopenharmony_ci{
339060ff233Sopenharmony_ci    (void)adapterScanld;
340060ff233Sopenharmony_ci    (void)status;
341060ff233Sopenharmony_ci}
342060ff233Sopenharmony_ci
343060ff233Sopenharmony_cistatic void FakeReportScanDataCallback(int32_t adapterScanld, const SoftBusBcScanResult *reportData)
344060ff233Sopenharmony_ci{
345060ff233Sopenharmony_ci    (void)adapterScanld;
346060ff233Sopenharmony_ci    (void)reportData;
347060ff233Sopenharmony_ci}
348060ff233Sopenharmony_ci
349060ff233Sopenharmony_cistatic void FakeScanStateChanged(int32_t resultCode, bool isStartScan)
350060ff233Sopenharmony_ci{
351060ff233Sopenharmony_ci    (void)resultCode;
352060ff233Sopenharmony_ci    (void)isStartScan;
353060ff233Sopenharmony_ci}
354060ff233Sopenharmony_ci
355060ff233Sopenharmony_cistatic void FakeLpDeviceInfoCallback(const SoftbusBroadcastUuid *uuid, int32_t type, uint8_t *data, uint32_t dataSize)
356060ff233Sopenharmony_ci{
357060ff233Sopenharmony_ci    (void)uuid;
358060ff233Sopenharmony_ci    (void)type;
359060ff233Sopenharmony_ci    (void)data;
360060ff233Sopenharmony_ci    (void)dataSize;
361060ff233Sopenharmony_ci}
362060ff233Sopenharmony_ci
363060ff233Sopenharmony_cistatic SoftbusScanCallback g_softbusBcBleScanCbTest = {
364060ff233Sopenharmony_ci    .OnStartScanCallback = FakeScanCallback,
365060ff233Sopenharmony_ci    .OnStopScanCallback = FakeScanCallback,
366060ff233Sopenharmony_ci    .OnReportScanDataCallback = FakeReportScanDataCallback,
367060ff233Sopenharmony_ci    .OnScanStateChanged = FakeScanStateChanged,
368060ff233Sopenharmony_ci    .OnLpDeviceInfoCallback = FakeLpDeviceInfoCallback,
369060ff233Sopenharmony_ci};
370060ff233Sopenharmony_ci
371060ff233Sopenharmony_ci/**
372060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterScanCb002
373060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterScanCb will return SOFTBUS_LOCK_ERR when never called init
374060ff233Sopenharmony_ci * @tc.type: FUNC
375060ff233Sopenharmony_ci * @tc.require: NONE
376060ff233Sopenharmony_ci */
377060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterScanCb002, TestSize.Level1)
378060ff233Sopenharmony_ci{
379060ff233Sopenharmony_ci    int32_t scannerld = 0;
380060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
381060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
382060ff233Sopenharmony_ci}
383060ff233Sopenharmony_ci
384060ff233Sopenharmony_ci/**
385060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterScanCb003
386060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterScanCb will return OHOS_BT_STATUS_FAIL
387060ff233Sopenharmony_ci * @tc.type: FUNC
388060ff233Sopenharmony_ci * @tc.require: NONE
389060ff233Sopenharmony_ci */
390060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterScanCb003, TestSize.Level1)
391060ff233Sopenharmony_ci{
392060ff233Sopenharmony_ci    MockBluetooth mocker;
393060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
394060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
395060ff233Sopenharmony_ci
396060ff233Sopenharmony_ci    int32_t scannerld = 0;
397060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_FAIL));
398060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
399060ff233Sopenharmony_ci    EXPECT_EQ(ret, OHOS_BT_STATUS_FAIL);
400060ff233Sopenharmony_ci
401060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
402060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
403060ff233Sopenharmony_ci}
404060ff233Sopenharmony_ci
405060ff233Sopenharmony_ci/**
406060ff233Sopenharmony_ci * @tc.name: TestSoftbusRegisterScanCb004
407060ff233Sopenharmony_ci * @tc.desc: Test SoftbusRegisterScanCb will return SOFTBUS_BC_ADAPTER_REGISTER_FAIL when scan channel are all uesd
408060ff233Sopenharmony_ci * @tc.type: FUNC
409060ff233Sopenharmony_ci * @tc.require: NONE
410060ff233Sopenharmony_ci */
411060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusRegisterScanCb004, TestSize.Level1)
412060ff233Sopenharmony_ci{
413060ff233Sopenharmony_ci    MockBluetooth mocker;
414060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
415060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
416060ff233Sopenharmony_ci
417060ff233Sopenharmony_ci    int32_t scannerld = 0;
418060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
419060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
420060ff233Sopenharmony_ci    EXPECT_EQ(ret, OHOS_BT_STATUS_SUCCESS);
421060ff233Sopenharmony_ci
422060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
423060ff233Sopenharmony_ci    EXPECT_EQ(ret, OHOS_BT_STATUS_SUCCESS);
424060ff233Sopenharmony_ci
425060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
426060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_REGISTER_FAIL);
427060ff233Sopenharmony_ci
428060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
429060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
430060ff233Sopenharmony_ci}
431060ff233Sopenharmony_ci
432060ff233Sopenharmony_ci/**
433060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterScanCb001
434060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterScanCb will return SOFTBUS_INVALID_PARAM when given invalid param
435060ff233Sopenharmony_ci * @tc.type: FUNC
436060ff233Sopenharmony_ci * @tc.require: NONE
437060ff233Sopenharmony_ci */
438060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterScanCb001, TestSize.Level1)
439060ff233Sopenharmony_ci{
440060ff233Sopenharmony_ci    int32_t scannerld = -1;
441060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->UnRegisterScanListener(GATT_SCAN_MAX_NUM);
442060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
443060ff233Sopenharmony_ci
444060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterScanListener(scannerld);
445060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
446060ff233Sopenharmony_ci}
447060ff233Sopenharmony_ci
448060ff233Sopenharmony_ci/**
449060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterScanCb002
450060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterScanCb will return SOFTBUS_LOCK_ERR when never called init
451060ff233Sopenharmony_ci * @tc.type: FUNC
452060ff233Sopenharmony_ci * @tc.require: NONE
453060ff233Sopenharmony_ci */
454060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterScanCb002, TestSize.Level1)
455060ff233Sopenharmony_ci{
456060ff233Sopenharmony_ci    int32_t scannerld = 0;
457060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->UnRegisterScanListener(scannerld);
458060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
459060ff233Sopenharmony_ci}
460060ff233Sopenharmony_ci
461060ff233Sopenharmony_ci/**
462060ff233Sopenharmony_ci * @tc.name: TestSoftbusUnRegisterScanCb003
463060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUnRegisterScanCb will return SOFTBUS_OK when successfully unregistered
464060ff233Sopenharmony_ci * @tc.type: FUNC
465060ff233Sopenharmony_ci * @tc.require: NONE
466060ff233Sopenharmony_ci */
467060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUnRegisterScanCb003, TestSize.Level1)
468060ff233Sopenharmony_ci{
469060ff233Sopenharmony_ci    MockBluetooth mocker;
470060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
471060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
472060ff233Sopenharmony_ci
473060ff233Sopenharmony_ci    int32_t scannerld = 0;
474060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
475060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterScanListener(scannerld);
476060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
477060ff233Sopenharmony_ci
478060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UnRegisterScanListener(scannerld);
479060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
480060ff233Sopenharmony_ci
481060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
482060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
483060ff233Sopenharmony_ci}
484060ff233Sopenharmony_ci
485060ff233Sopenharmony_ci/**
486060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartAdv001
487060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartAdv will return SOFTBUS_INVALID_PARAM when given invalid param
488060ff233Sopenharmony_ci * @tc.type: FUNC
489060ff233Sopenharmony_ci * @tc.require: NONE
490060ff233Sopenharmony_ci */
491060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartAdv001, TestSize.Level1)
492060ff233Sopenharmony_ci{
493060ff233Sopenharmony_ci    int32_t advld = 0;
494060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->StartBroadcasting(advld, nullptr, nullptr);
495060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
496060ff233Sopenharmony_ci}
497060ff233Sopenharmony_ci
498060ff233Sopenharmony_ci//SoftbusBroadcastData类型的数据填充
499060ff233Sopenharmony_ciconst char ADV_DATA_EXAMPLE[] = {
500060ff233Sopenharmony_ci    0x02, 0x01, 0x02, 0x15, 0x16,
501060ff233Sopenharmony_ci    0xEE, 0xFD, 0x04, 0x05, 0x90,
502060ff233Sopenharmony_ci    0x00, 0x00, 0x04, 0x00,
503060ff233Sopenharmony_ci    0x18, 0x33, 0x39, 0x36,
504060ff233Sopenharmony_ci    0x62, 0x33, 0x61, 0x33, 0x31,
505060ff233Sopenharmony_ci    0x21, 0x00, 0x02, 0x0A, 0xEF,
506060ff233Sopenharmony_ci};
507060ff233Sopenharmony_ciconst unsigned char SCAN_RSP_DATA_EXAMPLE[] = {0x03, 0xFF, 0x7D, 0x02};
508060ff233Sopenharmony_ci
509060ff233Sopenharmony_ci/**
510060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartAdv002
511060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartAdv will return SOFTBUS_LOCK_ERR when never called init
512060ff233Sopenharmony_ci * @tc.type: FUNC
513060ff233Sopenharmony_ci * @tc.require: NONE
514060ff233Sopenharmony_ci */
515060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartAdv002, TestSize.Level1)
516060ff233Sopenharmony_ci{
517060ff233Sopenharmony_ci    int32_t advld = 0;
518060ff233Sopenharmony_ci    SoftbusBroadcastParam params = {};
519060ff233Sopenharmony_ci    SoftbusBroadcastData data = {};
520060ff233Sopenharmony_ci    data.bcData.payloadLen = sizeof(ADV_DATA_EXAMPLE);
521060ff233Sopenharmony_ci    data.bcData.payload = (uint8_t *)ADV_DATA_EXAMPLE;
522060ff233Sopenharmony_ci    data.rspData.payloadLen = sizeof(SCAN_RSP_DATA_EXAMPLE);
523060ff233Sopenharmony_ci    data.rspData.payload = (uint8_t *)SCAN_RSP_DATA_EXAMPLE;
524060ff233Sopenharmony_ci
525060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->StartBroadcasting(advld, &params, &data);
526060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
527060ff233Sopenharmony_ci}
528060ff233Sopenharmony_ci
529060ff233Sopenharmony_ci/**
530060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartAdv003
531060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartAdv will return SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL when advld is not used
532060ff233Sopenharmony_ci * @tc.type: FUNC
533060ff233Sopenharmony_ci * @tc.require: NONE
534060ff233Sopenharmony_ci */
535060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartAdv003, TestSize.Level1)
536060ff233Sopenharmony_ci{
537060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
538060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
539060ff233Sopenharmony_ci
540060ff233Sopenharmony_ci    int32_t advld = 0;
541060ff233Sopenharmony_ci    SoftbusBroadcastParam params = {};
542060ff233Sopenharmony_ci    SoftbusBroadcastData data = {};
543060ff233Sopenharmony_ci    data.bcData.payloadLen = sizeof(ADV_DATA_EXAMPLE);
544060ff233Sopenharmony_ci    data.bcData.payload = (uint8_t *)ADV_DATA_EXAMPLE;
545060ff233Sopenharmony_ci    data.rspData.payloadLen = sizeof(SCAN_RSP_DATA_EXAMPLE);
546060ff233Sopenharmony_ci    data.rspData.payload = (uint8_t *)SCAN_RSP_DATA_EXAMPLE;
547060ff233Sopenharmony_ci
548060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StartBroadcasting(GATT_ADV_MAX_NUM, &params, &data);
549060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
550060ff233Sopenharmony_ci
551060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StartBroadcasting(advld, &params, &data);
552060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
553060ff233Sopenharmony_ci
554060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
555060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
556060ff233Sopenharmony_ci}
557060ff233Sopenharmony_ci
558060ff233Sopenharmony_ci/**
559060ff233Sopenharmony_ci * @tc.name: TestSoftbusStopAdv001
560060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStopAdv will return SOFTBUS_LOCK_ERR when never called lnit
561060ff233Sopenharmony_ci * @tc.type: FUNC
562060ff233Sopenharmony_ci * @tc.require: NONE
563060ff233Sopenharmony_ci */
564060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStopAdv001, TestSize.Level1)
565060ff233Sopenharmony_ci{
566060ff233Sopenharmony_ci    int32_t advld = 0;
567060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->StopBroadcasting(advld);
568060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
569060ff233Sopenharmony_ci}
570060ff233Sopenharmony_ci
571060ff233Sopenharmony_ci/**
572060ff233Sopenharmony_ci * @tc.name: TestSoftbusStopAdv002
573060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStopAdv will return SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL when advld never registed
574060ff233Sopenharmony_ci * @tc.type: FUNC
575060ff233Sopenharmony_ci * @tc.require: NONE
576060ff233Sopenharmony_ci */
577060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStopAdv002, TestSize.Level1)
578060ff233Sopenharmony_ci{
579060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
580060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
581060ff233Sopenharmony_ci
582060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StopBroadcasting(GATT_ADV_MAX_NUM);
583060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
584060ff233Sopenharmony_ci
585060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
586060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
587060ff233Sopenharmony_ci}
588060ff233Sopenharmony_ci
589060ff233Sopenharmony_ci/**
590060ff233Sopenharmony_ci * @tc.name: TestSoftbusStopAdv004
591060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStopAdv will return SOFTBUS_OK when advld has been registed
592060ff233Sopenharmony_ci * @tc.type: FUNC
593060ff233Sopenharmony_ci * @tc.require: NONE
594060ff233Sopenharmony_ci */
595060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStopAdv004, TestSize.Level1)
596060ff233Sopenharmony_ci{
597060ff233Sopenharmony_ci    MockBluetooth mocker;
598060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
599060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
600060ff233Sopenharmony_ci
601060ff233Sopenharmony_ci    int32_t advld = 0;
602060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
603060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
604060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
605060ff233Sopenharmony_ci
606060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStopAdv).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
607060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StopBroadcasting(advld);
608060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
609060ff233Sopenharmony_ci
610060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
611060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
612060ff233Sopenharmony_ci}
613060ff233Sopenharmony_ci
614060ff233Sopenharmony_ci/**
615060ff233Sopenharmony_ci * @tc.name: TestSoftbusStopAdv005
616060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStopAdv will return SOFTBUS_OK when advld has been stopped
617060ff233Sopenharmony_ci * @tc.type: FUNC
618060ff233Sopenharmony_ci * @tc.require: NONE
619060ff233Sopenharmony_ci */
620060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStopAdv005, TestSize.Level1)
621060ff233Sopenharmony_ci{
622060ff233Sopenharmony_ci    MockBluetooth mocker;
623060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
624060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
625060ff233Sopenharmony_ci
626060ff233Sopenharmony_ci    int32_t advld = 0;
627060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
628060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
629060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
630060ff233Sopenharmony_ci
631060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStopAdv).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
632060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StopBroadcasting(advld);
633060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
634060ff233Sopenharmony_ci
635060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StopBroadcasting(advld);
636060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
637060ff233Sopenharmony_ci
638060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
639060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
640060ff233Sopenharmony_ci}
641060ff233Sopenharmony_ci
642060ff233Sopenharmony_ci/**
643060ff233Sopenharmony_ci * @tc.name: TestSoftbusSetAdvData001
644060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetAdvData will return SOFTBUS_INVALID_PARAM when given invalid param
645060ff233Sopenharmony_ci * @tc.type: FUNC
646060ff233Sopenharmony_ci * @tc.require: NONE
647060ff233Sopenharmony_ci */
648060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusSetAdvData001, TestSize.Level1)
649060ff233Sopenharmony_ci{
650060ff233Sopenharmony_ci    int32_t advld = 0;
651060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->SetBroadcastingData(advld, nullptr);
652060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
653060ff233Sopenharmony_ci}
654060ff233Sopenharmony_ci
655060ff233Sopenharmony_ci/**
656060ff233Sopenharmony_ci * @tc.name: TestSoftbusSetAdvData002
657060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetAdvData will return SOFTBUS_LOCK_ERR when never lnit
658060ff233Sopenharmony_ci * @tc.type: FUNC
659060ff233Sopenharmony_ci * @tc.require: NONE
660060ff233Sopenharmony_ci */
661060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusSetAdvData002, TestSize.Level1)
662060ff233Sopenharmony_ci{
663060ff233Sopenharmony_ci    int32_t advld = 0;
664060ff233Sopenharmony_ci    SoftbusBroadcastData data = {};
665060ff233Sopenharmony_ci    data.bcData.payloadLen = sizeof(ADV_DATA_EXAMPLE);
666060ff233Sopenharmony_ci    data.bcData.payload = (uint8_t *)ADV_DATA_EXAMPLE;
667060ff233Sopenharmony_ci    data.rspData.payloadLen = sizeof(SCAN_RSP_DATA_EXAMPLE);
668060ff233Sopenharmony_ci    data.rspData.payload = (uint8_t *)SCAN_RSP_DATA_EXAMPLE;
669060ff233Sopenharmony_ci
670060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->SetBroadcastingData(advld, &data);
671060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
672060ff233Sopenharmony_ci}
673060ff233Sopenharmony_ci
674060ff233Sopenharmony_ci/**
675060ff233Sopenharmony_ci * @tc.name: TestSoftbusSetAdvData003
676060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetAdvData will return SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL when advld is not used
677060ff233Sopenharmony_ci * @tc.type: FUNC
678060ff233Sopenharmony_ci * @tc.require: NONE
679060ff233Sopenharmony_ci */
680060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusSetAdvData003, TestSize.Level1)
681060ff233Sopenharmony_ci{
682060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
683060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
684060ff233Sopenharmony_ci
685060ff233Sopenharmony_ci    SoftbusBroadcastData data = {};
686060ff233Sopenharmony_ci    data.bcData.payloadLen = sizeof(ADV_DATA_EXAMPLE);
687060ff233Sopenharmony_ci    data.bcData.payload = (uint8_t *)ADV_DATA_EXAMPLE;
688060ff233Sopenharmony_ci    data.rspData.payloadLen = sizeof(SCAN_RSP_DATA_EXAMPLE);
689060ff233Sopenharmony_ci    data.rspData.payload = (uint8_t *)SCAN_RSP_DATA_EXAMPLE;
690060ff233Sopenharmony_ci
691060ff233Sopenharmony_ci    ret = MockBluetooth::interface->SetBroadcastingData(GATT_ADV_MAX_NUM, &data);
692060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
693060ff233Sopenharmony_ci
694060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
695060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
696060ff233Sopenharmony_ci}
697060ff233Sopenharmony_ci
698060ff233Sopenharmony_ci/**
699060ff233Sopenharmony_ci * @tc.name: TestSoftbusSetAdvData005
700060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetAdvData will return SOFTBUS_ALREADY_TRIGGERED when broadcast has already registed
701060ff233Sopenharmony_ci * @tc.type: FUNC
702060ff233Sopenharmony_ci * @tc.require: NONE
703060ff233Sopenharmony_ci */
704060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusSetAdvData005, TestSize.Level1)
705060ff233Sopenharmony_ci{
706060ff233Sopenharmony_ci    MockBluetooth mocker;
707060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
708060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
709060ff233Sopenharmony_ci
710060ff233Sopenharmony_ci    int32_t advld = 0;
711060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleGattRegisterCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
712060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
713060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
714060ff233Sopenharmony_ci
715060ff233Sopenharmony_ci    SoftbusBroadcastData data = {};
716060ff233Sopenharmony_ci    data.bcData.payloadLen = sizeof(ADV_DATA_EXAMPLE);
717060ff233Sopenharmony_ci    data.bcData.payload = (uint8_t *)ADV_DATA_EXAMPLE;
718060ff233Sopenharmony_ci    data.rspData.payloadLen = sizeof(SCAN_RSP_DATA_EXAMPLE);
719060ff233Sopenharmony_ci    data.rspData.payload = (uint8_t *)SCAN_RSP_DATA_EXAMPLE;
720060ff233Sopenharmony_ci
721060ff233Sopenharmony_ci    ret = MockBluetooth::interface->SetBroadcastingData(advld, &data);
722060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_ALREADY_TRIGGERED);
723060ff233Sopenharmony_ci
724060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
725060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
726060ff233Sopenharmony_ci}
727060ff233Sopenharmony_ci
728060ff233Sopenharmony_ci/**
729060ff233Sopenharmony_ci * @tc.name: TestSoftbusUpdateAdvData001
730060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUpdateAdvData will return SOFTBUS_LOCK_ERR when never called init
731060ff233Sopenharmony_ci * @tc.type: FUNC
732060ff233Sopenharmony_ci * @tc.require: NONE
733060ff233Sopenharmony_ci */
734060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUpdateAdvData001, TestSize.Level1)
735060ff233Sopenharmony_ci{
736060ff233Sopenharmony_ci    int32_t advld = 0;
737060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->UpdateBroadcasting(advld, nullptr, nullptr);
738060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
739060ff233Sopenharmony_ci}
740060ff233Sopenharmony_ci
741060ff233Sopenharmony_ci/**
742060ff233Sopenharmony_ci * @tc.name: TestSoftbusUpdateAdvData002
743060ff233Sopenharmony_ci * @tc.desc: Test SoftbusUpdateAdvData will return SOFTBUS_INVALID_PARAM when given invalid params
744060ff233Sopenharmony_ci * @tc.type: FUNC
745060ff233Sopenharmony_ci * @tc.require: NONE
746060ff233Sopenharmony_ci */
747060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusUpdateAdvData002, TestSize.Level1)
748060ff233Sopenharmony_ci{
749060ff233Sopenharmony_ci    MockBluetooth mocker;
750060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
751060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
752060ff233Sopenharmony_ci
753060ff233Sopenharmony_ci    int32_t advld = 0;
754060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleGattRegisterCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
755060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
756060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
757060ff233Sopenharmony_ci
758060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStopAdv).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
759060ff233Sopenharmony_ci    ret = MockBluetooth::interface->UpdateBroadcasting(advld, nullptr, nullptr);
760060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
761060ff233Sopenharmony_ci
762060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
763060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
764060ff233Sopenharmony_ci}
765060ff233Sopenharmony_ci
766060ff233Sopenharmony_ci/**
767060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartScan001
768060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartScan will return SOFTBUS_INVALID_PARAM when given invalid params
769060ff233Sopenharmony_ci * @tc.type: FUNC
770060ff233Sopenharmony_ci * @tc.require: NONE
771060ff233Sopenharmony_ci */
772060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartScan001, TestSize.Level1)
773060ff233Sopenharmony_ci{
774060ff233Sopenharmony_ci    int32_t scannerld = 0;
775060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->StartScan(scannerld, nullptr, nullptr, 0);
776060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
777060ff233Sopenharmony_ci}
778060ff233Sopenharmony_ci
779060ff233Sopenharmony_ci/**
780060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartScan002
781060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartScan will return SOFTBUS_LOCK_ERR when never called init
782060ff233Sopenharmony_ci * @tc.type: FUNC
783060ff233Sopenharmony_ci * @tc.require: NONE
784060ff233Sopenharmony_ci */
785060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartScan002, TestSize.Level1)
786060ff233Sopenharmony_ci{
787060ff233Sopenharmony_ci    SoftBusBcScanParams scanParam = {
788060ff233Sopenharmony_ci        .scanInterval = SOFTBUS_BC_SCAN_WINDOW_P10,
789060ff233Sopenharmony_ci        .scanWindow = SOFTBUS_BC_SCAN_INTERVAL_P10,
790060ff233Sopenharmony_ci        .scanType = SOFTBUS_BC_SCAN_TYPE_ACTIVE,
791060ff233Sopenharmony_ci        .scanPhy = SOFTBUS_BC_SCAN_PHY_1M,
792060ff233Sopenharmony_ci        .scanFilterPolicy = SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL,
793060ff233Sopenharmony_ci    };
794060ff233Sopenharmony_ci
795060ff233Sopenharmony_ci    SoftBusBcScanFilter softBusBcScanFilter = {};
796060ff233Sopenharmony_ci    softBusBcScanFilter.address = (int8_t*)"address";
797060ff233Sopenharmony_ci    softBusBcScanFilter.deviceName = (int8_t*)"deviceName";
798060ff233Sopenharmony_ci    softBusBcScanFilter.serviceUuid = 1;
799060ff233Sopenharmony_ci    softBusBcScanFilter.serviceDataLength = 1;
800060ff233Sopenharmony_ci    softBusBcScanFilter.manufactureId = 1;
801060ff233Sopenharmony_ci    softBusBcScanFilter.manufactureDataLength = 1;
802060ff233Sopenharmony_ci
803060ff233Sopenharmony_ci    int32_t scannerld = 0;
804060ff233Sopenharmony_ci    int32_t filterSize = 1;
805060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->StartScan(scannerld, &scanParam, &softBusBcScanFilter, filterSize);
806060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_LOCK_ERR);
807060ff233Sopenharmony_ci}
808060ff233Sopenharmony_ci
809060ff233Sopenharmony_ci/**
810060ff233Sopenharmony_ci * @tc.name: TestSoftbusStartScan003
811060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStartScan will return SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL when given invalid params scannerld
812060ff233Sopenharmony_ci * @tc.type: FUNC
813060ff233Sopenharmony_ci * @tc.require: NONE
814060ff233Sopenharmony_ci */
815060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusStartScan003, TestSize.Level1)
816060ff233Sopenharmony_ci{
817060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
818060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
819060ff233Sopenharmony_ci
820060ff233Sopenharmony_ci    SoftBusBcScanParams scanParam = {
821060ff233Sopenharmony_ci        .scanInterval = SOFTBUS_BC_SCAN_WINDOW_P10,
822060ff233Sopenharmony_ci        .scanWindow = SOFTBUS_BC_SCAN_INTERVAL_P10,
823060ff233Sopenharmony_ci        .scanType = SOFTBUS_BC_SCAN_TYPE_ACTIVE,
824060ff233Sopenharmony_ci        .scanPhy = SOFTBUS_BC_SCAN_PHY_1M,
825060ff233Sopenharmony_ci        .scanFilterPolicy = SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL,
826060ff233Sopenharmony_ci    };
827060ff233Sopenharmony_ci
828060ff233Sopenharmony_ci    SoftBusBcScanFilter softBusBcScanFilter = {};
829060ff233Sopenharmony_ci    softBusBcScanFilter.address = (int8_t*)"address";
830060ff233Sopenharmony_ci    softBusBcScanFilter.deviceName = (int8_t*)"deviceName";
831060ff233Sopenharmony_ci    softBusBcScanFilter.serviceUuid = 1;
832060ff233Sopenharmony_ci    softBusBcScanFilter.serviceDataLength = 1;
833060ff233Sopenharmony_ci    softBusBcScanFilter.manufactureId = 1;
834060ff233Sopenharmony_ci    softBusBcScanFilter.manufactureDataLength = 1;
835060ff233Sopenharmony_ci
836060ff233Sopenharmony_ci    int32_t filterSize = 1;
837060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StartScan(GATT_SCAN_MAX_NUM, &scanParam, &softBusBcScanFilter, filterSize);
838060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
839060ff233Sopenharmony_ci
840060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
841060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
842060ff233Sopenharmony_ci}
843060ff233Sopenharmony_ci
844060ff233Sopenharmony_ci/**
845060ff233Sopenharmony_ci * @tc.name: SoftbusGetBroadcastHandle001
846060ff233Sopenharmony_ci * @tc.desc: Test SoftbusGetBroadcastHandle is  SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL
847060ff233Sopenharmony_ci * @tc.type: FUNC
848060ff233Sopenharmony_ci * @tc.require: NONE
849060ff233Sopenharmony_ci */
850060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusGetBroadcastHandle001, TestSize.Level1)
851060ff233Sopenharmony_ci{
852060ff233Sopenharmony_ci    MockBluetooth mocker;
853060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
854060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
855060ff233Sopenharmony_ci
856060ff233Sopenharmony_ci    int32_t bchand = 0;
857060ff233Sopenharmony_ci
858060ff233Sopenharmony_ci    ret = MockBluetooth::interface->GetBroadcastHandle(GATT_ADV_MAX_NUM, &bchand);
859060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
860060ff233Sopenharmony_ci
861060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
862060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
863060ff233Sopenharmony_ci}
864060ff233Sopenharmony_ci
865060ff233Sopenharmony_ci/**
866060ff233Sopenharmony_ci * @tc.name: SoftbusGetBroadcastHandle002
867060ff233Sopenharmony_ci * @tc.desc: Test SoftbusGetBroadcastHandle is  SOFTBUS_OK
868060ff233Sopenharmony_ci * @tc.type: FUNC
869060ff233Sopenharmony_ci * @tc.require: NONE
870060ff233Sopenharmony_ci */
871060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusGetBroadcastHandle002, TestSize.Level1)
872060ff233Sopenharmony_ci{
873060ff233Sopenharmony_ci    MockBluetooth mocker;
874060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
875060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
876060ff233Sopenharmony_ci
877060ff233Sopenharmony_ci    int32_t advld = 0;
878060ff233Sopenharmony_ci    int32_t bchand = 0;
879060ff233Sopenharmony_ci
880060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleRegisterScanCallbacks).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
881060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
882060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
883060ff233Sopenharmony_ci
884060ff233Sopenharmony_ci    EXPECT_CALL(mocker, GetAdvHandle).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
885060ff233Sopenharmony_ci    ret = MockBluetooth::interface->GetBroadcastHandle(advld, &bchand);
886060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
887060ff233Sopenharmony_ci
888060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
889060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
890060ff233Sopenharmony_ci}
891060ff233Sopenharmony_ci
892060ff233Sopenharmony_ci/**
893060ff233Sopenharmony_ci * @tc.name: SoftbusEnableSyncDataToLp
894060ff233Sopenharmony_ci * @tc.desc: Test SoftbusEnableSyncDataToLp is  SOFTBUS_OK
895060ff233Sopenharmony_ci * @tc.type: FUNC
896060ff233Sopenharmony_ci * @tc.require: NONE
897060ff233Sopenharmony_ci */
898060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusEnableSyncDataToLp, TestSize.Level1)
899060ff233Sopenharmony_ci{
900060ff233Sopenharmony_ci    MockBluetooth mocker;
901060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
902060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
903060ff233Sopenharmony_ci
904060ff233Sopenharmony_ci    EXPECT_CALL(mocker, EnableSyncDataToLpDevice).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
905060ff233Sopenharmony_ci    ret = MockBluetooth::interface->EnableSyncDataToLpDevice();
906060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
907060ff233Sopenharmony_ci
908060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
909060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
910060ff233Sopenharmony_ci}
911060ff233Sopenharmony_ci
912060ff233Sopenharmony_ci/**
913060ff233Sopenharmony_ci * @tc.name: SoftbusDisableSyncDataToLp
914060ff233Sopenharmony_ci * @tc.desc: Test DisableSyncDataToLpDevice is  SOFTBUS_OK
915060ff233Sopenharmony_ci * @tc.type: FUNC
916060ff233Sopenharmony_ci * @tc.require: NONE
917060ff233Sopenharmony_ci */
918060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, DisableSyncDataToLpDevice, TestSize.Level1)
919060ff233Sopenharmony_ci{
920060ff233Sopenharmony_ci    MockBluetooth mocker;
921060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
922060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
923060ff233Sopenharmony_ci
924060ff233Sopenharmony_ci    EXPECT_CALL(mocker, DisableSyncDataToLpDevice).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
925060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DisableSyncDataToLpDevice();
926060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
927060ff233Sopenharmony_ci
928060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
929060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
930060ff233Sopenharmony_ci}
931060ff233Sopenharmony_ci
932060ff233Sopenharmony_ci/**
933060ff233Sopenharmony_ci * @tc.name: SoftbusSetScanReportChanToLp001
934060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetScanReportChanToLp is  SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL
935060ff233Sopenharmony_ci * @tc.type: FUNC
936060ff233Sopenharmony_ci * @tc.require: NONE
937060ff233Sopenharmony_ci */
938060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusSetScanReportChanToLp001, TestSize.Level1)
939060ff233Sopenharmony_ci{
940060ff233Sopenharmony_ci    MockBluetooth mocker;
941060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
942060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
943060ff233Sopenharmony_ci
944060ff233Sopenharmony_ci    ret = MockBluetooth::interface->SetScanReportChannelToLpDevice(GATT_ADV_MAX_NUM, false);
945060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
946060ff233Sopenharmony_ci
947060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
948060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
949060ff233Sopenharmony_ci}
950060ff233Sopenharmony_ci
951060ff233Sopenharmony_ci/**
952060ff233Sopenharmony_ci * @tc.name: SoftbusSetLpAdvParam
953060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetLpAdvParam is  SOFTBUS_OK
954060ff233Sopenharmony_ci * @tc.type: FUNC
955060ff233Sopenharmony_ci * @tc.require: NONE
956060ff233Sopenharmony_ci */
957060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusSetLpAdvParam, TestSize.Level1)
958060ff233Sopenharmony_ci{
959060ff233Sopenharmony_ci    MockBluetooth mocker;
960060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
961060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
962060ff233Sopenharmony_ci
963060ff233Sopenharmony_ci    int32_t duration = 0;
964060ff233Sopenharmony_ci    int32_t maxExtAdvEvents = 0;
965060ff233Sopenharmony_ci    int32_t window = 0;
966060ff233Sopenharmony_ci    int32_t interval = 0;
967060ff233Sopenharmony_ci    int32_t bcHandle = 0;
968060ff233Sopenharmony_ci
969060ff233Sopenharmony_ci    EXPECT_CALL(mocker, SetLpDeviceAdvParam).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
970060ff233Sopenharmony_ci    ret = MockBluetooth::interface->SetLpDeviceParam(duration, maxExtAdvEvents, window, interval, bcHandle);
971060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
972060ff233Sopenharmony_ci
973060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
974060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
975060ff233Sopenharmony_ci}
976060ff233Sopenharmony_ci
977060ff233Sopenharmony_ci/**
978060ff233Sopenharmony_ci * @tc.name: SoftbusStopScan001
979060ff233Sopenharmony_ci * @tc.desc: Test SoftbusStopScan is  SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL
980060ff233Sopenharmony_ci * @tc.type: FUNC
981060ff233Sopenharmony_ci * @tc.require: NONE
982060ff233Sopenharmony_ci */
983060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, SoftbusStopScan001, TestSize.Level1)
984060ff233Sopenharmony_ci{
985060ff233Sopenharmony_ci    MockBluetooth mocker;
986060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
987060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
988060ff233Sopenharmony_ci
989060ff233Sopenharmony_ci    ret = MockBluetooth::interface->StopScan(GATT_ADV_MAX_NUM);
990060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_NOT_IN_USED_FAIL);
991060ff233Sopenharmony_ci
992060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
993060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
994060ff233Sopenharmony_ci}
995060ff233Sopenharmony_ci
996060ff233Sopenharmony_ci/**
997060ff233Sopenharmony_ci * @tc.name: TestWrapperAdvEnableCb
998060ff233Sopenharmony_ci * @tc.desc: Test WrapperAdvEnableCb
999060ff233Sopenharmony_ci * @tc.type: FUNC
1000060ff233Sopenharmony_ci * @tc.require: NONE
1001060ff233Sopenharmony_ci */
1002060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestWrapperAdvEnableCb, TestSize.Level1)
1003060ff233Sopenharmony_ci{
1004060ff233Sopenharmony_ci    DISC_LOGI(DISC_TEST, "TestWrapperAdvEnableCb enter");
1005060ff233Sopenharmony_ci    MockBluetooth mocker;
1006060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
1007060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1008060ff233Sopenharmony_ci
1009060ff233Sopenharmony_ci    int32_t advld = 0;
1010060ff233Sopenharmony_ci
1011060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterBroadcaster(&advld, &g_softbusBcBleCbTest);
1012060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1013060ff233Sopenharmony_ci
1014060ff233Sopenharmony_ci    MockBluetooth::btGattCallback->advDataCb(advld, 1);
1015060ff233Sopenharmony_ci
1016060ff233Sopenharmony_ci    MockBluetooth::btGattCallback->advUpdateCb(advld, 1);
1017060ff233Sopenharmony_ci
1018060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
1019060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1020060ff233Sopenharmony_ci}
1021060ff233Sopenharmony_ci
1022060ff233Sopenharmony_ci/**
1023060ff233Sopenharmony_ci * @tc.name: TestWrapperScanStateChangeCb0
1024060ff233Sopenharmony_ci * @tc.desc: Test WrapperScanStateChangeCb0
1025060ff233Sopenharmony_ci * @tc.type: FUNC
1026060ff233Sopenharmony_ci * @tc.require: NONE
1027060ff233Sopenharmony_ci */
1028060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestWrapperScanStateChangeCb0, TestSize.Level1)
1029060ff233Sopenharmony_ci{
1030060ff233Sopenharmony_ci    DISC_LOGI(DISC_TEST, "TestWrapperAdvEnableCb enter");
1031060ff233Sopenharmony_ci    MockBluetooth mocker;
1032060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
1033060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1034060ff233Sopenharmony_ci
1035060ff233Sopenharmony_ci    int32_t scannerld = 0;
1036060ff233Sopenharmony_ci
1037060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
1038060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1039060ff233Sopenharmony_ci
1040060ff233Sopenharmony_ci    MockBluetooth::bleScanCallback->scanStateChangeCb(scannerld, true);
1041060ff233Sopenharmony_ci    MockBluetooth::bleScanCallback->scanStateChangeCb(scannerld, false);
1042060ff233Sopenharmony_ci
1043060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
1044060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1045060ff233Sopenharmony_ci}
1046060ff233Sopenharmony_ci
1047060ff233Sopenharmony_ci/**
1048060ff233Sopenharmony_ci * @tc.name: TestWrapperLpDeviceInfoCb
1049060ff233Sopenharmony_ci * @tc.desc: Test WrapperLpDeviceInfoCb
1050060ff233Sopenharmony_ci * @tc.type: FUNC
1051060ff233Sopenharmony_ci * @tc.require: NONE
1052060ff233Sopenharmony_ci */
1053060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestWrapperLpDeviceInfoCb, TestSize.Level1)
1054060ff233Sopenharmony_ci{
1055060ff233Sopenharmony_ci    DISC_LOGI(DISC_TEST, "TestWrapperAdvEnableCb enter");
1056060ff233Sopenharmony_ci    MockBluetooth mocker;
1057060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
1058060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1059060ff233Sopenharmony_ci
1060060ff233Sopenharmony_ci    int32_t scannerld = 0;
1061060ff233Sopenharmony_ci    BtUuid uuid = {};
1062060ff233Sopenharmony_ci    int32_t type = 0;
1063060ff233Sopenharmony_ci    uint8_t data = 0;
1064060ff233Sopenharmony_ci    uint32_t dataSize = 0;
1065060ff233Sopenharmony_ci
1066060ff233Sopenharmony_ci    ret = MockBluetooth::interface->RegisterScanListener(&scannerld, &g_softbusBcBleScanCbTest);
1067060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_BC_ADAPTER_REGISTER_FAIL);
1068060ff233Sopenharmony_ci
1069060ff233Sopenharmony_ci    MockBluetooth::bleScanCallback->lpDeviceInfoCb(&uuid, type, &data, dataSize);
1070060ff233Sopenharmony_ci
1071060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
1072060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1073060ff233Sopenharmony_ci}
1074060ff233Sopenharmony_ci
1075060ff233Sopenharmony_ci/**
1076060ff233Sopenharmony_ci * @tc.name: TestIsLpAvailable
1077060ff233Sopenharmony_ci * @tc.desc: Test IsLpAvailable
1078060ff233Sopenharmony_ci * @tc.type: FUNC
1079060ff233Sopenharmony_ci * @tc.require: NONE
1080060ff233Sopenharmony_ci*/
1081060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestIsLpAvailable, TestSize.Level1)
1082060ff233Sopenharmony_ci{
1083060ff233Sopenharmony_ci    MockBluetooth mocker;
1084060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
1085060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1086060ff233Sopenharmony_ci
1087060ff233Sopenharmony_ci    ret = MockBluetooth::interface->IsLpDeviceAvailable();
1088060ff233Sopenharmony_ci    EXPECT_EQ(ret, false);
1089060ff233Sopenharmony_ci
1090060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
1091060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1092060ff233Sopenharmony_ci}
1093060ff233Sopenharmony_ci
1094060ff233Sopenharmony_ci/**
1095060ff233Sopenharmony_ci * @tc.name: TestSoftbusSetLpParam
1096060ff233Sopenharmony_ci * @tc.desc: Test SoftbusSetLpParam
1097060ff233Sopenharmony_ci * @tc.type: FUNC
1098060ff233Sopenharmony_ci * @tc.require: NONE
1099060ff233Sopenharmony_ci */
1100060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, TestSoftbusSetLpParam, TestSize.Level1)
1101060ff233Sopenharmony_ci{
1102060ff233Sopenharmony_ci    MockBluetooth mocker;
1103060ff233Sopenharmony_ci    int32_t ret = MockBluetooth::interface->Init();
1104060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1105060ff233Sopenharmony_ci
1106060ff233Sopenharmony_ci    SoftBusLpBroadcastParam bcParam = {};
1107060ff233Sopenharmony_ci    SoftBusLpScanParam scanParam = {};
1108060ff233Sopenharmony_ci
1109060ff233Sopenharmony_ci    ret = MockBluetooth::interface->SetAdvFilterParam(SOFTBUS_BURST_TYPE, &bcParam, &scanParam);
1110060ff233Sopenharmony_ci    EXPECT_EQ(ret, false);
1111060ff233Sopenharmony_ci
1112060ff233Sopenharmony_ci    ret = MockBluetooth::interface->DeInit();
1113060ff233Sopenharmony_ci    EXPECT_EQ(ret, SOFTBUS_OK);
1114060ff233Sopenharmony_ci}
1115060ff233Sopenharmony_ci
1116060ff233Sopenharmony_ci/**
1117060ff233Sopenharmony_ci * @tc.name: AdapterBleGattTest_RegisterScanListener
1118060ff233Sopenharmony_ci * @tc.desc: test register scan listener
1119060ff233Sopenharmony_ci * @tc.type: FUNC
1120060ff233Sopenharmony_ci * @tc.require: NONE
1121060ff233Sopenharmony_ci */
1122060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, RegisterScanListener, TestSize.Level3)
1123060ff233Sopenharmony_ci{
1124060ff233Sopenharmony_ci    MockBluetooth mocker;
1125060ff233Sopenharmony_ci    int32_t scannerId = -1;
1126060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->RegisterScanListener(&scannerId, nullptr), SOFTBUS_INVALID_PARAM);
1127060ff233Sopenharmony_ci    int32_t scanListerIds[GATT_SCAN_MAX_NUM] = {};
1128060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_ERR;
1129060ff233Sopenharmony_ci    for (size_t i = 0; i < GATT_SCAN_MAX_NUM; i++) {
1130060ff233Sopenharmony_ci        ret = MockBluetooth::interface->RegisterScanListener(&scanListerIds[i], GetStubScanListener());
1131060ff233Sopenharmony_ci        ASSERT_EQ(ret, SOFTBUS_LOCK_ERR);
1132060ff233Sopenharmony_ci    }
1133060ff233Sopenharmony_ci
1134060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->RegisterScanListener(&scannerId, GetStubScanListener()),
1135060ff233Sopenharmony_ci        SOFTBUS_LOCK_ERR);
1136060ff233Sopenharmony_ci
1137060ff233Sopenharmony_ci    for (size_t i = 0; i < GATT_SCAN_MAX_NUM; i++) {
1138060ff233Sopenharmony_ci        ASSERT_EQ(MockBluetooth::interface->UnRegisterScanListener(scanListerIds[i]), SOFTBUS_LOCK_ERR);
1139060ff233Sopenharmony_ci    }
1140060ff233Sopenharmony_ci}
1141060ff233Sopenharmony_ci
1142060ff233Sopenharmony_ci/**
1143060ff233Sopenharmony_ci * @tc.name: AdapterBleGattTest_UnRegisterScanListener
1144060ff233Sopenharmony_ci * @tc.desc: test unregister scan listener
1145060ff233Sopenharmony_ci * @tc.type: FUNC
1146060ff233Sopenharmony_ci * @tc.require: NONE
1147060ff233Sopenharmony_ci */
1148060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, UnRegisterScanListener, TestSize.Level3)
1149060ff233Sopenharmony_ci{
1150060ff233Sopenharmony_ci    MockBluetooth mocker;
1151060ff233Sopenharmony_ci    int32_t scannerId = -1;
1152060ff233Sopenharmony_ci    auto result = PrepareScanListener(&scannerId);
1153060ff233Sopenharmony_ci
1154060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->UnRegisterScanListener(-1), SOFTBUS_INVALID_PARAM);
1155060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->UnRegisterScanListener(GATT_SCAN_MAX_NUM), SOFTBUS_INVALID_PARAM);
1156060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->UnRegisterScanListener(scannerId), SOFTBUS_INVALID_PARAM);
1157060ff233Sopenharmony_ci}
1158060ff233Sopenharmony_ci
1159060ff233Sopenharmony_ci/**
1160060ff233Sopenharmony_ci * @tc.name: AdapterBleGattTest_ScanLifecycle
1161060ff233Sopenharmony_ci * @tc.desc: test complete scan life cycle
1162060ff233Sopenharmony_ci * @tc.type: FUNC
1163060ff233Sopenharmony_ci * @tc.require: NONE
1164060ff233Sopenharmony_ci */
1165060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, ScanLifecycle, TestSize.Level3)
1166060ff233Sopenharmony_ci{
1167060ff233Sopenharmony_ci    MockBluetooth mocker;
1168060ff233Sopenharmony_ci    int32_t scannerId = -1;
1169060ff233Sopenharmony_ci    auto result = PrepareScanListener(&scannerId);
1170060ff233Sopenharmony_ci
1171060ff233Sopenharmony_ci    auto filter = CreateScanFilter();
1172060ff233Sopenharmony_ci    ASSERT_NE(filter, nullptr);
1173060ff233Sopenharmony_ci
1174060ff233Sopenharmony_ci    SoftBusBcScanParams scanParam = {
1175060ff233Sopenharmony_ci        .scanInterval = SOFTBUS_BC_SCAN_WINDOW_P10,
1176060ff233Sopenharmony_ci        .scanWindow = SOFTBUS_BC_SCAN_INTERVAL_P10,
1177060ff233Sopenharmony_ci        .scanType = SOFTBUS_BC_SCAN_TYPE_ACTIVE,
1178060ff233Sopenharmony_ci        .scanPhy = SOFTBUS_BC_SCAN_PHY_1M,
1179060ff233Sopenharmony_ci        .scanFilterPolicy = SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL,
1180060ff233Sopenharmony_ci    };
1181060ff233Sopenharmony_ci
1182060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStartScanEx).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
1183060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StartScan(scannerId, &scanParam, filter, 1), SOFTBUS_LOCK_ERR);
1184060ff233Sopenharmony_ci
1185060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStopScan).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
1186060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StopScan(scannerId), SOFTBUS_LOCK_ERR);
1187060ff233Sopenharmony_ci
1188060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->UnRegisterScanListener(scannerId), SOFTBUS_INVALID_PARAM);
1189060ff233Sopenharmony_ci}
1190060ff233Sopenharmony_ci
1191060ff233Sopenharmony_ci/**
1192060ff233Sopenharmony_ci * @tc.name: AdapterBleGattTest_ScanResultCb
1193060ff233Sopenharmony_ci * @tc.desc: test scan result callback
1194060ff233Sopenharmony_ci * @tc.type: FUNC
1195060ff233Sopenharmony_ci * @tc.require: NONE
1196060ff233Sopenharmony_ci */
1197060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, ScanResultCb, TestSize.Level3)
1198060ff233Sopenharmony_ci{
1199060ff233Sopenharmony_ci    MockBluetooth mocker;
1200060ff233Sopenharmony_ci    int32_t scannerId = -1;
1201060ff233Sopenharmony_ci    auto result = PrepareScanListener(&scannerId);
1202060ff233Sopenharmony_ci
1203060ff233Sopenharmony_ci    auto filter = CreateScanFilter();
1204060ff233Sopenharmony_ci    ASSERT_NE(filter, nullptr);
1205060ff233Sopenharmony_ci
1206060ff233Sopenharmony_ci    SoftBusBcScanParams scanParam = {
1207060ff233Sopenharmony_ci        .scanInterval = SOFTBUS_BC_SCAN_WINDOW_P10,
1208060ff233Sopenharmony_ci        .scanWindow = SOFTBUS_BC_SCAN_INTERVAL_P10,
1209060ff233Sopenharmony_ci        .scanType = SOFTBUS_BC_SCAN_TYPE_ACTIVE,
1210060ff233Sopenharmony_ci        .scanPhy = SOFTBUS_BC_SCAN_PHY_1M,
1211060ff233Sopenharmony_ci        .scanFilterPolicy = SOFTBUS_BC_SCAN_FILTER_POLICY_ACCEPT_ALL,
1212060ff233Sopenharmony_ci    };
1213060ff233Sopenharmony_ci
1214060ff233Sopenharmony_ci    EXPECT_CALL(mocker, BleStartScanEx).WillRepeatedly(Return(OHOS_BT_STATUS_SUCCESS));
1215060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StartScan(scannerId, nullptr, filter, 1), SOFTBUS_INVALID_PARAM);
1216060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StartScan(scannerId, &scanParam, nullptr, 1), SOFTBUS_INVALID_PARAM);
1217060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StartScan(scannerId, &scanParam, filter, 0), SOFTBUS_INVALID_PARAM);
1218060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->StartScan(scannerId, &scanParam, filter, 1), SOFTBUS_LOCK_ERR);
1219060ff233Sopenharmony_ci
1220060ff233Sopenharmony_ci    const unsigned char scanDataExample[] = {0x02, 0x01, 0x02, 0x15, 0x16, 0xEE, 0xFD, 0x04, 0x05, 0x90, 0x00, 0x00,
1221060ff233Sopenharmony_ci        0x04, 0x00, 0x18, 0x33, 0x39, 0x36, 0x62, 0x33, 0x61, 0x33, 0x31, 0x21, 0x00, 0x02, 0x0A, 0xEF, 0x03, 0xFF,
1222060ff233Sopenharmony_ci        0x7D, 0x02};
1223060ff233Sopenharmony_ci    SoftBusBcScanResult expectScanResult = {0};
1224060ff233Sopenharmony_ci    expectScanResult.data.bcData.payloadLen = sizeof(scanDataExample);
1225060ff233Sopenharmony_ci    expectScanResult.data.bcData.payload = (unsigned char *)scanDataExample;
1226060ff233Sopenharmony_ci    BtScanResultData mockScanResult = {0};
1227060ff233Sopenharmony_ci    mockScanResult.advLen = sizeof(scanDataExample);
1228060ff233Sopenharmony_ci    mockScanResult.advData = (unsigned char *)scanDataExample;
1229060ff233Sopenharmony_ci
1230060ff233Sopenharmony_ci    mockScanResult.eventType = OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE;
1231060ff233Sopenharmony_ci    mockScanResult.dataStatus = OHOS_BLE_DATA_COMPLETE;
1232060ff233Sopenharmony_ci    mockScanResult.addrType = OHOS_BLE_PUBLIC_DEVICE_ADDRESS;
1233060ff233Sopenharmony_ci    mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
1234060ff233Sopenharmony_ci    mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_NO_PACKET;
1235060ff233Sopenharmony_ci    mockScanResult.directAddrType = OHOS_BLE_PUBLIC_DEVICE_ADDRESS;
1236060ff233Sopenharmony_ci    ASSERT_FALSE(scanResultCtx.Expect(scannerId, &expectScanResult));
1237060ff233Sopenharmony_ci
1238060ff233Sopenharmony_ci    mockScanResult.eventType = OHOS_BLE_EVT_NON_CONNECTABLE_NON_SCANNABLE_DIRECTED;
1239060ff233Sopenharmony_ci    mockScanResult.dataStatus = OHOS_BLE_DATA_INCOMPLETE_MORE_TO_COME;
1240060ff233Sopenharmony_ci    mockScanResult.addrType = OHOS_BLE_RANDOM_DEVICE_ADDRESS;
1241060ff233Sopenharmony_ci    mockScanResult.primaryPhy = OHOS_BLE_SCAN_PHY_1M;
1242060ff233Sopenharmony_ci    mockScanResult.secondaryPhy = OHOS_BLE_SCAN_PHY_1M;
1243060ff233Sopenharmony_ci    mockScanResult.directAddrType = OHOS_BLE_RANDOM_DEVICE_ADDRESS;
1244060ff233Sopenharmony_ci    ASSERT_FALSE(scanResultCtx.Expect(scannerId, &expectScanResult));
1245060ff233Sopenharmony_ci}
1246060ff233Sopenharmony_ci
1247060ff233Sopenharmony_ci/**
1248060ff233Sopenharmony_ci * @tc.name: AdapterBleGattTest_RegisterBroadcaster
1249060ff233Sopenharmony_ci * @tc.desc: test register adv callback
1250060ff233Sopenharmony_ci * @tc.type: FUNC
1251060ff233Sopenharmony_ci * @tc.require: NONE
1252060ff233Sopenharmony_ci */
1253060ff233Sopenharmony_ciHWTEST_F(SoftbusBleGattTest, RegisterBroadcaster, TestSize.Level3)
1254060ff233Sopenharmony_ci{
1255060ff233Sopenharmony_ci    int32_t advId = -1;
1256060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->RegisterBroadcaster(&advId, nullptr), SOFTBUS_INVALID_PARAM);
1257060ff233Sopenharmony_ci    int32_t advIds[GATT_ADV_MAX_NUM];
1258060ff233Sopenharmony_ci    for (size_t i = 0; i < GATT_ADV_MAX_NUM; i++) {
1259060ff233Sopenharmony_ci        ASSERT_EQ(MockBluetooth::interface->RegisterBroadcaster(&advIds[i], GetStubAdvCallback()), SOFTBUS_LOCK_ERR);
1260060ff233Sopenharmony_ci    }
1261060ff233Sopenharmony_ci    ASSERT_EQ(MockBluetooth::interface->RegisterBroadcaster(&advId, GetStubAdvCallback()),
1262060ff233Sopenharmony_ci        SOFTBUS_LOCK_ERR);
1263060ff233Sopenharmony_ci    for (size_t i = 0; i < GATT_ADV_MAX_NUM; i++) {
1264060ff233Sopenharmony_ci        ASSERT_EQ(MockBluetooth::interface->UnRegisterBroadcaster(advIds[i]), SOFTBUS_LOCK_ERR);
1265060ff233Sopenharmony_ci    }
1266060ff233Sopenharmony_ci}
1267060ff233Sopenharmony_ci
1268060ff233Sopenharmony_ciScanResultCtx::ScanResultCtx(const char *identifier) : RecordCtx(identifier)
1269060ff233Sopenharmony_ci{
1270060ff233Sopenharmony_ci    Reset();
1271060ff233Sopenharmony_ci}
1272060ff233Sopenharmony_ciScanResultCtx::~ScanResultCtx()
1273060ff233Sopenharmony_ci{
1274060ff233Sopenharmony_ci    Reset();
1275060ff233Sopenharmony_ci}
1276060ff233Sopenharmony_ci
1277060ff233Sopenharmony_civoid ScanResultCtx::Reset()
1278060ff233Sopenharmony_ci{
1279060ff233Sopenharmony_ci    SoftBusFree(scanResult.data.bcData.payload);
1280060ff233Sopenharmony_ci    SoftBusFree(scanResult.data.rspData.payload);
1281060ff233Sopenharmony_ci    scanResult.data.bcData.payload = nullptr;
1282060ff233Sopenharmony_ci    scanResult.data.rspData.payload = nullptr;
1283060ff233Sopenharmony_ci}
1284060ff233Sopenharmony_ci
1285060ff233Sopenharmony_cibool ScanResultCtx::Update(int32_t id, const SoftBusBcScanResult *scanResult)
1286060ff233Sopenharmony_ci{
1287060ff233Sopenharmony_ci    if (!RecordCtx::Update(id)) {
1288060ff233Sopenharmony_ci        return false;
1289060ff233Sopenharmony_ci    }
1290060ff233Sopenharmony_ci    this->scanResult = *scanResult;
1291060ff233Sopenharmony_ci    unsigned char *cpyAdvData = static_cast<unsigned char *>(SoftBusCalloc(this->scanResult.data.bcData.payloadLen));
1292060ff233Sopenharmony_ci    if (cpyAdvData == nullptr) {
1293060ff233Sopenharmony_ci        DISC_LOGE(DISC_TEST, "malloc failed in OnReportScanDataCallback, can not save ctx, id=%{public}d", id);
1294060ff233Sopenharmony_ci        return false;
1295060ff233Sopenharmony_ci    }
1296060ff233Sopenharmony_ci
1297060ff233Sopenharmony_ci    if (memcpy_s(cpyAdvData, this->scanResult.data.bcData.payloadLen, scanResult->data.bcData.payload,
1298060ff233Sopenharmony_ci        scanResult->data.bcData.payloadLen) != EOK) {
1299060ff233Sopenharmony_ci        DISC_LOGE(DISC_TEST, "malloc failed in OnReportScanDataCallback, can not save ctx, id=%{public}d", id);
1300060ff233Sopenharmony_ci        SoftBusFree(cpyAdvData);
1301060ff233Sopenharmony_ci        return false;
1302060ff233Sopenharmony_ci    }
1303060ff233Sopenharmony_ci    this->scanResult.data.bcData.payload = cpyAdvData;
1304060ff233Sopenharmony_ci    return true;
1305060ff233Sopenharmony_ci}
1306060ff233Sopenharmony_ci
1307060ff233Sopenharmony_citesting::AssertionResult ScanResultCtx::Expect(int32_t id, const SoftBusBcScanResult *scanResultParam)
1308060ff233Sopenharmony_ci{
1309060ff233Sopenharmony_ci    auto result = RecordCtx::Expect(id);
1310060ff233Sopenharmony_ci    if (!result) {
1311060ff233Sopenharmony_ci        goto ClEANUP;
1312060ff233Sopenharmony_ci    }
1313060ff233Sopenharmony_ci
1314060ff233Sopenharmony_ci    if (this->scanResult.data.bcData.payloadLen == scanResultParam->data.bcData.payloadLen &&
1315060ff233Sopenharmony_ci        memcmp(this->scanResult.data.bcData.payload, scanResultParam->data.bcData.payload,
1316060ff233Sopenharmony_ci        scanResultParam->data.bcData.payloadLen) == 0) {
1317060ff233Sopenharmony_ci        result = testing::AssertionSuccess();
1318060ff233Sopenharmony_ci        goto ClEANUP;
1319060ff233Sopenharmony_ci    }
1320060ff233Sopenharmony_ci    result = testing::AssertionFailure() << identifier << " is call by unexpectedly scan result.";
1321060ff233Sopenharmony_ciClEANUP:
1322060ff233Sopenharmony_ci    Reset();
1323060ff233Sopenharmony_ci    return result;
1324060ff233Sopenharmony_ci}
1325060ff233Sopenharmony_ci
1326060ff233Sopenharmony_ci} // namespace OHOS