OSDN Git Service

gd: Clean up bluetooth_test_gd
authorChris Manton <cmanton@google.com>
Fri, 21 Feb 2020 03:58:43 +0000 (19:58 -0800)
committerChris Manton <cmanton@google.com>
Fri, 21 Feb 2020 03:58:43 +0000 (19:58 -0800)
Bug: 146363362
Test: bluetooth_test_gd
Change-Id: I0f3fb81d2b79b781918d18ea89a3ed64574a9610

gd/l2cap/le/internal/fixed_channel_impl_test.cc
gd/l2cap/le/internal/link_mock.h

index f88efac..d9388f6 100644 (file)
@@ -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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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<testing::MockAclConnection>(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_);
index cb2292c..63bb884 100644 (file)
@@ -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<MockAclConnection>(), parameter_provider, nullptr, nullptr){};
+  explicit MockLink(os::Handler* handler, l2cap::internal::ParameterProvider* parameter_provider,
+                    std::unique_ptr<MockAclConnection> 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));