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_trans_mock.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 void *g_connectionBleTransInterface;
ConnectionBleTransInterfaceMock()23 ConnectionBleTransInterfaceMock::ConnectionBleTransInterfaceMock()
24 {
25     g_connectionBleTransInterface = reinterpret_cast<void *>(this);
26 }
27 
~ConnectionBleTransInterfaceMock()28 ConnectionBleTransInterfaceMock::~ConnectionBleTransInterfaceMock()
29 {
30     g_connectionBleTransInterface = nullptr;
31 }
32 
GetConnectionBleTransInterface()33 static ConnectionBleTransInterface *GetConnectionBleTransInterface()
34 {
35     return reinterpret_cast<ConnectionBleTransInterface *>(g_connectionBleTransInterface);
36 }
37 
38 extern "C"
39 {
ConnBleGetConnectionById(uint32_t connectionId)40 ConnBleConnection *ConnBleGetConnectionById(uint32_t connectionId)
41 {
42     return GetConnectionBleTransInterface()->ConnBleGetConnectionById(connectionId);
43 }
44 
ConnBleSend(ConnBleConnection * connection,const uint8_t * data,uint32_t dataLen,int32_t module)45 int32_t ConnBleSend(ConnBleConnection *connection, const uint8_t *data, uint32_t dataLen, int32_t module)
46 {
47     return GetConnectionBleTransInterface()->ConnBleSend(connection, data, dataLen, module);
48 }
49 
AddNumberToJsonObject(cJSON * json,const char * const string,int32_t num)50 bool AddNumberToJsonObject(cJSON *json, const char *const string, int32_t num)
51 {
52     return GetConnectionBleTransInterface()->AddNumberToJsonObject(json, string, num);
53 }
54 
cJSON_CreateObject()55 cJSON *cJSON_CreateObject()
56 {
57     return GetConnectionBleTransInterface()->cJSON_CreateObject();
58 }
59 
AddNumber16ToJsonObject(cJSON * json,const char * const string,uint16_t num)60 bool AddNumber16ToJsonObject(cJSON *json, const char *const string, uint16_t num)
61 {
62     return GetConnectionBleTransInterface()->AddNumber16ToJsonObject(json, string, num);
63 }
64 
cJSON_PrintUnformatted(const cJSON * json)65 char *cJSON_PrintUnformatted(const cJSON *json)
66 {
67     return GetConnectionBleTransInterface()->cJSON_PrintUnformatted(json);
68 }
69 }
70 }
71