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 "br_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22 void *g_connectionBrInterface;
ConnectionBrInterfaceMock()23 ConnectionBrInterfaceMock::ConnectionBrInterfaceMock()
24 {
25 g_connectionBrInterface = reinterpret_cast<void *>(this);
26 }
27
~ConnectionBrInterfaceMock()28 ConnectionBrInterfaceMock::~ConnectionBrInterfaceMock()
29 {
30 g_connectionBrInterface = nullptr;
31 }
32
GetConnectionBrInterface()33 static ConnectionBrInterface *GetConnectionBrInterface()
34 {
35 return reinterpret_cast<ConnectionBrInterface *>(g_connectionBrInterface);
36 }
37
ActionOfSoftbusGetConfig1(ConfigType type,unsigned char * val,uint32_t len)38 int32_t ConnectionBrInterfaceMock::ActionOfSoftbusGetConfig1(ConfigType type, unsigned char *val, uint32_t len)
39 {
40 unsigned char val1[4] = {'B', 'a'};
41 if (memcpy_s((void *)val, sizeof(int32_t), val1, sizeof(val1)) != EOK) {
42 return SOFTBUS_MEM_ERR;
43 }
44 return SOFTBUS_OK;
45 }
46
ActionOfSoftbusGetConfig2(ConfigType type,unsigned char * val,uint32_t len)47 int32_t ConnectionBrInterfaceMock::ActionOfSoftbusGetConfig2(ConfigType type, unsigned char *val, uint32_t len)
48 {
49 unsigned char val1[4] = {1, 0, 0, 0};
50 if (memcpy_s((void *)val, sizeof(int32_t), val1, sizeof(val1)) != EOK) {
51 return SOFTBUS_MEM_ERR;
52 }
53 return SOFTBUS_OK;
54 }
55
56 extern "C" {
SoftBusGetBtMacAddr(SoftBusBtAddr * mac)57 int SoftBusGetBtMacAddr(SoftBusBtAddr *mac)
58 {
59 return GetConnectionBrInterface()->SoftBusGetBtMacAddr(mac);
60 }
61
LnnDCReportConnectException(const ConnectOption * option,int32_t errorCode)62 void LnnDCReportConnectException(const ConnectOption *option, int32_t errorCode)
63 {
64 return GetConnectionBrInterface()->LnnDCReportConnectException(option, errorCode);
65 }
66
SoftbusGetConfig(ConfigType type,unsigned char * val,uint32_t len)67 int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len)
68 {
69 return GetConnectionBrInterface()->SoftbusGetConfig(type, val, len);
70 }
71
InitSppSocketDriver()72 SppSocketDriver *InitSppSocketDriver()
73 {
74 return GetConnectionBrInterface()->InitSppSocketDriver();
75 }
76
SoftBusAddBtStateListener(const SoftBusBtStateListener * listener)77 int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener)
78 {
79 return GetConnectionBrInterface()->SoftBusAddBtStateListener(listener);
80 }
81
ConnGetHeadSize(void)82 uint32_t ConnGetHeadSize(void)
83 {
84 return GetConnectionBrInterface()->ConnGetHeadSize();
85 }
86
ConnBrOnAckRequest(ConnBrConnection * connection,const cJSON * json)87 int32_t ConnBrOnAckRequest(ConnBrConnection *connection, const cJSON *json)
88 {
89 return GetConnectionBrInterface()->ConnBrOnAckRequest(connection, json);
90 }
91
ConnBrOnAckResponse(ConnBrConnection * connection,const cJSON * json)92 int32_t ConnBrOnAckResponse(ConnBrConnection *connection, const cJSON *json)
93 {
94 return GetConnectionBrInterface()->ConnBrOnAckResponse(connection, json);
95 }
96
ConnBleGetConnectionByAddr(const char * addr,ConnSideType side,BleProtocolType protocol)97 ConnBleConnection *ConnBleGetConnectionByAddr(const char *addr, ConnSideType side, BleProtocolType protocol)
98 {
99 return GetConnectionBrInterface()->ConnBleGetConnectionByAddr(addr, side, protocol);
100 }
101
ConnBleReturnConnection(ConnBleConnection ** connection)102 void ConnBleReturnConnection(ConnBleConnection **connection)
103 {
104 return GetConnectionBrInterface()->ConnBleReturnConnection(connection);
105 }
106
LnnDCClearConnectException(const ConnectOption * option)107 void LnnDCClearConnectException(const ConnectOption *option)
108 {
109 return GetConnectionBrInterface()->LnnDCClearConnectException(option);
110 }
111
ConnBrEnqueueNonBlock(const void * msg)112 int32_t ConnBrEnqueueNonBlock(const void *msg)
113 {
114 return GetConnectionBrInterface()->ConnBrEnqueueNonBlock(msg);
115 }
116
ConnBrDequeueBlock(void ** msg)117 int32_t ConnBrDequeueBlock(void **msg)
118 {
119 return GetConnectionBrInterface()->ConnBrDequeueBlock(msg);
120 }
121
ConnBrCreateBrPendingPacket(uint32_t id,int64_t seq)122 int32_t ConnBrCreateBrPendingPacket(uint32_t id, int64_t seq)
123 {
124 return GetConnectionBrInterface()->ConnBrCreateBrPendingPacket(id, seq);
125 }
126
ConnBrDelBrPendingPacket(uint32_t id,int64_t seq)127 void ConnBrDelBrPendingPacket(uint32_t id, int64_t seq)
128 {
129 return GetConnectionBrInterface()->ConnBrDelBrPendingPacket(id, seq);
130 }
131
ConnBrGetBrPendingPacket(uint32_t id,int64_t seq,uint32_t waitMillis,void ** data)132 int32_t ConnBrGetBrPendingPacket(uint32_t id, int64_t seq, uint32_t waitMillis, void **data)
133 {
134 return GetConnectionBrInterface()->ConnBrGetBrPendingPacket(id, seq, waitMillis, data);
135 }
136
ConnBrInnerQueueInit(void)137 int32_t ConnBrInnerQueueInit(void)
138 {
139 return GetConnectionBrInterface()->ConnBrInnerQueueInit();
140 }
141
ConnBrInnerQueueDeinit(void)142 void ConnBrInnerQueueDeinit(void)
143 {
144 return GetConnectionBrInterface()->ConnBrInnerQueueDeinit();
145 }
146
ConnBrInitBrPendingPacket(void)147 int32_t ConnBrInitBrPendingPacket(void)
148 {
149 return GetConnectionBrInterface()->ConnBrInitBrPendingPacket();
150 }
151
ConnGetNewRequestId(ConnModule moduleId)152 uint32_t ConnGetNewRequestId(ConnModule moduleId)
153 {
154 return GetConnectionBrInterface()->ConnGetNewRequestId(moduleId);
155 }
156
ConnBleKeepAlive(uint32_t connectionId,uint32_t requestId,uint32_t time)157 int32_t ConnBleKeepAlive(uint32_t connectionId, uint32_t requestId, uint32_t time)
158 {
159 return GetConnectionBrInterface()->ConnBleKeepAlive(connectionId, requestId, time);
160 }
161
ConnBleRemoveKeepAlive(uint32_t connectionId,uint32_t requestId)162 int32_t ConnBleRemoveKeepAlive(uint32_t connectionId, uint32_t requestId)
163 {
164 return GetConnectionBrInterface()->ConnBleRemoveKeepAlive(connectionId, requestId);
165 }
166
SoftBusThreadCreate(SoftBusThread * thread,SoftBusThreadAttr * threadAttr,void * (* threadEntry)(void *),void * arg)167 int32_t SoftBusThreadCreate(
168 SoftBusThread *thread, SoftBusThreadAttr *threadAttr, void *(*threadEntry) (void *), void *arg)
169 {
170 return GetConnectionBrInterface()->SoftBusThreadCreate(thread, threadAttr, threadEntry, arg);
171 }
172 }
173 }
174