From 2834639ddfba276a5519551c616e5ea9e9e68184 Mon Sep 17 00:00:00 2001 From: dcherniev Date: Fri, 12 May 2017 16:10:51 +0300 Subject: [PATCH 1/2] Complement checks for invalid HMI responses Added additional check for one of the cases which should consider received HMI response as invalid response. --- .../src/commands/command_request_impl.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/components/application_manager/src/commands/command_request_impl.cc b/src/components/application_manager/src/commands/command_request_impl.cc index bafad525638..333bbe60742 100644 --- a/src/components/application_manager/src/commands/command_request_impl.cc +++ b/src/components/application_manager/src/commands/command_request_impl.cc @@ -232,8 +232,7 @@ void CommandRequestImpl::SendResponse( } // Add disallowed parameters and info from request back to response with - // appropriate - // reasons (VehicleData result codes) + // appropriate reasons (VehicleData result codes) if (result_code != mobile_apis::Result::APPLICATION_NOT_REGISTERED) { const mobile_apis::FunctionID::eType& id = static_cast(function_id()); @@ -247,7 +246,20 @@ void CommandRequestImpl::SendResponse( } response[strings::msg_params][strings::success] = success; - response[strings::msg_params][strings::result_code] = result_code; + + // In case result type was not recognized the response that we received from + // HMI is considered as invalid response + if (mobile_apis::Result::INVALID_ENUM == result_code) { + LOG4CXX_ERROR(logger_, + "HMI response contains unrecognizable result code, so it is " + "considered as invalid response"); + response[strings::msg_params][strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + response[strings::msg_params][strings::info] = + std::string("Invalid message received from vehicle"); + } else { + response[strings::msg_params][strings::result_code] = result_code; + } application_manager_.ManageMobileCommand(result, ORIGIN_SDL); } From c8d2be35b3be733ce7a559cb2be5ae278822a225 Mon Sep 17 00:00:00 2001 From: dcherniev Date: Mon, 15 May 2017 12:21:47 +0300 Subject: [PATCH 2/2] Fix for unit tests Changed few expectations in unit tests from INVALID_ENUM into GENERIC_ERROR. --- .../test/commands/mobile/alert_maneuver_request_test.cc | 2 +- .../test/commands/mobile/alert_request_test.cc | 2 +- .../test/commands/mobile/update_turn_list_request_test.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc index a835239a900..c0c85a0485c 100644 --- a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc @@ -238,7 +238,7 @@ TEST_F(AlertManeuverRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { MessageSharedPtr result_msg( CatchMobileCommandResult(CallOnEvent(*command, event))); - EXPECT_EQ(mobile_apis::Result::INVALID_ENUM, + EXPECT_EQ(mobile_apis::Result::GENERIC_ERROR, static_cast( (*result_msg)[am::strings::msg_params][am::strings::result_code] .asInt())); diff --git a/src/components/application_manager/test/commands/mobile/alert_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_request_test.cc index 43151c2d989..748feabef04 100644 --- a/src/components/application_manager/test/commands/mobile/alert_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/alert_request_test.cc @@ -355,7 +355,7 @@ TEST_F(AlertRequestTest, Run_AlertFrequencyIsTooHigh_UNSUCCESS) { TEST_F(AlertRequestTest, Run_FailToProcessSoftButtons_UNSUCCESS) { Expectations(); const mobile_apis::Result::eType result_code = - mobile_apis::Result::INVALID_ENUM; + mobile_apis::Result::GENERIC_ERROR; EXPECT_CALL(mock_message_helper_, ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) diff --git a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc b/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc index cab67e641cc..d2e518065b5 100644 --- a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc @@ -156,7 +156,7 @@ TEST_F(UpdateTurnListRequestTest, EXPECT_CALL(app_mngr_, GetPolicyHandler()) .WillOnce(ReturnRef(mock_policy_handler_)); - const mobile_result::eType kExpectedResult = mobile_result::INVALID_ENUM; + const mobile_result::eType kExpectedResult = mobile_result::GENERIC_ERROR; EXPECT_CALL(mock_message_helper_, ProcessSoftButtons((*command_msg_)[am::strings::msg_params], Eq(mock_app),