diff options
Diffstat (limited to 'src/components/protocol_handler/test/protocol_handler_tm_test.cc')
-rw-r--r-- | src/components/protocol_handler/test/protocol_handler_tm_test.cc | 525 |
1 files changed, 422 insertions, 103 deletions
diff --git a/src/components/protocol_handler/test/protocol_handler_tm_test.cc b/src/components/protocol_handler/test/protocol_handler_tm_test.cc index 1a7be866d9..308901e013 100644 --- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc +++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc @@ -36,7 +36,7 @@ #include "protocol/common.h" #include "protocol_handler/control_message_matcher.h" #include "protocol_handler/mock_protocol_handler.h" -#include "protocol_handler/protocol_observer_mock.h" +#include "protocol_handler/mock_protocol_observer.h" #include "protocol_handler/mock_protocol_handler_settings.h" #include "protocol_handler/mock_session_observer.h" #include "connection_handler/mock_connection_handler.h" @@ -44,6 +44,7 @@ #include "security_manager/mock_ssl_context.h" #include "transport_manager/mock_transport_manager.h" #include "utils/make_shared.h" +#include "utils/test_async_waiter.h" namespace test { namespace components { @@ -104,6 +105,10 @@ using ::testing::SetArgPointee; typedef std::vector<uint8_t> UCharDataVector; +namespace { +const uint32_t kAsyncExpectationsTimeout = 10000u; +} + class ProtocolHandlerImplTest : public ::testing::Test { protected: void InitProtocolHandlerImpl(const size_t period_msec, @@ -156,8 +161,10 @@ class ProtocolHandlerImplTest : public ::testing::Test { } void TearDown() OVERRIDE { - // Wait call methods in thread - testing::Mock::AsyncVerifyAndClearExpectations(10000); + const_cast<protocol_handler::impl::FromMobileQueue&>( + protocol_handler_impl->get_from_mobile_queue()).WaitDumpQueue(); + const_cast<protocol_handler::impl::ToMobileQueue&>( + protocol_handler_impl->get_to_mobile_queue()).WaitDumpQueue(); } // Emulate connection establish @@ -168,9 +175,14 @@ class ProtocolHandlerImplTest : public ::testing::Test { std::string("BTMAC")), connection_id); } - void AddSession() { + + void AddSession(const ::utils::SharedPtr<TestAsyncWaiter>& waiter, + uint32_t& times) { + ASSERT_TRUE(NULL != waiter.get()); + AddConnection(); const ServiceType start_service = kRpc; + #ifdef ENABLE_SECURITY // For enabled protection callback shall use protection ON const bool callback_protection_flag = PROTECTION_ON; @@ -179,6 +191,7 @@ class ProtocolHandlerImplTest : public ::testing::Test { // use protection OFF const bool callback_protection_flag = PROTECTION_OFF; #endif // ENABLE_SECURITY + // Expect ConnectionHandler check EXPECT_CALL(session_observer_mock, OnSessionStartedCallback(connection_id, @@ -188,13 +201,15 @@ class ProtocolHandlerImplTest : public ::testing::Test { _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(session_id))); + times++; // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); @@ -206,6 +221,7 @@ class ProtocolHandlerImplTest : public ::testing::Test { protocol_handler_impl->set_security_manager(&security_manager_mock); } #endif // ENABLE_SECURITY + void SendTMMessage(uint8_t connection_id, uint8_t version, bool protection, @@ -327,6 +343,9 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Unprotected_SessionObserverReject) { const int call_times = 5; AddConnection(); + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -338,14 +357,17 @@ TEST_F(ProtocolHandlerImplTest, .Times(call_times) . // Return sessions start rejection - WillRepeatedly(Return(SESSION_START_REJECT)); + WillRepeatedly( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(SESSION_START_REJECT))); + times += call_times; // Expect send NAck EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times) - .WillRepeatedly(Return(E_SUCCESS)); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times += call_times; SendControlMessage( PROTECTION_OFF, kControl, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); @@ -357,6 +379,8 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, kMobileNav, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); SendControlMessage( PROTECTION_OFF, kBulk, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send NAck on session_observer rejection @@ -375,6 +399,9 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { // use protection OFF const bool callback_protection_flag = PROTECTION_OFF; #endif // ENABLE_SECURITY + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -386,14 +413,17 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { .Times(call_times) . // Return sessions start rejection - WillRepeatedly(Return(SESSION_START_REJECT)); + WillRepeatedly( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(SESSION_START_REJECT))); + times += call_times; // Expect send NAck with encryption OFF EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times) - .WillRepeatedly(Return(E_SUCCESS)); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times += call_times; SendControlMessage( PROTECTION_ON, kControl, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); @@ -405,6 +435,8 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { PROTECTION_ON, kMobileNav, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); SendControlMessage( PROTECTION_ON, kBulk, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack on session_observer accept @@ -414,6 +446,9 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Unprotected_SessionObserverAccept) { AddConnection(); const ServiceType start_service = kRpc; + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -421,17 +456,21 @@ TEST_F(ProtocolHandlerImplTest, connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; SetProtocolVersion2(); // Expect send Ack EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_OFF, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack on session_observer accept @@ -441,7 +480,14 @@ TEST_F(ProtocolHandlerImplTest, */ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverAccept) { SetProtocolVersion2(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } // TODO(EZamakhov): add test for get_hash_id/set_hash_id from // protocol_handler_impl.cc @@ -449,7 +495,12 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverAccept) { * ProtocolHandler shall send NAck on session_observer rejection */ TEST_F(ProtocolHandlerImplTest, EndSession_SessionObserverReject) { - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + const ServiceType service = kRpc; // Expect ConnectionHandler check @@ -457,23 +508,33 @@ TEST_F(ProtocolHandlerImplTest, EndSession_SessionObserverReject) { OnSessionEndedCallback(connection_id, session_id, _, service)) . // reject session start - WillOnce(Return(SESSION_START_REJECT)); + WillOnce( + DoAll(NotifyTestAsyncWaiter(waiter), Return(SESSION_START_REJECT))); + times++; SetProtocolVersion2(); // Expect send NAck EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_END_SERVICE_NACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_OFF, service, session_id, FRAME_DATA_END_SERVICE); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send NAck on wrong hash code */ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + const ServiceType service = kRpc; // Expect ConnectionHandler check @@ -481,17 +542,21 @@ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { OnSessionEndedCallback(connection_id, session_id, _, service)) . // return sessions start success - WillOnce(Return(connection_key)); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(connection_key))); + times++; SetProtocolVersion2(); // Expect send Ack EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_END_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_OFF, service, session_id, FRAME_DATA_END_SERVICE); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } #ifdef ENABLE_SECURITY @@ -500,7 +565,12 @@ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { * Check session_observer with PROTECTION_OFF and Ack with PROTECTION_OFF */ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) { - AddConnection(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Add security manager AddSecurityManager(); const ServiceType start_service = kRpc; @@ -511,14 +581,17 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) { connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(session_id))); + times++; SetProtocolVersion2(); // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))) + .RetiresOnSaturation(); + times++; SendTMMessage(connection_id, PROTOCOL_VERSION_1, @@ -529,6 +602,8 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) { NEW_SESSION_ID, 0, message_id); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall not call Security logics on start session with @@ -539,6 +614,9 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { // Add security manager AddSecurityManager(); const ServiceType start_service = kRpc; + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -546,17 +624,21 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { connection_id, NEW_SESSION_ID, start_service, PROTECTION_OFF, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; SetProtocolVersion2(); // Expect send Ack with PROTECTION_OFF (on no Security Manager) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_OFF, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_OFF on fail SLL creation @@ -565,6 +647,9 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -572,23 +657,28 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; SetProtocolVersion2(); // Expect start protection for unprotected session EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)) . // Return fail protection - WillOnce(ReturnNull()); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + times++; // Expect send Ack with PROTECTION_OFF (on fail SLL creation) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on already established and @@ -599,6 +689,9 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -606,33 +699,42 @@ TEST_F(ProtocolHandlerImplTest, connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; SetProtocolVersion2(); // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)) . // Return new SSLContext - WillOnce(Return(&ssl_context_mock)); + WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(&ssl_context_mock))); + times++; // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()) . // emulate SSL is initilized - WillOnce(Return(true)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, - SetProtectionFlag(connection_key, start_service)); + SetProtectionFlag(connection_key, start_service)) + .WillOnce(NotifyTestAsyncWaiter(&waiter)); + times++; // Expect send Ack with PROTECTION_ON (on SSL is initilized) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_OFF on session handshhake fail @@ -642,6 +744,9 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); AddSecurityManager(); const ServiceType start_service = kRpc; + + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -649,7 +754,8 @@ TEST_F(ProtocolHandlerImplTest, connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; std::vector<int> services; // TODO(AKutsan) : APPLINK-21398 use named constants instead of magic numbers @@ -668,13 +774,15 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(ssl_context_mock, IsInitCompleted()) . // emulate SSL is not initilized - WillOnce(Return(false)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(Return(true)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + times++; // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) @@ -694,10 +802,13 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -714,6 +825,8 @@ TEST_F(ProtocolHandlerImplTest, ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -721,52 +834,66 @@ TEST_F(ProtocolHandlerImplTest, connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)) . // Return new SSLContext - WillOnce(Return(&ssl_context_mock)); + WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(&ssl_context_mock))); + times++; // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()) . // emulate SSL is not initilized - WillOnce(Return(false)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(Return(true)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + times++; // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) // Emulate handshake fail - .WillOnce(Invoke(OnHandshakeDoneFunctor( - connection_key, - security_manager::SSLContext::Handshake_Result_Success))); + .WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), + Invoke(OnHandshakeDoneFunctor( + connection_key, + security_manager::SSLContext::Handshake_Result_Success)))); + times++; // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)) . // Emulate protection for service is not enabled - WillOnce(ReturnNull()); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, - SetProtectionFlag(connection_key, start_service)); + SetProtectionFlag(connection_key, start_service)) + .WillOnce(NotifyTestAsyncWaiter(&waiter)); + times++; // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -783,6 +910,8 @@ TEST_F( ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -790,13 +919,16 @@ TEST_F( connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)) . // Return new SSLContext - WillOnce(Return(&ssl_context_mock)); + WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(&ssl_context_mock))); + times++; // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()) @@ -808,34 +940,44 @@ TEST_F( EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(Return(true)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + times++; // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) // Emulate handshake fail - .WillOnce(Invoke(OnHandshakeDoneFunctor( - connection_key, - security_manager::SSLContext::Handshake_Result_Success))); + .WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), + Invoke(OnHandshakeDoneFunctor( + connection_key, + security_manager::SSLContext::Handshake_Result_Success)))); + times++; // Listener check SSLContext EXPECT_CALL(session_observer_mock, GetSSLContext(connection_key, start_service)) . // Emulate protection for service is not enabled - WillOnce(ReturnNull()); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, - SetProtectionFlag(connection_key, start_service)); + SetProtectionFlag(connection_key, start_service)) + .WillOnce(NotifyTestAsyncWaiter(&waiter)); + times++; // Expect send Ack with PROTECTION_OFF (on fail handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -851,6 +993,8 @@ TEST_F(ProtocolHandlerImplTest, ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); + TestAsyncWaiter waiter; + uint32_t times = 0; // Expect ConnectionHandler check EXPECT_CALL( session_observer_mock, @@ -858,28 +1002,35 @@ TEST_F(ProtocolHandlerImplTest, connection_id, NEW_SESSION_ID, start_service, PROTECTION_ON, _)) . // Return sessions start success - WillOnce(Return(session_id)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(session_id))); + times++; // call new SSLContext creation EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key)) . // Return new SSLContext - WillOnce(Return(&ssl_context_mock)); + WillOnce( + DoAll(NotifyTestAsyncWaiter(&waiter), Return(&ssl_context_mock))); + times++; // Initilization check EXPECT_CALL(ssl_context_mock, IsInitCompleted()) . // emulate SSL is not initilized - WillOnce(Return(false)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(Return(false)); + WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + times++; // Wait restart handshake operation - EXPECT_CALL(security_manager_mock, StartHandshake(connection_key)); + EXPECT_CALL(security_manager_mock, StartHandshake(connection_key)) + .WillOnce(NotifyTestAsyncWaiter(&waiter)); + times++; // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) @@ -903,23 +1054,32 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + times++; SendControlMessage( PROTECTION_ON, start_service, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); + + EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); } #endif // ENABLE_SECURITY -TEST_F(ProtocolHandlerImplTest, FloodVerification) { +TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect flood notification to CH EXPECT_CALL(session_observer_mock, OnApplicationFloodCallBack(connection_key)) - .Times(1); + .WillOnce(NotifyTestAsyncWaiter(waiter)); + times++; ON_CALL(protocol_handler_settings_mock, message_frequency_time()) .WillByDefault(Return(period_msec)); @@ -938,13 +1098,21 @@ TEST_F(ProtocolHandlerImplTest, FloodVerification) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, period_msec)); } -TEST_F(ProtocolHandlerImplTest, FloodVerification_ThresholdValue) { + +TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_ThresholdValue) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); ON_CALL(protocol_handler_settings_mock, message_frequency_time()) .WillByDefault(Return(period_msec)); @@ -954,6 +1122,7 @@ TEST_F(ProtocolHandlerImplTest, FloodVerification_ThresholdValue) { // Expect NO flood notification to CH EXPECT_CALL(session_observer_mock, OnApplicationFloodCallBack(connection_key)) .Times(0); + for (size_t i = 0; i < max_messages - 1; ++i) { SendTMMessage(connection_id, PROTOCOL_VERSION_3, @@ -966,13 +1135,21 @@ TEST_F(ProtocolHandlerImplTest, FloodVerification_ThresholdValue) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, period_msec)); } -TEST_F(ProtocolHandlerImplTest, FloodVerification_VideoFrameSkip) { + +TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_VideoFrameSkip) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect NO flood notification to CH on video data streaming for (size_t i = 0; i < max_messages + 1; ++i) { @@ -987,13 +1164,21 @@ TEST_F(ProtocolHandlerImplTest, FloodVerification_VideoFrameSkip) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, period_msec)); } -TEST_F(ProtocolHandlerImplTest, FloodVerification_AudioFrameSkip) { + +TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_AudioFrameSkip) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect NO flood notification to CH on video data streaming for (size_t i = 0; i < max_messages + 1; ++i) { @@ -1008,13 +1193,21 @@ TEST_F(ProtocolHandlerImplTest, FloodVerification_AudioFrameSkip) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, period_msec)); } -TEST_F(ProtocolHandlerImplTest, FloodVerificationDisable) { + +TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerificationDisable) { const size_t period_msec = 0; const size_t max_messages = 0; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect NO flood notification to session observer for (size_t i = 0; i < max_messages + 1; ++i) { @@ -1029,6 +1222,8 @@ TEST_F(ProtocolHandlerImplTest, FloodVerificationDisable) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, MalformedVerificationDisable) { @@ -1036,7 +1231,12 @@ TEST_F(ProtocolHandlerImplTest, MalformedVerificationDisable) { const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, false, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) @@ -1055,18 +1255,26 @@ TEST_F(ProtocolHandlerImplTest, MalformedVerificationDisable) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification) { +TEST_F(ProtocolHandlerImplTest, DISABLED_MalformedLimitVerification) { const size_t period_msec = 10000; const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) - .Times(1); + .WillOnce(NotifyTestAsyncWaiter(waiter)); + times++; // Sending malformed packets const uint8_t malformed_version = PROTOCOL_VERSION_MAX; @@ -1094,18 +1302,27 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedStock) { +TEST_F(ProtocolHandlerImplTest, + DISABLED_MalformedLimitVerification_MalformedStock) { const size_t period_msec = 10000; const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) - .Times(1); + .WillOnce(NotifyTestAsyncWaiter(waiter)); + times++; // Sending malformed packets const uint8_t malformed_version = PROTOCOL_VERSION_MAX; @@ -1158,6 +1375,8 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedStock) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedOnly) { @@ -1165,7 +1384,12 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedOnly) { const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect NO malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) @@ -1212,6 +1436,8 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedOnly) { // No common message } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullTimePeriod) { @@ -1219,7 +1445,12 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullTimePeriod) { const size_t max_messages = 1000; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect no malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) @@ -1239,13 +1470,21 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullTimePeriod) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } + TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullCount) { const size_t period_msec = 10000; const size_t max_messages = 0; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - AddSession(); + + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); // Expect no malformed notification to CH EXPECT_CALL(session_observer_mock, OnMalformedMessageCallback(connection_id)) @@ -1265,6 +1504,8 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullCount) { message_id, &some_data[0]); } + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, @@ -1275,13 +1516,20 @@ TEST_F(ProtocolHandlerImplTest, .WillOnce(Return(false)); // Expect not send End Service EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_)).Times(0); + // Act protocol_handler_impl->SendEndSession(connection_id, session_id); } -TEST_F(ProtocolHandlerImplTest, SendEndServicePrivate_EndSession_MessageSent) { +TEST_F(ProtocolHandlerImplTest, + DISABLED_SendEndServicePrivate_EndSession_MessageSent) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Expect check connection with ProtocolVersionUsed EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(connection_id, session_id, _)) @@ -1294,12 +1542,19 @@ TEST_F(ProtocolHandlerImplTest, SendEndServicePrivate_EndSession_MessageSent) { .WillOnce(Return(E_SUCCESS)); // Act protocol_handler_impl->SendEndSession(connection_id, session_id); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendEndServicePrivate_ServiceTypeControl_MessageSent) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Expect check connection with ProtocolVersionUsed EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(connection_id, session_id, _)) @@ -1310,9 +1565,13 @@ TEST_F(ProtocolHandlerImplTest, FRAME_DATA_END_SERVICE, PROTECTION_OFF, kControl))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; + // Act protocol_handler_impl->SendEndService(connection_id, session_id, kControl); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendHeartBeat_NoConnection_NotSent) { @@ -1322,13 +1581,19 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeat_NoConnection_NotSent) { .WillOnce(Return(false)); // Expect not send HeartBeat EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_)).Times(0); + // Act protocol_handler_impl->SendHeartBeat(connection_id, session_id); } TEST_F(ProtocolHandlerImplTest, SendHeartBeat_Successful) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Expect check connection with ProtocolVersionUsed EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(connection_id, session_id, _)) @@ -1339,13 +1604,21 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeat_Successful) { SendMessageToDevice(ExpectedMessage( FRAME_TYPE_CONTROL, FRAME_DATA_HEART_BEAT, PROTECTION_OFF, kControl))) .WillOnce(Return(E_SUCCESS)); + // Act protocol_handler_impl->SendHeartBeat(connection_id, session_id); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_Successful) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Expect double check connection and protocol version with // ProtocolVersionUsed EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(connection_id, _, _)) @@ -1357,15 +1630,25 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_Successful) { FRAME_DATA_HEART_BEAT_ACK, PROTECTION_OFF, kControl))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; + // Act SendControlMessage( PROTECTION_OFF, kControl, session_id, FRAME_DATA_HEART_BEAT); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_WrongProtocolVersion_NotSent) { +TEST_F(ProtocolHandlerImplTest, + DISABLED_SendHeartBeatAck_WrongProtocolVersion_NotSent) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + // Expect two checks of connection and protocol version with // ProtocolVersionUsed EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(connection_id, _, _)) @@ -1383,12 +1666,19 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_WrongProtocolVersion_NotSent) { PROTECTION_OFF, kControl, session_id, FRAME_DATA_HEART_BEAT); SendControlMessage( PROTECTION_OFF, kControl, session_id, FRAME_DATA_HEART_BEAT); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendSingleControlMessage) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + const bool is_final = true; const uint32_t total_data_size = 1; UCharDataVector data(total_data_size); @@ -1399,8 +1689,8 @@ TEST_F(ProtocolHandlerImplTest, PairFromKey(message->connection_key(), _, _)) .WillOnce( DoAll(SetArgPointee<1>(connection_id), SetArgPointee<2>(session_id))); -// Expect getting ssl context #ifdef ENABLE_SECURITY + // Expect getting ssl context EXPECT_CALL(session_observer_mock, GetSSLContext(message->connection_key(), message->service_type())) .WillOnce(Return(&ssl_context_mock)); @@ -1411,14 +1701,22 @@ TEST_F(ProtocolHandlerImplTest, SendMessageToDevice(ExpectedMessage( FRAME_TYPE_SINGLE, FRAME_DATA_SINGLE, PROTECTION_OFF, kControl))) .WillOnce(Return(E_SUCCESS)); + // Act protocol_handler_impl->SendMessageToMobileApp(message, is_final); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendSingleNonControlMessage) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + const bool is_final = true; const uint32_t total_data_size = 1; UCharDataVector data(total_data_size); @@ -1429,26 +1727,39 @@ TEST_F(ProtocolHandlerImplTest, PairFromKey(message->connection_key(), _, _)) .WillOnce( DoAll(SetArgPointee<1>(connection_id), SetArgPointee<2>(session_id))); -// Expect getting ssl context + #ifdef ENABLE_SECURITY + // Expect getting ssl context EXPECT_CALL(session_observer_mock, GetSSLContext(message->connection_key(), message->service_type())) .Times(2) - .WillRepeatedly(Return(&ssl_context_mock)); + .WillRepeatedly( + DoAll(NotifyTestAsyncWaiter(waiter), Return(&ssl_context_mock))); + times += 2; AddSecurityManager(); #endif // ENABLE_SECURITY + // Expect send message to mobile EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ExpectedMessage( FRAME_TYPE_SINGLE, FRAME_DATA_SINGLE, PROTECTION_OFF, kRpc))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; + // Act protocol_handler_impl->SendMessageToMobileApp(message, is_final); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendMultiframeMessage) { // Arrange - AddSession(); + ::utils::SharedPtr<TestAsyncWaiter> waiter = + utils::MakeShared<TestAsyncWaiter>(); + uint32_t times = 0; + + AddSession(waiter, times); + const bool is_final = true; const uint32_t total_data_size = MAXIMUM_FRAME_DATA_V2_SIZE * 2; UCharDataVector data(total_data_size); @@ -1460,33 +1771,41 @@ TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendMultiframeMessage) { PairFromKey(message->connection_key(), _, _)) .WillOnce( DoAll(SetArgPointee<1>(connection_id), SetArgPointee<2>(session_id))); -// Expect getting ssl context #ifdef ENABLE_SECURITY + // Expect getting ssl context EXPECT_CALL(session_observer_mock, GetSSLContext(message->connection_key(), message->service_type())) .Times(4) - .WillRepeatedly(Return(&ssl_context_mock)); + .WillRepeatedly( + DoAll(NotifyTestAsyncWaiter(waiter), Return(&ssl_context_mock))); + times += 4; AddSecurityManager(); #endif // ENABLE_SECURITY // Expect sending message frame by frame to mobile EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ExpectedMessage( FRAME_TYPE_FIRST, FRAME_DATA_FIRST, PROTECTION_OFF, kBulk))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ExpectedMessage(FRAME_TYPE_CONSECUTIVE, first_consecutive_frame, PROTECTION_OFF, kBulk))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ExpectedMessage(FRAME_TYPE_CONSECUTIVE, FRAME_DATA_LAST_CONSECUTIVE, PROTECTION_OFF, kBulk))) - .WillOnce(Return(E_SUCCESS)); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); + times++; + // Act protocol_handler_impl->SendMessageToMobileApp(message, is_final); + + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } } // namespace protocol_handler_test |