1 /*
2  * Copyright (c) 2024 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 "connection_ble_mock.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 void *g_connectionBleInterface;
ConnectionBleInterfaceMock()23 ConnectionBleInterfaceMock::ConnectionBleInterfaceMock()
24 {
25     g_connectionBleInterface = reinterpret_cast<void *>(this);
26 }
27 
~ConnectionBleInterfaceMock()28 ConnectionBleInterfaceMock::~ConnectionBleInterfaceMock()
29 {
30     g_connectionBleInterface = nullptr;
31 }
32 
GetConnectionBleInterface()33 static ConnectionBleInterface *GetConnectionBleInterface()
34 {
35     return reinterpret_cast<ConnectionBleInterface *>(g_connectionBleInterface);
36 }
37 
38 extern "C" {
AddNumberToJsonObject(cJSON * json,const char * const string,int num)39 bool AddNumberToJsonObject(cJSON *json, const char * const string, int num)
40 {
41     return GetConnectionBleInterface()->AddNumberToJsonObject(json, string, num);
42 }
43 
ConvertBtMacToBinary(const char * strMac,uint32_t strMacLen,uint8_t * binMac,uint32_t binMacLen)44 int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, uint32_t binMacLen)
45 {
46     return GetConnectionBleInterface()->ConvertBtMacToBinary(strMac, strMacLen, binMac, binMacLen);
47 }
48 
SoftbusGattcConnect(int32_t clientId,SoftBusBtAddr * addr)49 int32_t SoftbusGattcConnect(int32_t clientId, SoftBusBtAddr *addr)
50 {
51     return GetConnectionBleInterface()->SoftbusGattcConnect(clientId, addr);
52 }
53 
BleGattcDisconnect(int clientId)54 int BleGattcDisconnect(int clientId)
55 {
56     return GetConnectionBleInterface()->BleGattcDisconnect(clientId);
57 }
58 
SoftBusGattsAddService(SoftBusBtUuid srvcUuid,bool isPrimary,int number)59 int SoftBusGattsAddService(SoftBusBtUuid srvcUuid, bool isPrimary, int number)
60 {
61     return GetConnectionBleInterface()->SoftBusGattsAddService(srvcUuid, isPrimary, number);
62 }
63 
SoftBusGattsStopService(int srvcHandle)64 int SoftBusGattsStopService(int srvcHandle)
65 {
66     return GetConnectionBleInterface()->SoftBusGattsStopService(srvcHandle);
67 }
68 
SoftBusGattsDisconnect(SoftBusBtAddr btAddr,int connId)69 int SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int connId)
70 {
71     return GetConnectionBleInterface()->SoftBusGattsDisconnect(btAddr, connId);
72 }
73 
SoftbusGattcRefreshServices(int32_t clientId)74 int32_t SoftbusGattcRefreshServices(int32_t clientId)
75 {
76     return GetConnectionBleInterface()->SoftbusGattcRefreshServices(clientId);
77 }
78 
SoftbusGattcSearchServices(int32_t clientId)79 int32_t SoftbusGattcSearchServices(int32_t clientId)
80 {
81     return GetConnectionBleInterface()->SoftbusGattcSearchServices(clientId);
82 }
83 
GetJsonObjectSignedNumberItem(const cJSON * json,const char * const string,int * target)84 bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const string, int *target)
85 {
86     return GetConnectionBleInterface()->GetJsonObjectSignedNumberItem(json, string, target);
87 }
88 
BleGattsAddService(int serverId,BtUuid srvcUuid,bool isPrimary,int number)89 int BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number)
90 {
91     return GetConnectionBleInterface()->BleGattsAddService(serverId, srvcUuid, isPrimary, number);
92 }
93 
BleGattcUnRegister(int clientId)94 int BleGattcUnRegister(int clientId)
95 {
96     return GetConnectionBleInterface()->BleGattcUnRegister(clientId);
97 }
98 }
99 }
100