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 "softbus_ble_mock.h"
17060ff233Sopenharmony_ci
18060ff233Sopenharmony_ci#include "disc_log.h"
19060ff233Sopenharmony_ci#include "softbus_error_code.h"
20060ff233Sopenharmony_ci
21060ff233Sopenharmony_ciManagerMock *ManagerMock::managerMock = nullptr;
22060ff233Sopenharmony_ciconst SoftbusBroadcastCallback *ManagerMock::broadcastCallback = nullptr;
23060ff233Sopenharmony_ciconst SoftbusScanCallback *ManagerMock::scanCallback = nullptr;
24060ff233Sopenharmony_ci
25060ff233Sopenharmony_cistatic int32_t g_advId = 0;
26060ff233Sopenharmony_cistatic int32_t g_listenerId = 0;
27060ff233Sopenharmony_cistatic void ActionOfSoftbusBleAdapterInit(void);
28060ff233Sopenharmony_ci
29060ff233Sopenharmony_ciint32_t ActionOfSoftBusAddBtStateListener(const SoftBusBtStateListener *listener)
30060ff233Sopenharmony_ci{
31060ff233Sopenharmony_ci    return SOFTBUS_OK;
32060ff233Sopenharmony_ci}
33060ff233Sopenharmony_ci
34060ff233Sopenharmony_ciint32_t ActionOfSoftBusRemoveBtStateListener(int32_t listenerId)
35060ff233Sopenharmony_ci{
36060ff233Sopenharmony_ci    return SOFTBUS_OK;
37060ff233Sopenharmony_ci}
38060ff233Sopenharmony_ci
39060ff233Sopenharmony_ciManagerMock::ManagerMock()
40060ff233Sopenharmony_ci{
41060ff233Sopenharmony_ci    ManagerMock::managerMock = this;
42060ff233Sopenharmony_ci    EXPECT_CALL(*this, SoftbusBleAdapterInit).WillRepeatedly(ActionOfSoftbusBleAdapterInit);
43060ff233Sopenharmony_ci    EXPECT_CALL(*this, SoftBusAddBtStateListener).WillRepeatedly(ActionOfSoftBusAddBtStateListener);
44060ff233Sopenharmony_ci    EXPECT_CALL(*this, SoftBusRemoveBtStateListener).WillRepeatedly(ActionOfSoftBusRemoveBtStateListener);
45060ff233Sopenharmony_ci}
46060ff233Sopenharmony_ci
47060ff233Sopenharmony_ciManagerMock::~ManagerMock()
48060ff233Sopenharmony_ci{
49060ff233Sopenharmony_ci    ManagerMock::managerMock = nullptr;
50060ff233Sopenharmony_ci}
51060ff233Sopenharmony_ci
52060ff233Sopenharmony_ciManagerMock *ManagerMock::GetMock()
53060ff233Sopenharmony_ci{
54060ff233Sopenharmony_ci    return managerMock;
55060ff233Sopenharmony_ci}
56060ff233Sopenharmony_ci
57060ff233Sopenharmony_civoid SoftbusBleAdapterInit()
58060ff233Sopenharmony_ci{
59060ff233Sopenharmony_ci    ManagerMock::GetMock()->SoftbusBleAdapterInit();
60060ff233Sopenharmony_ci}
61060ff233Sopenharmony_ci
62060ff233Sopenharmony_cistatic int32_t MockInit(void)
63060ff233Sopenharmony_ci{
64060ff233Sopenharmony_ci    return SOFTBUS_OK;
65060ff233Sopenharmony_ci}
66060ff233Sopenharmony_ci
67060ff233Sopenharmony_cistatic int32_t MockDeInit(void)
68060ff233Sopenharmony_ci{
69060ff233Sopenharmony_ci    return SOFTBUS_OK;
70060ff233Sopenharmony_ci}
71060ff233Sopenharmony_ci
72060ff233Sopenharmony_ciint32_t SoftBusAddBtStateListener(const SoftBusBtStateListener *listener)
73060ff233Sopenharmony_ci{
74060ff233Sopenharmony_ci    return ManagerMock::GetMock()->SoftBusAddBtStateListener(listener);
75060ff233Sopenharmony_ci}
76060ff233Sopenharmony_ci
77060ff233Sopenharmony_ciint32_t SoftBusRemoveBtStateListener(int32_t listenerId)
78060ff233Sopenharmony_ci{
79060ff233Sopenharmony_ci    return ManagerMock::GetMock()->SoftBusRemoveBtStateListener(listenerId);
80060ff233Sopenharmony_ci}
81060ff233Sopenharmony_ci
82060ff233Sopenharmony_cistatic int32_t MockRegisterBroadcaster(int32_t *bcId, const SoftbusBroadcastCallback *cb)
83060ff233Sopenharmony_ci{
84060ff233Sopenharmony_ci    ManagerMock::broadcastCallback = cb;
85060ff233Sopenharmony_ci    *bcId = g_advId;
86060ff233Sopenharmony_ci    g_advId++;
87060ff233Sopenharmony_ci    return SOFTBUS_OK;
88060ff233Sopenharmony_ci}
89060ff233Sopenharmony_ci
90060ff233Sopenharmony_cistatic int32_t MockUnRegisterBroadcaster(int32_t bcId)
91060ff233Sopenharmony_ci{
92060ff233Sopenharmony_ci    ManagerMock::broadcastCallback = nullptr;
93060ff233Sopenharmony_ci    g_advId--;
94060ff233Sopenharmony_ci    return SOFTBUS_OK;
95060ff233Sopenharmony_ci}
96060ff233Sopenharmony_ci
97060ff233Sopenharmony_cistatic int32_t MockRegisterScanListener(int32_t *scanerId, const SoftbusScanCallback *cb)
98060ff233Sopenharmony_ci{
99060ff233Sopenharmony_ci    ManagerMock::scanCallback = cb;
100060ff233Sopenharmony_ci    *scanerId = g_listenerId;
101060ff233Sopenharmony_ci    g_listenerId++;
102060ff233Sopenharmony_ci    return SOFTBUS_OK;
103060ff233Sopenharmony_ci}
104060ff233Sopenharmony_ci
105060ff233Sopenharmony_cistatic int32_t MockUnRegisterScanListener(int32_t scanerId)
106060ff233Sopenharmony_ci{
107060ff233Sopenharmony_ci    ManagerMock::scanCallback = nullptr;
108060ff233Sopenharmony_ci    g_listenerId--;
109060ff233Sopenharmony_ci    return SOFTBUS_OK;
110060ff233Sopenharmony_ci}
111060ff233Sopenharmony_ci
112060ff233Sopenharmony_cistatic int32_t MockStartBroadcasting(int32_t bcId, const SoftbusBroadcastParam *param, const SoftbusBroadcastData *data)
113060ff233Sopenharmony_ci{
114060ff233Sopenharmony_ci    ManagerMock::broadcastCallback->OnStartBroadcastingCallback(bcId, (int32_t)SOFTBUS_BC_STATUS_SUCCESS);
115060ff233Sopenharmony_ci    return SOFTBUS_OK;
116060ff233Sopenharmony_ci}
117060ff233Sopenharmony_ci
118060ff233Sopenharmony_cistatic int32_t MockStopBroadcasting(int32_t bcId)
119060ff233Sopenharmony_ci{
120060ff233Sopenharmony_ci    ManagerMock::broadcastCallback->OnStopBroadcastingCallback(bcId, (int32_t)SOFTBUS_BC_STATUS_SUCCESS);
121060ff233Sopenharmony_ci    return SOFTBUS_OK;
122060ff233Sopenharmony_ci}
123060ff233Sopenharmony_ci
124060ff233Sopenharmony_cistatic int32_t MockSetBroadcastingData(int32_t bcId, const SoftbusBroadcastData *data)
125060ff233Sopenharmony_ci{
126060ff233Sopenharmony_ci    ManagerMock::broadcastCallback->OnSetBroadcastingCallback(bcId, (int32_t)SOFTBUS_BC_STATUS_SUCCESS);
127060ff233Sopenharmony_ci    return SOFTBUS_OK;
128060ff233Sopenharmony_ci}
129060ff233Sopenharmony_ci
130060ff233Sopenharmony_cistatic int32_t MockUpdateBroadcasting(int32_t bcId, const SoftbusBroadcastParam *param,
131060ff233Sopenharmony_ci    const SoftbusBroadcastData *data)
132060ff233Sopenharmony_ci{
133060ff233Sopenharmony_ci    ManagerMock::broadcastCallback->OnUpdateBroadcastingCallback(bcId, (int32_t)SOFTBUS_BC_STATUS_SUCCESS);
134060ff233Sopenharmony_ci    return SOFTBUS_OK;
135060ff233Sopenharmony_ci}
136060ff233Sopenharmony_ci
137060ff233Sopenharmony_cistatic int32_t MockStartScan(int32_t scanerId, const SoftBusBcScanParams *param, const SoftBusBcScanFilter *scanFilter,
138060ff233Sopenharmony_ci    int32_t filterSize)
139060ff233Sopenharmony_ci{
140060ff233Sopenharmony_ci    return SOFTBUS_OK;
141060ff233Sopenharmony_ci}
142060ff233Sopenharmony_ci
143060ff233Sopenharmony_cistatic int32_t MockStopScan(int32_t scanerId)
144060ff233Sopenharmony_ci{
145060ff233Sopenharmony_ci    return SOFTBUS_OK;
146060ff233Sopenharmony_ci}
147060ff233Sopenharmony_ci
148060ff233Sopenharmony_cistatic bool MockIsLpDeviceAvailable(void)
149060ff233Sopenharmony_ci{
150060ff233Sopenharmony_ci    return true;
151060ff233Sopenharmony_ci}
152060ff233Sopenharmony_ci
153060ff233Sopenharmony_cistatic bool MockSetAdvFilterParam(LpServerType type,
154060ff233Sopenharmony_ci    const SoftBusLpBroadcastParam *bcParam, const SoftBusLpScanParam *scanParam)
155060ff233Sopenharmony_ci{
156060ff233Sopenharmony_ci    return SOFTBUS_OK;
157060ff233Sopenharmony_ci}
158060ff233Sopenharmony_ci
159060ff233Sopenharmony_cistatic int32_t MockGetBroadcastHandle(int32_t bcId, int32_t *bcHandle)
160060ff233Sopenharmony_ci{
161060ff233Sopenharmony_ci    return SOFTBUS_OK;
162060ff233Sopenharmony_ci}
163060ff233Sopenharmony_ci
164060ff233Sopenharmony_cistatic int32_t MockEnableSyncDataToLpDevice(void)
165060ff233Sopenharmony_ci{
166060ff233Sopenharmony_ci    return SOFTBUS_OK;
167060ff233Sopenharmony_ci}
168060ff233Sopenharmony_ci
169060ff233Sopenharmony_cistatic int32_t MockDisableSyncDataToLpDevice(void)
170060ff233Sopenharmony_ci{
171060ff233Sopenharmony_ci    return SOFTBUS_OK;
172060ff233Sopenharmony_ci}
173060ff233Sopenharmony_ci
174060ff233Sopenharmony_cistatic int32_t MockSetScanReportChannelToLpDevice(int32_t scannerId, bool enable)
175060ff233Sopenharmony_ci{
176060ff233Sopenharmony_ci    return SOFTBUS_OK;
177060ff233Sopenharmony_ci}
178060ff233Sopenharmony_ci
179060ff233Sopenharmony_cistatic int32_t MockSetLpDeviceParam(int32_t duration, int32_t maxExtAdvEvents, int32_t window,
180060ff233Sopenharmony_ci    int32_t interval, int32_t bcHandle)
181060ff233Sopenharmony_ci{
182060ff233Sopenharmony_ci    return SOFTBUS_OK;
183060ff233Sopenharmony_ci}
184060ff233Sopenharmony_ci
185060ff233Sopenharmony_cistatic void ActionOfSoftbusBleAdapterInit()
186060ff233Sopenharmony_ci{
187060ff233Sopenharmony_ci    DISC_LOGI(DISC_TEST, "enter");
188060ff233Sopenharmony_ci    static SoftbusBroadcastMediumInterface interface = {
189060ff233Sopenharmony_ci        .Init = MockInit,
190060ff233Sopenharmony_ci        .DeInit = MockDeInit,
191060ff233Sopenharmony_ci        .RegisterBroadcaster = MockRegisterBroadcaster,
192060ff233Sopenharmony_ci        .UnRegisterBroadcaster = MockUnRegisterBroadcaster,
193060ff233Sopenharmony_ci        .RegisterScanListener = MockRegisterScanListener,
194060ff233Sopenharmony_ci        .UnRegisterScanListener = MockUnRegisterScanListener,
195060ff233Sopenharmony_ci        .StartBroadcasting = MockStartBroadcasting,
196060ff233Sopenharmony_ci        .StopBroadcasting = MockStopBroadcasting,
197060ff233Sopenharmony_ci        .SetBroadcastingData = MockSetBroadcastingData,
198060ff233Sopenharmony_ci        .UpdateBroadcasting = MockUpdateBroadcasting,
199060ff233Sopenharmony_ci        .StartScan = MockStartScan,
200060ff233Sopenharmony_ci        .StopScan = MockStopScan,
201060ff233Sopenharmony_ci        .IsLpDeviceAvailable = MockIsLpDeviceAvailable,
202060ff233Sopenharmony_ci        .SetAdvFilterParam = MockSetAdvFilterParam,
203060ff233Sopenharmony_ci        .GetBroadcastHandle = MockGetBroadcastHandle,
204060ff233Sopenharmony_ci        .EnableSyncDataToLpDevice  = MockEnableSyncDataToLpDevice,
205060ff233Sopenharmony_ci        .DisableSyncDataToLpDevice = MockDisableSyncDataToLpDevice,
206060ff233Sopenharmony_ci        .SetScanReportChannelToLpDevice = MockSetScanReportChannelToLpDevice,
207060ff233Sopenharmony_ci        .SetLpDeviceParam = MockSetLpDeviceParam,
208060ff233Sopenharmony_ci    };
209060ff233Sopenharmony_ci    if (RegisterBroadcastMediumFunction(BROADCAST_MEDIUM_TYPE_BLE, &interface) != 0) {
210060ff233Sopenharmony_ci        DISC_LOGE(DISC_TEST, "Register gatt interface failed.");
211060ff233Sopenharmony_ci    }
212060ff233Sopenharmony_ci}
213060ff233Sopenharmony_ci
214060ff233Sopenharmony_civoid SoftbusBleAdapterDeInit(void)
215060ff233Sopenharmony_ci{
216060ff233Sopenharmony_ci    DISC_LOGI(DISC_TEST, "enter");
217060ff233Sopenharmony_ci}
218