diff options
author | dtrunov <dtrunov@luxoft.com> | 2016-10-03 15:53:13 +0300 |
---|---|---|
committer | dtrunov <dtrunov@luxoft.com> | 2016-10-03 15:53:13 +0300 |
commit | 08793826cd9ba59f0733b72aa8b829e0a38e5814 (patch) | |
tree | 2dc1e8d48c873d5d6c8db9c4b799057bd7dde9f9 | |
parent | ff2bdeaf8a627fc698ff83f4987921b5773a3955 (diff) | |
download | sdl_core-08793826cd9ba59f0733b72aa8b829e0a38e5814.tar.gz |
Fix failed UTs
Fix UTs for mobile commands, and hmi commands.
Related issue [APPLINK-25088](https://adc.luxoft.com/jira/browse/APPLINK-25088)
5 files changed, 284 insertions, 131 deletions
diff --git a/src/components/application_manager/test/commands/hmi/CMakeLists.txt b/src/components/application_manager/test/commands/hmi/CMakeLists.txt index 01d599ce97..6175fe9e19 100644 --- a/src/components/application_manager/test/commands/hmi/CMakeLists.txt +++ b/src/components/application_manager/test/commands/hmi/CMakeLists.txt @@ -40,6 +40,7 @@ set (SOURCES ${AM_SOURCE_DIR}/src/smart_object_keys.cc ${AM_SOURCE_DIR}/test/mock_message_helper.cc ${COMMANDS_TEST_SOURCE_DIR}/hmi/vi_is_ready_request_test.cc + ${COMMANDS_TEST_SOURCE_DIR}/hmi/vr_is_ready_request_test.cc ) set(LIBRARIES diff --git a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc index f9de7131bd..1d76cf7cf1 100644 --- a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc @@ -106,7 +106,6 @@ class VIIsReadyRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNic CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) .WillOnce(Return(ivi_type)); EXPECT_CALL(app_mngr_, ManageHMICommand(ivi_type)); - } void PrepareEvent(bool is_message_contain_param, diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc index 311d78e1d4..6f563901e6 100644 --- a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc +++ b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc @@ -30,13 +30,19 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#include "application_manager/commands/hmi/vi_is_ready_response.h" +#include "application_manager/commands/hmi/vr_is_ready_request.h" #include "gtest/gtest.h" #include "utils/shared_ptr.h" -#include "application_manager/commands/commands_test.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" #include "application_manager/mock_application_manager.h" -#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" namespace test { namespace components { @@ -44,27 +50,141 @@ namespace commands_test { namespace hmi_commands_test { using ::testing::_; +using ::testing::ReturnRef; namespace am = ::application_manager; using am::commands::MessageSharedPtr; -using am::commands::VIIsReadyResponse; +using am::commands::VRIsReadyRequest; +using am::MockMessageHelper; +using am::event_engine::Event; -typedef SharedPtr<VIIsReadyResponse> VIIsReadyResponsePtr; +typedef SharedPtr<VRIsReadyRequest> VRIsReadyRequestPtr; -class VIIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +class VRIsReadyRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { public: - VIIsReadyResponseTest() - : command_(CreateCommand<VIIsReadyResponse>(message_)) {} + VRIsReadyRequestTest() + : command_(CreateCommand<VRIsReadyRequest>()) {} - VIIsReadyResponsePtr command_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; + void SetUpExpectations(bool is_vr_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + const bool is_send_message_by_timeout = false; + if (is_send_message_to_hmi) { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillRepeatedly(ReturnRef(mock_hmi_capabilities_)); + ExpectSendMessagesToHMI(is_send_message_by_timeout); + } else { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_vr_cooperating(is_vr_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, + state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + if (is_send_message_by_timeout) { + EXPECT_CALL(app_mngr_, hmi_capabilities()) + .WillOnce(ReturnRef(mock_hmi_capabilities_)); + } + + smart_objects::SmartObjectSPtr language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(app_mngr_, ManageHMICommand(language)); + + smart_objects::SmartObjectSPtr support_language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, + _)).WillOnce(Return(support_language)); + EXPECT_CALL(app_mngr_, ManageHMICommand(support_language)); + + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(app_mngr_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vr_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if(is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vr_cooperating_available; + } + event.set_smart_object(*msg); + } + + VRIsReadyRequestPtr command_; + am::MockHmiInterfaces mock_hmi_interfaces_; + application_manager_test::MockHMICapabilities mock_hmi_capabilities_; }; -TEST_F(VIIsReadyResponseTest, - Run_CheckCallOfOnVIIsReady_Success) { - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, OnVIIsReady()); - command_->Run(); +TEST_F(VRIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { +const bool is_vr_cooperating_available = false; +const bool is_send_message_to_hmi = false; +const bool is_message_contain_param = true; +Event event(hmi_apis::FunctionID::VR_IsReady); +PrepareEvent(is_message_contain_param, event); +SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); +command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vr_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + const bool is_send_message_by_timeout = true; + ExpectSendMessagesToHMI(is_send_message_by_timeout); + command_->onTimeOut(); } } // namespace mobile_commands_test diff --git a/src/components/application_manager/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/test/commands/mobile/change_registration_test.cc index 275bb3be8a..e8aee29055 100644 --- a/src/components/application_manager/test/commands/mobile/change_registration_test.cc +++ b/src/components/application_manager/test/commands/mobile/change_registration_test.cc @@ -50,6 +50,7 @@ #include "application_manager/mock_message_helper.h" #include "application_manager/mock_hmi_capabilities.h" #include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" namespace test { namespace components { @@ -61,6 +62,7 @@ using am::ApplicationManager; using am::commands::MessageSharedPtr; using am::ApplicationSharedPtr; using am::MockMessageHelper; +using am::MockHmiInterfaces; using ::testing::_; using ::utils::SharedPtr; using ::testing::Return; @@ -85,62 +87,81 @@ class ChangeRegistrationRequestTest sync_primitives::Lock app_set_lock_; sync_primitives::Lock lock_; - MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr CreateMsgFromMobile() { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); (*msg)[strings::params][strings::connection_key] = kConnectionKey; smart_objects::SmartObject msg_params = smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::cmd_id] = kCmdId; - msg_params[strings::vr_commands] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - msg_params[strings::vr_commands][0] = "lamer"; - msg_params[strings::type] = 34; - msg_params[strings::grammar_id] = 12; - msg_params[strings::app_id] = kAppId; + msg_params[strings::hmi_display_language] = + mobile_apis::Language::EN_US; + msg_params[strings::language] = + mobile_apis::Language::EN_US; (*msg)[strings::msg_params] = msg_params; - return msg; } + void PrepareExpectationBeforeRun() { + ON_CALL(app_mngr_, hmi_capabilities()) + .WillByDefault(ReturnRef(hmi_capabilities_)); + smart_objects::SmartObject supported_languages(smart_objects::SmartType_Array); + supported_languages[0] = static_cast<int32_t>(mobile_apis::Language::EN_US); + EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(&supported_languages)); + EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(&supported_languages)); + EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(&supported_languages)); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(hmi_interfaces_)); + EXPECT_CALL(hmi_interfaces_, GetInterfaceFromFunction( + hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(hmi_interfaces_, GetInterfaceState( + am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(hmi_interfaces_, GetInterfaceFromFunction( + hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + EXPECT_CALL(hmi_interfaces_, GetInterfaceState( + am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(hmi_interfaces_, GetInterfaceFromFunction( + hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + EXPECT_CALL(hmi_interfaces_, GetInterfaceState( + am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void CreateResponseFromHMI(MessageSharedPtr msg, + hmi_apis::Common_Result::eType result, + const std::string& info) { + (*msg)[strings::params][hmi_response::code] = + static_cast<int32_t>(result); + (*msg)[strings::msg_params][strings::info] = info; + } + typedef TypeIf<kMocksAreNice, NiceMock<application_manager_test::MockHMICapabilities>, application_manager_test::MockHMICapabilities>::Result MockHMICapabilities; + MockHMICapabilities hmi_capabilities_; + MockHmiInterfaces hmi_interfaces_; + }; typedef ChangeRegistrationRequestTest::MockHMICapabilities MockHMICapabilities; TEST_F(ChangeRegistrationRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateFullParamsVRSO(); - - utils::SharedPtr<ChangeRegistrationRequest> req_vr = - CreateCommand<ChangeRegistrationRequest>(msg_vr); + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + utils::SharedPtr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); MockAppPtr mock_app = CreateMockApp(); ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WARNINGS; - (*msg)[strings::params][strings::info] = "info"; - (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; - - am::event_engine::Event event(hmi_apis::FunctionID::VR_ChangeRegistration); - event.set_smart_object(*msg); - - smart_objects::SmartObject* ptr = NULL; - ON_CALL(*mock_app, FindCommand(kCmdId)).WillByDefault(Return(ptr)); - EXPECT_EQ(NULL, ptr); - - am::CommandsMap commands_map; - ON_CALL(*mock_app, commands_map()) - .WillByDefault( - Return(DataAccessor<am::CommandsMap>(commands_map, lock_))); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - am::ApplicationSet application_set; const utils::custom_string::CustomString name("name"); MockAppPtr app = CreateMockApp(); @@ -152,32 +173,43 @@ TEST_F(ChangeRegistrationRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL( - app_mngr_, - ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(Return(true)); + PrepareExpectationBeforeRun(); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI( + ui_response, hmi_apis::Common_Result::WARNINGS,"ui_info"); + CreateResponseFromHMI( + vr_response, hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, "unsupported_resource"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; - req_vr->Run(); - - MessageSharedPtr vr_command_result; EXPECT_CALL( - app_mngr_, - ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + app_mngr_, + ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - req_vr->on_event(event); + command->on_event(event_ui); + command->on_event(event_vr); + command->on_event(event_tts); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), - false); + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + true); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::WARNINGS)); - if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::info].asString(), - (*msg)[strings::msg_params][strings::info].asString()); - } + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); } } // namespace commands_test diff --git a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc index 417dc33586..a5f0e837fa 100644 --- a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc +++ b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc @@ -68,6 +68,7 @@ using ::testing::ReturnRef; using am::commands::PerformInteractionRequest; using ::test::components::application_manager_test::MockApplication; + namespace strings = ::application_manager::strings; namespace hmi_response = ::application_manager::hmi_response; @@ -84,39 +85,40 @@ class PerformInteractionRequestTest }; TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { - MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); - - (*msg_vr)[strings::msg_params][strings::interaction_mode] = + MessageSharedPtr response_msg_vr = CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + static_cast<uint64_t>(hmi_apis::Common_Result::SUCCESS); + (*response_msg_vr)[strings::msg_params][strings::info] = "info"; + MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); + (*request_msg)[strings::msg_params][strings::interaction_mode] = mobile_apis::InteractionMode::BOTH; - (*msg_vr)[strings::msg_params][strings::result_code] = - am::mobile_api::Result::GENERIC_ERROR; - (*msg_vr)[strings::msg_params][strings::success] = false; - utils::SharedPtr<PerformInteractionRequest> req_vr = - CreateCommand<PerformInteractionRequest>(msg_vr); + utils::SharedPtr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(request_msg); MockAppPtr mock_app; + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - MockHmiInterfaces hmi_interfaces; - ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); - Event event(hmi_apis::FunctionID::VR_PerformInteraction); - event.set_smart_object(*msg_vr); - req_vr->on_event(event); - req_vr->Init(); + Event event(hmi_apis::FunctionID::VR_PerformInteraction); + event.set_smart_object(*response_msg_vr); + command->Init(); + command->on_event(event); + MessageSharedPtr response_to_mobile = CreateMessage(smart_objects::SmartType_Map); + (*response_to_mobile)[strings::msg_params][strings::result_code] = + static_cast<uint64_t>(am::mobile_api::Result::GENERIC_ERROR); MockMessageHelper* mock_message_helper = MockMessageHelper::message_helper_mock(); EXPECT_CALL( *mock_message_helper, CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(msg_vr)); + .WillOnce(Return(response_to_mobile)); MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - req_vr->onTimeOut(); + command->onTimeOut(); EXPECT_EQ( (*vr_command_result)[strings::msg_params][strings::success].asBool(), @@ -127,62 +129,61 @@ TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { } TEST_F(PerformInteractionRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); - (*msg_vr)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_vr)[strings::msg_params][strings::interaction_mode] = + MessageSharedPtr msg_from_mobile = CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = mobile_apis::InteractionMode::VR_ONLY; - utils::SharedPtr<PerformInteractionRequest> req_vr = - CreateCommand<PerformInteractionRequest>(msg_vr); - req_vr->Init(); - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + utils::SharedPtr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + command->Init(); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + MockHmiInterfaces hmi_interfaces; - ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); - ON_CALL(hmi_interfaces, GetInterfaceFromFunction(_)) - .WillByDefault( - Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); - ON_CALL(hmi_interfaces, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][hmi_response::code] = + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(hmi_interfaces)); + + MessageSharedPtr response_msg_vr = CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[strings::params][strings::info] = "info"; - (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_vr)[strings::params][strings::info] = "VR is not supported by system"; + (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; - am::event_engine::Event event(hmi_apis::FunctionID::VR_PerformInteraction); - event.set_smart_object(*msg); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); - smart_objects::SmartObject* ptr = NULL; - ON_CALL(*mock_app, FindCommand(kCmdId)).WillByDefault(Return(ptr)); - EXPECT_EQ(NULL, ptr); + MessageSharedPtr response_msg_ui = CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; - am::CommandsMap commands_map; - ON_CALL(*mock_app, commands_map()) - .WillByDefault( - Return(DataAccessor<am::CommandsMap>(commands_map, lock_))); + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + EXPECT_CALL(hmi_interfaces, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(hmi_interfaces, GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; - MessageSharedPtr vr_command_result; EXPECT_CALL( app_mngr_, ManageMobileCommand(_, am::commands::Command::CommandOrigin::ORIGIN_SDL)) - .WillOnce(Return(true)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - req_vr->on_event(event); + command->on_event(event_vr); + command->on_event(event_ui); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), true); EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast<int32_t>(hmi_apis::Common_Result::SUCCESS)); - if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::info].asString(), - (*msg)[strings::msg_params][strings::info].asString()); - } + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::info].asString(), + (*response_msg_vr)[strings::msg_params][strings::info].asString()); } } // namespace commands_test |