diff options
author | Alexander <akutsan@luxoft.com> | 2019-01-10 14:24:29 +0000 |
---|---|---|
committer | igapchuck <igapchuck@luxoft.com> | 2019-07-24 10:26:36 +0300 |
commit | 056173456d80ce93ad8266c928f442d5d20a0f3a (patch) | |
tree | 44717ab94a56c4bda98019e62775deee6a6fd395 | |
parent | 8e77a09d4c6800e28e2d8693381bb75a0d14c89e (diff) | |
download | sdl_core-056173456d80ce93ad8266c928f442d5d20a0f3a.tar.gz |
Unit tests for sdl_passanger mode lock screen dismissal
2 files changed, 62 insertions, 31 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc index 1653889789..88be43b4b3 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -1801,6 +1801,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); typedef boost::optional<bool> OptionalBool; + ON_CALL(mock_policy_handler_, LockScreenDismissalEnabledState()) .WillByDefault(Return(OptionalBool(true))); ON_CALL(app_mngr_, applications()).WillByDefault(Return(applications_)); @@ -1812,8 +1813,7 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationInvalidApp) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr message = CreateMessage(); (*message)[am::strings::msg_params][am::hmi_notification::state] = state; std::shared_ptr<Command> command = @@ -1853,14 +1853,13 @@ TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); EXPECT_CALL(mock_policy_handler_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) .WillOnce(GetMessage(message)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); command->Run(); EXPECT_EQ( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc index 52732de56d..38c21cfbc4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -53,13 +53,15 @@ namespace on_driver_distraction_notification { using ::testing::_; using ::testing::Eq; +using ::testing::NiceMock; using ::testing::Return; +using ::testing::SaveArg; + namespace am = ::application_manager; using am::commands::MessageSharedPtr; using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification; using namespace am::commands; - -typedef std::shared_ptr<OnDriverDistractionNotification> NotificationPtr; +using test::components::commands_test::MobileResultCodeIs; class HMIOnDriverDistractionNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { @@ -77,7 +79,16 @@ class HMIOnDriverDistractionNotificationTest MockAppPtr mock_app_; std::shared_ptr<sync_primitives::Lock> app_set_lock_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; + am::ApplicationSet app_set_; + DataAccessor<am::ApplicationSet> accessor; + NiceMock<policy_test::MockPolicyHandlerInterface> + mock_policy_handler_interface_; + + void InitMocksRelations() { + ON_CALL(app_mngr_, applications()).WillByDefault(Return(accessor)); + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_interface_)); + } }; MATCHER_P2(CheckNotificationParams, function_id, state, "") { @@ -97,9 +108,9 @@ ACTION_P(GetArg3, result) { arg3 = *result; } -TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_SUCCESS) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; @@ -108,30 +119,48 @@ TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); - MockAppPtr mock_app = CreateMockApp(); - am::ApplicationSet app_set; - app_set.insert(mock_app); + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); - DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); policy::CheckPermissionResult result; - result.hmi_level_permitted = policy::kRpcDisallowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); + result.hmi_level_permitted = policy::kRpcAllowed; EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) .WillOnce(GetArg3(&result)); - EXPECT_CALL(*mock_app, + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)); + command->Run(); +} + +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_PushMobileMessage_If_DisallowedByPolicy) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + NotificationPtr command( + CreateCommand<OnDriverDistractionNotification>(commands_msg)); + + ON_CALL(mock_policy_handler_interface_, LockScreenDismissalEnabledState()) + .WillByDefault(Return(OptionalBool(true))); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcDisallowed; + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(*mock_app_, PushMobileMessage(CheckNotificationParams( am::mobile_api::FunctionID::OnDriverDistractionID, state))); + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); command->Run(); } TEST_F(HMIOnDriverDistractionNotificationTest, - Run_SendNotificationToMobile_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; + Run_SendNotificationIfLockScreenDismissalMissed) { + const auto state = hmi_apis::Common_DriverDistractionState::DD_ON; MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; @@ -143,17 +172,20 @@ TEST_F(HMIOnDriverDistractionNotificationTest, policy::CheckPermissionResult result; result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); + ON_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillByDefault(GetArg3(&result)); + + MessageSharedPtr command_result; EXPECT_CALL(mock_rpc_service_, - ManageMobileCommand( - CheckNotificationParams( - am::mobile_api::FunctionID::OnDriverDistractionID, state), - Command::CommandSource::SOURCE_SDL)); + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); command->Run(); + + auto& msg_params = + (*command_result)[application_manager::strings::msg_params]; + EXPECT_FALSE(msg_params.keyExists( + application_manager::mobile_notification::lock_screen_dismissal_enabled)); } } // namespace on_driver_distraction_notification |