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_manager_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22 void *g_connectionBleManagerInterface;
ConnectionBleManagerInterfaceMock()23 ConnectionBleManagerInterfaceMock::ConnectionBleManagerInterfaceMock()
24 {
25 g_connectionBleManagerInterface = reinterpret_cast<void *>(this);
26 }
27
~ConnectionBleManagerInterfaceMock()28 ConnectionBleManagerInterfaceMock::~ConnectionBleManagerInterfaceMock()
29 {
30 g_connectionBleManagerInterface = nullptr;
31 }
32
GetConnectionBleInterface()33 static ConnectionBleManagerInterface *GetConnectionBleInterface()
34 {
35 return reinterpret_cast<ConnectionBleManagerInterface *>(g_connectionBleManagerInterface);
36 }
37
ActionOfGetdelta(const cJSON * json,const char * const str,int32_t * target)38 bool ConnectionBleManagerInterfaceMock::ActionOfGetdelta(
39 const cJSON *json, const char * const str, int32_t *target)
40 {
41 (void)json;
42 (void)str;
43 if (target != nullptr) {
44 *target = -1;
45 }
46 return true;
47 }
48
ActionOfGetPeerRc1(const cJSON * json,const char * const str,int32_t * target)49 bool ConnectionBleManagerInterfaceMock::ActionOfGetPeerRc1(
50 const cJSON *json, const char * const str, int32_t *target)
51 {
52 (void)json;
53 (void)str;
54 if (target != nullptr) {
55 *target = 1;
56 }
57 return true;
58 }
59
ActionOfGetPeerRc0(const cJSON * json,const char * const str,int32_t * target)60 bool ConnectionBleManagerInterfaceMock::ActionOfGetPeerRc0(
61 const cJSON *json, const char * const str, int32_t *target)
62 {
63 (void)json;
64 (void)str;
65 if (target != nullptr) {
66 *target = 0;
67 }
68 return true;
69 }
70
71 extern "C" {
ConnBlePostBytesInner(uint32_t connectionId,uint8_t * data,uint32_t dataLen,int32_t pid,int32_t flag,int32_t module,int64_t seq,PostBytesFinishAction postBytesFinishAction)72 int ConnBlePostBytesInner(uint32_t connectionId, uint8_t *data, uint32_t dataLen, int32_t pid, int32_t flag,
73 int32_t module, int64_t seq, PostBytesFinishAction postBytesFinishAction)
74 {
75 return GetConnectionBleInterface()->ConnBlePostBytesInner(
76 connectionId, data, dataLen, pid, flag, module, seq, postBytesFinishAction);
77 }
78
ConnBleTransConfigPostLimit(const LimitConfiguration * configuration)79 int32_t ConnBleTransConfigPostLimit(const LimitConfiguration *configuration)
80 {
81 return 0;
82 }
83
LnnGetConnSubFeatureByUdidHashStr(const char * udidHashStr,uint64_t * connSubFeature)84 int32_t LnnGetConnSubFeatureByUdidHashStr(const char *udidHashStr, uint64_t *connSubFeature)
85 {
86 return GetConnectionBleInterface()->LnnGetConnSubFeatureByUdidHashStr(udidHashStr, connSubFeature);
87 }
88
LnnRegisterEventHandler(LnnEventType event,LnnEventHandler handler)89 int32_t LnnRegisterEventHandler(LnnEventType event, LnnEventHandler handler)
90 {
91 return GetConnectionBleInterface()->LnnRegisterEventHandler(event, handler);
92 }
93
ConnBlePackCtlMessage(BleCtlMessageSerializationContext ctx,uint8_t ** outData,uint32_t * outLen)94 int64_t ConnBlePackCtlMessage(BleCtlMessageSerializationContext ctx, uint8_t **outData, uint32_t *outLen)
95 {
96 return GetConnectionBleInterface()->ConnBlePackCtlMessage(ctx, outData, outLen);
97 }
98
LnnGetRemoteStrInfo(const char * netWorkId,InfoKey key,char * info,uint32_t len)99 int32_t LnnGetRemoteStrInfo(const char *netWorkId, InfoKey key, char *info, uint32_t len)
100 {
101 return GetConnectionBleInterface()->LnnGetRemoteStrInfo(netWorkId, key, info, len);
102 }
103
LnnGetLocalStrInfo(InfoKey key,char * info,uint32_t len)104 int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
105 {
106 return GetConnectionBleInterface()->LnnGetLocalStrInfo(key, info, len);
107 }
108
LnnGetLocalNumInfo(InfoKey key,int32_t * info)109 int32_t LnnGetLocalNumInfo(InfoKey key, int32_t *info)
110 {
111 return GetConnectionBleInterface()->LnnGetLocalNumInfo(key, info);
112 }
113
SoftBusGattsAddDescriptor(int srvcHandle,SoftBusBtUuid descUuid,int permissions)114 int SoftBusGattsAddDescriptor(int srvcHandle, SoftBusBtUuid descUuid, int permissions)
115 {
116 return GetConnectionBleInterface()->SoftBusGattsAddDescriptor(srvcHandle, descUuid, permissions);
117 }
118
SoftBusGattsStartService(int srvcHandle)119 int SoftBusGattsStartService(int srvcHandle)
120 {
121 return GetConnectionBleInterface()->SoftBusGattsStartService(srvcHandle);
122 }
123
SoftBusGattsSendResponse(SoftBusGattsResponse * param)124 int SoftBusGattsSendResponse(SoftBusGattsResponse *param)
125 {
126 return GetConnectionBleInterface()->SoftBusGattsSendResponse(param);
127 }
128
LegacyBleCreateConnection(const char * addr,ConnSideType side,int32_t underlayerHandle,bool fastestConnectEnable)129 ConnBleConnection *LegacyBleCreateConnection(
130 const char *addr, ConnSideType side, int32_t underlayerHandle, bool fastestConnectEnable)
131 {
132 return GetConnectionBleInterface()->LegacyBleCreateConnection(addr, side, underlayerHandle, fastestConnectEnable);
133 }
134
LegacyBleSaveConnection(ConnBleConnection * connection)135 int32_t LegacyBleSaveConnection(ConnBleConnection *connection)
136 {
137 return GetConnectionBleInterface()->LegacyBleSaveConnection(connection);
138 }
139
SoftBusGattsAddCharacteristic(int srvcHandle,SoftBusBtUuid characUuid,int properties,int permissions)140 int SoftBusGattsAddCharacteristic(int srvcHandle, SoftBusBtUuid characUuid, int properties, int permissions)
141 {
142 return GetConnectionBleInterface()->SoftBusGattsAddCharacteristic(srvcHandle, characUuid, properties, permissions);
143 }
144
ConnGattClientConnect(ConnBleConnection * connection)145 int32_t ConnGattClientConnect(ConnBleConnection *connection)
146 {
147 return GetConnectionBleInterface()->ConnGattClientConnect(connection);
148 }
149
ConnGattClientDisconnect(ConnBleConnection * connection,bool grace,bool refreshGatt)150 int32_t ConnGattClientDisconnect(ConnBleConnection *connection, bool grace, bool refreshGatt)
151 {
152 return GetConnectionBleInterface()->ConnGattClientDisconnect(connection, grace, refreshGatt);
153 }
154
ConnGattClientSend(ConnBleConnection * connection,const uint8_t * data,uint32_t dataLen,int32_t module)155 int32_t ConnGattClientSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
156 {
157 return GetConnectionBleInterface()->ConnGattClientSend(connection, data, dataLen, module);
158 }
159
ConnGattClientUpdatePriority(ConnBleConnection * connection,ConnectBlePriority priority)160 int32_t ConnGattClientUpdatePriority(ConnBleConnection *connection, ConnectBlePriority priority)
161 {
162 return GetConnectionBleInterface()->ConnGattClientUpdatePriority(connection, priority);
163 }
164
ConnGattServerStartService()165 int32_t ConnGattServerStartService()
166 {
167 return GetConnectionBleInterface()->ConnGattServerStartService();
168 }
169
ConnGattServerStopService()170 int32_t ConnGattServerStopService()
171 {
172 return GetConnectionBleInterface()->ConnGattServerStopService();
173 }
174
ConnGattServerSend(ConnBleConnection * connection,const uint8_t * data,uint32_t dataLen,int32_t module)175 int32_t ConnGattServerSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
176 {
177 return GetConnectionBleInterface()->ConnGattServerSend(connection, data, dataLen, module);
178 }
179
ConnGattServerConnect(ConnBleConnection * connection)180 int32_t ConnGattServerConnect(ConnBleConnection *connection)
181 {
182 return GetConnectionBleInterface()->ConnGattServerConnect(connection);
183 }
184
ConnGattServerDisconnect(ConnBleConnection * connection)185 int32_t ConnGattServerDisconnect(ConnBleConnection *connection)
186 {
187 return GetConnectionBleInterface()->ConnGattServerDisconnect(connection);
188 }
189
ConnGattInitClientModule(SoftBusLooper * looper,const ConnBleClientEventListener * listener)190 int32_t ConnGattInitClientModule(SoftBusLooper *looper, const ConnBleClientEventListener *listener)
191 {
192 return GetConnectionBleInterface()->ConnGattInitClientModule(looper, listener);
193 }
194
ConnGattInitServerModule(SoftBusLooper * looper,const ConnBleServerEventListener * listener)195 int32_t ConnGattInitServerModule(SoftBusLooper *looper, const ConnBleServerEventListener *listener)
196 {
197 return GetConnectionBleInterface()->ConnGattInitServerModule(looper, listener);
198 }
199
GetJsonObjectSignedNumberItem(const cJSON * json,const char * const str,int32_t * target)200 bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const str, int32_t *target)
201 {
202 return GetConnectionBleInterface()->GetJsonObjectSignedNumberItem(json, str, target);
203 }
204
GetJsonObjectNumber16Item(const cJSON * json,const char * const str,uint16_t * target)205 bool GetJsonObjectNumber16Item(const cJSON *json, const char * const str, uint16_t *target)
206 {
207 return GetConnectionBleInterface()->GetJsonObjectNumber16Item(json, str, target);
208 }
209 }
210 } // namespace OHOS
211