1 /* 2 * Copyright 2021 HIMSA II K/S - www.himsa.com. 3 * Represented by EHIMA - www.ehima.com 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 #pragma once 18 19 #include <base/functional/callback.h> 20 #include <gmock/gmock.h> 21 22 #include "bta_gatt_api.h" 23 #include "types/bluetooth/uuid.h" 24 #include "types/raw_address.h" 25 26 namespace gatt { 27 28 class BtaGattInterface { 29 public: 30 virtual void AppRegister(tBTA_GATTC_CBACK* p_client_cb, 31 BtaAppRegisterCallback cb, bool eatt_support) = 0; 32 virtual void AppDeregister(tGATT_IF client_if) = 0; 33 virtual void Open(tGATT_IF client_if, const RawAddress& remote_bda, 34 tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport, 35 bool opportunistic, uint8_t initiating_phys) = 0; 36 virtual void Open(tGATT_IF client_if, const RawAddress& remote_bda, 37 tBTM_BLE_CONN_TYPE connection_type, bool opportunistic) = 0; 38 virtual void CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda, 39 bool is_direct) = 0; 40 virtual void Close(uint16_t conn_id) = 0; 41 virtual void ServiceSearchRequest(uint16_t conn_id, 42 const bluetooth::Uuid* p_srvc_uuid) = 0; 43 virtual void SendIndConfirm(uint16_t conn_id, uint16_t cid) = 0; 44 virtual const std::list<Service>* GetServices(uint16_t conn_id) = 0; 45 virtual const Characteristic* GetCharacteristic(uint16_t conn_id, 46 uint16_t handle) = 0; 47 virtual const Service* GetOwningService(uint16_t conn_id, 48 uint16_t handle) = 0; 49 virtual tGATT_STATUS RegisterForNotifications(tGATT_IF client_if, 50 const RawAddress& remote_bda, 51 uint16_t handle) = 0; 52 virtual tGATT_STATUS DeregisterForNotifications(tGATT_IF client_if, 53 const RawAddress& remote_bda, 54 uint16_t handle) = 0; 55 virtual ~BtaGattInterface() = default; 56 }; 57 58 class MockBtaGattInterface : public BtaGattInterface { 59 public: 60 MOCK_METHOD((void), AppRegister, 61 (tBTA_GATTC_CBACK * p_client_cb, BtaAppRegisterCallback cb, 62 bool eatt_support), 63 (override)); 64 MOCK_METHOD((void), AppDeregister, (tGATT_IF client_if), (override)); 65 MOCK_METHOD((void), Open, 66 (tGATT_IF client_if, const RawAddress& remote_bda, 67 tBTM_BLE_CONN_TYPE connection_type, tBT_TRANSPORT transport, 68 bool opportunistic, uint8_t initiating_phys), 69 (override)); 70 MOCK_METHOD((void), Open, 71 (tGATT_IF client_if, const RawAddress& remote_bda, 72 tBTM_BLE_CONN_TYPE connection_type, bool opportunistic)); 73 MOCK_METHOD((void), CancelOpen, 74 (tGATT_IF client_if, const RawAddress& remote_bda, 75 bool is_direct)); 76 MOCK_METHOD((void), Close, (uint16_t conn_id)); 77 MOCK_METHOD((void), ServiceSearchRequest, 78 (uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid)); 79 MOCK_METHOD((void), SendIndConfirm, (uint16_t conn_id, uint16_t cid), 80 (override)); 81 MOCK_METHOD((std::list<Service>*), GetServices, (uint16_t conn_id)); 82 MOCK_METHOD((const Characteristic*), GetCharacteristic, 83 (uint16_t conn_id, uint16_t handle)); 84 MOCK_METHOD((const Service*), GetOwningService, 85 (uint16_t conn_id, uint16_t handle)); 86 MOCK_METHOD((tGATT_STATUS), RegisterForNotifications, 87 (tGATT_IF client_if, const RawAddress& remote_bda, 88 uint16_t handle)); 89 MOCK_METHOD((tGATT_STATUS), DeregisterForNotifications, 90 (tGATT_IF client_if, const RawAddress& remote_bda, 91 uint16_t handle)); 92 }; 93 94 /** 95 * Set the {@link MockBtaGattInterface} for testing 96 * 97 * @param mock_bta_gatt_interface pointer to mock bta gatt interface, 98 * could be null 99 */ 100 void SetMockBtaGattInterface(MockBtaGattInterface* mock_bta_gatt_interface); 101 102 } // namespace gatt 103