diff options
author | Yana Chernysheva (GitHub) <59469418+ychernysheva@users.noreply.github.com> | 2021-02-03 22:55:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-03 15:55:57 -0500 |
commit | fa8b0a0e58db33e4f2d1245ef7525b67bbeb8b48 (patch) | |
tree | a266381e883f2c65797977b76b88cf03c47b3a02 | |
parent | 16323b0915775a42b81d2ad92d5bdcfafcdf61e4 (diff) | |
download | sdl_core-fa8b0a0e58db33e4f2d1245ef7525b67bbeb8b48.tar.gz |
CCB: Fix unit tests stuck (#3624)
* Replace TestAsyncWaiter references with shared_ptr, which
avoid invalid references to TestAsyncWaiter when it goes out of scope,
which can(sometimes, but not always) lead to hard-to-trace-and-reprpduce
segfaults, deadlocks and sigaborts.
* Fix review comments
* Update PolicyHandlerTest with TestAsyncWaiter
* fixup! Update PolicyHandlerTest with TestAsyncWaiter
* Fix and enable disabled tests
Co-authored-by: VladSemenyuk <vsemenyuk@luxoft.com>
14 files changed, 381 insertions, 469 deletions
diff --git a/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc b/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc index 08868a239f..41d300cc4a 100644 --- a/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc +++ b/src/components/application_manager/test/app_launch/app_launch_ctrl_test.cc @@ -202,7 +202,7 @@ TEST_F(AppLaunchCtrlTest, StoredAppIsLaunchedAfterDeviceConnected) { app_launch::ApplicationDataPtr app_to_launch = GetTestAppData(0); MockAppPtr app = GetTestApp(0); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); applications_on_device.push_back(app_to_launch); EXPECT_CALL(app_launch_data_mock_, GetApplicationDataByDevice(app_to_launch->device_mac_)) @@ -212,11 +212,11 @@ TEST_F(AppLaunchCtrlTest, StoredAppIsLaunchedAfterDeviceConnected) { RunAppOnDevice(app_to_launch->device_mac_, app_to_launch->bundle_id_)) .Times(AtLeast(1)) .WillOnce(DoAll(InvokeOnAppRegistered(app_launch_ctrl_.get(), app.get()), - NotifyTestAsyncWaiter(&waiter))); + NotifyTestAsyncWaiter(waiter))); app_launch_ctrl_->OnDeviceConnected(app_to_launch->device_mac_); const uint32_t wait_time = MAX_TEST_DURATION + settings_.app_launch_wait_time(); - EXPECT_TRUE(waiter.WaitFor(1, wait_time)); + EXPECT_TRUE(waiter->WaitFor(1, wait_time)); } TEST_F(AppLaunchCtrlTest, RelaunchAppIfNotRegisteredMultipleTimes) { @@ -224,7 +224,7 @@ TEST_F(AppLaunchCtrlTest, RelaunchAppIfNotRegisteredMultipleTimes) { app_launch::ApplicationDataPtr app_to_launch = GetTestAppData(0); applications_on_device.push_back(app_to_launch); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); const uint32_t times = settings_.app_launch_max_retry_attempt(); EXPECT_CALL(app_launch_data_mock_, GetApplicationDataByDevice(app_to_launch->device_mac_)) @@ -234,14 +234,14 @@ TEST_F(AppLaunchCtrlTest, RelaunchAppIfNotRegisteredMultipleTimes) { connection_handler_mock_, RunAppOnDevice(app_to_launch->device_mac_, app_to_launch->bundle_id_)) .Times(times) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); app_launch_ctrl_->OnDeviceConnected(app_to_launch->device_mac_); const uint32_t wait_time = MAX_TEST_DURATION + settings_.app_launch_wait_time() + settings_.app_launch_max_retry_attempt() * settings_.app_launch_retry_wait_time(); - EXPECT_TRUE(waiter.WaitFor(times, wait_time)); + EXPECT_TRUE(waiter->WaitFor(times, wait_time)); } TEST_F(AppLaunchCtrlTest, LaunchMultipleApps) { @@ -253,7 +253,7 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleApps) { apps.push_back(it->second); } - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); const uint32_t times = apps_and_data.size(); EXPECT_CALL(app_launch_data_mock_, GetApplicationDataByDevice(DeviceMac(1))) .WillOnce(Return(apps)); @@ -267,13 +267,13 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleApps) { .Times(AtLeast(1)) .WillOnce(DoAll( InvokeOnAppRegistered(app_launch_ctrl_.get(), it->first.get()), - NotifyTestAsyncWaiter(&waiter))); + NotifyTestAsyncWaiter(waiter))); } app_launch_ctrl_->OnDeviceConnected(DeviceMac(1)); const uint32_t wait_time = MAX_TEST_DURATION + settings_.app_launch_wait_time() + apps.size() * settings_.wait_time_between_apps(); - waiter.WaitFor(times, wait_time); + waiter->WaitFor(times, wait_time); } TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsNoRegister) { @@ -285,7 +285,7 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsNoRegister) { apps.push_back(it->second); } - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); const uint32_t times = settings_.app_launch_max_retry_attempt() * apps_and_data.size(); EXPECT_CALL(app_launch_data_mock_, GetApplicationDataByDevice(DeviceMac(1))) @@ -300,13 +300,13 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsNoRegister) { RunAppOnDevice(app_data.second->device_mac_, app_data.second->bundle_id_)) .Times(settings_.app_launch_max_retry_attempt()) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); } app_launch_ctrl_->OnDeviceConnected(DeviceMac(1)); const uint32_t wait_time = MAX_TEST_DURATION + settings_.app_launch_wait_time() + apps.size() * settings_.wait_time_between_apps(); - waiter.WaitFor(times, wait_time); + waiter->WaitFor(times, wait_time); } TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsInHMILevelOrder) { @@ -343,7 +343,7 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsInHMILevelOrder) { apps.push_back(app_data); } - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); const uint32_t times = apps_and_data.size(); EXPECT_CALL(app_launch_data_mock_, GetApplicationDataByDevice(DeviceMac(1))) .WillOnce(Return(apps)); @@ -356,7 +356,7 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsInHMILevelOrder) { .Times(AtLeast(1)) .WillRepeatedly(DoAll( InvokeOnAppRegistered(app_launch_ctrl_.get(), it->first.get()), - NotifyTestAsyncWaiter(&waiter))); + NotifyTestAsyncWaiter(waiter))); } app_launch_ctrl_->OnDeviceConnected(DeviceMac(1)); @@ -364,7 +364,7 @@ TEST_F(AppLaunchCtrlTest, LaunchMultipleAppsInHMILevelOrder) { const uint32_t wait_time = MAX_TEST_DURATION + settings_.app_launch_wait_time() + apps.size() * settings_.wait_time_between_apps(); - waiter.WaitFor(times, wait_time); + waiter->WaitFor(times, wait_time); } } // namespace app_launch_test diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index f566bed934..b9a74f14ba 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -72,6 +72,7 @@ #include "policy/mock_policy_manager.h" #include "policy/usage_statistics/mock_statistics_manager.h" #include "protocol_handler/mock_session_observer.h" +#include "utils/test_async_waiter.h" #include "smart_objects/enum_schema_item.h" @@ -291,40 +292,6 @@ class PolicyHandlerTest : public ::testing::Test { } }; -namespace { -/** - * @brief The WaitAsync class - * can wait for a certain amount of function calls from different - * threads, or a timeout expires. - */ -class WaitAsync { - public: - WaitAsync(const uint32_t count, const uint32_t timeout) - : count_(count), timeout_(timeout) {} - - void Notify() { - count_--; - cond_var_.NotifyOne(); - } - - bool Wait(sync_primitives::AutoLock& auto_lock) { - while (count_ > 0) { - sync_primitives::ConditionalVariable::WaitStatus wait_status = - cond_var_.WaitFor(auto_lock, timeout_); - if (wait_status == sync_primitives::ConditionalVariable::kTimeout) { - return false; - } - } - return true; - } - - private: - int count_; - const uint32_t timeout_; - sync_primitives::ConditionalVariable cond_var_; -}; -} // namespace - TEST_F(PolicyHandlerTest, LoadPolicyLibrary_Method_ExpectLibraryLoaded) { // Check before policy enabled from ini file EXPECT_CALL(policy_settings_, enable_policy()).WillRepeatedly(Return(false)); @@ -2258,24 +2225,20 @@ TEST_F(PolicyHandlerTest, EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId_)); EXPECT_CALL(*mock_app_, device()).WillOnce(Return(device)); - sync_primitives::Lock wait_hmi_lock_first; - sync_primitives::AutoLock auto_lock_first(wait_hmi_lock_first); - WaitAsync waiter_first(kCallsCount_, kTimeout_); + auto waiter_first = TestAsyncWaiter::createInstance(); #ifdef EXTERNAL_PROPRIETARY_MODE EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_, _)) - .WillOnce(NotifyAsync(&waiter_first)); + .WillOnce(NotifyTestAsyncWaiter(waiter_first)); #else EXPECT_CALL(*mock_policy_manager_, SetUserConsentForApp(_)) - .WillOnce(NotifyAsync(&waiter_first)); + .WillOnce(NotifyTestAsyncWaiter(waiter_first)); #endif ExternalConsentStatusItem item(1u, 1u, kStatusOn); ExternalConsentStatus external_consent_status; external_consent_status.insert(item); #ifdef EXTERNAL_PROPRIETARY_MODE - sync_primitives::Lock wait_hmi_lock_second; - sync_primitives::AutoLock auto_lock_second(wait_hmi_lock_second); - WaitAsync waiter_second(kCallsCount_, kTimeout_); + auto waiter_second = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_policy_manager_, SetExternalConsentStatus(external_consent_status)) @@ -2286,9 +2249,9 @@ TEST_F(PolicyHandlerTest, policy_handler_.OnAppPermissionConsent(kConnectionKey_, permissions); #endif - EXPECT_TRUE(waiter_first.Wait(auto_lock_first)); + EXPECT_TRUE(waiter_first->WaitFor(kCallsCount_, kTimeout_)); #ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_TRUE(waiter_second.Wait(auto_lock_second)); + EXPECT_TRUE(waiter_second->WaitFor(kCallsCount_, kTimeout_)); #endif } @@ -2309,9 +2272,7 @@ TEST_F(PolicyHandlerTest, permissions.group_permissions.push_back(group_permission_allowed); - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(app_manager_, application(_)).Times(0); @@ -2328,7 +2289,7 @@ TEST_F(PolicyHandlerTest, policy_handler_.OnAppPermissionConsent(invalid_connection_key, permissions); #endif - EXPECT_FALSE(waiter.Wait(auto_lock)); + EXPECT_FALSE(waiter->WaitFor(kCallsCount_, kTimeout_)); } TEST_F(PolicyHandlerTest, @@ -2348,9 +2309,7 @@ TEST_F(PolicyHandlerTest, permissions.group_permissions.push_back(group_permission_allowed); - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(app_manager_, application(_)).Times(0); @@ -2369,7 +2328,7 @@ TEST_F(PolicyHandlerTest, policy_handler_.OnAppPermissionConsent(invalid_connection_key, permissions); #endif - EXPECT_FALSE(waiter.Wait(auto_lock)); + EXPECT_FALSE(waiter->WaitFor(kCallsCount_, kTimeout_)); } ACTION_P(SetDeviceParamsMacAdress, mac_adress) { @@ -2421,13 +2380,11 @@ TEST_F(PolicyHandlerTest, ExternalConsentStatus external_consent_status; external_consent_status.insert(item); #ifdef EXTERNAL_PROPRIETARY_MODE - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_policy_manager_, SetExternalConsentStatus(external_consent_status)) - .WillOnce(DoAll(NotifyAsync(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); policy_handler_.OnAppPermissionConsent( invalid_connection_key, permissions, external_consent_status); #else @@ -2436,7 +2393,7 @@ TEST_F(PolicyHandlerTest, Mock::VerifyAndClearExpectations(mock_app_.get()); #ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_TRUE(waiter.Wait(auto_lock)); + EXPECT_TRUE(waiter->WaitFor(kCallsCount_, kTimeout_)); #endif } @@ -2485,9 +2442,7 @@ TEST_F(PolicyHandlerTest, ExternalConsentStatus external_consent_status; external_consent_status.insert(item); #ifdef EXTERNAL_PROPRIETARY_MODE - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter = TestAsyncWaiter::createInstance(); ON_CALL(*mock_policy_manager_, IsNeedToUpdateExternalConsentStatus(_)) .WillByDefault(Return(false)); @@ -2502,7 +2457,7 @@ TEST_F(PolicyHandlerTest, Mock::VerifyAndClearExpectations(mock_app_.get()); #ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_FALSE(waiter.Wait(auto_lock)); + EXPECT_FALSE(waiter->WaitFor(kCallsCount_, kTimeout_)); #endif } @@ -2553,37 +2508,33 @@ TEST_F(PolicyHandlerTest, AddStatisticsInfo_UnknownStatistics_UNSUCCESS) { TEST_F(PolicyHandlerTest, AddStatisticsInfo_SUCCESS) { EnablePolicyAndPolicyManagerMock(); - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_policy_manager_, Increment(_)) - .WillOnce(NotifyAsync(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); policy_handler_.AddStatisticsInfo( hmi_apis::Common_StatisticsType::iAPP_BUFFER_FULL); - EXPECT_TRUE(waiter.Wait(auto_lock)); + EXPECT_TRUE(waiter->WaitFor(kCallsCount_, kTimeout_)); } TEST_F(PolicyHandlerTest, OnSystemError_SUCCESS) { EnablePolicyAndPolicyManagerMock(); - sync_primitives::Lock wait_hmi_lock; - sync_primitives::AutoLock auto_lock(wait_hmi_lock); - WaitAsync waiter(kCallsCount_, kTimeout_); + auto waiter_first = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_policy_manager_, Increment(_)) - .WillOnce(NotifyAsync(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter_first)); policy_handler_.OnSystemError(hmi_apis::Common_SystemError::SYNC_REBOOTED); - EXPECT_TRUE(waiter.Wait(auto_lock)); + EXPECT_TRUE(waiter_first->WaitFor(kCallsCount_, kTimeout_)); - WaitAsync waiter1(kCallsCount_, kTimeout_); - EXPECT_CALL(*mock_policy_manager_, Increment(_)) - .WillOnce(NotifyAsync(&waiter1)); + auto waiter_second = TestAsyncWaiter::createInstance(); + EXPECT_CALL(*mock_policy_manager_, Increment(_)) + .WillOnce(NotifyTestAsyncWaiter(waiter_second)); policy_handler_.OnSystemError( hmi_apis::Common_SystemError::SYNC_OUT_OF_MEMMORY); - EXPECT_TRUE(waiter1.Wait(auto_lock)); + EXPECT_TRUE(waiter_second->WaitFor(kCallsCount_, kTimeout_)); } TEST_F(PolicyHandlerTest, RemoteAppsUrl_EndpointsEmpty_UNSUCCESS) { diff --git a/src/components/application_manager/test/request_controller/request_controller_test.cc b/src/components/application_manager/test/request_controller/request_controller_test.cc index 71e12b2825..992bf8e303 100644 --- a/src/components/application_manager/test/request_controller/request_controller_test.cc +++ b/src/components/application_manager/test/request_controller/request_controller_test.cc @@ -162,35 +162,35 @@ class RequestControllerTestClass : public ::testing::Test { TEST_F(RequestControllerTestClass, AddMobileRequest_DuplicateCorrelationId_INVALID_ID) { RequestPtr request_valid = GetMockRequest(); - TestAsyncWaiter waiter_valid; + auto waiter_valid = TestAsyncWaiter::createInstance(); ON_CALL(*request_valid, default_timeout()).WillByDefault(Return(0)); EXPECT_CALL(*request_valid, Init()).WillOnce(Return(true)); EXPECT_CALL(*request_valid, Run()) .Times(1) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter_valid)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter_valid)); EXPECT_EQ(RequestController::SUCCESS, AddRequest(default_settings_, request_valid, RequestInfo::RequestType::MobileRequest, mobile_apis::HMILevel::HMI_NONE)); - EXPECT_TRUE(waiter_valid.WaitFor(1, 1000)); + EXPECT_TRUE(waiter_valid->WaitFor(1, 1000)); // The command should not be run if another command with the same // correlation_id is waiting for a response RequestPtr request_dup_corr_id = GetMockRequest(); - TestAsyncWaiter waiter_dup; + auto waiter_dup = TestAsyncWaiter::createInstance(); ON_CALL(*request_dup_corr_id, default_timeout()).WillByDefault(Return(0)); EXPECT_CALL(*request_dup_corr_id, Init()).WillOnce(Return(true)); ON_CALL(*request_dup_corr_id, Run()) - .WillByDefault(NotifyTestAsyncWaiter(&waiter_dup)); + .WillByDefault(NotifyTestAsyncWaiter(waiter_dup)); EXPECT_EQ(RequestController::SUCCESS, AddRequest(default_settings_, request_dup_corr_id, RequestInfo::RequestType::MobileRequest, mobile_apis::HMILevel::HMI_NONE)); - EXPECT_FALSE(waiter_dup.WaitFor(1, 1000)); + EXPECT_FALSE(waiter_dup->WaitFor(1, 1000)); } TEST_F(RequestControllerTestClass, @@ -282,17 +282,17 @@ TEST_F(RequestControllerTestClass, OnTimer_SUCCESS) { RequestPtr mock_request = GetMockRequest( kDefaultCorrelationID, kDefaultConnectionKey, request_timeout); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_EQ(RequestController::SUCCESS, AddRequest(default_settings_, mock_request, RequestInfo::RequestType::MobileRequest)); EXPECT_CALL(*mock_request, onTimeOut()) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); // Waiting for call of `onTimeOut` for `kTimeScale` seconds - EXPECT_TRUE(waiter.WaitFor(1, kTimeScale)); + EXPECT_TRUE(waiter->WaitFor(1, kTimeScale)); } } // namespace request_controller_test diff --git a/src/components/application_manager/test/rpc_passing_handler_test.cc b/src/components/application_manager/test/rpc_passing_handler_test.cc index 6eac6ca0b1..4e7f401646 100644 --- a/src/components/application_manager/test/rpc_passing_handler_test.cc +++ b/src/components/application_manager/test/rpc_passing_handler_test.cc @@ -390,7 +390,7 @@ TEST_F(RPCPassingHandlerTest, TEST_F(RPCPassingHandlerTest, RPCPassingTest_REQUEST_Timeout) { uint32_t timeout_in_ms = 4; - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); app_services_.push_back(CreateAppService( kConnectionKey_NAV_ASP, "Navigation service", "NAVIGATION")); 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 87dac9182e..1e66454ce7 100644 --- a/src/components/connection_handler/test/connection_handler_impl_test.cc +++ b/src/components/connection_handler/test/connection_handler_impl_test.cc @@ -1045,34 +1045,34 @@ TEST_F(ConnectionHandlerTest, CloseSessionWithCommonReason) { connection_handler_->set_protocol_handler(&mock_protocol_handler_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_protocol_handler_, SendEndSession(uid_, out_context_.new_session_id_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; InSequence seq; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kMobileNav, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kAudio, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kBulk, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kRpc, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_handler_->CloseSession(connection_key_, kCommon); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ConnectionHandlerTest, CloseSessionWithFloodReason) { @@ -1087,34 +1087,34 @@ TEST_F(ConnectionHandlerTest, CloseSessionWithFloodReason) { connection_handler_->set_protocol_handler(&mock_protocol_handler_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_protocol_handler_, SendEndSession(uid_, out_context_.new_session_id_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; InSequence seq; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kMobileNav, kFlood)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kAudio, kFlood)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kBulk, kFlood)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kRpc, kFlood)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_handler_->CloseSession(connection_key_, kFlood); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ConnectionHandlerTest, CloseSessionWithMalformedMessage) { @@ -1129,7 +1129,7 @@ TEST_F(ConnectionHandlerTest, CloseSessionWithMalformedMessage) { connection_handler_->set_protocol_handler(&mock_protocol_handler_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_protocol_handler_, SendEndSession(uid_, out_context_.new_session_id_)) @@ -1138,24 +1138,24 @@ TEST_F(ConnectionHandlerTest, CloseSessionWithMalformedMessage) { InSequence seq; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kMobileNav, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kAudio, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kBulk, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kRpc, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_handler_->CloseSession(connection_key_, kMalformed); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ConnectionHandlerTest, CloseConnectionSessionsWithMalformedMessage) { @@ -1170,7 +1170,7 @@ TEST_F(ConnectionHandlerTest, CloseConnectionSessionsWithMalformedMessage) { connection_handler_->set_protocol_handler(&mock_protocol_handler_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_protocol_handler_, SendEndSession(uid_, out_context_.new_session_id_)) @@ -1179,24 +1179,24 @@ TEST_F(ConnectionHandlerTest, CloseConnectionSessionsWithMalformedMessage) { InSequence seq; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kMobileNav, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kAudio, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kBulk, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kRpc, kMalformed)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_handler_->CloseConnectionSessions(uid_, kMalformed); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ConnectionHandlerTest, CloseConnectionSessionsInvalidConnectionId) { @@ -1229,34 +1229,34 @@ TEST_F(ConnectionHandlerTest, CloseConnectionSessionsWithCommonReason) { connection_handler_->set_protocol_handler(&mock_protocol_handler_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_protocol_handler_, SendEndSession(uid_, out_context_.new_session_id_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; InSequence seq; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kMobileNav, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kAudio, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kBulk, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_connection_handler_observer, OnServiceEndedCallback(connection_key_, kRpc, kCommon)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_handler_->CloseConnectionSessions(uid_, kCommon); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ConnectionHandlerTest, StartService_withServices) { diff --git a/src/components/connection_handler/test/heart_beat_monitor_test.cc b/src/components/connection_handler/test/heart_beat_monitor_test.cc index d736255134..2ca8a46184 100644 --- a/src/components/connection_handler/test/heart_beat_monitor_test.cc +++ b/src/components/connection_handler/test/heart_beat_monitor_test.cc @@ -123,19 +123,19 @@ TEST_F(HeartBeatMonitorTest, TimerElapsed) { const uint32_t session = connection_->AddNewSession(kDefaultConnectionHandle); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(connection_handler_mock_, CloseSession(_, session, _)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), RemoveSession(connection_, session))); times++; EXPECT_CALL(connection_handler_mock_, SendHeartBeat(_, session)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_->StartHeartBeat(session); - EXPECT_TRUE(waiter.WaitFor( + EXPECT_TRUE(waiter->WaitFor( times, 2 * timeout_ * MICROSECONDS_IN_MILLISECONDS + MICROSECONDS_IN_SECOND)); } @@ -166,13 +166,13 @@ TEST_F(HeartBeatMonitorTest, NotKeptAlive) { const uint32_t session = connection_->AddNewSession(kDefaultConnectionHandle); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(connection_handler_mock_, SendHeartBeat(_, session)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(connection_handler_mock_, CloseSession(_, session, _)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), RemoveSession(connection_, session))); times++; @@ -180,7 +180,7 @@ TEST_F(HeartBeatMonitorTest, NotKeptAlive) { usleep(timeout_); connection_->KeepAlive(session); - EXPECT_TRUE(waiter.WaitFor( + EXPECT_TRUE(waiter->WaitFor( times, 2 * timeout_ * MICROSECONDS_IN_MILLISECONDS + MICROSECONDS_IN_SECOND)); } @@ -203,28 +203,28 @@ TEST_F(HeartBeatMonitorTest, TwoSessionsElapsed) { const uint32_t kSession2 = connection_->AddNewSession(kAnotherConnectionHandle); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(connection_handler_mock_, CloseSession(_, kSession1, _)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), RemoveSession(connection_, kSession1))); times++; EXPECT_CALL(connection_handler_mock_, CloseSession(_, kSession2, _)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), RemoveSession(connection_, kSession2))); times++; EXPECT_CALL(connection_handler_mock_, SendHeartBeat(_, kSession1)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(connection_handler_mock_, SendHeartBeat(_, kSession2)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; connection_->StartHeartBeat(kSession1); connection_->StartHeartBeat(kSession2); - EXPECT_TRUE(waiter.WaitFor( + EXPECT_TRUE(waiter->WaitFor( times, 2 * timeout_ * MICROSECONDS_IN_MILLISECONDS + MICROSECONDS_IN_SECOND)); } @@ -256,21 +256,21 @@ TEST_F(HeartBeatMonitorTest, DecreaseHeartBeatTimeout) { const uint32_t kSession = connection_->AddNewSession(kDefaultConnectionHandle); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(connection_handler_mock_, CloseSession(_, kSession, _)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), RemoveSession(connection_, kSession))); times++; EXPECT_CALL(connection_handler_mock_, SendHeartBeat(_, kSession)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; const uint32_t new_timeout = timeout_ - kTime_offset; connection_->StartHeartBeat(kSession); connection_->SetHeartBeatTimeout(new_timeout, kSession); - EXPECT_TRUE(waiter.WaitFor( + EXPECT_TRUE(waiter->WaitFor( times, 2 * timeout_ * MICROSECONDS_IN_MILLISECONDS + MICROSECONDS_IN_SECOND)); } diff --git a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc index c9ad49efed..a750bc236b 100644 --- a/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc +++ b/src/components/hmi_message_handler/test/hmi_message_handler_impl_test.cc @@ -175,11 +175,11 @@ TEST_F(HMIMessageHandlerImplTest, OnMessageReceived_InvalidObserver_Cancelled) { TEST_F(HMIMessageHandlerImplTest, SendMessageToHMI_Success) { hmi_message_handler::MessageSharedPointer message = CreateMessage(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); MockHMIMessageAdapterImpl message_adapter(hmi_handler_); EXPECT_CALL(message_adapter, SendMessageToHMI(message)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); hmi_handler_->AddHMIMessageAdapter(&message_adapter); hmi_handler_->SendMessageToHMI(message); @@ -187,7 +187,7 @@ TEST_F(HMIMessageHandlerImplTest, SendMessageToHMI_Success) { // Wait for the message to be processed hmi_handler_->messages_to_hmi()->WaitDumpQueue(); - EXPECT_TRUE(waiter.WaitFor(1, 100)); + EXPECT_TRUE(waiter->WaitFor(1, 100)); } TEST(WebsocketSessionTest, SendMessage_UnpreparedConnection_WithoutFall) { diff --git a/src/components/include/test/utils/test_async_waiter.h b/src/components/include/test/utils/test_async_waiter.h index 12d6cd04b7..6ad9ca12c5 100644 --- a/src/components/include/test/utils/test_async_waiter.h +++ b/src/components/include/test/utils/test_async_waiter.h @@ -48,17 +48,15 @@ namespace test { * * Usage example: * TEST() { - * TestAsyncWaiter waiter; + * auto waiter = TestAsyncWaiter::createInstance(); * EXPECT_CALL(mock, InterestingCall()) * .Times(n) - * .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); - * EXPECT_TRUE(waiter.WaitFor(n, 1000)); + * .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); + * EXPECT_TRUE(waiter->WaitFor(n, 1000)); * } */ class TestAsyncWaiter { public: - TestAsyncWaiter() : notified_(false), count_(0), lock_(), cond_var_() {} - /** * @brief WaitFor * Waits for specified number of notifications but not longer @@ -80,6 +78,10 @@ class TestAsyncWaiter { return true; } + static std::shared_ptr<TestAsyncWaiter> createInstance() { + return std::shared_ptr<TestAsyncWaiter>(new TestAsyncWaiter()); + } + /** * @brief Notify * Notifies async waiter @@ -92,6 +94,8 @@ class TestAsyncWaiter { } private: + TestAsyncWaiter() : notified_(false), count_(0), lock_(), cond_var_() {} + bool notified_; uint32_t count_; sync_primitives::Lock lock_; diff --git a/src/components/policy/policy_external/test/update_status_manager_test.cc b/src/components/policy/policy_external/test/update_status_manager_test.cc index 29952bd18e..c5b8f78c77 100644 --- a/src/components/policy/policy_external/test/update_status_manager_test.cc +++ b/src/components/policy/policy_external/test/update_status_manager_test.cc @@ -37,6 +37,7 @@ #include "policy/policy_manager_impl.h" #include "utils/conditional_variable.h" +#include "utils/test_async_waiter.h" namespace test { namespace components { @@ -78,44 +79,6 @@ class UpdateStatusManagerTest : public ::testing::Test { void TearDown() OVERRIDE {} }; -namespace { -/** - * @brief The WaitAsync class - * can wait for a certain amount of function calls from different - * threads, or a timeout expires. - */ -class WaitAsync { - public: - WaitAsync(const uint32_t count, const uint32_t timeout) - : count_(count), timeout_(timeout) {} - - void Notify() { - count_--; - cond_var_.NotifyOne(); - } - - bool Wait(sync_primitives::AutoLock& auto_lock) { - while (count_ > 0) { - sync_primitives::ConditionalVariable::WaitStatus wait_status = - cond_var_.WaitFor(auto_lock, timeout_); - if (wait_status == sync_primitives::ConditionalVariable::kTimeout) { - return false; - } - } - return true; - } - - private: - int count_; - const uint32_t timeout_; - sync_primitives::ConditionalVariable cond_var_; -}; -} // namespace - -ACTION_P(NotifyAsync, waiter) { - waiter->Notify(); -} - ACTION_P2(RetryFailed, manager, listener) { manager->OnResetRetrySequence(); listener->OnPTUFinished(false); @@ -124,18 +87,17 @@ ACTION_P2(RetryFailed, manager, listener) { TEST_F(UpdateStatusManagerTest, OnUpdateSentOut_WaitForTimeoutExpired_ExpectStatusUpdateNeeded) { // Arrange - sync_primitives::Lock lock; - sync_primitives::AutoLock auto_lock(lock); const uint32_t count = 3u; const uint32_t timeout = 2u * k_timeout_; - WaitAsync waiter(count, timeout); + auto waiter = TestAsyncWaiter::createInstance(); + EXPECT_CALL(listener_, OnUpdateStatusChanged(_)) - .WillRepeatedly(NotifyAsync(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); manager_->ScheduleUpdate(); manager_->OnUpdateSentOut(k_timeout_); status_ = manager_->GetLastUpdateStatus(); EXPECT_EQ(StatusUpdatePending, status_); - EXPECT_TRUE(waiter.Wait(auto_lock)); + EXPECT_TRUE(waiter->WaitFor(count, timeout)); status_ = manager_->GetLastUpdateStatus(); // Check EXPECT_EQ(StatusUpdateRequired, status_); @@ -148,9 +110,9 @@ TEST_F( sync_primitives::AutoLock auto_lock(lock); const uint32_t count = 3u; const uint32_t timeout = 2u * k_timeout_; - WaitAsync waiter(count, timeout); + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(listener_, OnUpdateStatusChanged(_)) - .WillRepeatedly(NotifyAsync(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); EXPECT_CALL(mock_ptu_retry_handler_, RetrySequenceFailed()) .WillOnce(RetryFailed(manager_, &listener_)); manager_->ScheduleUpdate(); @@ -167,7 +129,7 @@ TEST_F( EXPECT_CALL(listener_, OnPTUFinished(false)); } EXPECT_EQ(StatusUpdatePending, status_); - EXPECT_TRUE(waiter.Wait(auto_lock)); + EXPECT_TRUE(waiter->WaitFor(count, timeout)); status_ = manager_->GetLastUpdateStatus(); // Check EXPECT_EQ(StatusUpdateRequired, status_); 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 995a96372a..86c39e3551 100644 --- a/src/components/protocol_handler/test/protocol_handler_tm_test.cc +++ b/src/components/protocol_handler/test/protocol_handler_tm_test.cc @@ -242,6 +242,7 @@ class ProtocolHandlerImplTest : public ::testing::Test { const_cast<protocol_handler::impl::ToMobileQueue&>( protocol_handler_impl->get_to_mobile_queue()) .WaitDumpQueue(); + protocol_handler_impl->Stop(); } // Emulate connection establish @@ -272,7 +273,7 @@ class ProtocolHandlerImplTest : public ::testing::Test { void AddSession(const std::shared_ptr<TestAsyncWaiter>& waiter, uint32_t& times) { using namespace protocol_handler; - ASSERT_TRUE(NULL != waiter.get()); + ASSERT_TRUE(NULL != waiter); AddConnection(); const ServiceType start_service = kRpc; @@ -548,7 +549,7 @@ TEST_F(ProtocolHandlerImplTest, const int call_times = 5; AddConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; ServiceType service_type; // Expect verification of allowed transport @@ -581,7 +582,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start rejection WillRepeatedly( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), SaveArg<2>(&service_type), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, @@ -605,7 +606,7 @@ TEST_F(ProtocolHandlerImplTest, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times += call_times; SendControlMessage( @@ -619,7 +620,7 @@ TEST_F(ProtocolHandlerImplTest, SendControlMessage( PROTECTION_OFF, kBulk, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send NAck on session_observer rejection @@ -640,7 +641,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { const bool callback_protection_flag = PROTECTION_OFF; #endif // ENABLE_SECURITY - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; ServiceType service_type; // Expect verification of allowed transport @@ -673,7 +674,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { . // Return sessions start rejection WillRepeatedly(DoAll( - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), SaveArg<2>(&service_type), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, @@ -697,7 +698,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) .Times(call_times) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times += call_times; SendControlMessage( @@ -711,7 +712,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverReject) { SendControlMessage( PROTECTION_ON, kBulk, NEW_SESSION_ID, FRAME_DATA_START_SERVICE); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack on session_observer accept @@ -723,7 +724,7 @@ TEST_F(ProtocolHandlerImplTest, AddConnection(); const ServiceType start_service = kRpc; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -750,7 +751,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -768,13 +769,13 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack on session_observer accept @@ -785,7 +786,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, StartSession_Protected_SessionObserverAccept) { SetProtocolVersion2(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -853,7 +854,7 @@ TEST_F(ProtocolHandlerImplTest, std::string("BTMAC")), connection_id2); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport @@ -896,7 +897,7 @@ TEST_F(ProtocolHandlerImplTest, An<const BsonObject*>())) // don't call NotifySessionStartedContext() immediately, instead call it // after second OnSessionStartedCallback() - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; BsonObject bson_params2; @@ -922,7 +923,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, An<const BsonObject*>())) .WillOnce(DoAll( - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id2, @@ -964,7 +965,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, connection_id1, Eq(ack_params)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; BsonArray bson_arr; @@ -986,7 +987,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, connection_id2, Eq(nack_params)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; SendTMMessage(connection_id1, @@ -1011,7 +1012,7 @@ TEST_F(ProtocolHandlerImplTest, message_id, params2.size() > 0 ? ¶ms2[0] : NULL); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); bson_object_deinitialize(&bson_params1); bson_object_deinitialize(&bson_params2); @@ -1026,7 +1027,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Audio_RejectByTransportType) { AddConnection(); const ServiceType start_service = kAudio; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1050,13 +1051,13 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Audio_RejectByTransportType) { EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* @@ -1068,7 +1069,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Video_RejectByTransportType) { AddConnection(); const ServiceType start_service = kMobileNav; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1093,13 +1094,13 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Video_RejectByTransportType) { EXPECT_CALL(transport_manager_mock, SendMessageToDevice(ControlMessage(FRAME_DATA_START_SERVICE_NACK, PROTECTION_OFF))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } // TODO(EZamakhov): add test for get_hash_id/set_hash_id from @@ -1108,7 +1109,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_Video_RejectByTransportType) { * ProtocolHandler shall send NAck on session_observer rejection */ TEST_F(ProtocolHandlerImplTest, EndSession_SessionObserverReject) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -1148,7 +1149,7 @@ TEST_F(ProtocolHandlerImplTest, EndSession_SessionObserverReject) { * ProtocolHandler shall send NAck on wrong hash code */ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -1184,7 +1185,7 @@ TEST_F(ProtocolHandlerImplTest, EndSession_Success) { #ifdef ENABLE_SECURITY TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtocoloV1) { using namespace protocol_handler; - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -1262,7 +1263,7 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { AddSecurityManager(); const ServiceType start_service = kRpc; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1289,7 +1290,7 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -1307,13 +1308,13 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionUnprotected) { EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_OFF on fail SLL creation @@ -1324,7 +1325,7 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { AddSecurityManager(); const ServiceType start_service = kRpc; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; protocol_handler::SessionContext context = GetSessionContext(connection_id, @@ -1360,7 +1361,7 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, context, @@ -1376,20 +1377,20 @@ TEST_F(ProtocolHandlerImplTest, SecurityEnable_StartSessionProtected_Fail) { ContextCreationStrategy::kUseExisting)) . // Return fail protection - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on already established and @@ -1402,7 +1403,7 @@ TEST_F(ProtocolHandlerImplTest, AddSecurityManager(); const ServiceType start_service = kRpc; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1429,7 +1430,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -1447,34 +1448,33 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key, _)) . // Return new SSLContext - WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), 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(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .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(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_OFF on session handshhake fail @@ -1486,7 +1486,7 @@ TEST_F(ProtocolHandlerImplTest, AddSecurityManager(); const ServiceType start_service = kRpc; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; protocol_handler::SessionContext context = GetSessionContext(connection_id, NEW_SESSION_ID, @@ -1521,7 +1521,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, context, @@ -1546,14 +1546,14 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(ssl_context_mock, IsInitCompleted()) . // emulate SSL is not initilized - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(false))); times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Expect add listener for handshake result @@ -1567,13 +1567,13 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -1591,7 +1591,7 @@ TEST_F(ProtocolHandlerImplTest, ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1618,7 +1618,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -1635,29 +1635,28 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key, _)) . // Return new SSLContext - WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), 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(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(false))); times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success)))); @@ -1668,26 +1667,26 @@ TEST_F(ProtocolHandlerImplTest, GetSSLContext(connection_key, start_service)) . // Emulate protection for service is not enabled - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), ReturnNull())); times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .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(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -1705,7 +1704,7 @@ TEST_F( ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1732,7 +1731,7 @@ TEST_F( . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -1749,8 +1748,7 @@ TEST_F( EXPECT_CALL(security_manager_mock, CreateSSLContext(connection_key, _)) . // Return new SSLContext - WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), Return(&ssl_context_mock))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(&ssl_context_mock))); times++; // Initilization check @@ -1763,14 +1761,14 @@ TEST_F( EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success)))); @@ -1781,26 +1779,26 @@ TEST_F( GetSSLContext(connection_key, start_service)) . // Emulate protection for service is not enabled - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), ReturnNull())); times++; // Expect service protection enable EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .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(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * ProtocolHandler shall send Ack with PROTECTION_ON on session handshhake @@ -1817,7 +1815,7 @@ TEST_F(ProtocolHandlerImplTest, ON_CALL(protocol_handler_settings_mock, force_protected_service()) .WillByDefault(ReturnRefOfCopy(services)); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect verification of allowed transport EXPECT_CALL(session_observer_mock, @@ -1844,7 +1842,7 @@ TEST_F(ProtocolHandlerImplTest, . // Return sessions start success WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), InvokeMemberFuncWithArg3(protocol_handler_impl.get(), &ProtocolHandler::NotifySessionStarted, GetSessionContext(connection_id, @@ -1864,34 +1862,33 @@ TEST_F(ProtocolHandlerImplTest, ContextCreationStrategy::kUseExisting)) . // Return new SSLContext - WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), 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(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(false))); times++; // Pending handshake check EXPECT_CALL(ssl_context_mock, IsHandshakePending()) . // emulate is pending - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(false))); times++; // Wait restart handshake operation EXPECT_CALL(security_manager_mock, StartHandshake(connection_key)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; // Expect add listener for handshake result EXPECT_CALL(security_manager_mock, AddListener(_)) // Emulate handshake .WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), Invoke(OnHandshakeDoneFunctor( connection_key, security_manager::SSLContext::Handshake_Result_Success)))); @@ -1902,30 +1899,30 @@ TEST_F(ProtocolHandlerImplTest, GetSSLContext(connection_key, start_service)) . // Emulate protection for service is not enabled - WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), ReturnNull())); times++; EXPECT_CALL(security_manager_mock, IsSystemTimeProviderReady()) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; EXPECT_CALL(session_observer_mock, SetProtectionFlag(connection_key, start_service)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; // Expect send Ack with PROTECTION_ON (on successfull handshake) EXPECT_CALL(transport_manager_mock, SendMessageToDevice( ControlMessage(FRAME_DATA_START_SERVICE_ACK, PROTECTION_ON))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), 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)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } #endif // ENABLE_SECURITY @@ -1945,7 +1942,7 @@ void ProtocolHandlerImplTest::VerifySecondaryTransportParamsInStartSessionAck( .WillRepeatedly(Return(maximum_rpc_payload_size)); InitProtocolHandlerImpl(0u, 0u); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 5; @@ -2050,7 +2047,7 @@ void ProtocolHandlerImplTest::VerifySecondaryTransportParamsInStartSessionAck( transport_manager_mock, SendMessageToDevice(ControlMessage( FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF, connection_id, _))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; #ifdef ENABLE_SECURITY @@ -2071,7 +2068,7 @@ void ProtocolHandlerImplTest::VerifySecondaryTransportParamsInStartSessionAck( false /* protection */, full_version); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } void ProtocolHandlerImplTest::VerifyCloudAppParamsInStartSessionAck( @@ -2081,7 +2078,7 @@ void ProtocolHandlerImplTest::VerifyCloudAppParamsInStartSessionAck( .WillRepeatedly(Return(maximum_rpc_payload_size)); InitProtocolHandlerImpl(0u, 0u); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 5; @@ -2162,7 +2159,7 @@ void ProtocolHandlerImplTest::VerifyCloudAppParamsInStartSessionAck( PROTECTION_OFF, connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; #ifdef ENABLE_SECURITY @@ -2185,7 +2182,7 @@ void ProtocolHandlerImplTest::VerifyCloudAppParamsInStartSessionAck( false /* protection */, full_version); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, @@ -2549,7 +2546,7 @@ TEST_F( // Secondary transport param should not be included for apps with v5.0.0 TEST_F(ProtocolHandlerImplTest, StartSessionAck_Unprotected_NoSecondaryTransportParamsForV5) { - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 5; @@ -2620,7 +2617,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; connection_handler::SessionTransports dummy_st = {0, 0}; @@ -2653,7 +2650,7 @@ TEST_F(ProtocolHandlerImplTest, false /* protection */, full_version); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, StartSessionAck_PrimaryTransportUSBHostMode) { @@ -2721,7 +2718,7 @@ TEST_F(ProtocolHandlerImplTest, StartSessionAck_CloudAppAuthTokenAvailable) { TEST_F(ProtocolHandlerImplTest, TransportEventUpdate_afterVersionNegotiation_TCPEnabled) { - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 5; @@ -2791,7 +2788,7 @@ TEST_F(ProtocolHandlerImplTest, transport_manager_mock, SendMessageToDevice(ControlMessage( FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF, connection_id, _))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(_, _, An<uint8_t&>())) @@ -2818,7 +2815,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; #ifdef ENABLE_SECURITY @@ -2839,12 +2836,12 @@ TEST_F(ProtocolHandlerImplTest, false /* protection */, full_version); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, TransportEventUpdate_afterVersionNegotiation_TCPDisabled) { - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 5; @@ -2912,7 +2909,7 @@ TEST_F(ProtocolHandlerImplTest, transport_manager_mock, SendMessageToDevice(ControlMessage( FRAME_DATA_START_SERVICE_ACK, PROTECTION_OFF, connection_id, _))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; EXPECT_CALL(session_observer_mock, ProtocolVersionUsed(_, _, An<uint8_t&>())) @@ -2939,7 +2936,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; #ifdef ENABLE_SECURITY @@ -2960,7 +2957,7 @@ TEST_F(ProtocolHandlerImplTest, false /* protection */, full_version); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, @@ -2968,7 +2965,7 @@ TEST_F(ProtocolHandlerImplTest, using connection_handler::SessionConnectionMap; using connection_handler::SessionTransports; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; char tcp_address[] = "172.16.2.3"; @@ -3022,12 +3019,12 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, device2_primary_connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; tm_listener->OnTransportConfigUpdated(configs); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, @@ -3035,7 +3032,7 @@ TEST_F(ProtocolHandlerImplTest, using connection_handler::SessionConnectionMap; using connection_handler::SessionTransports; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; char tcp_address[] = "172.16.2.3"; @@ -3092,7 +3089,7 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, device1_primary_connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; EXPECT_CALL( transport_manager_mock, @@ -3100,18 +3097,18 @@ TEST_F(ProtocolHandlerImplTest, PROTECTION_OFF, device3_primary_connection_id, Eq(expected_param)))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; tm_listener->OnTransportConfigUpdated(configs); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_SUCCESS) { AddConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; transport_manager::ConnectionUID primary_connection_id = 123; @@ -3131,7 +3128,7 @@ TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_SUCCESS) { PROTECTION_OFF, connection_id, _))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; SendControlMessage(PROTECTION_OFF, @@ -3140,13 +3137,13 @@ TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_SUCCESS) { FRAME_DATA_REGISTER_SECONDARY_TRANSPORT, PROTOCOL_VERSION_5); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_FAILURE) { AddConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; transport_manager::ConnectionUID primary_connection_id = 123; @@ -3167,7 +3164,7 @@ TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_FAILURE) { PROTECTION_OFF, connection_id, _))) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times++; SendControlMessage(PROTECTION_OFF, @@ -3176,16 +3173,16 @@ TEST_F(ProtocolHandlerImplTest, RegisterSecondaryTransport_FAILURE) { FRAME_DATA_REGISTER_SECONDARY_TRANSPORT, PROTOCOL_VERSION_5); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification) { +TEST_F(ProtocolHandlerImplTest, FloodVerification) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3224,13 +3221,13 @@ TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_ThresholdValue) { +TEST_F(ProtocolHandlerImplTest, FloodVerification_ThresholdValue) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3268,13 +3265,13 @@ TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_ThresholdValue) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_VideoFrameSkip) { +TEST_F(ProtocolHandlerImplTest, FloodVerification_VideoFrameSkip) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3304,13 +3301,13 @@ TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_VideoFrameSkip) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_AudioFrameSkip) { +TEST_F(ProtocolHandlerImplTest, FloodVerification_AudioFrameSkip) { const size_t period_msec = 10000; const size_t max_messages = 1000; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3340,13 +3337,13 @@ TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerification_AudioFrameSkip) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_FloodVerificationDisable) { +TEST_F(ProtocolHandlerImplTest, FloodVerificationDisable) { const size_t period_msec = 0; const size_t max_messages = 0; InitProtocolHandlerImpl(period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3382,7 +3379,7 @@ TEST_F(ProtocolHandlerImplTest, MalformedVerificationDisable) { InitProtocolHandlerImpl(0u, 0u, false, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3408,13 +3405,13 @@ TEST_F(ProtocolHandlerImplTest, MalformedVerificationDisable) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, DISABLED_MalformedLimitVerification) { +TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification) { const size_t period_msec = 10000; const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3462,14 +3459,13 @@ TEST_F(ProtocolHandlerImplTest, DISABLED_MalformedLimitVerification) { EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, - DISABLED_MalformedLimitVerification_MalformedStock) { +TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedStock) { const size_t period_msec = 10000; const size_t max_messages = 100; InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3548,7 +3544,7 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_MalformedOnly) { InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3608,7 +3604,7 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullTimePeriod) { InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3641,7 +3637,7 @@ TEST_F(ProtocolHandlerImplTest, MalformedLimitVerification_NullCount) { InitProtocolHandlerImpl(0u, 0u, true, period_msec, max_messages); AddConnection(); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3731,10 +3727,9 @@ TEST_F(ProtocolHandlerImplTest, protocol_handler_impl->SendEndSession(connection_id, session_id); } -TEST_F(ProtocolHandlerImplTest, - DISABLED_SendEndServicePrivate_EndSession_MessageSent) { +TEST_F(ProtocolHandlerImplTest, SendEndServicePrivate_EndSession_MessageSent) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3761,7 +3756,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, SendEndServicePrivate_ServiceTypeControl_MessageSent) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3800,7 +3795,7 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeat_NoConnection_NotSent) { TEST_F(ProtocolHandlerImplTest, SendHeartBeat_Successful) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3825,7 +3820,7 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeat_Successful) { TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_Successful) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3855,7 +3850,7 @@ TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_Successful) { TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_ProtocolVersionUsedFail_Cancelled) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3876,10 +3871,9 @@ TEST_F(ProtocolHandlerImplTest, EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } -TEST_F(ProtocolHandlerImplTest, - DISABLED_SendHeartBeatAck_WrongProtocolVersion_NotSent) { +TEST_F(ProtocolHandlerImplTest, SendHeartBeatAck_WrongProtocolVersion_NotSent) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3913,7 +3907,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendSingleControlMessage) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3954,7 +3948,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendSingleNonControlMessage) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -3999,7 +3993,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendMultiframeMessage) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4058,7 +4052,7 @@ TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_SendMultiframeMessage) { TEST_F(ProtocolHandlerImplTest, SendMessageToMobileApp_NullMessagePointer_Cancelled) { // Arrange - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4471,7 +4465,7 @@ TEST_F(ProtocolHandlerImplTest, GetHashId_ProtocolVersion5_ValidData) { } TEST_F(ProtocolHandlerImplTest, SetHashId_CorrectHashId) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 3; @@ -4515,7 +4509,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_CorrectHashId) { } TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_NOT_SUPPORTED) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 3; @@ -4551,7 +4545,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_NOT_SUPPORTED) { } TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_WRONG) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; const uint8_t input_protocol_version = 3; @@ -4589,7 +4583,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_WRONG) { TEST_F(ProtocolHandlerImplTest, PopValidAndExpiredMultiframes) { using namespace protocol_handler; - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4633,7 +4627,7 @@ TEST_F(ProtocolHandlerImplTest, PopValidAndExpiredMultiframes) { } TEST_F(ProtocolHandlerImplTest, HandleFromMobile_FrameTypeSingle_Handled) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4660,7 +4654,7 @@ TEST_F(ProtocolHandlerImplTest, HandleFromMobile_FrameTypeSingle_Handled) { #ifdef ENABLE_SECURITY TEST_F(ProtocolHandlerImplTest, EncryptFrame_NoSecurityManagerSet_Cancelled) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4691,7 +4685,7 @@ TEST_F(ProtocolHandlerImplTest, EncryptFrame_NoSecurityManagerSet_Cancelled) { TEST_F(ProtocolHandlerImplTest, EncryptFrame_ControlFrameType_ContinueUnencrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4723,7 +4717,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, EncryptFrame_SSLContextInitNotCompleted_ContinueUnencrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4763,7 +4757,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, EncryptFrame_EncryptFailed_ContinueUnencrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4817,7 +4811,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, EncryptFrame_EncryptSucceeded_ContinueEncrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4867,7 +4861,7 @@ TEST_F(ProtocolHandlerImplTest, } TEST_F(ProtocolHandlerImplTest, DecryptFrame_NoSecurityManager_Cancelled) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4898,28 +4892,29 @@ TEST_F(ProtocolHandlerImplTest, DecryptFrame_NoSecurityManager_Cancelled) { } TEST_F(ProtocolHandlerImplTest, - DISABLED_DecryptFrame_ProtectionFlagOff_ContinueUndecrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + DecryptFrame_ProtectionFlagOff_ContinueUndecrypted) { + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); - - const uint8_t data_size = 0u; + const uint8_t data_size = 1u; + const uint8_t data_value = 7u; ProtocolFramePtr frame_ptr = std::make_shared<ProtocolPacket>(connection_id, PROTOCOL_VERSION_3, PROTECTION_OFF, - FRAME_TYPE_FIRST, + FRAME_TYPE_SINGLE, kAudio, - FRAME_DATA_FIRST, + FRAME_DATA_SINGLE, session_id, data_size, message_id, - null_data_); + &data_value); EXPECT_CALL(ssl_context_mock, Decrypt(_, _, _, _)).Times(0); protocol_handler_impl->SetTelemetryObserver(&telemetry_observer_mock); EXPECT_CALL(telemetry_observer_mock, StartMessageProcess(message_id, _)); + EXPECT_CALL(telemetry_observer_mock, EndMessageProcess(_)); connection_handler::SessionTransports st; st.primary_transport = connection_id; @@ -4932,8 +4927,8 @@ TEST_F(ProtocolHandlerImplTest, } TEST_F(ProtocolHandlerImplTest, - DISABLED_DecryptFrame_FrameTypeControl_ContinueUndecrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + DecryptFrame_FrameTypeControl_ContinueUndecrypted) { + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -4970,7 +4965,7 @@ TEST_F(ProtocolHandlerImplTest, TEST_F(ProtocolHandlerImplTest, DecryptFrame_SSLContextInitNotCompleted_Cancelled) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -5004,7 +4999,7 @@ TEST_F(ProtocolHandlerImplTest, } TEST_F(ProtocolHandlerImplTest, DecryptFrame_DecryptFailed_Cancelled) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -5048,7 +5043,7 @@ TEST_F(ProtocolHandlerImplTest, DecryptFrame_DecryptFailed_Cancelled) { TEST_F(ProtocolHandlerImplTest, DecryptFrame_DecryptSucceeded_ContinueDecrypted) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -5115,7 +5110,7 @@ TEST_F(ProtocolHandlerImplTest, SendFrame_EncryptFailed_FAIL) { #endif // ENABLE_SECURITY TEST_F(ProtocolHandlerImplTest, SendServiceDataAck_PreVersion5) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -5142,7 +5137,7 @@ TEST_F(ProtocolHandlerImplTest, SendServiceDataAck_PreVersion5) { } TEST_F(ProtocolHandlerImplTest, SendServiceDataAck_AfterVersion5) { - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); @@ -5255,7 +5250,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_NACKReason_SessionObserverReject) { .WillRepeatedly(ReturnNull()); #endif // ENABLE_SECURITY - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; ServiceType service_type; // Expect verification of allowed transport @@ -5284,7 +5279,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_NACKReason_SessionObserverReject) { . // Return sessions start rejection WillRepeatedly( - DoAll(NotifyTestAsyncWaiter(&waiter), + DoAll(NotifyTestAsyncWaiter(waiter), SaveArg<2>(&service_type), InvokeMemberFuncWithArg3( protocol_handler_impl.get(), @@ -5323,7 +5318,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_NACKReason_SessionObserverReject) { Eq(nack_params)))) .Times(call_times) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(E_SUCCESS))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(E_SUCCESS))); times += call_times; for (const ServiceType& service_type : service_types) { @@ -5334,7 +5329,7 @@ TEST_F(ProtocolHandlerImplTest, StartSession_NACKReason_SessionObserverReject) { PROTOCOL_VERSION_5); } - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* @@ -5346,7 +5341,7 @@ TEST_F(ProtocolHandlerImplTest, const utils::SemanticVersion min_reason_param_version(5, 3, 0); std::string err_reason = "Wrong hash_id for session " + std::to_string(session_id); - std::shared_ptr<TestAsyncWaiter> waiter = std::make_shared<TestAsyncWaiter>(); + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; AddSession(waiter, times); diff --git a/src/components/security_manager/test/security_manager_test.cc b/src/components/security_manager/test/security_manager_test.cc index 4145334115..912ffff4c7 100644 --- a/src/components/security_manager/test/security_manager_test.cc +++ b/src/components/security_manager/test/security_manager_test.cc @@ -284,7 +284,7 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)); EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) @@ -295,14 +295,14 @@ TEST_F(SecurityManagerTest, SecurityManager_NULLCryptoManager) { InternalErrorWithErrId(SecurityManager::ERROR_NOT_SUPPORTED), false, kIsFinal)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST, // It could be any query id SecurityQuery::INVALID_QUERY_ID); const uint8_t data = 0; EmulateMobileMessage(header, &data, 1); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } /* * Shall skip all OnMobileMessageSent @@ -377,14 +377,14 @@ TEST_F(SecurityManagerTest, GetInvalidQueryId) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Expect InternalError with ERROR_ID @@ -394,14 +394,14 @@ TEST_F(SecurityManagerTest, GetInvalidQueryId) { InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_ID), false, kIsFinal)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; const SecurityQuery::QueryHeader header(SecurityQuery::REQUEST, SecurityQuery::INVALID_QUERY_ID); const uint8_t data = 0; EmulateMobileMessage(header, &data, 1); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); } /* * Shall send Internall Error on call @@ -577,7 +577,7 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_WrongDataSize) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)); EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) @@ -590,11 +590,11 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_WrongDataSize) { InternalErrorWithErrId(SecurityManager::ERROR_INVALID_QUERY_SIZE), false, kIsFinal)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); EmulateMobileMessageHandshake(NULL, 0); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } /* * Shall send InternallError on @@ -607,14 +607,14 @@ TEST_F(SecurityManagerTest, DISABLED_ProcessHandshakeData_ServiceNotProtected) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; EXPECT_CALL( mock_protocol_handler, @@ -622,24 +622,24 @@ TEST_F(SecurityManagerTest, DISABLED_ProcessHandshakeData_ServiceNotProtected) { InternalErrorWithErrId(SecurityManager::ERROR_SERVICE_NOT_PROTECTED), false, kIsFinal)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); times++; // Expect notifying listeners (unsuccess) EXPECT_CALL(*mock_sm_listener, OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Emulate SessionObserver result EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), ReturnNull())); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), ReturnNull())); times++; const uint8_t data[] = {0x1, 0x2}; EmulateMobileMessageHandshake(data, sizeof(data) / sizeof(data[0])); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); // Listener was destroyed after OnHandshakeDone call mock_sm_listener.release(); @@ -658,16 +658,16 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_InvalidData) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)) .Times(handshake_emulates) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); times += handshake_emulates; EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times += handshake_emulates; // Expect InternalError with ERROR_ID @@ -678,12 +678,12 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_InvalidData) { false, kIsFinal)) .Times(handshake_emulates) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); times += handshake_emulates; // Expect notifying listeners (unsuccess) EXPECT_CALL(*mock_sm_listener, OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Emulate SessionObserver and CryptoManager result @@ -700,19 +700,19 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_InvalidData) { _)) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_AbnormalFail))) .WillOnce(DoAll(SetArgPointee<2>((uint8_t*)NULL), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_AbnormalFail))) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(0), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_AbnormalFail))) .WillOnce(DoAll(SetArgPointee<2>((uint8_t*)NULL), SetArgPointee<3>(0), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_AbnormalFail))); times += 4; // matches to each single call above @@ -723,7 +723,7 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_InvalidData) { EmulateMobileMessageHandshake( handshake_data, handshake_data_size, handshake_emulates); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); // Listener was destroyed after OnHandshakeDone call mock_sm_listener.release(); @@ -740,16 +740,16 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_Answer) { uint32_t connection_id = 0; uint8_t session_id = 0; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; EXPECT_CALL(mock_session_observer, PairFromKey(kKey, _, _)) .Times(handshake_emulates) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); times += handshake_emulates; EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times += handshake_emulates; // Get size of raw message after @@ -758,23 +758,23 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_Answer) { SendMessageToMobileApp( RawMessageEqSize(raw_message_size), false, kIsFinal)) .Times(handshake_emulates) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); times += handshake_emulates; // Expect notifying listeners (unsuccess) EXPECT_CALL(*mock_sm_listener, OnHandshakeDone(kKey, SSLContext::Handshake_Result_Fail)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Emulate SessionObserver and CryptoManager result EXPECT_CALL(mock_ssl_context_exists, IsInitCompleted()) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(false))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(false))); times += handshake_emulates; EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl)) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(&mock_ssl_context_exists))); times += handshake_emulates; @@ -787,18 +787,18 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_Answer) { _)) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Success))) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Fail))); times += 2; // matches to each single call above EmulateMobileMessageHandshake( handshake_data, handshake_data_size, handshake_emulates); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); // Listener was destroyed after OnHandshakeDone call mock_sm_listener.release(); @@ -813,24 +813,24 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_HandshakeFinished) { // Count handshake calls const int handshake_emulates = 6; - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); uint32_t times = 0; // Expect no errors // Expect notifying listeners (success) EXPECT_CALL(*mock_sm_listener, OnHandshakeDone(kKey, SSLContext::Handshake_Result_Success)) - .WillOnce(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillOnce(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times++; // Emulate SessionObserver and CryptoManager result EXPECT_CALL(mock_session_observer, GetSSLContext(kKey, kControl)) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(&mock_ssl_context_exists))); times += handshake_emulates; EXPECT_CALL(mock_ssl_context_exists, IsInitCompleted()) .Times(handshake_emulates) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times += handshake_emulates; EXPECT_CALL( @@ -843,31 +843,31 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_HandshakeFinished) { // two states with correct out data WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Success))) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Fail))) . // two states with with null pointer data WillOnce(DoAll(SetArgPointee<2>((uint8_t*)NULL), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Success))) .WillOnce(DoAll(SetArgPointee<2>((uint8_t*)NULL), SetArgPointee<3>(handshake_data_out_size), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Fail))) . // two states with with null data size WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(0), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Success))) .WillOnce(DoAll(SetArgPointee<2>(handshake_data_out_pointer), SetArgPointee<3>(0), - NotifyTestAsyncWaiter(&waiter), + NotifyTestAsyncWaiter(waiter), Return(SSLContext::Handshake_Result_Success))); times += 6; // matches to each single call above @@ -880,19 +880,19 @@ TEST_F(SecurityManagerTest, ProcessHandshakeData_HandshakeFinished) { EXPECT_CALL(mock_session_observer, ProtocolVersionUsed(connection_id, session_id, An<uint8_t&>())) .Times(2) - .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(&waiter), Return(true))); + .WillRepeatedly(DoAll(NotifyTestAsyncWaiter(waiter), Return(true))); times += 2; // matches to the number above EXPECT_CALL(mock_protocol_handler, SendMessageToMobileApp(_, false, kIsFinal)) .Times(2) - .WillRepeatedly(NotifyTestAsyncWaiter(&waiter)); + .WillRepeatedly(NotifyTestAsyncWaiter(waiter)); times += 2; // matches to the number above // Expect NO InternalError with ERROR_ID EmulateMobileMessageHandshake( handshake_data, handshake_data_size, handshake_emulates); - EXPECT_TRUE(waiter.WaitFor(times, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout)); // Listener was destroyed after OnHandshakeDone call mock_sm_listener.release(); diff --git a/src/components/transport_manager/test/platform_specific/linux/linux_network_interface_listener_test.cc b/src/components/transport_manager/test/platform_specific/linux/linux_network_interface_listener_test.cc index befba30fbd..73cc8a5e9a 100644 --- a/src/components/transport_manager/test/platform_specific/linux/linux_network_interface_listener_test.cc +++ b/src/components/transport_manager/test/platform_specific/linux/linux_network_interface_listener_test.cc @@ -119,10 +119,10 @@ TEST_F(NetworkInterfaceListenerTest, Start_success) { // after stated, it is expected that the listener notifies current IP address // (if it's available) - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(mock_tcp_client_listener_, OnIPAddressUpdated(entries[0].ipv4_address, "")) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); EXPECT_TRUE(interface_listener_impl_->Start()); @@ -131,7 +131,7 @@ TEST_F(NetworkInterfaceListenerTest, Start_success) { EXPECT_TRUE(interface_listener_impl_->GetThread()->IsRunning()); - EXPECT_TRUE(waiter.WaitFor(1, kStartNotificationTimeoutMsec)); + EXPECT_TRUE(waiter->WaitFor(1, kStartNotificationTimeoutMsec)); Deinit(); } diff --git a/src/components/transport_manager/test/tcp_client_listener_test.cc b/src/components/transport_manager/test/tcp_client_listener_test.cc index d71db3e770..e29028b562 100644 --- a/src/components/transport_manager/test/tcp_client_listener_test.cc +++ b/src/components/transport_manager/test/tcp_client_listener_test.cc @@ -250,7 +250,7 @@ TEST_P(TcpClientListenerTest, ClientConnection) { int s = socket(AF_INET, SOCK_STREAM, 0); EXPECT_TRUE(0 <= s); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); // controller should be notified of AddDevice event DeviceSptr mock_device = std::make_shared<MockTCPDevice>( @@ -258,7 +258,7 @@ TEST_P(TcpClientListenerTest, ClientConnection) { EXPECT_CALL(adapter_controller_mock_, AddDevice(_)) .WillOnce(Return(mock_device)); EXPECT_CALL(adapter_controller_mock_, ConnectionCreated(_, _, _)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); // adapter_controller_mock_ may also receive ConnectDone() and // ConnectionFinished() from ThreadedSocketConnection. Ignore them as hey are @@ -273,7 +273,7 @@ TEST_P(TcpClientListenerTest, ClientConnection) { client_addr_len)); // since the connection is handled on another thread, wait for some time - EXPECT_TRUE(waiter.WaitFor(1, kConnectionCreatedTimeoutMsec)); + EXPECT_TRUE(waiter->WaitFor(1, kConnectionCreatedTimeoutMsec)); close(s); diff --git a/src/components/transport_manager/test/transport_manager_impl_test.cc b/src/components/transport_manager/test/transport_manager_impl_test.cc index 227367e750..52ef63f874 100644 --- a/src/components/transport_manager/test/transport_manager_impl_test.cc +++ b/src/components/transport_manager/test/transport_manager_impl_test.cc @@ -555,11 +555,11 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice) { // Arrange HandleConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, SendData(mac_address_, application_id_, test_message_)) .WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK))); + DoAll(NotifyTestAsyncWaiter(waiter), Return(TransportAdapter::OK))); #ifdef TELEMETRY_MONITOR EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get())); @@ -567,7 +567,7 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice) { EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_)); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, SendMessageToDevice_SendingFailed) { @@ -578,30 +578,30 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice_SendingFailed) { EXPECT_CALL(mock_metric_observer_, StartRawMsg(_)); #endif // TELEMETRY_MONITOR - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, SendData(mac_address_, application_id_, test_message_)) .WillOnce(Return(TransportAdapter::FAIL)); EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_)); #ifdef TELEMETRY_MONITOR EXPECT_CALL(mock_metric_observer_, StopRawMsg(_)).Times(0); #endif // TELEMETRY_MONITOR - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, SendMessageToDevice_StartTimeObserver) { // Arrange HandleConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, SendData(mac_address_, application_id_, test_message_)) .WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK))); + DoAll(NotifyTestAsyncWaiter(waiter), Return(TransportAdapter::OK))); #ifdef TELEMETRY_MONITOR EXPECT_CALL(mock_metric_observer_, StartRawMsg(_)); @@ -609,18 +609,18 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice_StartTimeObserver) { EXPECT_EQ(E_SUCCESS, tm_.SendMessageToDevice(test_message_)); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, SendMessageToDevice_SendDone) { // Arrange HandleConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, SendData(mac_address_, application_id_, test_message_)) .WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK))); + DoAll(NotifyTestAsyncWaiter(waiter), Return(TransportAdapter::OK))); #ifdef TELEMETRY_MONITOR EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get())); @@ -630,7 +630,7 @@ TEST_F(TransportManagerImplTest, SendMessageToDevice_SendDone) { HandleSendDone(); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F( @@ -639,11 +639,11 @@ TEST_F( // Arrange HandleConnection(); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, SendData(mac_address_, application_id_, test_message_)) .WillOnce( - DoAll(NotifyTestAsyncWaiter(&waiter), Return(TransportAdapter::OK))); + DoAll(NotifyTestAsyncWaiter(waiter), Return(TransportAdapter::OK))); #ifdef TELEMETRY_MONITOR EXPECT_CALL(mock_metric_observer_, StartRawMsg(test_message_.get())); @@ -654,7 +654,7 @@ TEST_F( HandleSendFailed(); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, RemoveDevice_DeviceWasAdded) { @@ -749,7 +749,7 @@ TEST_F(TransportManagerImplTest, UpdateDeviceList_RemoveDevice) { * Tests which check correct handling and receiving events */ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceDone) { - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_DONE, mock_adapter_, mac_address_, @@ -758,15 +758,15 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceDone) { error_); EXPECT_CALL(*tm_listener_, OnScanDevicesFinished()) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); tm_.ReceiveEventFromDevice(test_event); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceFail) { - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); TransportAdapterEvent test_event(EventTypeEnum::ON_SEARCH_FAIL, mock_adapter_, mac_address_, @@ -775,11 +775,11 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_OnSearchDeviceFail) { error_); EXPECT_CALL(*tm_listener_, OnScanDevicesFailed(_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); tm_.ReceiveEventFromDevice(test_event); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) { @@ -793,7 +793,7 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) { std::vector<DeviceInfo> vector_dev_info; vector_dev_info.push_back(dev_info_); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*mock_adapter_, GetDeviceList()) .Times(AtLeast(1)) .WillRepeatedly(Return(device_list_)); @@ -805,14 +805,14 @@ TEST_F(TransportManagerImplTest, ReceiveEventFromDevice_DeviceListUpdated) { .WillRepeatedly(Return(dev_info_.connection_type())); EXPECT_CALL(*tm_listener_, OnDeviceFound(dev_info_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); EXPECT_CALL(*tm_listener_, OnDeviceAdded(dev_info_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); tm_.ReceiveEventFromDevice(test_event); device_list_.pop_back(); - EXPECT_TRUE(waiter.WaitFor(2, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(2, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, CheckEvents) { @@ -972,13 +972,13 @@ TEST_F(TransportManagerImplTest, HandleMessage_ConnectionNotExist) { SendData(mac_address_, application_id_, test_message_)) .Times(0); - TestAsyncWaiter waiter; + auto waiter = TestAsyncWaiter::createInstance(); EXPECT_CALL(*tm_listener_, OnTMMessageSendFailed(_, test_message_)) - .WillOnce(NotifyTestAsyncWaiter(&waiter)); + .WillOnce(NotifyTestAsyncWaiter(waiter)); tm_.TestHandle(test_message_); - EXPECT_TRUE(waiter.WaitFor(1, kAsyncExpectationsTimeout)); + EXPECT_TRUE(waiter->WaitFor(1, kAsyncExpectationsTimeout)); } TEST_F(TransportManagerImplTest, SearchDevices_TMIsNotInitialized) { |