From 325bf4094287e4ab3cf8bd0fee43aef3e585d218 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Thu, 19 Jul 2018 09:47:22 -0400 Subject: first run at making vrcommands optional --- .../include/application_manager/message_helper.h | 36 ++++++++++++++++ .../commands/mobile/perform_interaction_request.h | 14 +++++++ .../create_interaction_choice_set_request.cc | 15 +++++-- .../commands/mobile/perform_interaction_request.cc | 49 +++++++++++++++++++++- src/components/interfaces/MOBILE_API.xml | 2 +- 5 files changed, 111 insertions(+), 5 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 9559c2007e..3c90928d8a 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -50,6 +50,7 @@ #include "application_manager/policies/policy_handler_interface.h" #include "smart_objects/smart_object.h" #include "transport_manager/common.h" +#include namespace policy { class PolicyHandlerInterface; @@ -854,6 +855,41 @@ class MessageHelper { */ static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); + + + // Check whether each choice has the vrCommands field + // returns -1 for failure, 0 if all choice include vrCommands, and 1 if none do + // vrCommands is an all-or-none deal + static int CheckChoiceSet_VRCommands( + const smart_objects::SmartObject& choice_set) { + + // if this becomes true, someone doesn't have vrCommands + bool all_have = true; + // if this is true, no one has vrCommands + bool none_have = true; + smart_objects::SmartArray::const_iterator current_choice_set_it = choice_set.asArray()->begin(); + // Iterate through choices + for (; choice_set.asArray()->end() != current_choice_set_it; ++current_choice_set_it) { + // if the vrCommands is present + if (current_choice_set_it->keyExists(application_manager::strings::vr_commands)) { + // this one has the parameter + none_have = false; + } else { + // this one doesn't + all_have = false; + } + } + // everyone has it + if (all_have) { + return 0; + } + // No one has it + if (none_have) { + return 1; + } + // mix-and-match, this is an error + return -1; + } private: /** diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 40e706b851..02ea6945f7 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -211,6 +211,20 @@ class PerformInteractionRequest app_mngr::ApplicationSharedPtr app, const size_t choice_set_id_list_length, const smart_objects::SmartObject& choice_set_id_list) const; + + + /** + * @brief Checks each choice in each set for having a VRcommands parameter + * @param app contains pointer to application. + * @param choice_set_id_list_length contains amount + * of choice set ids. + * @param choice_set_id_list array of choice set ids + * @return returns false request has choice sets with no vrCommands + */ + bool CheckChoiceSetList_VRCommands( + app_mngr::ApplicationSharedPtr app, + const size_t choice_set_id_list_length, + const smart_objects::SmartObject& choice_set_id_list) const; /** * @brief Tells if there are sent requests without responses diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 7451ea7905..31f4deb50c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -124,10 +124,19 @@ void CreateInteractionChoiceSetRequest::Run() { SendResponse(false, result); return; } - uint32_t grammar_id = application_manager_.GenerateGrammarID(); - (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; + int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); + if (vr_status == -1) { + // this is an error + SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands."); + + } else if (vr_status == 0) { + // everyone had a vr command, setup the grammar + uint32_t grammar_id = application_manager_.GenerateGrammarID(); + (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; + SendVRAddCommandRequests(app); + } + // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); - SendVRAddCommandRequests(app); } mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 8710f3c3d6..bac700f89c 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,7 +163,18 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - + if (!CheckChoiceSetList_VRCommands( + app, + choice_set_id_list_length, + msg_params[strings::interaction_choice_set_id_list])) { + LOG4CXX_ERROR(logger_, + "PerformInteraction has choice sets with " + "missing vrCommands"); + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "Some choices don't contain VR commands."); + return; + } if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::SUCCESS != MessageHelper::VerifyImageVrHelpItems( @@ -942,6 +953,35 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( return false; } + +bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( + ApplicationSharedPtr app, + const size_t choice_set_id_list_length, + const smart_objects::SmartObject& choice_set_id_list) const { + LOG4CXX_AUTO_TRACE(logger_); + + smart_objects::SmartObject* choice_set = 0; + std::pair::iterator, bool> ins_res; + + for (size_t i = 0; i < choice_set_id_list_length; ++i) { + choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); + if (!choice_set) { + LOG4CXX_ERROR( + logger_, + "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); + return false; + } + + + int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); + // if not all choices have vr commands + if (vr_status != 0) { + return false; + } + } + return true; +} + bool PerformInteractionRequest::CheckChoiceIDFromRequest( ApplicationSharedPtr app, const size_t choice_set_id_list_length, @@ -961,6 +1001,13 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( "Couldn't find choiset_id = " << choice_set_id_list[i].asInt()); return false; } + + + int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); + // if not all choices have vr commands + if (vr_status != 0) { + + } choice_list_length = (*choice_set)[strings::choice_set].length(); const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 2766bb48d0..de7513386d 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -950,7 +950,7 @@ A choice is an option given to the user, which can be selected either by menu, or through voice recognition system. - + Optional secondary text to display; e.g. address of POI in a search result entry -- cgit v1.2.1 From b1d49ad732781c8213b01a491074e9ab554ca126 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Thu, 19 Jul 2018 16:28:21 -0400 Subject: more development, needs testing and performinteraction checks --- .../create_interaction_choice_set_request.cc | 10 +++++- .../commands/mobile/perform_interaction_request.cc | 38 ++++++++++++---------- .../mobile/create_interaction_choice_set_test.cc | 6 ++-- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 31f4deb50c..9b365b3f13 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -124,16 +124,24 @@ void CreateInteractionChoiceSetRequest::Run() { SendResponse(false, result); return; } + std::cerr << "checking choice set\n"; int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); if (vr_status == -1) { + std::cerr << "choice set has invalid MIXED set of VR parameters" << '\n'; // this is an error SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands."); + return; // exit now, this is a bad set } else if (vr_status == 0) { + std::cerr << "choice set has valid FULL set of VR parameters" << '\n'; + // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; SendVRAddCommandRequests(app); + } else { + std::cerr << "choice set has valid EMPTY set of VR parameters" << '\n'; + } // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); @@ -158,7 +166,7 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( (*current_choice_set_it)[strings::choice_id].asInt()); if (!ins_res.second) { LOG4CXX_ERROR(logger_, - "Choise with ID " + "Choice with ID " << (*current_choice_set_it)[strings::choice_id].asInt() << " already exists"); return mobile_apis::Result::INVALID_ID; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index bac700f89c..7753c16acf 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,18 +163,18 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - if (!CheckChoiceSetList_VRCommands( - app, - choice_set_id_list_length, - msg_params[strings::interaction_choice_set_id_list])) { - LOG4CXX_ERROR(logger_, - "PerformInteraction has choice sets with " - "missing vrCommands"); - SendResponse(false, - mobile_apis::Result::INVALID_DATA, - "Some choices don't contain VR commands."); - return; - } + // if (!CheckChoiceSetList_VRCommands( + // app, + // choice_set_id_list_length, + // msg_params[strings::interaction_choice_set_id_list])) { + // LOG4CXX_ERROR(logger_, + // "PerformInteraction has choice sets with " + // "missing vrCommands"); + // SendResponse(false, + // mobile_apis::Result::INVALID_DATA, + // "Some choices don't contain VR commands."); + // return; + // } if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::SUCCESS != MessageHelper::VerifyImageVrHelpItems( @@ -965,17 +965,19 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( for (size_t i = 0; i < choice_set_id_list_length; ++i) { choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); - if (!choice_set) { - LOG4CXX_ERROR( - logger_, - "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); - return false; - } + // this should never ever happen + // if (!choice_set) { + // LOG4CXX_ERROR( + // logger_, + // "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); + // return false; + // } int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); // if not all choices have vr commands if (vr_status != 0) { + std::cerr << "choice set has member missing vr commands\n"; return false; } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 10ffbded09..d7edd303ef 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -200,8 +200,10 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_vr = CreateFullParamsVRSO(); (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = 10; - (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = - "menu_name"; +(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = + "menu_name"; +(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::vr_commands][0] = + kVrCommands1; (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; utils::SharedPtr req_vr = CreateCommand(msg_vr); -- cgit v1.2.1 From 78e99ab9190fc62f34656e55ba29ff3ed7290877 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Mon, 23 Jul 2018 13:41:25 -0400 Subject: Create grammar only once --- .../mobile/create_interaction_choice_set_request.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 9b365b3f13..b20b657279 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -119,12 +119,7 @@ void CreateInteractionChoiceSetRequest::Run() { return; } - Result::eType result = CheckChoiceSet(app); - if (Result::SUCCESS != result) { - SendResponse(false, result); - return; - } - std::cerr << "checking choice set\n"; + int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); if (vr_status == -1) { std::cerr << "choice set has invalid MIXED set of VR parameters" << '\n'; @@ -134,14 +129,20 @@ void CreateInteractionChoiceSetRequest::Run() { } else if (vr_status == 0) { std::cerr << "choice set has valid FULL set of VR parameters" << '\n'; - + } else { + std::cerr << "choice set has valid EMPTY set of VR parameters" << '\n'; + } + + Result::eType result = CheckChoiceSet(app); + if (Result::SUCCESS != result) { + SendResponse(false, result); + return; + } + if (vr_status == 0) { // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; SendVRAddCommandRequests(app); - } else { - std::cerr << "choice set has valid EMPTY set of VR parameters" << '\n'; - } // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); -- cgit v1.2.1 From b5043f977fc861c581e7b912923847b0d85aea7c Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 24 Jul 2018 10:49:24 -0400 Subject: add perform interaction modifications --- .../commands/mobile/perform_interaction_request.cc | 50 +++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 7753c16acf..5a614b73c4 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,18 +163,18 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - // if (!CheckChoiceSetList_VRCommands( - // app, - // choice_set_id_list_length, - // msg_params[strings::interaction_choice_set_id_list])) { - // LOG4CXX_ERROR(logger_, - // "PerformInteraction has choice sets with " - // "missing vrCommands"); - // SendResponse(false, - // mobile_apis::Result::INVALID_DATA, - // "Some choices don't contain VR commands."); - // return; - // } + if (!CheckChoiceSetList_VRCommands( + app, + choice_set_id_list_length, + msg_params[strings::interaction_choice_set_id_list])) { + LOG4CXX_ERROR(logger_, + "PerformInteraction has choice sets with " + "missing vrCommands"); + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "Some choices don't contain VR commands."); + return; + } if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::SUCCESS != MessageHelper::VerifyImageVrHelpItems( @@ -964,17 +964,24 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( std::pair::iterator, bool> ins_res; for (size_t i = 0; i < choice_set_id_list_length; ++i) { + // std::cerr << "loop entered!\n"; choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); + // std::cerr << "set found!!\n"; + // this should never ever happen - // if (!choice_set) { - // LOG4CXX_ERROR( - // logger_, - // "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); - // return false; - // } + if (choice_set == nullptr) { + std::cerr << "bad choice set list!\n"; + return false; + } + // std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; + + // std::cerr << "checking status!!!\n"; + const smart_objects::SmartObject& choices_list = + (*choice_set)[strings::choice_set]; + int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); + // std::cerr << "status checked!!!!\n"; - int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); // if not all choices have vr commands if (vr_status != 0) { std::cerr << "choice set has member missing vr commands\n"; @@ -1005,11 +1012,6 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( } - int vr_status = MessageHelper::CheckChoiceSet_VRCommands(*choice_set); - // if not all choices have vr commands - if (vr_status != 0) { - - } choice_list_length = (*choice_set)[strings::choice_set].length(); const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; -- cgit v1.2.1 From 28246b04368088a1ebd11e3c1b6885cace6e643b Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 24 Jul 2018 13:53:31 -0400 Subject: Fix segfault, add perform interaction checks --- .../commands/mobile/perform_interaction_request.h | 4 +- .../create_interaction_choice_set_request.cc | 28 +++++++---- .../commands/mobile/perform_interaction_request.cc | 54 ++++++++++++---------- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 02ea6945f7..7684b3fd3f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -222,9 +222,7 @@ class PerformInteractionRequest * @return returns false request has choice sets with no vrCommands */ bool CheckChoiceSetList_VRCommands( - app_mngr::ApplicationSharedPtr app, - const size_t choice_set_id_list_length, - const smart_objects::SmartObject& choice_set_id_list) const; + app_mngr::ApplicationSharedPtr app); /** * @brief Tells if there are sent requests without responses diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index b20b657279..48f15aafda 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -124,7 +124,7 @@ void CreateInteractionChoiceSetRequest::Run() { if (vr_status == -1) { std::cerr << "choice set has invalid MIXED set of VR parameters" << '\n'; // this is an error - SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands."); + SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands. Either all or none must have voice commands."); return; // exit now, this is a bad set } else if (vr_status == 0) { @@ -139,13 +139,23 @@ void CreateInteractionChoiceSetRequest::Run() { return; } if (vr_status == 0) { + std::cerr << "creating grammar\n"; // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; - SendVRAddCommandRequests(app); } // continue on as usual + std::cerr << "adding choice set\n"; app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); + std::cerr << "added! choice set\n"; + + if (vr_status == 0) { + SendVRAddCommandRequests(app); + std::cerr << "requests sent!!!!\n"; + } else { + SendResponse(true, Result::SUCCESS); + + } } mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( @@ -191,12 +201,14 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( bool CreateInteractionChoiceSetRequest::compareSynonyms( const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice1, const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice2) { - smart_objects::SmartArray* vr_cmds_1 = - choice1[strings::vr_commands].asArray(); - DCHECK(vr_cmds_1 != NULL); - smart_objects::SmartArray* vr_cmds_2 = - choice2[strings::vr_commands].asArray(); - DCHECK(vr_cmds_2 != NULL); + // only compare if they both have vr commands + if (!(choice1.keyExists(strings::vr_commands) && + choice2.keyExists(strings::vr_commands))) { + std::cerr << "someone is empty!\n"; + return false; // clearly there isn't a duplicate if one of them is null + } + smart_objects::SmartArray* vr_cmds_1 = choice1[strings::vr_commands].asArray(); + smart_objects::SmartArray* vr_cmds_2 = choice2[strings::vr_commands].asArray(); smart_objects::SmartArray::iterator it; it = std::find_first_of(vr_cmds_1->begin(), diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 5a614b73c4..6a55936bcc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,18 +163,6 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - if (!CheckChoiceSetList_VRCommands( - app, - choice_set_id_list_length, - msg_params[strings::interaction_choice_set_id_list])) { - LOG4CXX_ERROR(logger_, - "PerformInteraction has choice sets with " - "missing vrCommands"); - SendResponse(false, - mobile_apis::Result::INVALID_DATA, - "Some choices don't contain VR commands."); - return; - } if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::SUCCESS != MessageHelper::VerifyImageVrHelpItems( @@ -197,7 +185,7 @@ void PerformInteractionRequest::Run() { case mobile_apis::InteractionMode::BOTH: { LOG4CXX_DEBUG(logger_, "Interaction Mode: BOTH"); if (!CheckChoiceSetVRSynonyms(app) || !CheckChoiceSetMenuNames(app) || - !CheckVrHelpItemPositions(app)) { + !CheckVrHelpItemPositions(app) || !CheckChoiceSetList_VRCommands(app)) { return; } break; @@ -212,7 +200,8 @@ void PerformInteractionRequest::Run() { } case mobile_apis::InteractionMode::VR_ONLY: { LOG4CXX_DEBUG(logger_, "Interaction Mode: VR_ONLY"); - if (!CheckChoiceSetVRSynonyms(app) || !CheckVrHelpItemPositions(app)) { + if (!CheckChoiceSetVRSynonyms(app) || !CheckVrHelpItemPositions(app) || + !CheckChoiceSetList_VRCommands(app)) { return; } break; @@ -757,6 +746,15 @@ bool PerformInteractionRequest::CheckChoiceSetVRSynonyms( size_t jj = 0; for (; ii < (*i_choice_set)[strings::choice_set].length(); ++ii) { for (; jj < (*j_choice_set)[strings::choice_set].length(); ++jj) { + if (!((*i_choice_set)[strings::choice_set][ii].keyExists( + strings::vr_commands) && + (*j_choice_set)[strings::choice_set][jj].keyExists( + strings::vr_commands))) { + LOG4CXX_DEBUG( + logger_, + "One or both sets has missing vr commands, skipping synonym check"); + return true; + } // choice_set pointer contains SmartObject msg_params smart_objects::SmartObject& ii_vr_commands = (*i_choice_set)[strings::choice_set][ii][strings::vr_commands]; @@ -955,36 +953,42 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( - ApplicationSharedPtr app, - const size_t choice_set_id_list_length, - const smart_objects::SmartObject& choice_set_id_list) const { + ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); + + const smart_objects::SmartObject& choice_set_id_list = + (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; - smart_objects::SmartObject* choice_set = 0; - std::pair::iterator, bool> ins_res; + smart_objects::SmartObject* choice_set = nullptr; - for (size_t i = 0; i < choice_set_id_list_length; ++i) { - // std::cerr << "loop entered!\n"; + for (size_t i = 0; i < choice_set_id_list.length(); ++i) { + std::cerr << "loop entered!\n"; choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); - // std::cerr << "set found!!\n"; + std::cerr << "set found!!\n"; // this should never ever happen if (choice_set == nullptr) { std::cerr << "bad choice set list!\n"; return false; } - // std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; + std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; - // std::cerr << "checking status!!!\n"; + std::cerr << "checking status!!!\n"; const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); - // std::cerr << "status checked!!!!\n"; + std::cerr << "status checked!!!!\n"; // if not all choices have vr commands if (vr_status != 0) { std::cerr << "choice set has member missing vr commands\n"; + LOG4CXX_ERROR(logger_, + "PerformInteraction has choice sets with " + "missing vrCommands, not in MANUAL_ONLY mode"); + SendResponse(false, + mobile_apis::Result::INVALID_DATA, + "Some choices don't contain VR commands."); return false; } } -- cgit v1.2.1 From 0ed004d9a7f961ccb964851dff1266949ebea1ee Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 24 Jul 2018 15:00:02 -0400 Subject: Cleanup, remove some typos --- .../create_interaction_choice_set_request.cc | 24 ++++++---------------- .../commands/mobile/perform_interaction_request.cc | 24 +++++++++------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 48f15aafda..91ef7c3bbd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -120,41 +120,30 @@ void CreateInteractionChoiceSetRequest::Run() { } + Result::eType result = CheckChoiceSet(app); + if (Result::SUCCESS != result) { + SendResponse(false, result); + return; + } int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); if (vr_status == -1) { - std::cerr << "choice set has invalid MIXED set of VR parameters" << '\n'; // this is an error SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands. Either all or none must have voice commands."); return; // exit now, this is a bad set } else if (vr_status == 0) { - std::cerr << "choice set has valid FULL set of VR parameters" << '\n'; - } else { - std::cerr << "choice set has valid EMPTY set of VR parameters" << '\n'; - } - - Result::eType result = CheckChoiceSet(app); - if (Result::SUCCESS != result) { - SendResponse(false, result); - return; - } - if (vr_status == 0) { - std::cerr << "creating grammar\n"; // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; } // continue on as usual - std::cerr << "adding choice set\n"; app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); - std::cerr << "added! choice set\n"; if (vr_status == 0) { + // we have VR commands SendVRAddCommandRequests(app); - std::cerr << "requests sent!!!!\n"; } else { SendResponse(true, Result::SUCCESS); - } } @@ -204,7 +193,6 @@ bool CreateInteractionChoiceSetRequest::compareSynonyms( // only compare if they both have vr commands if (!(choice1.keyExists(strings::vr_commands) && choice2.keyExists(strings::vr_commands))) { - std::cerr << "someone is empty!\n"; return false; // clearly there isn't a duplicate if one of them is null } smart_objects::SmartArray* vr_cmds_1 = choice1[strings::vr_commands].asArray(); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 6a55936bcc..98b5d96bb5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -354,15 +354,15 @@ bool PerformInteractionRequest::ProcessVRResponse( const SmartObject& hmi_msg_params = message[strings::msg_params]; if (hmi_msg_params.keyExists(strings::choice_id)) { - const int choise_id = hmi_msg_params[strings::choice_id].asInt(); - if (!CheckChoiceIDFromResponse(app, choise_id)) { + const int choice_id = hmi_msg_params[strings::choice_id].asInt(); + if (!CheckChoiceIDFromResponse(app, choice_id)) { LOG4CXX_ERROR(logger_, "Wrong choiceID was received from HMI"); TerminatePerformInteraction(); SendResponse( false, Result::GENERIC_ERROR, "Wrong choiceID was received from HMI"); return true; } - msg_params[strings::choice_id] = choise_id; + msg_params[strings::choice_id] = choice_id; } return false; } @@ -538,7 +538,7 @@ void PerformInteractionRequest::SendVRPerformInteractionRequest( smart_objects::SmartObject* choice_set = app->FindChoiceSet(choice_list[i].asInt()); if (!choice_set) { - LOG4CXX_WARN(logger_, "Couldn't found choiset"); + LOG4CXX_WARN(logger_, "Couldn't found choiceset"); continue; } msg_params[strings::grammar_id][grammar_id_index++] = @@ -962,27 +962,23 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( smart_objects::SmartObject* choice_set = nullptr; for (size_t i = 0; i < choice_set_id_list.length(); ++i) { - std::cerr << "loop entered!\n"; choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); - std::cerr << "set found!!\n"; - // this should never ever happen + // this should never ever happen since this was already checked if (choice_set == nullptr) { - std::cerr << "bad choice set list!\n"; + LOG4CXX_ERROR( + logger_, + "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); return false; } - std::cerr<< "SMARTTYPE is " << choice_set->getType() << std::endl; - std::cerr << "checking status!!!\n"; const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); - std::cerr << "status checked!!!!\n"; // if not all choices have vr commands if (vr_status != 0) { - std::cerr << "choice set has member missing vr commands\n"; LOG4CXX_ERROR(logger_, "PerformInteraction has choice sets with " "missing vrCommands, not in MANUAL_ONLY mode"); @@ -1011,7 +1007,7 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( if (!choice_set) { LOG4CXX_ERROR( logger_, - "Couldn't find choiset_id = " << choice_set_id_list[i].asInt()); + "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); return false; } @@ -1024,7 +1020,7 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( choice_id_set.insert(choices_list[k][strings::choice_id].asInt()); if (!ins_res.second) { LOG4CXX_ERROR(logger_, - "Choise with ID " + "choice with ID " << choices_list[k][strings::choice_id].asInt() << " already exists"); return false; -- cgit v1.2.1 From 1dc7bf3e56f927915c440ced3d102a2a53fb22db Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 24 Jul 2018 17:19:08 -0400 Subject: style fix --- .../include/application_manager/message_helper.h | 16 +++++----- .../commands/mobile/perform_interaction_request.h | 6 ++-- .../create_interaction_choice_set_request.cc | 23 +++++++++------ .../commands/mobile/perform_interaction_request.cc | 34 ++++++++++------------ .../mobile/create_interaction_choice_set_test.cc | 8 ++--- 5 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 3c90928d8a..b15cf0c615 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -855,23 +855,25 @@ class MessageHelper { */ static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); - - + // Check whether each choice has the vrCommands field - // returns -1 for failure, 0 if all choice include vrCommands, and 1 if none do + // returns -1 for failure, 0 if all choice include vrCommands, and 1 if none + // do // vrCommands is an all-or-none deal static int CheckChoiceSet_VRCommands( const smart_objects::SmartObject& choice_set) { - // if this becomes true, someone doesn't have vrCommands bool all_have = true; // if this is true, no one has vrCommands bool none_have = true; - smart_objects::SmartArray::const_iterator current_choice_set_it = choice_set.asArray()->begin(); + smart_objects::SmartArray::const_iterator current_choice_set_it = + choice_set.asArray()->begin(); // Iterate through choices - for (; choice_set.asArray()->end() != current_choice_set_it; ++current_choice_set_it) { + for (; choice_set.asArray()->end() != current_choice_set_it; + ++current_choice_set_it) { // if the vrCommands is present - if (current_choice_set_it->keyExists(application_manager::strings::vr_commands)) { + if (current_choice_set_it->keyExists( + application_manager::strings::vr_commands)) { // this one has the parameter none_have = false; } else { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 7684b3fd3f..8c98a4ff30 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -211,8 +211,7 @@ class PerformInteractionRequest app_mngr::ApplicationSharedPtr app, const size_t choice_set_id_list_length, const smart_objects::SmartObject& choice_set_id_list) const; - - + /** * @brief Checks each choice in each set for having a VRcommands parameter * @param app contains pointer to application. @@ -221,8 +220,7 @@ class PerformInteractionRequest * @param choice_set_id_list array of choice set ids * @return returns false request has choice sets with no vrCommands */ - bool CheckChoiceSetList_VRCommands( - app_mngr::ApplicationSharedPtr app); + bool CheckChoiceSetList_VRCommands(app_mngr::ApplicationSharedPtr app); /** * @brief Tells if there are sent requests without responses diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 87f270d48a..0d6114cc50 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -118,18 +118,21 @@ void CreateInteractionChoiceSetRequest::Run() { return; } - Result::eType result = CheckChoiceSet(app); if (Result::SUCCESS != result) { SendResponse(false, result); return; } - int vr_status = MessageHelper::CheckChoiceSet_VRCommands((*message_)[strings::msg_params][strings::choice_set]); + int vr_status = MessageHelper::CheckChoiceSet_VRCommands( + (*message_)[strings::msg_params][strings::choice_set]); if (vr_status == -1) { // this is an error - SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands. Either all or none must have voice commands."); - return; // exit now, this is a bad set - + SendResponse(false, + Result::INVALID_DATA, + "Some choices don't contain VR commands. Either all or none " + "must have voice commands."); + return; // exit now, this is a bad set + } else if (vr_status == 0) { // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); @@ -137,7 +140,7 @@ void CreateInteractionChoiceSetRequest::Run() { } // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); - + if (vr_status == 0) { // we have VR commands SendVRAddCommandRequests(app); @@ -189,13 +192,15 @@ mobile_apis::Result::eType CreateInteractionChoiceSetRequest::CheckChoiceSet( bool CreateInteractionChoiceSetRequest::compareSynonyms( const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice1, const NsSmartDeviceLink::NsSmartObjects::SmartObject& choice2) { - // only compare if they both have vr commands + // only compare if they both have vr commands if (!(choice1.keyExists(strings::vr_commands) && choice2.keyExists(strings::vr_commands))) { return false; // clearly there isn't a duplicate if one of them is null } - smart_objects::SmartArray* vr_cmds_1 = choice1[strings::vr_commands].asArray(); - smart_objects::SmartArray* vr_cmds_2 = choice2[strings::vr_commands].asArray(); + smart_objects::SmartArray* vr_cmds_1 = + choice1[strings::vr_commands].asArray(); + smart_objects::SmartArray* vr_cmds_2 = + choice2[strings::vr_commands].asArray(); smart_objects::SmartArray::iterator it; it = std::find_first_of(vr_cmds_1->begin(), diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 98b5d96bb5..d013244f57 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -185,7 +185,8 @@ void PerformInteractionRequest::Run() { case mobile_apis::InteractionMode::BOTH: { LOG4CXX_DEBUG(logger_, "Interaction Mode: BOTH"); if (!CheckChoiceSetVRSynonyms(app) || !CheckChoiceSetMenuNames(app) || - !CheckVrHelpItemPositions(app) || !CheckChoiceSetList_VRCommands(app)) { + !CheckVrHelpItemPositions(app) || + !CheckChoiceSetList_VRCommands(app)) { return; } break; @@ -746,15 +747,15 @@ bool PerformInteractionRequest::CheckChoiceSetVRSynonyms( size_t jj = 0; for (; ii < (*i_choice_set)[strings::choice_set].length(); ++ii) { for (; jj < (*j_choice_set)[strings::choice_set].length(); ++jj) { - if (!((*i_choice_set)[strings::choice_set][ii].keyExists( - strings::vr_commands) && - (*j_choice_set)[strings::choice_set][jj].keyExists( - strings::vr_commands))) { - LOG4CXX_DEBUG( - logger_, - "One or both sets has missing vr commands, skipping synonym check"); - return true; - } + if (!((*i_choice_set)[strings::choice_set][ii].keyExists( + strings::vr_commands) && + (*j_choice_set)[strings::choice_set][jj].keyExists( + strings::vr_commands))) { + LOG4CXX_DEBUG(logger_, + "One or both sets has missing vr commands, skipping " + "synonym check"); + return true; + } // choice_set pointer contains SmartObject msg_params smart_objects::SmartObject& ii_vr_commands = (*i_choice_set)[strings::choice_set][ii][strings::vr_commands]; @@ -951,11 +952,10 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( return false; } - bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); - + const smart_objects::SmartObject& choice_set_id_list = (*message_)[strings::msg_params][strings::interaction_choice_set_id_list]; @@ -963,7 +963,7 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( for (size_t i = 0; i < choice_set_id_list.length(); ++i) { choice_set = app->FindChoiceSet(choice_set_id_list[i].asInt()); - + // this should never ever happen since this was already checked if (choice_set == nullptr) { LOG4CXX_ERROR( @@ -971,12 +971,11 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); return false; } - - + const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); - + // if not all choices have vr commands if (vr_status != 0) { LOG4CXX_ERROR(logger_, @@ -1010,8 +1009,7 @@ bool PerformInteractionRequest::CheckChoiceIDFromRequest( "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); return false; } - - + choice_list_length = (*choice_set)[strings::choice_set].length(); const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 349764b9e9..9066dc3a00 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -197,10 +197,10 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { MessageSharedPtr msg_vr = CreateFullParamsVRSO(); (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = 10; -(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = - "menu_name"; -(*msg_vr)[strings::msg_params][strings::choice_set][0][strings::vr_commands][0] = - kVrCommands1; + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = + "menu_name"; + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::vr_commands] + [0] = kVrCommands1; (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; std::shared_ptr req_vr = CreateCommand(msg_vr); -- cgit v1.2.1 From dfcf5aecebd93a8b8e99d1f4e631f6a7eb47c74d Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Mon, 30 Jul 2018 17:43:29 -0400 Subject: general cleanup on vr commands checks --- .../include/application_manager/message_helper.h | 50 ++++++---------------- .../commands/mobile/perform_interaction_request.h | 2 +- .../create_interaction_choice_set_request.cc | 10 ++--- .../commands/mobile/perform_interaction_request.cc | 10 ++--- .../src/message_helper/message_helper.cc | 32 ++++++++++++++ 5 files changed, 56 insertions(+), 48 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index b15cf0c615..f370cc6966 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -855,43 +855,19 @@ class MessageHelper { */ static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); - - // Check whether each choice has the vrCommands field - // returns -1 for failure, 0 if all choice include vrCommands, and 1 if none - // do - // vrCommands is an all-or-none deal - static int CheckChoiceSet_VRCommands( - const smart_objects::SmartObject& choice_set) { - // if this becomes true, someone doesn't have vrCommands - bool all_have = true; - // if this is true, no one has vrCommands - bool none_have = true; - smart_objects::SmartArray::const_iterator current_choice_set_it = - choice_set.asArray()->begin(); - // Iterate through choices - for (; choice_set.asArray()->end() != current_choice_set_it; - ++current_choice_set_it) { - // if the vrCommands is present - if (current_choice_set_it->keyExists( - application_manager::strings::vr_commands)) { - // this one has the parameter - none_have = false; - } else { - // this one doesn't - all_have = false; - } - } - // everyone has it - if (all_have) { - return 0; - } - // No one has it - if (none_have) { - return 1; - } - // mix-and-match, this is an error - return -1; - } + + enum ChoiceSetVRCommandsStatus { + MIXED, ALL, NONE + }; + + /** + * @brief Check whether each choice in the set has the vrCommands parameter + * vrCommands is an all-or-none deal + * @param choice set to check + * @return -1 for mixed, 0 if all choice include vrCommands, and 1 if none do + */ + static ChoiceSetVRCommandsStatus CheckChoiceSetVRCommands( + const smart_objects::SmartObject& choice_set); private: /** diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 8c98a4ff30..4ae6c90a62 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -220,7 +220,7 @@ class PerformInteractionRequest * @param choice_set_id_list array of choice set ids * @return returns false request has choice sets with no vrCommands */ - bool CheckChoiceSetList_VRCommands(app_mngr::ApplicationSharedPtr app); + bool CheckChoiceSetListVRCommands(app_mngr::ApplicationSharedPtr app); /** * @brief Tells if there are sent requests without responses diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc index 0d6114cc50..92c15afd6d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/create_interaction_choice_set_request.cc @@ -123,17 +123,16 @@ void CreateInteractionChoiceSetRequest::Run() { SendResponse(false, result); return; } - int vr_status = MessageHelper::CheckChoiceSet_VRCommands( + auto vr_status = MessageHelper::CheckChoiceSetVRCommands( (*message_)[strings::msg_params][strings::choice_set]); - if (vr_status == -1) { + if (vr_status == MessageHelper::ChoiceSetVRCommandsStatus::MIXED) { // this is an error SendResponse(false, Result::INVALID_DATA, "Some choices don't contain VR commands. Either all or none " "must have voice commands."); return; // exit now, this is a bad set - - } else if (vr_status == 0) { + } else if (vr_status == MessageHelper::ChoiceSetVRCommandsStatus::ALL) { // everyone had a vr command, setup the grammar uint32_t grammar_id = application_manager_.GenerateGrammarID(); (*message_)[strings::msg_params][strings::grammar_id] = grammar_id; @@ -141,10 +140,11 @@ void CreateInteractionChoiceSetRequest::Run() { // continue on as usual app->AddChoiceSet(choice_set_id_, (*message_)[strings::msg_params]); - if (vr_status == 0) { + if (vr_status == MessageHelper::ChoiceSetVRCommandsStatus::ALL) { // we have VR commands SendVRAddCommandRequests(app); } else { + // we have none, just return with success SendResponse(true, Result::SUCCESS); } } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index d013244f57..a9370845ad 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -186,7 +186,7 @@ void PerformInteractionRequest::Run() { LOG4CXX_DEBUG(logger_, "Interaction Mode: BOTH"); if (!CheckChoiceSetVRSynonyms(app) || !CheckChoiceSetMenuNames(app) || !CheckVrHelpItemPositions(app) || - !CheckChoiceSetList_VRCommands(app)) { + !CheckChoiceSetListVRCommands(app)) { return; } break; @@ -202,7 +202,7 @@ void PerformInteractionRequest::Run() { case mobile_apis::InteractionMode::VR_ONLY: { LOG4CXX_DEBUG(logger_, "Interaction Mode: VR_ONLY"); if (!CheckChoiceSetVRSynonyms(app) || !CheckVrHelpItemPositions(app) || - !CheckChoiceSetList_VRCommands(app)) { + !CheckChoiceSetListVRCommands(app)) { return; } break; @@ -952,7 +952,7 @@ bool PerformInteractionRequest::CheckChoiceIDFromResponse( return false; } -bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( +bool PerformInteractionRequest::CheckChoiceSetListVRCommands( ApplicationSharedPtr app) { LOG4CXX_AUTO_TRACE(logger_); @@ -974,10 +974,10 @@ bool PerformInteractionRequest::CheckChoiceSetList_VRCommands( const smart_objects::SmartObject& choices_list = (*choice_set)[strings::choice_set]; - int vr_status = MessageHelper::CheckChoiceSet_VRCommands(choices_list); + auto vr_status = MessageHelper::CheckChoiceSetVRCommands(choices_list); // if not all choices have vr commands - if (vr_status != 0) { + if (vr_status != MessageHelper::ChoiceSetVRCommandsStatus::ALL) { LOG4CXX_ERROR(logger_, "PerformInteraction has choice sets with " "missing vrCommands, not in MANUAL_ONLY mode"); diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 978724a671..31622bc911 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -326,6 +326,38 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateMessageForHMI( return message; } +MessageHelper::ChoiceSetVRCommandsStatus MessageHelper::CheckChoiceSetVRCommands(const smart_objects::SmartObject& choice_set) { + // if this is false, someone doesn't have vrCommands + bool all_have = true; + // if this is false, someone has vrCommands + bool none_have = true; + smart_objects::SmartArray::const_iterator current_choice_set_it = + choice_set.asArray()->begin(); + // Iterate through choices + for (; choice_set.asArray()->end() != current_choice_set_it; + ++current_choice_set_it) { + // if the vrCommands is present + if (current_choice_set_it->keyExists( + application_manager::strings::vr_commands)) { + // this one has the parameter + none_have = false; + } else { + // this one doesn't + all_have = false; + } + } + // everyone has it + if (all_have) { + return MessageHelper::ChoiceSetVRCommandsStatus::ALL; + } + // No one has it + if (none_have) { + return MessageHelper::ChoiceSetVRCommandsStatus::NONE; + } + // mix-and-match, this is an error + return MessageHelper::ChoiceSetVRCommandsStatus::MIXED; +} + smart_objects::SmartObjectSPtr MessageHelper::CreateHashUpdateNotification( const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); -- cgit v1.2.1 From 8bb20b6fcc0cbb1bb777331359c60d4f728674e1 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 31 Jul 2018 10:13:17 -0400 Subject: more cleanup, add mock implementations --- .../include/application_manager/message_helper.h | 32 ++++++----- .../src/message_helper/message_helper.cc | 66 +++++++++++----------- .../application_manager/mock_message_helper.h | 3 + .../test/mock_message_helper.cc | 6 ++ 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index f370cc6966..bfdadd40c9 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -635,6 +635,25 @@ class MessageHelper { smart_objects::SmartObject& image, ApplicationConstSharedPtr app, ApplicationManager& app_mngr); + + /** + * @brief Stores whether a choice set has correct VRCommands + * MIXED means some choices have VRCommands and others don't + * ALL means all do, NONE means none do + */ + enum ChoiceSetVRCommandsStatus { + MIXED, ALL, NONE + }; + + + /** + * @brief Check whether each choice in the set has the vrCommands parameter + * vrCommands is an all-or-none deal + * @param choice set to check + * @return a ChoiceSetVRCommandsStatus representing the state of the choice set + */ + static ChoiceSetVRCommandsStatus CheckChoiceSetVRCommands( + const smart_objects::SmartObject& choice_set); /* * @brief Finds "Image" structure in request and verify image file presence @@ -855,19 +874,6 @@ class MessageHelper { */ static smart_objects::SmartObjectSPtr CreateMessageForHMI( hmi_apis::messageType::eType message_type, const uint32_t correlation_id); - - enum ChoiceSetVRCommandsStatus { - MIXED, ALL, NONE - }; - - /** - * @brief Check whether each choice in the set has the vrCommands parameter - * vrCommands is an all-or-none deal - * @param choice set to check - * @return -1 for mixed, 0 if all choice include vrCommands, and 1 if none do - */ - static ChoiceSetVRCommandsStatus CheckChoiceSetVRCommands( - const smart_objects::SmartObject& choice_set); private: /** diff --git a/src/components/application_manager/src/message_helper/message_helper.cc b/src/components/application_manager/src/message_helper/message_helper.cc index 31622bc911..19458ef3b2 100644 --- a/src/components/application_manager/src/message_helper/message_helper.cc +++ b/src/components/application_manager/src/message_helper/message_helper.cc @@ -326,38 +326,6 @@ smart_objects::SmartObjectSPtr MessageHelper::CreateMessageForHMI( return message; } -MessageHelper::ChoiceSetVRCommandsStatus MessageHelper::CheckChoiceSetVRCommands(const smart_objects::SmartObject& choice_set) { - // if this is false, someone doesn't have vrCommands - bool all_have = true; - // if this is false, someone has vrCommands - bool none_have = true; - smart_objects::SmartArray::const_iterator current_choice_set_it = - choice_set.asArray()->begin(); - // Iterate through choices - for (; choice_set.asArray()->end() != current_choice_set_it; - ++current_choice_set_it) { - // if the vrCommands is present - if (current_choice_set_it->keyExists( - application_manager::strings::vr_commands)) { - // this one has the parameter - none_have = false; - } else { - // this one doesn't - all_have = false; - } - } - // everyone has it - if (all_have) { - return MessageHelper::ChoiceSetVRCommandsStatus::ALL; - } - // No one has it - if (none_have) { - return MessageHelper::ChoiceSetVRCommandsStatus::NONE; - } - // mix-and-match, this is an error - return MessageHelper::ChoiceSetVRCommandsStatus::MIXED; -} - smart_objects::SmartObjectSPtr MessageHelper::CreateHashUpdateNotification( const uint32_t app_id) { LOG4CXX_AUTO_TRACE(logger_); @@ -2729,6 +2697,40 @@ mobile_apis::Result::eType MessageHelper::VerifyImage( return result; } +MessageHelper::ChoiceSetVRCommandsStatus +MessageHelper::CheckChoiceSetVRCommands( + const smart_objects::SmartObject& choice_set) { + // if this is false, someone doesn't have vrCommands + bool all_have = true; + // if this is false, someone has vrCommands + bool none_have = true; + smart_objects::SmartArray::const_iterator current_choice_set_it = + choice_set.asArray()->begin(); + // Iterate through choices + for (; choice_set.asArray()->end() != current_choice_set_it; + ++current_choice_set_it) { + // if the vrCommands is present + if (current_choice_set_it->keyExists( + application_manager::strings::vr_commands)) { + // this one has the parameter + none_have = false; + } else { + // this one doesn't + all_have = false; + } + } + // everyone has it + if (all_have) { + return MessageHelper::ChoiceSetVRCommandsStatus::ALL; + } + // No one has it + if (none_have) { + return MessageHelper::ChoiceSetVRCommandsStatus::NONE; + } + // mix-and-match + return MessageHelper::ChoiceSetVRCommandsStatus::MIXED; +} + mobile_apis::Result::eType MessageHelper::VerifyImageVrHelpItems( smart_objects::SmartObject& message, ApplicationConstSharedPtr app, diff --git a/src/components/application_manager/test/include/application_manager/mock_message_helper.h b/src/components/application_manager/test/include/application_manager/mock_message_helper.h index 8641a3781e..8a06102e99 100644 --- a/src/components/application_manager/test/include/application_manager/mock_message_helper.h +++ b/src/components/application_manager/test/include/application_manager/mock_message_helper.h @@ -195,6 +195,9 @@ class MockMessageHelper { mobile_apis::Result::eType(smart_objects::SmartObject& message, ApplicationConstSharedPtr app, ApplicationManager& app_mngr)); + MOCK_METHOD1(CheckChoiceSetVRCommands, + MessageHelper::ChoiceSetVRCommandsStatus( + const smart_objects::SmartObject&)); MOCK_METHOD6(GetBCActivateAppRequestToHMI, smart_objects::SmartObjectSPtr( diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 9e2eb75a55..8ab70130c2 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -340,6 +340,12 @@ mobile_apis::Result::eType MessageHelper::VerifyImage( message, app, app_mngr); } +MessageHelper::ChoiceSetVRCommandsStatus +MessageHelper::CheckChoiceSetVRCommands( + const smart_objects::SmartObject& choice_set) { + return MockMessageHelper::message_helper_mock()->CheckChoiceSetVRCommands(choice_set); +} + mobile_apis::Result::eType MessageHelper::VerifyImageFiles( smart_objects::SmartObject& message, ApplicationConstSharedPtr app, -- cgit v1.2.1 From b22c65d4181a67345e79f409fd61e780be01e48c Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 31 Jul 2018 10:57:33 -0400 Subject: style fix --- .../include/application_manager/message_helper.h | 12 +++++------- .../application_manager/test/mock_message_helper.cc | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index bfdadd40c9..8e59a7307f 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -635,22 +635,20 @@ class MessageHelper { smart_objects::SmartObject& image, ApplicationConstSharedPtr app, ApplicationManager& app_mngr); - + /** * @brief Stores whether a choice set has correct VRCommands * MIXED means some choices have VRCommands and others don't * ALL means all do, NONE means none do - */ - enum ChoiceSetVRCommandsStatus { - MIXED, ALL, NONE - }; + */ + enum ChoiceSetVRCommandsStatus { MIXED, ALL, NONE }; - /** * @brief Check whether each choice in the set has the vrCommands parameter * vrCommands is an all-or-none deal * @param choice set to check - * @return a ChoiceSetVRCommandsStatus representing the state of the choice set + * @return a ChoiceSetVRCommandsStatus representing the state of the choice + * set */ static ChoiceSetVRCommandsStatus CheckChoiceSetVRCommands( const smart_objects::SmartObject& choice_set); diff --git a/src/components/application_manager/test/mock_message_helper.cc b/src/components/application_manager/test/mock_message_helper.cc index 8ab70130c2..0850361a20 100644 --- a/src/components/application_manager/test/mock_message_helper.cc +++ b/src/components/application_manager/test/mock_message_helper.cc @@ -343,7 +343,8 @@ mobile_apis::Result::eType MessageHelper::VerifyImage( MessageHelper::ChoiceSetVRCommandsStatus MessageHelper::CheckChoiceSetVRCommands( const smart_objects::SmartObject& choice_set) { - return MockMessageHelper::message_helper_mock()->CheckChoiceSetVRCommands(choice_set); + return MockMessageHelper::message_helper_mock()->CheckChoiceSetVRCommands( + choice_set); } mobile_apis::Result::eType MessageHelper::VerifyImageFiles( -- cgit v1.2.1 From 26de3d2f8bbfe4d47c7fe5e842ef3a001a3defa5 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 31 Jul 2018 13:35:04 -0400 Subject: add testing support for VR optional --- .../mobile/create_interaction_choice_set_test.cc | 61 +++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 9066dc3a00..be0ed884ac 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -233,7 +233,8 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); req_vr->Run(); MessageSharedPtr vr_command_result; @@ -437,6 +438,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -483,6 +487,40 @@ TEST_F(CreateInteractionChoiceSetRequestTest, command_->Run(); } +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_WithoutVrCommands_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillOnce(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::NONE)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + command_->Run(); +} + TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { Event event(hmi_apis::FunctionID::INVALID_ENUM); @@ -524,6 +562,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -558,6 +599,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -593,6 +637,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -641,6 +688,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -683,6 +733,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); @@ -725,6 +778,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); ON_CALL(app_mngr_, GetNextHMICorrelationID()) .WillByDefault(Return(kCorrelationId)); @@ -797,6 +853,9 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillRepeatedly(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()) .WillRepeatedly(Return(kGrammarId)); -- cgit v1.2.1 From 1597c8d598835e87b6fd11647b3c010d07b53341 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Tue, 31 Jul 2018 16:01:06 -0400 Subject: style fix --- .../mobile/create_interaction_choice_set_test.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index be0ed884ac..73f4470b38 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -438,7 +438,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -487,8 +487,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, command_->Run(); } -TEST_F(CreateInteractionChoiceSetRequestTest, - Run_WithoutVrCommands_SUCCESS) { +TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithoutVrCommands_SUCCESS) { (*message_)[am::strings::msg_params][am::strings::choice_set][0] [am::strings::menu_name] = kMenuName; (*message_)[am::strings::msg_params][am::strings::choice_set][0] @@ -508,7 +507,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - + EXPECT_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillOnce(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::NONE)); @@ -562,7 +561,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -599,7 +598,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -637,7 +636,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -688,7 +687,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -733,7 +732,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); @@ -778,7 +777,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillOnce(Return(mock_app_)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); @@ -853,7 +852,7 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillRepeatedly(Return(choice_set_id)); - + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); -- cgit v1.2.1 From b2c29fb656e52925eb6fd0c07b808feec395577d Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Wed, 1 Aug 2018 13:49:21 -0400 Subject: Cleanup comments, add a test for mixed vr commands --- .../include/application_manager/message_helper.h | 8 ++--- .../commands/mobile/perform_interaction_request.h | 5 +-- .../commands/mobile/perform_interaction_request.cc | 2 ++ .../mobile/create_interaction_choice_set_test.cc | 39 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/components/application_manager/include/application_manager/message_helper.h b/src/components/application_manager/include/application_manager/message_helper.h index 21d596fa03..73f49e3477 100644 --- a/src/components/application_manager/include/application_manager/message_helper.h +++ b/src/components/application_manager/include/application_manager/message_helper.h @@ -636,18 +636,16 @@ class MessageHelper { ApplicationManager& app_mngr); /** - * @brief Stores whether a choice set has correct VRCommands - * MIXED means some choices have VRCommands and others don't + * @brief Stores whether each choice in a set has the vrCommands parameter + * MIXED means some choices have vrCommands and others don't * ALL means all do, NONE means none do */ enum ChoiceSetVRCommandsStatus { MIXED, ALL, NONE }; /** * @brief Check whether each choice in the set has the vrCommands parameter - * vrCommands is an all-or-none deal * @param choice set to check - * @return a ChoiceSetVRCommandsStatus representing the state of the choice - * set + * @return a ChoiceSetVRCommandsStatus with the state of the choice set */ static ChoiceSetVRCommandsStatus CheckChoiceSetVRCommands( const smart_objects::SmartObject& choice_set); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h index 4ae6c90a62..2d4cbc9afc 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/mobile/perform_interaction_request.h @@ -215,10 +215,7 @@ class PerformInteractionRequest /** * @brief Checks each choice in each set for having a VRcommands parameter * @param app contains pointer to application. - * @param choice_set_id_list_length contains amount - * of choice set ids. - * @param choice_set_id_list array of choice set ids - * @return returns false request has choice sets with no vrCommands + * @return returns false if request has choice sets with no vrCommands */ bool CheckChoiceSetListVRCommands(app_mngr::ApplicationSharedPtr app); diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index 48760b99e4..af6f0639c6 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,6 +163,7 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } + if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::INVALID_DATA == MessageHelper::VerifyImageVrHelpItems( @@ -973,6 +974,7 @@ bool PerformInteractionRequest::CheckChoiceSetListVRCommands( LOG4CXX_ERROR( logger_, "Couldn't find choiceset_id = " << choice_set_id_list[i].asInt()); + SendResponse(false, mobile_apis::Result::INVALID_ID); return false; } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 73f4470b38..5bf97898b5 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -514,12 +514,51 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithoutVrCommands_SUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); + + // No VR commands + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); command_->Run(); } +TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithMixedVrCommands_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillOnce(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::MIXED)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(0);; + + command_->Run(); +} + TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { Event event(hmi_apis::FunctionID::INVALID_ENUM); -- cgit v1.2.1 From 88da8446551c6111e08e89ddb997fb4b2eb652b0 Mon Sep 17 00:00:00 2001 From: Conlain Kelly Date: Wed, 1 Aug 2018 13:52:16 -0400 Subject: yet another style fix --- .../src/commands/mobile/perform_interaction_request.cc | 2 +- .../commands/mobile/create_interaction_choice_set_test.cc | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc index af6f0639c6..42489fd8bd 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/perform_interaction_request.cc @@ -163,7 +163,7 @@ void PerformInteractionRequest::Run() { SendResponse(false, mobile_apis::Result::INVALID_ID); return; } - + if (msg_params.keyExists(strings::vr_help)) { if (mobile_apis::Result::INVALID_DATA == MessageHelper::VerifyImageVrHelpItems( diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc index 5bf97898b5..c42be48e57 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -514,16 +514,17 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithoutVrCommands_SUCCESS) { smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - - // No VR commands - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + // No VR commands + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); command_->Run(); } -TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithMixedVrCommands_UNSUCCESS) { +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_WithMixedVrCommands_UNSUCCESS) { (*message_)[am::strings::msg_params][am::strings::choice_set][0] [am::strings::menu_name] = kMenuName; (*message_)[am::strings::msg_params][am::strings::choice_set][0] @@ -551,10 +552,10 @@ TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithMixedVrCommands_UNSUCCESS) smart_objects::SmartObject* choice_set_id = NULL; EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); - + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(0);; + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(0); command_->Run(); } -- cgit v1.2.1 From 3825893a1567b04eaae0cf3fc349eb70210eb274 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Tue, 7 Aug 2018 13:59:58 -0400 Subject: Add vrCommand mobile_api history --- src/components/interfaces/MOBILE_API.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 43330d0415..b63316b899 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -979,7 +979,11 @@ A choice is an option given to the user, which can be selected either by menu, or through voice recognition system. - + + + + + Optional secondary text to display; e.g. address of POI in a search result entry -- cgit v1.2.1 From 64c664da19538162781886c3a1b880f02cebc439 Mon Sep 17 00:00:00 2001 From: JackLivio Date: Wed, 15 Aug 2018 13:14:04 -0400 Subject: Update mobile api with correct versioning --- src/components/interfaces/MOBILE_API.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index b820550c1a..33e262a886 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -1,7 +1,7 @@ - + The request succeeded @@ -981,7 +981,7 @@ - + -- cgit v1.2.1