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 "softbus_conn_br_connection.h" 20 #include "softbus_conn_br_manager.h" 21 #include "softbus_conn_br_trans.h" 22 23 #include <gmock/gmock.h> 24 #include "cJSON.h" 25 26 #include "softbus_adapter_bt_common.h" 27 #include "softbus_adapter_thread.h" 28 #include "softbus_config_type.h" 29 #include "softbus_def.h" 30 31 #include "softbus_conn_ble_connection.h" 32 #include "softbus_conn_common.h" 33 34 namespace OHOS { 35 class ConnectionBrInterface { 36 public: ConnectionBrInterface()37 ConnectionBrInterface() {}; ~ConnectionBrInterface()38 virtual ~ConnectionBrInterface() {}; 39 virtual int SoftBusGetBtMacAddr(SoftBusBtAddr *mac) = 0; 40 virtual void LnnDCReportConnectException(const ConnectOption *option, int32_t errorCode) = 0; 41 virtual int32_t SoftBusThreadCreate( 42 SoftBusThread *thread, SoftBusThreadAttr *threadAttr, void *(*threadEntry) (void *), void *arg) = 0; 43 virtual int SoftbusGetConfig(ConfigType type, unsigned char *val, uint32_t len) = 0; 44 virtual SppSocketDriver *InitSppSocketDriver() = 0; 45 virtual int SoftBusAddBtStateListener(const SoftBusBtStateListener *listener) = 0; 46 virtual uint32_t ConnGetHeadSize(void) = 0; 47 virtual int32_t ConnBrOnAckRequest(ConnBrConnection *connection, const cJSON *json) = 0; 48 virtual int32_t ConnBrOnAckResponse(ConnBrConnection *connection, const cJSON *json) = 0; 49 virtual ConnBleConnection *ConnBleGetConnectionByAddr( 50 const char *addr, ConnSideType side, BleProtocolType protocol) = 0; 51 virtual void ConnBleReturnConnection(ConnBleConnection **connection) = 0; 52 virtual void LnnDCClearConnectException(const ConnectOption *option) = 0; 53 virtual int32_t ConnBrEnqueueNonBlock(const void *msg) = 0; 54 virtual int32_t ConnBrDequeueBlock(void **msg) = 0; 55 virtual int32_t ConnBrCreateBrPendingPacket(uint32_t id, int64_t seq) = 0; 56 virtual void ConnBrDelBrPendingPacket(uint32_t id, int64_t seq) = 0; 57 virtual int32_t ConnBrGetBrPendingPacket(uint32_t id, int64_t seq, uint32_t waitMillis, void **data) = 0; 58 virtual int32_t ConnBrInnerQueueInit(void) = 0; 59 virtual void ConnBrInnerQueueDeinit(void) = 0; 60 virtual int32_t ConnBrInitBrPendingPacket(void) = 0; 61 virtual uint32_t ConnGetNewRequestId(ConnModule moduleId) = 0; 62 virtual int32_t ConnBleKeepAlive(uint32_t connectionId, uint32_t requestId, uint32_t time) = 0; 63 virtual int32_t ConnBleRemoveKeepAlive(uint32_t connectionId, uint32_t requestId) = 0; 64 }; 65 66 class ConnectionBrInterfaceMock : public ConnectionBrInterface { 67 public: 68 ConnectionBrInterfaceMock(); 69 ~ConnectionBrInterfaceMock() override; 70 MOCK_METHOD1(SoftBusGetBtMacAddr, int (SoftBusBtAddr *)); 71 MOCK_METHOD2(LnnDCReportConnectException, void(const ConnectOption*, int32_t)); 72 MOCK_METHOD4(SoftBusThreadCreate, int32_t(SoftBusThread *, SoftBusThreadAttr *, void *(void *), void *)); 73 MOCK_METHOD3(SoftbusGetConfig, int(ConfigType, unsigned char *, uint32_t)); 74 MOCK_METHOD0(InitSppSocketDriver, SppSocketDriver*()); 75 MOCK_METHOD1(SoftBusAddBtStateListener, int(const SoftBusBtStateListener *)); 76 MOCK_METHOD0(ConnGetHeadSize, uint32_t()); 77 MOCK_METHOD2(ConnBrOnAckRequest, int32_t(ConnBrConnection *, const cJSON *)); 78 MOCK_METHOD2(ConnBrOnAckResponse, int32_t(ConnBrConnection *, const cJSON *)); 79 MOCK_METHOD3(ConnBleGetConnectionByAddr, ConnBleConnection *(const char *, ConnSideType, BleProtocolType)); 80 MOCK_METHOD1(ConnBleReturnConnection, void(ConnBleConnection **)); 81 MOCK_METHOD1(LnnDCClearConnectException, void(const ConnectOption *)); 82 MOCK_METHOD1(ConnBrEnqueueNonBlock, int32_t(const void *)); 83 MOCK_METHOD1(ConnBrDequeueBlock, int32_t(void **)); 84 MOCK_METHOD2(ConnBrCreateBrPendingPacket, int32_t(uint32_t, int64_t)); 85 MOCK_METHOD2(ConnBrDelBrPendingPacket, void(uint32_t, int64_t)); 86 MOCK_METHOD4(ConnBrGetBrPendingPacket, int32_t(uint32_t, int64_t, uint32_t, void **)); 87 MOCK_METHOD0(ConnBrInnerQueueInit, int32_t()); 88 MOCK_METHOD0(ConnBrInnerQueueDeinit, void()); 89 MOCK_METHOD0(ConnBrInitBrPendingPacket, int32_t()); 90 MOCK_METHOD1(ConnGetNewRequestId, uint32_t(ConnModule)); 91 MOCK_METHOD3(ConnBleKeepAlive, int32_t(uint32_t, uint32_t, uint32_t)); 92 MOCK_METHOD2(ConnBleRemoveKeepAlive, int32_t(uint32_t, uint32_t)); 93 94 static int32_t ActionOfSoftbusGetConfig1(ConfigType type, unsigned char *val, uint32_t len); 95 static int32_t ActionOfSoftbusGetConfig2(ConfigType type, unsigned char *val, uint32_t len); 96 }; 97 } // namespace OHOS 98 #endif // CONNECTION_BR_MOCK_H 99