Loading system/profile/avrcp/connection_handler.cc +2 −0 Original line number Diff line number Diff line Loading @@ -243,6 +243,7 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event, << "Connection Close received from device that doesn't exist"; return; } avrc_->Close(handle); feature_map_.erase(device_map_[handle]->GetAddress()); device_map_[handle]->DeviceDisconnected(); device_map_.erase(handle); Loading Loading @@ -324,6 +325,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event, << "Connection Close received from device that doesn't exist"; return; } avrc_->Close(handle); feature_map_.erase(device_map_[handle]->GetAddress()); device_map_[handle]->DeviceDisconnected(); device_map_.erase(handle); Loading system/profile/avrcp/tests/avrcp_connection_handler_test.cc +34 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,37 @@ TEST_F(AvrcpConnectionHandlerTest, remoteDeviceConnectionTest) { ConnectionHandler::CleanUp(); } TEST_F(AvrcpConnectionHandlerTest, disconnectTest) { // Set an Expectation that Open will be called twice as an acceptor and save // the connection callback once it is called. tAVRC_CONN_CB conn_cb; EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny)) .Times(2) .WillOnce( DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0))) .WillOnce(DoAll(SetArgPointee<0>(2), Return(0))); // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); ASSERT_TRUE( ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); connection_handler_ = ConnectionHandler::Get(); // Call the callback with a message saying that a remote device has connected conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny); // Set up the expectation that Close will be called EXPECT_CALL(mock_avrcp_, Close(1)).Times(1); // Call the callback with a message saying that a remote device has // disconnected conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny); connection_handler_ = nullptr; ConnectionHandler::CleanUp(); } // Check that we can handle having a remote device connect to us, start SDP, and // open another acceptor connection TEST_F(AvrcpConnectionHandlerTest, multipleRemoteDeviceConnectionTest) { Loading Loading @@ -366,6 +397,9 @@ TEST_F(AvrcpConnectionHandlerTest, disconnectWhileDoingSdpTest) { // Signal that SDP has completed sdp_cb.Run(0); connection_handler_ = nullptr; ConnectionHandler::CleanUp(); } } // namespace avrcp Loading Loading
system/profile/avrcp/connection_handler.cc +2 −0 Original line number Diff line number Diff line Loading @@ -243,6 +243,7 @@ void ConnectionHandler::InitiatorControlCb(uint8_t handle, uint8_t event, << "Connection Close received from device that doesn't exist"; return; } avrc_->Close(handle); feature_map_.erase(device_map_[handle]->GetAddress()); device_map_[handle]->DeviceDisconnected(); device_map_.erase(handle); Loading Loading @@ -324,6 +325,7 @@ void ConnectionHandler::AcceptorControlCb(uint8_t handle, uint8_t event, << "Connection Close received from device that doesn't exist"; return; } avrc_->Close(handle); feature_map_.erase(device_map_[handle]->GetAddress()); device_map_[handle]->DeviceDisconnected(); device_map_.erase(handle); Loading
system/profile/avrcp/tests/avrcp_connection_handler_test.cc +34 −0 Original line number Diff line number Diff line Loading @@ -151,6 +151,37 @@ TEST_F(AvrcpConnectionHandlerTest, remoteDeviceConnectionTest) { ConnectionHandler::CleanUp(); } TEST_F(AvrcpConnectionHandlerTest, disconnectTest) { // Set an Expectation that Open will be called twice as an acceptor and save // the connection callback once it is called. tAVRC_CONN_CB conn_cb; EXPECT_CALL(mock_avrcp_, Open(_, _, RawAddress::kAny)) .Times(2) .WillOnce( DoAll(SetArgPointee<0>(1), SaveArgPointee<1>(&conn_cb), Return(0))) .WillOnce(DoAll(SetArgPointee<0>(2), Return(0))); // Initialize the interface auto bound_callback = base::Bind(&MockFunction<void(device_ptr)>::Call, base::Unretained(&device_cb)); ASSERT_TRUE( ConnectionHandler::Initialize(bound_callback, &mock_avrcp_, &mock_sdp_)); connection_handler_ = ConnectionHandler::Get(); // Call the callback with a message saying that a remote device has connected conn_cb.ctrl_cback.Run(1, AVRC_OPEN_IND_EVT, 0, &RawAddress::kAny); // Set up the expectation that Close will be called EXPECT_CALL(mock_avrcp_, Close(1)).Times(1); // Call the callback with a message saying that a remote device has // disconnected conn_cb.ctrl_cback.Run(1, AVRC_CLOSE_IND_EVT, 0, &RawAddress::kAny); connection_handler_ = nullptr; ConnectionHandler::CleanUp(); } // Check that we can handle having a remote device connect to us, start SDP, and // open another acceptor connection TEST_F(AvrcpConnectionHandlerTest, multipleRemoteDeviceConnectionTest) { Loading Loading @@ -366,6 +397,9 @@ TEST_F(AvrcpConnectionHandlerTest, disconnectWhileDoingSdpTest) { // Signal that SDP has completed sdp_cb.Run(0); connection_handler_ = nullptr; ConnectionHandler::CleanUp(); } } // namespace avrcp Loading