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 #ifndef CONNECTION_BR_MOCK_H 17 #define CONNECTION_BR_MOCK_H 18 19 #include <gmock/gmock.h> 20 #include <mutex> 21 #include "cJSON.h" 22 23 #include "conn_log.h" 24 #include "disc_interface.h" 25 #include "message_handler.h" 26 #include "softbus_adapter_bt_common.h" 27 #include "softbus_common.h" 28 #include "softbus_config_type.h" 29 #include "softbus_conn_ble_connection.h" 30 #include "ohos_bt_def.h" 31 #include "ohos_bt_gatt_client.h" 32 33 34 namespace OHOS { 35 class ConnectionBleInterface { 36 public: ConnectionBleInterface()37 ConnectionBleInterface() {}; ~ConnectionBleInterface()38 virtual ~ConnectionBleInterface() {}; 39 virtual bool AddNumberToJsonObject(cJSON *json, const char * const string, int32_t num) = 0; 40 virtual int32_t ConvertBtMacToBinary(const char *strMac, uint32_t strMacLen, uint8_t *binMac, 41 uint32_t binMacLen) = 0; 42 virtual int32_t SoftbusGattcConnect(int32_t clientId, SoftBusBtAddr *addr) = 0; 43 virtual int32_t BleGattcDisconnect(int32_t clientId) = 0; 44 virtual int32_t SoftBusGattsAddService(SoftBusBtUuid srvcUuid, bool isPrimary, int32_t number) = 0; 45 virtual int32_t SoftBusGattsStopService(int32_t srvcHandle) = 0; 46 virtual int32_t SoftBusGattsDisconnect(SoftBusBtAddr btAddr, int32_t connId) = 0; 47 virtual int32_t SoftbusGattcRefreshServices(int32_t clientId) = 0; 48 virtual int32_t SoftbusGattcSearchServices(int32_t clientId) = 0; 49 virtual bool GetJsonObjectSignedNumberItem(const cJSON *json, const char * const string, int *target) = 0; 50 virtual int BleGattsAddService(int serverId, BtUuid srvcUuid, bool isPrimary, int number) = 0; 51 virtual int BleGattcUnRegister(int clientId) = 0; 52 virtual int BleGattcSetPriority(int clientId, const BdAddr *bdAddr, BtGattPriority priority) = 0; 53 virtual int32_t BleHiDumperRegister(void) = 0; 54 }; 55 56 class ConnectionBleInterfaceMock : public ConnectionBleInterface { 57 public: 58 ConnectionBleInterfaceMock(); 59 ~ConnectionBleInterfaceMock() override; 60 MOCK_METHOD3(AddNumberToJsonObject, bool (cJSON *, const char * const, int)); 61 MOCK_METHOD4(ConvertBtMacToBinary, int32_t (const char *, uint32_t, uint8_t *, uint32_t)); 62 MOCK_METHOD2(SoftbusGattcConnect, int32_t (int32_t, SoftBusBtAddr *)); 63 MOCK_METHOD1(BleGattcDisconnect, int32_t (int)); 64 MOCK_METHOD3(SoftBusGattsAddService, int32_t (SoftBusBtUuid, bool, int)); 65 MOCK_METHOD1(SoftBusGattsStopService, int32_t (int)); 66 MOCK_METHOD2(SoftBusGattsDisconnect, int32_t (SoftBusBtAddr, int)); 67 MOCK_METHOD1(SoftbusGattcRefreshServices, int32_t (int32_t)); 68 MOCK_METHOD1(SoftbusGattcSearchServices, int32_t (int32_t)); 69 MOCK_METHOD3(GetJsonObjectSignedNumberItem, bool (const cJSON *, const char * const, int32_t *)); 70 MOCK_METHOD(int, BleGattsAddService, (int, BtUuid, bool, int), (override)); 71 MOCK_METHOD(int, BleGattcUnRegister, (int), (override)); 72 MOCK_METHOD(int, BleGattcSetPriority, (int, const BdAddr *, BtGattPriority), (override)); 73 MOCK_METHOD(int32_t, BleHiDumperRegister, (), (override)); 74 }; 75 } // namespace OHOS 76 #endif // CONNECTION_BLE_MOCK_H