1 /* 2 * Copyright 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include "hci/acl_manager.h" 19 #include "hci/acl_manager/classic_acl_connection.h" 20 #include "hci/acl_manager/connection_callbacks.h" 21 #include "hci/acl_manager/connection_management_callbacks.h" 22 #include "hci/acl_manager/le_acl_connection.h" 23 #include "hci/acl_manager/le_connection_callbacks.h" 24 #include "hci/acl_manager/le_connection_management_callbacks.h" 25 26 #include <gmock/gmock.h> 27 28 // Unit test interfaces 29 namespace bluetooth { 30 namespace hci { 31 namespace testing { 32 33 using acl_manager::LeAclConnection; 34 using acl_manager::LeConnectionCallbacks; 35 using acl_manager::LeConnectionManagementCallbacks; 36 37 using acl_manager::ClassicAclConnection; 38 using acl_manager::ConnectionCallbacks; 39 using acl_manager::ConnectionManagementCallbacks; 40 41 class MockClassicAclConnection : public ClassicAclConnection { 42 public: 43 MOCK_METHOD(Address, GetAddress, (), (const, override)); 44 MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override)); 45 MOCK_METHOD(void, RegisterCallbacks, (ConnectionManagementCallbacks * callbacks, os::Handler* handler), (override)); 46 MOCK_METHOD(bool, ReadRemoteVersionInformation, (), (override)); 47 MOCK_METHOD(bool, ReadRemoteSupportedFeatures, (), (override)); 48 MOCK_METHOD(bool, ReadRemoteExtendedFeatures, (uint8_t), (override)); 49 GetAclQueueEnd()50 QueueUpEnd* GetAclQueueEnd() const override { 51 return acl_queue_.GetUpEnd(); 52 } 53 mutable common::BidiQueue<PacketView<kLittleEndian>, BasePacketBuilder> acl_queue_{10}; 54 }; 55 56 class MockLeAclConnection : public LeAclConnection { 57 public: 58 MOCK_METHOD(AddressWithType, GetLocalAddress, (), (const, override)); 59 MOCK_METHOD(AddressWithType, GetRemoteAddress, (), (const, override)); 60 MOCK_METHOD(void, Disconnect, (DisconnectReason reason), (override)); 61 MOCK_METHOD(void, RegisterCallbacks, (LeConnectionManagementCallbacks * callbacks, os::Handler* handler), (override)); 62 MOCK_METHOD(bool, ReadRemoteVersionInformation, (), (override)); 63 GetAclQueueEnd()64 QueueUpEnd* GetAclQueueEnd() const override { 65 return acl_queue_.GetUpEnd(); 66 } 67 mutable common::BidiQueue<PacketView<kLittleEndian>, BasePacketBuilder> acl_queue_{10}; 68 }; 69 70 class MockAclManager : public AclManager { 71 public: 72 MOCK_METHOD(void, RegisterCallbacks, (ConnectionCallbacks * callbacks, os::Handler* handler), (override)); 73 MOCK_METHOD(void, RegisterLeCallbacks, (LeConnectionCallbacks * callbacks, os::Handler* handler), (override)); 74 MOCK_METHOD(void, CreateConnection, (Address address), (override)); 75 MOCK_METHOD(void, CreateLeConnection, (AddressWithType address_with_type, bool is_direct), (override)); 76 MOCK_METHOD(void, CancelConnect, (Address address), (override)); 77 MOCK_METHOD( 78 void, 79 SetPrivacyPolicyForInitiatorAddress, 80 (LeAddressManager::AddressPolicy address_policy, 81 AddressWithType fixed_address, 82 std::chrono::milliseconds minimum_rotation_time, 83 std::chrono::milliseconds maximum_rotation_time), 84 (override)); 85 86 // PRIVATE TO SHIM 87 MOCK_METHOD(void, HACK_SetScoDisconnectCallback, (std::function<void(uint16_t /* handle */, uint8_t /* reason */)>)); 88 }; 89 90 } // namespace testing 91 } // namespace hci 92 } // namespace bluetooth 93