From f5ce3f6498b485ffde32d13db53db768844d08af Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Thu, 20 Feb 2020 19:58:43 -0800 Subject: [PATCH] gd: Clean up bluetooth_test_gd Bug: 146363362 Test: bluetooth_test_gd Change-Id: I0f3fb81d2b79b781918d18ea89a3ed64574a9610 --- gd/l2cap/le/internal/fixed_channel_impl_test.cc | 63 +++++++++++++++++++++---- gd/l2cap/le/internal/link_mock.h | 6 ++- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/gd/l2cap/le/internal/fixed_channel_impl_test.cc b/gd/l2cap/le/internal/fixed_channel_impl_test.cc index f88efacfb..d9388f616 100644 --- a/gd/l2cap/le/internal/fixed_channel_impl_test.cc +++ b/gd/l2cap/le/internal/fixed_channel_impl_test.cc @@ -62,7 +62,12 @@ class L2capLeFixedChannelImplTest : public ::testing::Test { TEST_F(L2capLeFixedChannelImplTest, get_device) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); LOG_INFO("------------------"); @@ -72,7 +77,12 @@ TEST_F(L2capLeFixedChannelImplTest, get_device) { TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -93,7 +103,12 @@ TEST_F(L2capLeFixedChannelImplTest, close_triggers_callback) { TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_immediately) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -114,7 +129,12 @@ TEST_F(L2capLeFixedChannelImplTest, register_callback_after_close_should_call_im TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -138,7 +158,12 @@ TEST_F(L2capLeFixedChannelImplTest, close_twice_should_fail) { TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -158,7 +183,12 @@ TEST_F(L2capLeFixedChannelImplTest, multiple_registeration_should_fail) { TEST_F(L2capLeFixedChannelImplTest, call_acquire_before_registeration_should_fail) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -167,7 +197,12 @@ TEST_F(L2capLeFixedChannelImplTest, call_acquire_before_registeration_should_fai TEST_F(L2capLeFixedChannelImplTest, call_release_before_registeration_should_fail) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -176,7 +211,12 @@ TEST_F(L2capLeFixedChannelImplTest, call_release_before_registeration_should_fai TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); @@ -204,7 +244,12 @@ TEST_F(L2capLeFixedChannelImplTest, test_acquire_release_channel) { TEST_F(L2capLeFixedChannelImplTest, test_acquire_after_close) { MockParameterProvider mock_parameter_provider; - MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider); + EXPECT_CALL(mock_parameter_provider, GetLeLinkIdleDisconnectTimeout()).Times(1); + testing::MockAclConnection* mock_acl_connection = new testing::MockAclConnection(); + EXPECT_CALL(*mock_acl_connection, GetAddress()).Times(1); + EXPECT_CALL(*mock_acl_connection, GetAddressType()).Times(1); + MockLink mock_le_link(l2cap_handler_, &mock_parameter_provider, + std::unique_ptr(mock_acl_connection)); AddressWithType device{{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}}, hci::AddressType::PUBLIC_DEVICE_ADDRESS}; EXPECT_CALL(mock_le_link, GetDevice()).WillRepeatedly(Return(device)); FixedChannelImpl fixed_channel_impl(kSmpBrCid, &mock_le_link, l2cap_handler_); diff --git a/gd/l2cap/le/internal/link_mock.h b/gd/l2cap/le/internal/link_mock.h index cb2292c17..63bb88481 100644 --- a/gd/l2cap/le/internal/link_mock.h +++ b/gd/l2cap/le/internal/link_mock.h @@ -33,8 +33,10 @@ using hci::testing::MockAclConnection; class MockLink : public Link { public: - explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider) - : Link(handler, std::make_unique(), parameter_provider, nullptr, nullptr){}; + explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider, + std::unique_ptr mock_acl_connection) + : Link(handler, std::move(mock_acl_connection), parameter_provider, nullptr, nullptr){}; + MOCK_METHOD(hci::AddressWithType, GetDevice, (), (override)); MOCK_METHOD(hci::Role, GetRole, (), (override)); MOCK_METHOD(void, OnAclDisconnected, (hci::ErrorCode status), (override)); -- 2.11.0