Loading system/gd/hci/acl_manager/le_connection_callbacks_mock.h 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <gmock/gmock.h> #include <memory> #include "hci/acl_manager/le_acl_connection.h" #include "hci/address_with_type.h" #include "hci/hci_packets.h" namespace bluetooth { namespace hci { namespace acl_manager { class MockLeConnectionCallbacks : public LeConnectionCallbacks { public: MOCK_METHOD( void, OnLeConnectSuccess, (AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection), (override)); MOCK_METHOD( void, OnLeConnectFail, (AddressWithType address_with_type, ErrorCode reason, bool locally_initiated), (override)); }; } // namespace acl_manager } // namespace hci } // namespace bluetooth system/gd/hci/acl_manager/le_connection_management_callbacks_mock.h 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <gmock/gmock.h> #include <cstdint> #include "hci/acl_manager/le_connection_management_callbacks.h" #include "hci/address_with_type.h" #include "hci/hci_packets.h" namespace bluetooth { namespace hci { namespace acl_manager { class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbacks { public: MOCK_METHOD( void, OnConnectionUpdate, (hci::ErrorCode hci_status, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout), (override)); MOCK_METHOD( void, OnDataLengthChange, (uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time), (override)); MOCK_METHOD(void, OnDisconnection, (ErrorCode reason), (override)); MOCK_METHOD( void, OnReadRemoteVersionInformationComplete, (hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version), (override)); MOCK_METHOD( void, OnLeReadRemoteFeaturesComplete, (hci::ErrorCode hci_status, uint64_t features), (override)); MOCK_METHOD( void, OnPhyUpdate, (hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy), (override)); MOCK_METHOD( void, OnLeSubrateChange, (hci::ErrorCode hci_status, uint16_t subrate_factor, uint16_t peripheral_latency, uint16_t continuation_number, uint16_t supervision_timeout), (override)); }; } // namespace acl_manager } // namespace hci } // namespace bluetooth system/gd/hci/acl_manager_test.cc +47 −53 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <map> #include "common/bind.h" #include "hci/acl_manager/le_connection_callbacks_mock.h" #include "hci/acl_manager/le_connection_management_callbacks_mock.h" #include "hci/address.h" #include "hci/class_of_device.h" #include "hci/controller.h" Loading @@ -33,6 +35,8 @@ #include "os/thread.h" #include "packet/raw_builder.h" using testing::_; namespace bluetooth { namespace hci { namespace acl_manager { Loading Loading @@ -134,7 +138,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { // are cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); fake_registry_.StopAll(); } Loading @@ -160,10 +164,9 @@ class AclManagerNoCallbacksTest : public ::testing::Test { } std::future<void> GetLeConnectionFuture() { ASSERT_LOG(mock_le_connection_callbacks_.le_connection_promise_ == nullptr, "Promises promises ... Only one at a time"); mock_le_connection_callbacks_.le_connection_promise_ = std::make_unique<std::promise<void>>(); return mock_le_connection_callbacks_.le_connection_promise_->get_future(); ASSERT_LOG(le_connection_promise_ == nullptr, "Promises promises ... Only one at a time"); le_connection_promise_ = std::make_unique<std::promise<void>>(); return le_connection_promise_->get_future(); } std::shared_ptr<ClassicAclConnection> GetLastConnection() { Loading @@ -171,7 +174,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { } std::shared_ptr<LeAclConnection> GetLastLeConnection() { return mock_le_connection_callbacks_.le_connections_.back(); return le_connections_.back(); } void SendAclData(uint16_t handle, AclConnection::QueueUpEnd* queue_end) { Loading Loading @@ -222,25 +225,9 @@ class AclManagerNoCallbacksTest : public ::testing::Test { std::unique_ptr<std::promise<void>> connection_promise_; } mock_connection_callback_; class MockLeConnectionCallbacks : public LeConnectionCallbacks { public: void OnLeConnectSuccess(AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) override { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } } void Clear() { le_connections_.clear(); } MOCK_METHOD(void, OnLeConnectFail, (AddressWithType, ErrorCode reason, bool locally_initiated), (override)); std::list<std::shared_ptr<LeAclConnection>> le_connections_; std::unique_ptr<std::promise<void>> le_connection_promise_; } mock_le_connection_callbacks_; MockLeConnectionCallbacks mock_le_connection_callbacks_; }; class AclManagerTest : public AclManagerNoCallbacksTest { Loading Loading @@ -284,7 +271,7 @@ class AclManagerWithConnectionTest : public AclManagerTest { // is cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); connection_.reset(); fake_registry_.SynchronizeModuleHandler(&HciLayer::Factory, std::chrono::milliseconds(20)); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); Loading Loading @@ -407,6 +394,16 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type_, _)) .WillRepeatedly([this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, Loading @@ -433,7 +430,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { // is cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); connection_.reset(); fake_registry_.SynchronizeModuleHandler(&HciLayer::Factory, std::chrono::milliseconds(20)); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); Loading @@ -443,32 +440,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { uint16_t handle_ = 0x123; std::shared_ptr<LeAclConnection> connection_; AddressWithType remote_with_type_; class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbacks { public: MOCK_METHOD1(OnDisconnection, void(ErrorCode reason)); MOCK_METHOD4( OnConnectionUpdate, void( hci::ErrorCode hci_status, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout)); MOCK_METHOD4(OnDataLengthChange, void(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time)); MOCK_METHOD4( OnReadRemoteVersionInformationComplete, void(hci::ErrorCode hci_status, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)); MOCK_METHOD2(OnLeReadRemoteFeaturesComplete, void(hci::ErrorCode hci_status, uint64_t features)); MOCK_METHOD3(OnPhyUpdate, void(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy)); MOCK_METHOD5( OnLeSubrateChange, void( hci::ErrorCode hci_status, uint16_t subrate_factor, uint16_t peripheral_latency, uint16_t continuation_number, uint16_t supervision_timeout)); } mock_le_connection_management_callbacks_; MockLeConnectionManagementCallbacks mock_le_connection_management_callbacks_; }; // TODO: implement version of this test where controller supports Extended Advertising Feature in Loading Loading @@ -571,6 +543,17 @@ TEST_F(AclManagerTest, create_connection_with_fast_mode) { test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type, _)) .WillRepeatedly( [this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, 0x00, Loading Loading @@ -601,6 +584,17 @@ TEST_F(AclManagerTest, create_connection_with_slow_mode) { ASSERT_EQ(command_view.GetLeScanWindow(), kScanWindowSlow); test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type, _)) .WillRepeatedly( [this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, 0x00, Loading Loading
system/gd/hci/acl_manager/le_connection_callbacks_mock.h 0 → 100644 +47 −0 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <gmock/gmock.h> #include <memory> #include "hci/acl_manager/le_acl_connection.h" #include "hci/address_with_type.h" #include "hci/hci_packets.h" namespace bluetooth { namespace hci { namespace acl_manager { class MockLeConnectionCallbacks : public LeConnectionCallbacks { public: MOCK_METHOD( void, OnLeConnectSuccess, (AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection), (override)); MOCK_METHOD( void, OnLeConnectFail, (AddressWithType address_with_type, ErrorCode reason, bool locally_initiated), (override)); }; } // namespace acl_manager } // namespace hci } // namespace bluetooth
system/gd/hci/acl_manager/le_connection_management_callbacks_mock.h 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include <gmock/gmock.h> #include <cstdint> #include "hci/acl_manager/le_connection_management_callbacks.h" #include "hci/address_with_type.h" #include "hci/hci_packets.h" namespace bluetooth { namespace hci { namespace acl_manager { class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbacks { public: MOCK_METHOD( void, OnConnectionUpdate, (hci::ErrorCode hci_status, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout), (override)); MOCK_METHOD( void, OnDataLengthChange, (uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time), (override)); MOCK_METHOD(void, OnDisconnection, (ErrorCode reason), (override)); MOCK_METHOD( void, OnReadRemoteVersionInformationComplete, (hci::ErrorCode hci_status, uint8_t lmp_version, uint16_t manufacturer_name, uint16_t sub_version), (override)); MOCK_METHOD( void, OnLeReadRemoteFeaturesComplete, (hci::ErrorCode hci_status, uint64_t features), (override)); MOCK_METHOD( void, OnPhyUpdate, (hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy), (override)); MOCK_METHOD( void, OnLeSubrateChange, (hci::ErrorCode hci_status, uint16_t subrate_factor, uint16_t peripheral_latency, uint16_t continuation_number, uint16_t supervision_timeout), (override)); }; } // namespace acl_manager } // namespace hci } // namespace bluetooth
system/gd/hci/acl_manager_test.cc +47 −53 Original line number Diff line number Diff line Loading @@ -25,6 +25,8 @@ #include <map> #include "common/bind.h" #include "hci/acl_manager/le_connection_callbacks_mock.h" #include "hci/acl_manager/le_connection_management_callbacks_mock.h" #include "hci/address.h" #include "hci/class_of_device.h" #include "hci/controller.h" Loading @@ -33,6 +35,8 @@ #include "os/thread.h" #include "packet/raw_builder.h" using testing::_; namespace bluetooth { namespace hci { namespace acl_manager { Loading Loading @@ -134,7 +138,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { // are cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); fake_registry_.StopAll(); } Loading @@ -160,10 +164,9 @@ class AclManagerNoCallbacksTest : public ::testing::Test { } std::future<void> GetLeConnectionFuture() { ASSERT_LOG(mock_le_connection_callbacks_.le_connection_promise_ == nullptr, "Promises promises ... Only one at a time"); mock_le_connection_callbacks_.le_connection_promise_ = std::make_unique<std::promise<void>>(); return mock_le_connection_callbacks_.le_connection_promise_->get_future(); ASSERT_LOG(le_connection_promise_ == nullptr, "Promises promises ... Only one at a time"); le_connection_promise_ = std::make_unique<std::promise<void>>(); return le_connection_promise_->get_future(); } std::shared_ptr<ClassicAclConnection> GetLastConnection() { Loading @@ -171,7 +174,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { } std::shared_ptr<LeAclConnection> GetLastLeConnection() { return mock_le_connection_callbacks_.le_connections_.back(); return le_connections_.back(); } void SendAclData(uint16_t handle, AclConnection::QueueUpEnd* queue_end) { Loading Loading @@ -222,25 +225,9 @@ class AclManagerNoCallbacksTest : public ::testing::Test { std::unique_ptr<std::promise<void>> connection_promise_; } mock_connection_callback_; class MockLeConnectionCallbacks : public LeConnectionCallbacks { public: void OnLeConnectSuccess(AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) override { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } } void Clear() { le_connections_.clear(); } MOCK_METHOD(void, OnLeConnectFail, (AddressWithType, ErrorCode reason, bool locally_initiated), (override)); std::list<std::shared_ptr<LeAclConnection>> le_connections_; std::unique_ptr<std::promise<void>> le_connection_promise_; } mock_le_connection_callbacks_; MockLeConnectionCallbacks mock_le_connection_callbacks_; }; class AclManagerTest : public AclManagerNoCallbacksTest { Loading Loading @@ -284,7 +271,7 @@ class AclManagerWithConnectionTest : public AclManagerTest { // is cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); connection_.reset(); fake_registry_.SynchronizeModuleHandler(&HciLayer::Factory, std::chrono::milliseconds(20)); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); Loading Loading @@ -407,6 +394,16 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type_, _)) .WillRepeatedly([this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, Loading @@ -433,7 +430,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { // is cleared after the AclConnectionInterface is deleted // through fake_registry_. mock_connection_callback_.Clear(); mock_le_connection_callbacks_.Clear(); le_connections_.clear(); connection_.reset(); fake_registry_.SynchronizeModuleHandler(&HciLayer::Factory, std::chrono::milliseconds(20)); fake_registry_.SynchronizeModuleHandler(&AclManager::Factory, std::chrono::milliseconds(20)); Loading @@ -443,32 +440,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { uint16_t handle_ = 0x123; std::shared_ptr<LeAclConnection> connection_; AddressWithType remote_with_type_; class MockLeConnectionManagementCallbacks : public LeConnectionManagementCallbacks { public: MOCK_METHOD1(OnDisconnection, void(ErrorCode reason)); MOCK_METHOD4( OnConnectionUpdate, void( hci::ErrorCode hci_status, uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout)); MOCK_METHOD4(OnDataLengthChange, void(uint16_t tx_octets, uint16_t tx_time, uint16_t rx_octets, uint16_t rx_time)); MOCK_METHOD4( OnReadRemoteVersionInformationComplete, void(hci::ErrorCode hci_status, uint8_t version, uint16_t manufacturer_name, uint16_t sub_version)); MOCK_METHOD2(OnLeReadRemoteFeaturesComplete, void(hci::ErrorCode hci_status, uint64_t features)); MOCK_METHOD3(OnPhyUpdate, void(hci::ErrorCode hci_status, uint8_t tx_phy, uint8_t rx_phy)); MOCK_METHOD5( OnLeSubrateChange, void( hci::ErrorCode hci_status, uint16_t subrate_factor, uint16_t peripheral_latency, uint16_t continuation_number, uint16_t supervision_timeout)); } mock_le_connection_management_callbacks_; MockLeConnectionManagementCallbacks mock_le_connection_management_callbacks_; }; // TODO: implement version of this test where controller supports Extended Advertising Feature in Loading Loading @@ -571,6 +543,17 @@ TEST_F(AclManagerTest, create_connection_with_fast_mode) { test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type, _)) .WillRepeatedly( [this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, 0x00, Loading Loading @@ -601,6 +584,17 @@ TEST_F(AclManagerTest, create_connection_with_slow_mode) { ASSERT_EQ(command_view.GetLeScanWindow(), kScanWindowSlow); test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01)); auto first_connection = GetLeConnectionFuture(); EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(remote_with_type, _)) .WillRepeatedly( [this]( hci::AddressWithType address_with_type, std::unique_ptr<LeAclConnection> connection) { le_connections_.push_back(std::move(connection)); if (le_connection_promise_ != nullptr) { le_connection_promise_->set_value(); le_connection_promise_.reset(); } }); test_hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create( ErrorCode::SUCCESS, 0x00, Loading