• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bluetooth_mock.h"
17 
18 #include <securec.h>
19 
20 #include "softbus_common.h"
21 #include "softbus_errcode.h"
22 #include "softbus_log.h"
23 #include "softbus_utils.h"
24 
25 MockBluetooth *MockBluetooth::targetMocker = nullptr;
26 BtGapCallBacks *MockBluetooth::btGapCallback = nullptr;
27 BtGattCallbacks *MockBluetooth::btGattCallback = nullptr;
28 BleScanCallbacks  *MockBluetooth::bleScanCallback  = nullptr;
29 
ActionGapRegisterCallbacks(BtGapCallBacks * func)30 static int ActionGapRegisterCallbacks(BtGapCallBacks *func)
31 {
32     MockBluetooth::btGapCallback = func;
33     return OHOS_BT_STATUS_SUCCESS;
34 }
35 
ActionBleGattRegisterCallbacks(BtGattCallbacks * func)36 static int ActionBleGattRegisterCallbacks(BtGattCallbacks *func)
37 {
38     MockBluetooth::btGattCallback = func;
39     return OHOS_BT_STATUS_SUCCESS;
40 }
41 
GetMocker()42 MockBluetooth *MockBluetooth::GetMocker()
43 {
44     return targetMocker;
45 }
46 
MockBluetooth()47 MockBluetooth::MockBluetooth()
48 {
49     MockBluetooth::targetMocker = this;
50     // common callback is register glabal
51     EXPECT_CALL(*this, GapRegisterCallbacks).WillRepeatedly(ActionGapRegisterCallbacks);
52     EXPECT_CALL(*this, BleGattRegisterCallbacks).WillRepeatedly(ActionBleGattRegisterCallbacks);
53 }
54 
~MockBluetooth()55 MockBluetooth::~MockBluetooth()
56 {
57     MockBluetooth::targetMocker = nullptr;
58 }
59 
EnableBle(void)60 bool EnableBle(void)
61 {
62     return MockBluetooth::GetMocker()->EnableBle();
63 }
64 
DisableBle(void)65 bool DisableBle(void)
66 {
67     return MockBluetooth::GetMocker()->DisableBle();
68 }
69 
IsBleEnabled()70 bool IsBleEnabled()
71 {
72     return MockBluetooth::GetMocker()->IsBleEnabled();
73 }
74 
GetLocalAddr(unsigned char * mac,unsigned int len)75 bool GetLocalAddr(unsigned char *mac, unsigned int len)
76 {
77     return MockBluetooth::GetMocker()->GetLocalAddr(mac, len);
78 }
79 
SetLocalName(unsigned char * localName,unsigned char length)80 bool SetLocalName(unsigned char *localName, unsigned char length)
81 {
82     return MockBluetooth::GetMocker()->SetLocalName(localName, length);
83 }
84 
GapRegisterCallbacks(BtGapCallBacks * func)85 int GapRegisterCallbacks(BtGapCallBacks *func)
86 {
87     return MockBluetooth::GetMocker()->GapRegisterCallbacks(func);
88 }
89 
PairRequestReply(const BdAddr * bdAddr,int transport,bool accept)90 bool PairRequestReply(const BdAddr *bdAddr, int transport, bool accept)
91 {
92     return MockBluetooth::GetMocker()->PairRequestReply(bdAddr, transport, accept);
93 }
94 
SetDevicePairingConfirmation(const BdAddr * bdAddr,int transport,bool accept)95 bool SetDevicePairingConfirmation(const BdAddr *bdAddr, int transport, bool accept)
96 {
97     return MockBluetooth::GetMocker()->SetDevicePairingConfirmation(bdAddr, transport, accept);
98 }
99 
BleGattRegisterCallbacks(BtGattCallbacks * func)100 int BleGattRegisterCallbacks(BtGattCallbacks *func)
101 {
102     return MockBluetooth::GetMocker()->BleGattRegisterCallbacks(func);
103 }
104 
BleStartScanEx(int scannerId,BleScanConfigs * configs,BleScanNativeFilter * filter,unsigned int filterSize)105 int BleStartScanEx(int scannerId, BleScanConfigs *configs, BleScanNativeFilter *filter, unsigned int filterSize)
106 {
107     return MockBluetooth::GetMocker()->BleStartScanEx(scannerId, configs, filter, filterSize);
108 }
109 
BleStopScan(int scannerId)110 int BleStopScan(int scannerId)
111 {
112     return MockBluetooth::GetMocker()->BleStopScan(scannerId);
113 }
114 
BleStartAdvEx(int * advId,const StartAdvRawData rawData,BleAdvParams advParam)115 int BleStartAdvEx(int *advId, const StartAdvRawData rawData, BleAdvParams advParam)
116 {
117     return MockBluetooth::GetMocker()->BleStartAdvEx(advId, rawData, advParam);
118 }
119 
BleStopAdv(int advId)120 int BleStopAdv(int advId)
121 {
122     return MockBluetooth::GetMocker()->BleStopAdv(advId);
123 }
124 
BleGattcRegister(BtUuid appUuid)125 int BleGattcRegister(BtUuid appUuid)
126 {
127     return MockBluetooth::GetMocker()->BleGattcRegister(appUuid);
128 }
129 
BleGattcConnect(int clientId,BtGattClientCallbacks * func,const BdAddr * bdAddr,bool isAutoConnect,BtTransportType transport)130 int BleGattcConnect(
131     int clientId, BtGattClientCallbacks *func, const BdAddr *bdAddr, bool isAutoConnect, BtTransportType transport)
132 {
133     return MockBluetooth::GetMocker()->BleGattcConnect(clientId, func, bdAddr, isAutoConnect, transport);
134 }
135 
BleGattcDisconnect(int clientId)136 int BleGattcDisconnect(int clientId)
137 {
138     return MockBluetooth::GetMocker()->BleGattcDisconnect(clientId);
139 }
140 
BleGattcSearchServices(int clientId)141 int BleGattcSearchServices(int clientId)
142 {
143     return MockBluetooth::GetMocker()->BleGattcSearchServices(clientId);
144 }
145 
BleGattcGetService(int clientId,BtUuid serviceUuid)146 bool BleGattcGetService(int clientId, BtUuid serviceUuid)
147 {
148     return MockBluetooth::GetMocker()->BleGattcGetService(clientId, serviceUuid);
149 }
150 
BleGattcRegisterNotification(int clientId,BtGattCharacteristic characteristic,bool enable)151 int BleGattcRegisterNotification(int clientId, BtGattCharacteristic characteristic, bool enable)
152 {
153     return MockBluetooth::GetMocker()->BleGattcRegisterNotification(clientId, characteristic, enable);
154 }
155 
BleGattcConfigureMtuSize(int clientId,int mtuSize)156 int BleGattcConfigureMtuSize(int clientId, int mtuSize)
157 {
158     return MockBluetooth::GetMocker()->BleGattcConfigureMtuSize(clientId, mtuSize);
159 }
160 
BleGattcWriteCharacteristic(int clientId,BtGattCharacteristic characteristic,BtGattWriteType writeType,int len,const char * value)161 int BleGattcWriteCharacteristic(
162     int clientId, BtGattCharacteristic characteristic, BtGattWriteType writeType, int len, const char *value)
163 {
164     return MockBluetooth::GetMocker()->BleGattcWriteCharacteristic(clientId, characteristic, writeType, len, value);
165 }
166 
BleGattcUnRegister(int clientId)167 int BleGattcUnRegister(int clientId)
168 {
169     return MockBluetooth::GetMocker()->BleGattcUnRegister(clientId);
170 }
171 
BleGattcSetFastestConn(int clientId,bool fastestConnFlag)172 int BleGattcSetFastestConn(int clientId, bool fastestConnFlag)
173 {
174     return MockBluetooth::GetMocker()->BleGattcSetFastestConn(clientId, fastestConnFlag);
175 }
176 
BleGattcSetPriority(int clientId,const BdAddr * bdAddr,BtGattPriority priority)177 int BleGattcSetPriority(int clientId, const BdAddr *bdAddr, BtGattPriority priority)
178 {
179     return MockBluetooth::GetMocker()->BleGattcSetPriority(clientId, bdAddr, priority);
180 }
181 
BleGattsRegisterCallbacks(BtGattServerCallbacks * func)182 int BleGattsRegisterCallbacks(BtGattServerCallbacks *func)
183 {
184     return MockBluetooth::GetMocker()->BleGattsRegisterCallbacks(func);
185 }
186 
BleGattsRegister(BtUuid appUuid)187 int BleGattsRegister(BtUuid appUuid)
188 {
189     return MockBluetooth::GetMocker()->BleGattsRegister(appUuid);
190 }
191 
BleGattsAddService(int serverId,BtUuid srvcUuid,bool isPrimary,int number)192 int BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number)
193 {
194     return MockBluetooth::GetMocker()->BleGattsAddService(serverId, srvcUuid, isPrimary, number);
195 }
196 
BleGattsUnRegister(int serverId)197 int BleGattsUnRegister(int serverId)
198 {
199     return MockBluetooth::GetMocker()->BleGattsUnRegister(serverId);
200 }
201 
BleGattsAddCharacteristic(int serverId,int srvcHandle,BtUuid characUuid,int properties,int permissions)202 int BleGattsAddCharacteristic(int serverId, int srvcHandle, BtUuid characUuid, int properties, int permissions)
203 {
204     return MockBluetooth::GetMocker()->BleGattsAddCharacteristic(
205         serverId, srvcHandle, characUuid, properties, permissions);
206 }
207 
BleGattsAddDescriptor(int serverId,int srvcHandle,BtUuid descUuid,int permissions)208 int BleGattsAddDescriptor(int serverId, int srvcHandle, BtUuid descUuid, int permissions)
209 {
210     return MockBluetooth::GetMocker()->BleGattsAddDescriptor(serverId, srvcHandle, descUuid, permissions);
211 }
212 
BleGattsStartService(int serverId,int srvcHandle)213 int BleGattsStartService(int serverId, int srvcHandle)
214 {
215     return MockBluetooth::GetMocker()->BleGattsStartService(serverId, srvcHandle);
216 }
217 
BleGattsStopService(int serverId,int srvcHandle)218 int BleGattsStopService(int serverId, int srvcHandle)
219 {
220     return MockBluetooth::GetMocker()->BleGattsStopService(serverId, srvcHandle);
221 }
222 
BleGattsDeleteService(int serverId,int srvcHandle)223 int BleGattsDeleteService(int serverId, int srvcHandle)
224 {
225     return MockBluetooth::GetMocker()->BleGattsDeleteService(serverId, srvcHandle);
226 }
227 
BleGattsDisconnect(int serverId,BdAddr bdAddr,int connId)228 int BleGattsDisconnect(int serverId, BdAddr bdAddr, int connId)
229 {
230     return MockBluetooth::GetMocker()->BleGattsDisconnect(serverId, bdAddr, connId);
231 }
232 
BleGattsSendResponse(int serverId,GattsSendRspParam * param)233 int BleGattsSendResponse(int serverId, GattsSendRspParam *param)
234 {
235     return MockBluetooth::GetMocker()->BleGattsSendResponse(serverId, param);
236 }
237 
BleGattsSendIndication(int serverId,GattsSendIndParam * param)238 int BleGattsSendIndication(int serverId, GattsSendIndParam *param)
239 {
240     return MockBluetooth::GetMocker()->BleGattsSendIndication(serverId, param);
241 }