Skip to content

Commit

Permalink
Fix result code for PrepareAudioPassThru (#3854)
Browse files Browse the repository at this point in the history
* Fix result code for PrepareAudioPassThru

* Fix result code for PrepareAudioPassThru in error structure
  • Loading branch information
OlhaVorobiova authored Feb 14, 2022
1 parent 7a4a4e0 commit b74c738
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) {
hmi_apis::Common_Result::WRONG_LANGUAGE,
hmi_apis::Common_Result::RETRY,
hmi_apis::Common_Result::SAVED,
hmi_apis::Common_Result::TRUNCATED_DATA,
hmi_apis::Common_Result::UNSUPPORTED_RESOURCE);

if (is_tts_speak_success_unsuported) {
Expand All @@ -198,7 +199,7 @@ void PerformAudioPassThruRequest::on_event(const event_engine::Event& event) {
return;
}

const ResponseParams response_params = PrepareResponseParameters();
ResponseParams response_params = PrepareResponseParameters();

SendResponse(
response_params.success,
Expand All @@ -220,7 +221,9 @@ PerformAudioPassThruRequest::PrepareResponseParameters() {

response_params_.success =
PrepareResultForMobileResponse(ui_perform_info, tts_perform_info);
if (ui_perform_info.is_ok && tts_perform_info.is_unsupported_resource &&

if ((ui_perform_info.result_code == hmi_apis::Common_Result::SUCCESS) &&
ui_perform_info.is_ok && tts_perform_info.is_unsupported_resource &&
HmiInterfaces::STATE_AVAILABLE == tts_perform_info.interface_state) {
response_params_.result_code = mobile_apis::Result::WARNINGS;
response_params_.info = app_mngr::commands::MergeInfos(
Expand All @@ -231,12 +234,13 @@ PerformAudioPassThruRequest::PrepareResponseParameters() {

if (IsResultCodeUnsupported(ui_perform_info, tts_perform_info)) {
response_params_.result_code = mobile_apis::Result::UNSUPPORTED_RESOURCE;
} else {
AudioPassThruResults results = PrepareAudioPassThruResultCodeForResponse(
ui_perform_info, tts_perform_info);
response_params_.success = results.second;
response_params_.result_code = results.first;
}

AudioPassThruResults results = PrepareAudioPassThruResultCodeForResponse(
ui_perform_info, tts_perform_info);
response_params_.success = results.second;
response_params_.result_code = results.first;

response_params_.info = app_mngr::commands::MergeInfos(
ui_perform_info, ui_info_, tts_perform_info, tts_info_);

Expand Down Expand Up @@ -407,30 +411,27 @@ PerformAudioPassThruRequest::PrepareAudioPassThruResultCodeForResponse(
const hmi_apis::Common_Result::eType tts_result = tts_response.result_code;
bool result = false;

if ((ui_result == hmi_apis::Common_Result::SUCCESS) &&
(tts_result == hmi_apis::Common_Result::SUCCESS)) {
result = true;
}

if ((ui_result == hmi_apis::Common_Result::SUCCESS) &&
(tts_result == hmi_apis::Common_Result::INVALID_ENUM)) {
if ((application_manager::commands::IsHMIResultSuccess(ui_result) ||
(ui_result == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)) &&
(application_manager::commands::IsHMIResultSuccess(tts_result) ||
(tts_result == hmi_apis::Common_Result::UNSUPPORTED_RESOURCE) ||
(tts_result == hmi_apis::Common_Result::INVALID_ENUM))) {
result = true;
}

if ((ui_result == hmi_apis::Common_Result::SUCCESS) &&
(tts_result != hmi_apis::Common_Result::SUCCESS) &&
(tts_result != hmi_apis::Common_Result::INVALID_ENUM)) {
common_result = hmi_apis::Common_Result::WARNINGS;
result = true;
} else if (ui_response.is_ok &&
tts_result == hmi_apis::Common_Result::WARNINGS) {
(((tts_result != hmi_apis::Common_Result::SUCCESS) &&
(tts_result != hmi_apis::Common_Result::INVALID_ENUM)) ||
(ui_response.is_ok &&
tts_result == hmi_apis::Common_Result::WARNINGS))) {
common_result = hmi_apis::Common_Result::WARNINGS;
result = true;
} else if (ui_result == hmi_apis::Common_Result::INVALID_ENUM) {
common_result = tts_result;
} else {
common_result = ui_result;
}

result_code = MessageHelper::HMIToMobileResult(common_result);
return std::make_pair(result_code, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ TEST_F(PerformAudioPassThruRequestTest,

EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success]
.asBool(),
false);
true);
EXPECT_EQ(
(*response_to_mobile)[am::strings::msg_params][am::strings::result_code]
.asInt(),
Expand Down
9 changes: 9 additions & 0 deletions src/components/utils/include/utils/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ bool Compare(T what, T to, T to1, T to2, T to3, T to4, T to5) {
Compare<T, CompareType, CmpStrategy>(what, to4, to5));
}

template <typename T,
bool (*CompareType)(T, T),
bool (*CmpStrategy)(bool, bool)>
bool Compare(T what, T to, T to1, T to2, T to3, T to4, T to5, T to6) {
return CmpStrategy(
Compare<T, CompareType, CmpStrategy>(what, to, to1, to2, to3),
Compare<T, CompareType, CmpStrategy>(what, to4, to5, to6));
}

template <typename Container>
bool in_range(const Container& container,
const typename Container::value_type& value) {
Expand Down

0 comments on commit b74c738

Please sign in to comment.