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/callback.h> 20 #include <gmock/gmock.h> 21 22 #include "bta_gatt_api.h" 23 24 namespace gatt { 25 26 class BtaGattInterface { 27 public: 28 virtual void AppRegister(tBTA_GATTC_CBACK* p_client_cb, 29 BtaAppRegisterCallback cb, bool eatt_support) = 0; 30 virtual void AppDeregister(tGATT_IF client_if) = 0; 31 virtual void Open(tGATT_IF client_if, const RawAddress& remote_bda, 32 bool is_direct, tBT_TRANSPORT transport, 33 bool opportunistic) = 0; 34 virtual void Open(tGATT_IF client_if, const RawAddress& remote_bda, 35 bool is_direct, bool opportunistic) = 0; 36 virtual void CancelOpen(tGATT_IF client_if, const RawAddress& remote_bda, 37 bool is_direct) = 0; 38 virtual void Close(uint16_t conn_id) = 0; 39 virtual void ServiceSearchRequest(uint16_t conn_id, 40 const bluetooth::Uuid* p_srvc_uuid) = 0; 41 virtual const std::list<Service>* GetServices(uint16_t conn_id) = 0; 42 virtual const Characteristic* GetCharacteristic(uint16_t conn_id, 43 uint16_t handle) = 0; 44 virtual const Service* GetOwningService(uint16_t conn_id, 45 uint16_t handle) = 0; 46 virtual tGATT_STATUS RegisterForNotifications(tGATT_IF client_if, 47 const RawAddress& remote_bda, 48 uint16_t handle) = 0; 49 virtual tGATT_STATUS DeregisterForNotifications(tGATT_IF client_if, 50 const RawAddress& remote_bda, 51 uint16_t handle) = 0; 52 virtual ~BtaGattInterface() = default; 53 }; 54 55 class MockBtaGattInterface : public BtaGattInterface { 56 public: 57 MOCK_METHOD((void), AppRegister, 58 (tBTA_GATTC_CBACK * p_client_cb, BtaAppRegisterCallback cb, 59 bool eatt_support), 60 (override)); 61 MOCK_METHOD((void), AppDeregister, (tGATT_IF client_if), (override)); 62 MOCK_METHOD((void), Open, 63 (tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct, 64 tBT_TRANSPORT transport, bool opportunistic)); 65 MOCK_METHOD((void), Open, 66 (tGATT_IF client_if, const RawAddress& remote_bda, bool is_direct, 67 bool opportunistic)); 68 MOCK_METHOD((void), CancelOpen, 69 (tGATT_IF client_if, const RawAddress& remote_bda, 70 bool is_direct)); 71 MOCK_METHOD((void), Close, (uint16_t conn_id)); 72 MOCK_METHOD((void), ServiceSearchRequest, 73 (uint16_t conn_id, const bluetooth::Uuid* p_srvc_uuid)); 74 MOCK_METHOD((std::list<Service>*), GetServices, (uint16_t conn_id)); 75 MOCK_METHOD((const Characteristic*), GetCharacteristic, 76 (uint16_t conn_id, uint16_t handle)); 77 MOCK_METHOD((const Service*), GetOwningService, 78 (uint16_t conn_id, uint16_t handle)); 79 MOCK_METHOD((tGATT_STATUS), RegisterForNotifications, 80 (tGATT_IF client_if, const RawAddress& remote_bda, 81 uint16_t handle)); 82 MOCK_METHOD((tGATT_STATUS), DeregisterForNotifications, 83 (tGATT_IF client_if, const RawAddress& remote_bda, 84 uint16_t handle)); 85 }; 86 87 /** 88 * Set the {@link MockBtaGattInterface} for testing 89 * 90 * @param mock_bta_gatt_interface pointer to mock bta gatt interface, 91 * could be null 92 */ 93 void SetMockBtaGattInterface(MockBtaGattInterface* mock_bta_gatt_interface); 94 95 } // namespace gatt 96