diff options
Diffstat (limited to 'src/components/connection_handler/test/connection_handler_impl_test.cc')
-rw-r--r-- | src/components/connection_handler/test/connection_handler_impl_test.cc | 75 |
1 files changed, 62 insertions, 13 deletions
diff --git a/src/components/connection_handler/test/connection_handler_impl_test.cc b/src/components/connection_handler/test/connection_handler_impl_test.cc index 5a8feda2db..9305eee2ee 100644 --- a/src/components/connection_handler/test/connection_handler_impl_test.cc +++ b/src/components/connection_handler/test/connection_handler_impl_test.cc @@ -65,9 +65,9 @@ using ::testing::ReturnRefOfCopy; using ::testing::SaveArg; using ::testing::SaveArgPointee; -// custom action to call a member function with 3 arguments -ACTION_P5(InvokeMemberFuncWithArg3, ptr, memberFunc, a, b, c) { - (ptr->*memberFunc)(a, b, c); +// custom action to call a member function with 4 arguments +ACTION_P6(InvokeMemberFuncWithArg4, ptr, memberFunc, a, b, c, d) { + (ptr->*memberFunc)(a, b, c, d); } namespace { @@ -855,6 +855,24 @@ TEST_F(ConnectionHandlerTest, OnConnectionClosed) { connection_handler_->OnConnectionClosed(uid_); } +TEST_F(ConnectionHandlerTest, OnFinalMessageCallback_OnConnectionClosed) { + AddTestDeviceConnection(); + AddTestSession(); + + connection_handler_test::MockConnectionHandlerObserver + mock_connection_handler_observer; + connection_handler_->set_connection_handler_observer( + &mock_connection_handler_observer); + + EXPECT_CALL(mock_connection_handler_observer, + OnServiceEndedCallback(connection_key_, kBulk, kFinalMessage)); + EXPECT_CALL(mock_connection_handler_observer, + OnServiceEndedCallback(connection_key_, kRpc, kFinalMessage)); + + connection_handler_->OnFinalMessageCallback(connection_key_); + connection_handler_->OnConnectionClosed(uid_); +} + TEST_F(ConnectionHandlerTest, OnUnexpectedDisconnect) { AddTestDeviceConnection(); AddTestSession(); @@ -874,6 +892,27 @@ TEST_F(ConnectionHandlerTest, OnUnexpectedDisconnect) { connection_handler_->OnUnexpectedDisconnect(uid_, err); } +TEST_F(ConnectionHandlerTest, OnFinalMessageCallback_OnUnexpectedDisconnect) { + AddTestDeviceConnection(); + AddTestSession(); + + connection_handler_test::MockConnectionHandlerObserver + mock_connection_handler_observer; + connection_handler_->set_connection_handler_observer( + &mock_connection_handler_observer); + + EXPECT_CALL(mock_connection_handler_observer, + OnServiceEndedCallback( + connection_key_, kBulk, CloseSessionReason::kFinalMessage)); + EXPECT_CALL(mock_connection_handler_observer, + OnServiceEndedCallback( + connection_key_, kRpc, CloseSessionReason::kFinalMessage)); + + connection_handler_->OnFinalMessageCallback(connection_key_); + transport_manager::CommunicationError err; + connection_handler_->OnUnexpectedDisconnect(uid_, err); +} + TEST_F(ConnectionHandlerTest, ConnectToDevice) { // Precondition const uint32_t dev_handle1 = 1; @@ -1307,16 +1346,18 @@ TEST_F(ConnectionHandlerTest, SessionStarted_WithRpc) { connection_handler_->set_connection_handler_observer( &mock_connection_handler_observer); std::vector<std::string> empty; + std::string reason; uint32_t session_key = connection_handler_->KeyFromPair(uid_, out_context_.initial_session_id_); EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback(device_handle_, _, kRpc, NULL)) - .WillOnce(InvokeMemberFuncWithArg3( + .WillOnce(InvokeMemberFuncWithArg4( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, session_key, true, - ByRef(empty))); + ByRef(empty), + reason)); connection_handler_->set_protocol_handler(&mock_protocol_handler_); EXPECT_CALL(mock_protocol_handler_, NotifySessionStarted(_, _, _)) @@ -1345,15 +1386,17 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_SUCCESS) { uint32_t session_key = connection_handler_->KeyFromPair(uid_, out_context_.new_session_id_); std::vector<std::string> empty; + std::string reason; EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback( device_handle_, session_key, kMobileNav, dummy_params)) - .WillOnce(InvokeMemberFuncWithArg3( + .WillOnce(InvokeMemberFuncWithArg4( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, session_key, true, - ByRef(empty))); + ByRef(empty), + reason)); // confirm that NotifySessionStarted() is called connection_handler_->set_protocol_handler(&mock_protocol_handler_); @@ -1385,15 +1428,17 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_FAILURE) { uint32_t session_key = connection_handler_->KeyFromPair(uid_, out_context_.new_session_id_); std::vector<std::string> empty; + std::string reason; EXPECT_CALL(mock_connection_handler_observer, OnServiceStartedCallback( device_handle_, session_key, kMobileNav, dummy_params)) - .WillOnce(InvokeMemberFuncWithArg3( + .WillOnce(InvokeMemberFuncWithArg4( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, session_key, false, - ByRef(empty))); + ByRef(empty), + reason)); // confirm that NotifySessionStarted() is called connection_handler_->set_protocol_handler(&mock_protocol_handler_); @@ -1455,6 +1500,8 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_Multiple) { connection_handler_->KeyFromPair(uid_, context_second.new_session_id_); std::vector<std::string> empty; + std::string reason; + ChangeProtocol(uid_, context_first.new_session_id_, protocol_handler::PROTOCOL_VERSION_3); @@ -1472,18 +1519,20 @@ TEST_F(ConnectionHandlerTest, ServiceStarted_Video_Multiple) { device_handle_, session_key2, kMobileNav, dummy_params)) // call NotifyServiceStartedResult() twice, first for the second session // then for the first session - .WillOnce(DoAll(InvokeMemberFuncWithArg3( + .WillOnce(DoAll(InvokeMemberFuncWithArg4( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, session_key2, false, - ByRef(empty)), - InvokeMemberFuncWithArg3( + ByRef(empty), + reason), + InvokeMemberFuncWithArg4( connection_handler_, &ConnectionHandler::NotifyServiceStartedResult, session_key1, true, - ByRef(empty)))); + ByRef(empty), + reason))); // verify that connection handler will not mix up the two results SessionContext new_context_first, new_context_second; |