From 9e86dafadf845bcfcbf8fabf2c928bc357d01431 Mon Sep 17 00:00:00 2001 From: "Oleksandr Lohvinenko (GitHub)" Date: Fri, 25 May 2018 19:29:45 +0300 Subject: Migrated unit tests. --- .../test/commands/hmi/dummy_hmi_commands_test.cc | 35 +-- .../commands/hmi/simple_requests_to_hmi_test.cc | 16 +- .../commands/hmi/simple_response_from_hmi_test.cc | 12 - .../hmi/vi_get_vehicle_data_response_test.cc | 153 ----------- .../test/commands/hmi/vi_is_ready_request_test.cc | 169 ------------ .../mobile/diagnostic_message_request_test.cc | 1 - .../commands/mobile/dummy_mobile_commands_test.cc | 32 +-- .../test/commands/mobile/get_dtcs_request_test.cc | 142 ---------- .../mobile/get_vehicle_data_request_test.cc | 262 ------------------- .../mobile/on_vehicle_data_notification_test.cc | 148 ----------- .../test/commands/mobile/read_did_request_test.cc | 165 ------------ .../mobile/simple_response_commands_test.cc | 10 - .../mobile/unsubscribe_vehicle_request_test.cc | 288 --------------------- .../mobile/unsubscribe_vehicle_response_test.cc | 114 -------- .../vehicle_info_plugin/test/CMakeLists.txt | 64 +++++ .../hmi/vi_get_vehicle_data_response_test.cc | 153 +++++++++++ .../test/commands/hmi/vi_is_ready_request_test.cc | 169 ++++++++++++ .../test/commands/mobile/get_dtcs_request_test.cc | 142 ++++++++++ .../mobile/get_vehicle_data_request_test.cc | 262 +++++++++++++++++++ .../mobile/on_vehicle_data_notification_test.cc | 148 +++++++++++ .../test/commands/mobile/read_did_request_test.cc | 164 ++++++++++++ .../mobile/unsubscribe_vehicle_request_test.cc | 288 +++++++++++++++++++++ .../mobile/unsubscribe_vehicle_response_test.cc | 114 ++++++++ 23 files changed, 1510 insertions(+), 1541 deletions(-) delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc index 62e9243ec2..b5a33784b8 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -154,25 +154,10 @@ #include "hmi/tts_get_capabilities_response.h" #include "hmi/vr_perform_interaction_request.h" #include "hmi/vr_perform_interaction_response.h" -#include "hmi/vi_is_ready_request.h" -#include "hmi/vi_is_ready_response.h" -#include "hmi/vi_read_did_request.h" -#include "hmi/vi_read_did_response.h" #include "hmi/sdl_activate_app_request.h" #include "hmi/sdl_activate_app_response.h" #include "hmi/on_app_permission_changed_notification.h" #include "hmi/on_event_changed_notification.h" -#include "hmi/vi_get_vehicle_data_request.h" -#include "hmi/vi_get_vehicle_data_response.h" -#include "hmi/on_vi_vehicle_data_notification.h" -#include "hmi/vi_subscribe_vehicle_data_request.h" -#include "hmi/vi_subscribe_vehicle_data_response.h" -#include "hmi/vi_unsubscribe_vehicle_data_request.h" -#include "hmi/vi_unsubscribe_vehicle_data_response.h" -#include "hmi/vi_get_dtcs_request.h" -#include "hmi/vi_get_dtcs_response.h" -#include "hmi/vi_diagnostic_message_request.h" -#include "hmi/vi_diagnostic_message_response.h" #include "hmi/vi_get_vehicle_type_request.h" #include "hmi/vi_get_vehicle_type_response.h" #include "hmi/navi_is_ready_request.h" @@ -211,7 +196,6 @@ #include "hmi/on_button_event_notification.h" #include "hmi/on_button_press_notification.h" #include "hmi/on_button_subscription_notification.h" -#include "hmi/on_vi_vehicle_data_notification.h" #include "hmi/on_ui_keyboard_input_notification.h" #include "hmi/on_ui_touch_event_notification.h" #include "hmi/on_ui_reset_timeout_notification.h" @@ -447,19 +431,9 @@ typedef Types HMICommandsListSecond; + commands::UIIsReadyRequest> HMICommandsListSecond; -typedef Types RequestCommandsList2; -typedef Types RequestCommandsList3; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc index 1f89e4aefa..a7c07f8b1e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc @@ -59,10 +59,7 @@ #include "application_manager/mock_event_dispatcher.h" #include "application_manager/mock_hmi_capabilities.h" #include "application_manager/policies/mock_policy_handler_interface.h" -#include "hmi/vi_read_did_response.h" -#include "hmi/vi_subscribe_vehicle_data_response.h" #include "hmi/vi_get_vehicle_type_response.h" -#include "hmi/vi_is_ready_response.h" #include "hmi/dial_number_response.h" #include "hmi/close_popup_response.h" #include "hmi/tts_set_global_properties_response.h" @@ -78,12 +75,9 @@ #include "hmi/ui_end_audio_pass_thru_response.h" #include "hmi/ui_perform_audio_pass_thru_response.h" #include "hmi/ui_perform_interaction_response.h" -#include "hmi/vi_diagnostic_message_response.h" -#include "hmi/vi_get_dtcs_response.h" #include "hmi/ui_set_media_clock_timer_response.h" #include "hmi/ui_show_response.h" #include "hmi/ui_slider_response.h" -#include "hmi/vi_unsubscribe_vehicle_data_response.h" #include "hmi/vr_add_command_response.h" #include "hmi/vr_change_registration_response.h" #include "hmi/vr_delete_command_response.h" @@ -183,16 +177,10 @@ typedef Types< hmi_apis::FunctionID::UI_DeleteSubMenu>, CommandData, - CommandData, - CommandData, CommandData, CommandData, - CommandData, CommandData, CommandData -#include -#include - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/message_helper.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "hmi/vi_get_vehicle_data_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vi_get_vehicle_data_response { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::MessageSharedPtr; -using sdl_rpc_plugin::commands::VIGetVehicleDataResponse; -using am::event_engine::Event; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr VIGetVehicleDataResponsePtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; -} // namespace - -class VIGetVehicleDataResponseTest - : public CommandsTest {}; - -TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStrNumber; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][strings::message_type] = - hmi_apis::messageType::response; - - VIGetVehicleDataResponsePtr command( - CreateCommand(command_msg)); - - am::event_engine::Event event( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - event.set_smart_object(*command_msg); - - EXPECT_CALL(mock_policy_handler_, OnVehicleDataUpdated(*command_msg)); - - MockEventDispatcher mock_event_dispatcher; - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher)); - EXPECT_CALL(mock_event_dispatcher, raise_event(_)); - - command->Run(); -} - -TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStrNumber; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][strings::message_type] = - hmi_apis::messageType::error_response; - (*command_msg)[strings::params][strings::data][strings::slider_position] = 1; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; - (*command_msg)[am::strings::params][am::strings::error_msg] = "test_error"; - (*command_msg)[am::strings::params][am::strings::protocol_type] = - am::commands::CommandImpl::hmi_protocol_type_; - (*command_msg)[strings::params][strings::protocol_version] = - am::commands::CommandImpl::protocol_version_; - - smart_objects::SmartObject result(smart_objects::SmartType_Map); - result[strings::msg_params] = (*command_msg)[strings::params][strings::data]; - result[strings::params][hmi_response::code] = - (*command_msg)[strings::params][hmi_response::code]; - result[strings::params][strings::correlation_id] = - (*command_msg)[strings::params][strings::correlation_id]; - result[strings::params][strings::error_msg] = - (*command_msg)[strings::params][strings::error_msg]; - result[strings::params][strings::message_type] = - (*command_msg)[strings::params][strings::message_type]; - result[strings::params][strings::protocol_type] = - (*command_msg)[strings::params][strings::protocol_type]; - result[strings::params][strings::protocol_version] = - (*command_msg)[strings::params][strings::protocol_version]; - - VIGetVehicleDataResponsePtr command( - CreateCommand(command_msg)); - - am::event_engine::Event event( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - event.set_smart_object(result); - - MockEventDispatcher mock_event_dispatcher; - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher)); - EXPECT_CALL(mock_event_dispatcher, raise_event(_)); - - command->Run(); -} - -} // namespace vi_get_vehicle_data_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc deleted file mode 100644 index f09ff72856..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "hmi/vi_is_ready_request.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.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/hmi_interfaces.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vi_is_ready_request { - -using ::testing::_; -using ::testing::ReturnRef; -using ::testing::Return; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using sdl_rpc_plugin::commands::VIIsReadyRequest; -using am::event_engine::Event; - -typedef SharedPtr VIIsReadyRequestPtr; - -class VIIsReadyRequestTest - : public CommandRequestTest { - public: - VIIsReadyRequestTest() : command_(CreateCommand()) {} - - void SetUpExpectations(bool is_vi_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, - am::HmiInterfaces::InterfaceState state) { - EXPECT_CALL(mock_hmi_capabilities_, - set_is_ivi_cooperating(is_vi_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_VehicleInfo, state)); - } else { - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - } - EXPECT_CALL(mock_policy_handler_, OnVIIsReady()); - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) - .WillOnce(Return(state)); - - if (is_send_message_to_hmi) { - ExpectSendMessagesToHMI(); - } - } - - void ExpectSendMessagesToHMI() { - smart_objects::SmartObjectSPtr ivi_type; - EXPECT_CALL( - mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) - .WillOnce(Return(ivi_type)); - EXPECT_CALL(mock_rpc_service_, ManageHMICommand(ivi_type)); - } - - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_vi_cooperating_available = false) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { - (*msg)[am::strings::msg_params][am::strings::available] = - is_vi_cooperating_available; - } - event.set_smart_object(*msg); - } - - VIIsReadyRequestPtr command_; -}; - -TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; - Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); - command_->on_event(event); -} - -TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); - command_->on_event(event); -} - -TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { - const bool is_vi_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); - SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); - command_->on_event(event); -} - -TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { - ExpectSendMessagesToHMI(); - command_->onTimeOut(); -} - -} // namespace vi_is_ready_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc index 73799ad337..0ae24c7b9e 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc @@ -45,7 +45,6 @@ #include "application_manager/mock_application.h" #include "application_manager/event_engine/event.h" #include "application_manager/mock_message_helper.h" -#include "mobile/diagnostic_message_request.h" #include "interfaces/MOBILE_API.h" namespace test { diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc index e711ddce1c..a8afe4007f 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc @@ -57,17 +57,11 @@ #include "mobile/delete_interaction_choice_set_response.h" #include "mobile/delete_sub_menu_request.h" #include "mobile/delete_sub_menu_response.h" -#include "mobile/diagnostic_message_request.h" -#include "mobile/diagnostic_message_response.h" #include "mobile/dial_number_request.h" #include "mobile/dial_number_response.h" #include "mobile/end_audio_pass_thru_request.h" #include "mobile/end_audio_pass_thru_response.h" #include "mobile/generic_response.h" -#include "mobile/get_dtcs_request.h" -#include "mobile/get_dtcs_response.h" -#include "mobile/get_vehicle_data_request.h" -#include "mobile/get_vehicle_data_response.h" #include "mobile/get_way_points_request.h" #include "mobile/get_way_points_response.h" #include "mobile/list_files_request.h" @@ -87,7 +81,6 @@ #include "mobile/on_system_request_notification.h" #include "mobile/on_tbt_client_state_notification.h" #include "mobile/on_touch_event_notification.h" -#include "mobile/on_vehicle_data_notification.h" #include "mobile/on_way_point_change_notification.h" #include "mobile/perform_audio_pass_thru_request.h" #include "mobile/perform_audio_pass_thru_response.h" @@ -95,8 +88,6 @@ #include "mobile/perform_interaction_response.h" #include "mobile/put_file_request.h" #include "mobile/put_file_response.h" -#include "mobile/read_did_request.h" -#include "mobile/read_did_response.h" #include "mobile/register_app_interface_request.h" #include "mobile/register_app_interface_response.h" #include "mobile/reset_global_properties_request.h" @@ -123,8 +114,6 @@ #include "mobile/speak_response.h" #include "mobile/subscribe_button_request.h" #include "mobile/subscribe_button_response.h" -#include "mobile/subscribe_vehicle_data_request.h" -#include "mobile/subscribe_vehicle_data_response.h" #include "mobile/subscribe_way_points_request.h" #include "mobile/subscribe_way_points_response.h" #include "mobile/system_response.h" @@ -132,8 +121,6 @@ #include "mobile/unregister_app_interface_response.h" #include "mobile/unsubscribe_button_request.h" #include "mobile/unsubscribe_button_response.h" -#include "mobile/unsubscribe_vehicle_data_request.h" -#include "mobile/unsubscribe_vehicle_data_response.h" #include "mobile/unsubscribe_way_points_request.h" #include "mobile/unsubscribe_way_points_response.h" #include "mobile/update_turn_list_request.h" @@ -228,17 +215,11 @@ typedef Types MobileCommandsListFirst; -typedef Types MobileCommandsListSecond; + commands::UnsubscribeButtonResponse> MobileCommandsListSecond; -typedef Types MobileCommandsListThird; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc deleted file mode 100644 index c8d652ebd9..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/event_engine/event.h" -#include "mobile/get_dtcs_request.h" -#include "application_manager/mock_message_helper.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace get_dtcs_request { - -using ::testing::_; -using ::testing::Return; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using sdl_rpc_plugin::commands::GetDTCsRequest; -using am::event_engine::Event; -using am::MockMessageHelper; -using testing::Mock; -namespace mobile_result = mobile_apis::Result; - -typedef SharedPtr GetDTCsRequestPtr; - -class GetDTCsRequestTest - : public CommandRequestTest { - public: - GetDTCsRequestTest() : CommandRequestTest() {} -}; - -TEST_F(GetDTCsRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - GetDTCsRequestPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(GetDTCsRequestTest, Run_SUCCESS) { - const uint32_t kConnectionKey = 2u; - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::dtc_mask] = 0; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - GetDTCsRequestPtr command(CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::VehicleInfo_GetDTCs))); - - command->Run(); -} - -TEST_F(GetDTCsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - GetDTCsRequestPtr command(CreateCommand()); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->on_event(event); -} - -TEST_F(GetDTCsRequestTest, OnEvent_SUCCESS) { - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::msg_params] = 0; - (*event_msg)[am::strings::params][am::hmi_response::code] = - mobile_apis::Result::SUCCESS; - - Event event(hmi_apis::FunctionID::VehicleInfo_GetDTCs); - event.set_smart_object(*event_msg); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - - GetDTCsRequestPtr command(CreateCommand()); - command->on_event(event); -} - -} // namespace get_dtcs_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc deleted file mode 100644 index f111985c06..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/application.h" -#include "application_manager/message_helper.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/event_engine/event.h" -#include "mobile/get_vehicle_data_request.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace get_vehicle_data_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using sdl_rpc_plugin::commands::GetVehicleDataRequest; -using am::event_engine::Event; -namespace mobile_result = mobile_apis::Result; - -typedef SharedPtr GetVehicleDataRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class GetVehicleDataRequestTest - : public CommandRequestTest {}; - -class UnwrappedGetVehicleDataRequest : public GetVehicleDataRequest { - public: - UnwrappedGetVehicleDataRequest(const MessageSharedPtr& message, - am::ApplicationManager& application_manager, - app_mngr::rpc_service::RPCService& rpc_service, - app_mngr::HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handler) - : GetVehicleDataRequest(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handler) {} - - policy::RPCParams& get_disallowed_params() { - return removed_parameters_permissions_.disallowed_params; - } - - using GetVehicleDataRequest::on_event; -}; - -#ifdef HMI_DBUS_API -// HMI_DBUS_API currently not supported -#else - -TEST_F(GetVehicleDataRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - GetVehicleDataRequestPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(GetVehicleDataRequestTest, Run_TooHighFrequency_UNSUCCESS) { - const mobile_apis::FunctionID::eType kFunctionId = - mobile_apis::FunctionID::GetVehicleDataID; - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::function_id] = kFunctionId; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - GetVehicleDataRequestPtr command( - CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL( - *app, - AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::CONFIG_FILE)) - .WillOnce(Return(true)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::REJECTED), _)); - - command->Run(); -} - -TEST_F(GetVehicleDataRequestTest, Run_EmptyMsgParams_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - GetVehicleDataRequestPtr command( - CreateCommand(command_msg)); - - const am::VehicleData kEmptyVehicleData; - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(kEmptyVehicleData)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(GetVehicleDataRequestTest, - Run_EmptyMsgParamsAndHasDisallowedParams_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - SharedPtr command( - CreateCommand(command_msg)); - - const am::VehicleData kEmptyVehicleData; - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillRepeatedly(ReturnRef(kEmptyVehicleData)); - - policy::RPCParams& disallowed_params = command->get_disallowed_params(); - disallowed_params.insert("test_param"); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::DISALLOWED), _)); - - command->Run(); -} - -TEST_F(GetVehicleDataRequestTest, Run_SUCCESS) { - const std::string kMsgParamKey("test_key"); - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - - GetVehicleDataRequestPtr command( - CreateCommand(command_msg)); - - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type( - kMsgParamKey, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::VehicleInfo_GetVehicleData))); - - command->Run(); -} - -TEST_F(GetVehicleDataRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - SharedPtr command( - CreateCommand(command_msg)); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->on_event(event); -} - -TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { - const hmi_apis::Common_Result::eType hmi_response_code = - hmi_apis::Common_Result::DATA_NOT_AVAILABLE; - const mobile_result::eType mobile_response_code = - mobile_result::DATA_NOT_AVAILABLE; - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - SharedPtr command( - CreateCommand(command_msg)); - - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; - (*event_msg)[am::strings::params][am::strings::error_msg] = "test_error"; - (*event_msg)[am::strings::msg_params][am::hmi_response::method] = 0; - - Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); - event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); - - command->on_event(event); -} - -#endif // HMI_DBUS_API - -} // namespace get_vehicle_data_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc deleted file mode 100644 index f862db6442..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "gtest/gtest.h" -#include "mobile/on_vehicle_data_notification.h" -#include "utils/shared_ptr.h" -#include "utils/custom_string.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_impl.h" -#include "application_manager/message_helper.h" -#include "application_manager/mock_message_helper.h" -#include "utils/helpers.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_vehicle_data_notification { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -using am::commands::MessageSharedPtr; -using sdl_rpc_plugin::commands::OnVehicleDataNotification; - -typedef ::utils::SharedPtr NotificationPtr; - -namespace { -const uint32_t kAppId = 1u; -} // namespace - -class OnVehicleDataNotificationTest - : public CommandsTest { - public: - OnVehicleDataNotificationTest() - : command_msg_(CreateMessage(smart_objects::SmartType_Map)) - , command_(CreateCommand(command_msg_)) {} - - MessageSharedPtr command_msg_; - NotificationPtr command_; -}; - -MATCHER_P2(CheckMessageData, key, value, "") { - const bool kIsMobileProtocolTypeCorrect = - (*arg)[am::strings::params][am::strings::protocol_type].asInt() == - am::commands::CommandImpl::mobile_protocol_type_; - - const bool kIsProtocolVersionCorrect = - (*arg)[am::strings::params][am::strings::protocol_version].asInt() == - am::commands::CommandImpl::protocol_version_; - - const bool kIsNotificationCorrect = - (*arg)[am::strings::params][am::strings::message_type].asInt() == - am::MessageType::kNotification; - - const bool kIsConnectionKeyCorrect = - (*arg)[am::strings::params][am::strings::connection_key].asUInt() == - kAppId; - - const bool kAreMsgParamsCorrect = - (*arg)[am::strings::msg_params][key].asInt() == value; - - using namespace helpers; - return Compare(true, - kIsMobileProtocolTypeCorrect, - kIsProtocolVersionCorrect, - kIsNotificationCorrect, - kIsConnectionKeyCorrect, - kAreMsgParamsCorrect); -} - -TEST_F(OnVehicleDataNotificationTest, - Run_NotEmptyListOfAppsSubscribedForEvent_SUCCESS) { - am::VehicleData test_vehicle_data; - test_vehicle_data.insert(am::VehicleData::value_type( - am::strings::fuel_level, - mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL)); - - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(test_vehicle_data)); - - const int kFuelLevel = 100; - (*command_msg_)[am::strings::msg_params][am::strings::fuel_level] = - kFuelLevel; - - MockAppPtr mock_app(CreateMockApp()); - std::vector applications; - applications.push_back(mock_app); - - EXPECT_CALL( - app_mngr_, - IviInfoUpdated(mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL, - kFuelLevel)).WillOnce(Return(applications)); - - EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); - ::utils::custom_string::CustomString dummy_name("test_app"); - ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(dummy_name)); - - EXPECT_CALL(mock_rpc_service_, - SendMessageToMobile( - CheckMessageData(am::strings::fuel_level, kFuelLevel), _)); - - command_->Run(); -} - -} // namespace on_vehicle_data_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc deleted file mode 100644 index 1224a0ccb4..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "mobile/read_did_request.h" -#include "interfaces/MOBILE_API.h" -#include "interfaces/HMI_API.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace read_did_request { - -using ::testing::_; -using ::testing::DoAll; -using ::testing::Return; -using ::testing::SaveArg; -namespace am = ::application_manager; -using sdl_rpc_plugin::commands::ReadDIDRequest; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using ::utils::SharedPtr; - -class ReadDIDRequestTest - : public CommandRequestTest {}; - -TEST_F(ReadDIDRequestTest, OnEvent_WrongEventId_UNSUCCESS) { - Event event(Event::EventID::INVALID_ENUM); - SharedPtr command(CreateCommand()); - EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->on_event(event); -} - -TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { - Event event(Event::EventID::VehicleInfo_ReadDID); - - SharedPtr command(CreateCommand()); - - const hmi_apis::Common_Result::eType hmi_response_code = - hmi_apis::Common_Result::SUCCESS; - const mobile_apis::Result::eType mobile_response_code = - mobile_apis::Result::SUCCESS; - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; - (*event_msg)[am::strings::msg_params] = 0; - - event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - - command->on_event(event); -} - -TEST_F(ReadDIDRequestTest, Run_AppNotRegistered_UNSUCCESS) { - SharedPtr command(CreateCommand()); - - ON_CALL(app_mngr_, application(_)) - .WillByDefault(Return(SharedPtr())); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(ReadDIDRequestTest, Run_CommandLimitsExceeded_UNSUCCESS) { - SharedPtr command(CreateCommand()); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(true)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::REJECTED, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(ReadDIDRequestTest, Run_EmptyDidLocation_UNSUCCESS) { - MockAppPtr app(CreateMockApp()); - SharedPtr command(CreateCommand()); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(false)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::INVALID_DATA, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(ReadDIDRequestTest, Run_SUCCESS) { - MockAppPtr app(CreateMockApp()); - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - (*msg)[am::strings::msg_params][am::strings::did_location]["SomeData"] = 0; - SharedPtr command(CreateCommand(msg)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(false)); - - MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); - EXPECT_EQ(hmi_apis::FunctionID::VehicleInfo_ReadDID, - static_cast( - (*result_msg)[am::strings::params][am::strings::function_id] - .asInt())); -} - -} // namespace read_did_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc index 665d71d3de..cf1f7c6711 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc @@ -38,25 +38,20 @@ #include "utils/shared_ptr.h" #include "application_manager/commands/commands_test.h" #include "application_manager/mock_application_manager.h" -#include "mobile/read_did_response.h" #include "mobile/delete_command_response.h" #include "mobile/alert_maneuver_response.h" #include "mobile/alert_response.h" #include "mobile/list_files_response.h" #include "mobile/subscribe_button_response.h" #include "mobile/add_sub_menu_response.h" -#include "mobile/diagnostic_message_response.h" #include "mobile/dial_number_response.h" #include "mobile/end_audio_pass_thru_response.h" -#include "mobile/get_dtcs_response.h" -#include "mobile/get_vehicle_data_response.h" #include "mobile/unregister_app_interface_response.h" #include "mobile/unsubscribe_button_response.h" #include "mobile/unsubscribe_way_points_response.h" #include "mobile/update_turn_list_response.h" #include "mobile/slider_response.h" #include "mobile/speak_response.h" -#include "mobile/subscribe_vehicle_data_response.h" #include "mobile/subscribe_way_points_response.h" #include "mobile/system_response.h" #include "mobile/get_way_points_response.h" @@ -98,24 +93,19 @@ class MobileResponseCommandsTest }; typedef Types -#include - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "mobile/unsubscribe_vehicle_data_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace unsubscribe_vehicle_data_request { - -namespace am = ::application_manager; -namespace mobile_result = mobile_apis::Result; - -using ::testing::_; - -using sdl_rpc_plugin::commands::UnsubscribeVehicleDataRequest; -using am::commands::MessageSharedPtr; - -typedef ::utils::SharedPtr CommandPtr; - -namespace { -const uint32_t kConnectionKey = 1u; -const std::string kMsgParamKey = "test_key"; -const mobile_apis::VehicleDataType::eType kVehicleType = - mobile_apis::VehicleDataType::VEHICLEDATA_SPEED; -} // namespace - -class UnsubscribeVehicleRequestTest - : public CommandRequestTest { - protected: - void UnsubscribeSuccessfully(); - sync_primitives::Lock app_set_lock_; -}; - -TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr command(CreateCommand()); - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(UnsubscribeVehicleRequestTest, - Run_DataToUnsubscribeIsNotExisted_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][am::strings::button_name] = - kVehicleType; - - am::VehicleData data; - EXPECT_CALL(mock_message_helper_, vehicle_data()).WillOnce(ReturnRef(data)); - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(UnsubscribeVehicleRequestTest, - Run_UnsubscribeNotSubscribedBeforeData_IGNORED) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = kVehicleType; - - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - - command->Run(); -} - -TEST_F(UnsubscribeVehicleRequestTest, - Run_UnsubscribeNotSubscribedBeforeData_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - - command->Run(); -} - -TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - - am::VehicleData vehicle_data; - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - - am::ApplicationSet application_set_; - MockAppPtr mock_app(CreateMockApp()); - application_set_.insert(mock_app); - DataAccessor accessor(application_set_, app_set_lock_); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - - EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType)) - .WillRepeatedly(Return(true)); - - EXPECT_CALL(*mock_app, UnsubscribeFromIVI(kVehicleType)) - .WillRepeatedly(Return(true)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - CommandPtr command(CreateCommand(command_msg)); - command->Run(); -} - -TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeData_SUCCESS) { - UnsubscribeSuccessfully(); -} - -TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - CommandPtr command(CreateCommand(command_msg)); - - am::VehicleData vehicle_data; - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); - EXPECT_CALL(mock_message_helper_, vehicle_data()) - .WillOnce(ReturnRef(vehicle_data)); - EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType)) - .WillRepeatedly(Return(false)); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - command->Init(); - command->Run(); - - am::event_engine::Event test_event( - hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData); - SmartObject message(smart_objects::SmartType_Map); - const hmi_apis::Common_Result::eType hmi_result = - hmi_apis::Common_Result::SUCCESS; - message[am::strings::params][am::hmi_response::code] = hmi_result; - message[am::strings::msg_params][kMsgParamKey] = true; - test_event.set_smart_object(message); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - EXPECT_CALL(*mock_app, UpdateHash()); - - command->on_event(test_event); -} - -TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { - UnsubscribeSuccessfully(); - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; - CommandPtr command(CreateCommand(command_msg)); - MockAppPtr mock_app(CreateMockApp()); - - am::event_engine::Event test_event( - hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData); - SmartObject message(smart_objects::SmartType_Map); - const hmi_apis::Common_Result::eType hmi_result = - hmi_apis::Common_Result::SUCCESS; - message[am::strings::params][am::hmi_response::code] = hmi_result; - message[am::strings::msg_params][kMsgParamKey] = true; - test_event.set_smart_object(message); - - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - command->on_event(test_event); -} - -} // namespace unsubscribe_vehicle_data_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc deleted file mode 100644 index 8e3ea78ee6..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018, Ford Motor Company - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with the - * distribution. - * - * Neither the name of the Ford Motor Company nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "mobile/unsubscribe_vehicle_data_response.h" -#include -#include -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_application_manager.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace unsubscribe_vehicle_data_response { - -namespace commands = ::application_manager::commands; - -using ::testing::_; -using ::testing::NotNull; -using ::testing::Types; - -using sdl_rpc_plugin::commands::UnsubscribeVehicleDataResponse; -using commands::MessageSharedPtr; -namespace am = ::application_manager; - -class UnsubscribeVehicleResponseTest - : public CommandsTest {}; - -MATCHER_P(ResultCodeIs, result_code, "") { - return result_code == - static_cast( - (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); -} - -TEST_F(UnsubscribeVehicleResponseTest, - Run_SendFalseResponseToMobile_SendInvalidEnum) { - MessageSharedPtr command_msg = - ::utils::MakeShared(smart_objects::SmartType_Map); - (*command_msg)[am::strings::msg_params][am::strings::success] = false; - - ::utils::SharedPtr command = - CreateCommand(command_msg); - - EXPECT_CALL( - mock_rpc_service_, - SendMessageToMobile(ResultCodeIs(mobile_apis::Result::INVALID_ENUM), _)); - command->Run(); -} - -TEST_F(UnsubscribeVehicleResponseTest, - Run_SendSuccessfulResponseToMobile_SUCCESS) { - MessageSharedPtr command_msg = - ::utils::MakeShared(smart_objects::SmartType_Map); - (*command_msg)[am::strings::msg_params][am::strings::success] = true; - ::utils::SharedPtr command = - CreateCommand(command_msg); - - EXPECT_CALL( - mock_rpc_service_, - SendMessageToMobile(ResultCodeIs(mobile_apis::Result::SUCCESS), _)); - command->Run(); -} - -TEST_F(UnsubscribeVehicleResponseTest, - Run_SendResponseToMobile_SendCodeToMobile) { - MessageSharedPtr command_msg = - ::utils::MakeShared(smart_objects::SmartType_Map); - (*command_msg)[am::strings::msg_params][am::strings::success] = true; - - mobile_apis::Result::eType result_type = mobile_apis::Result::WARNINGS; - (*command_msg)[am::strings::msg_params][am::strings::result_code] = - result_type; - ::utils::SharedPtr command = - CreateCommand(command_msg); - - command->Run(); -} - -} // namespace unsubscribe_vehicle_data_response -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt new file mode 100644 index 0000000000..3ea4a50a8a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/CMakeLists.txt @@ -0,0 +1,64 @@ +# Copyright (c) 2018, Ford Motor Company +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with the +# distribution. +# +# Neither the name of the copyright holders nor the names of their contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories( + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/vehicle_info_plugin/include/vehicle_info_plugin/commands/ + ${COMPONENTS_DIR}/application_manager/test/include/ +) + + +set(COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) + +file(GLOB SOURCES + ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc + ${COMPONENTS_DIR}/application_manager/test/mock_application_helper.cc + ${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc + ${COMMANDS_TEST_DIR}/hmi/* + ${COMMANDS_TEST_DIR}/mobile/* + ${COMPONENTS_DIR}/application_manager/src/message.cc + ${COMPONENTS_DIR}/application_manager/src/event_engine/* +) + +set(LIBRARIES + gmock + Utils + SmartObjects + HMI_API + MOBILE_API + connectionHandler + vehicle_info_plugin + jsoncpp +) + +create_cotired_test("vi_commands_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc new file mode 100644 index 0000000000..ddfc8e8a55 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/message_helper.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/vi_get_vehicle_data_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_data_response { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using am::commands::MessageSharedPtr; +using vehicle_info_plugin::commands::VIGetVehicleDataResponse; +using am::event_engine::Event; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr VIGetVehicleDataResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 1u; +const std::string kStrNumber = "123"; +} // namespace + +class VIGetVehicleDataResponseTest + : public CommandsTest {}; + +TEST_F(VIGetVehicleDataResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][strings::message_type] = + hmi_apis::messageType::response; + + VIGetVehicleDataResponsePtr command( + CreateCommand(command_msg)); + + am::event_engine::Event event( + hmi_apis::FunctionID::VehicleInfo_GetVehicleData); + event.set_smart_object(*command_msg); + + EXPECT_CALL(mock_policy_handler_, OnVehicleDataUpdated(*command_msg)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +TEST_F(VIGetVehicleDataResponseTest, ErrorResponse_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][strings::message_type] = + hmi_apis::messageType::error_response; + (*command_msg)[strings::params][strings::data][strings::slider_position] = 1; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*command_msg)[am::strings::params][am::strings::error_msg] = "test_error"; + (*command_msg)[am::strings::params][am::strings::protocol_type] = + am::commands::CommandImpl::hmi_protocol_type_; + (*command_msg)[strings::params][strings::protocol_version] = + am::commands::CommandImpl::protocol_version_; + + smart_objects::SmartObject result(smart_objects::SmartType_Map); + result[strings::msg_params] = (*command_msg)[strings::params][strings::data]; + result[strings::params][hmi_response::code] = + (*command_msg)[strings::params][hmi_response::code]; + result[strings::params][strings::correlation_id] = + (*command_msg)[strings::params][strings::correlation_id]; + result[strings::params][strings::error_msg] = + (*command_msg)[strings::params][strings::error_msg]; + result[strings::params][strings::message_type] = + (*command_msg)[strings::params][strings::message_type]; + result[strings::params][strings::protocol_type] = + (*command_msg)[strings::params][strings::protocol_type]; + result[strings::params][strings::protocol_version] = + (*command_msg)[strings::params][strings::protocol_version]; + + VIGetVehicleDataResponsePtr command( + CreateCommand(command_msg)); + + am::event_engine::Event event( + hmi_apis::FunctionID::VehicleInfo_GetVehicleData); + event.set_smart_object(result); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace vi_get_vehicle_data_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc new file mode 100644 index 0000000000..d0093f45cf --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "hmi/vi_is_ready_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.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/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +using ::testing::Return; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using vehicle_info_plugin::commands::VIIsReadyRequest; +using am::event_engine::Event; + +typedef SharedPtr VIIsReadyRequestPtr; + +class VIIsReadyRequestTest + : public CommandRequestTest { + public: + VIIsReadyRequestTest() : command_(CreateCommand()) {} + + void SetUpExpectations(bool is_vi_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + EXPECT_CALL(mock_hmi_capabilities_, + set_is_ivi_cooperating(is_vi_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_VehicleInfo, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_policy_handler_, OnVIIsReady()); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) + .WillOnce(Return(state)); + + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr ivi_type; + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VehicleInfo_GetVehicleType, _)) + .WillOnce(Return(ivi_type)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(ivi_type)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vi_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vi_cooperating_available; + } + event.set_smart_object(*msg); + } + + VIIsReadyRequestPtr command_; +}; + +TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vi_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_vi_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vi_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); + PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); + SetUpExpectations(is_vi_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace vi_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc new file mode 100644 index 0000000000..9719d3ceed --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_dtcs_request_test.cc @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" +#include "mobile/get_dtcs_request.h" +#include "application_manager/mock_message_helper.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace get_dtcs_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using vehicle_info_plugin::commands::GetDTCsRequest; +using am::event_engine::Event; +using am::MockMessageHelper; +using testing::Mock; +namespace mobile_result = mobile_apis::Result; + +typedef SharedPtr GetDTCsRequestPtr; + +class GetDTCsRequestTest + : public CommandRequestTest { + public: + GetDTCsRequestTest() : CommandRequestTest() {} +}; + +TEST_F(GetDTCsRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + GetDTCsRequestPtr command(CreateCommand()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(GetDTCsRequestTest, Run_SUCCESS) { + const uint32_t kConnectionKey = 2u; + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::dtc_mask] = 0; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + GetDTCsRequestPtr command(CreateCommand(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VehicleInfo_GetDTCs))); + + command->Run(); +} + +TEST_F(GetDTCsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + GetDTCsRequestPtr command(CreateCommand()); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->on_event(event); +} + +TEST_F(GetDTCsRequestTest, OnEvent_SUCCESS) { + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::msg_params] = 0; + (*event_msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::SUCCESS; + + Event event(hmi_apis::FunctionID::VehicleInfo_GetDTCs); + event.set_smart_object(*event_msg); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + GetDTCsRequestPtr command(CreateCommand()); + command->on_event(event); +} + +} // namespace get_dtcs_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc new file mode 100644 index 0000000000..d8e4c3d075 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/get_vehicle_data_request_test.cc @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/message_helper.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "mobile/get_vehicle_data_request.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace get_vehicle_data_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using vehicle_info_plugin::commands::GetVehicleDataRequest; +using am::event_engine::Event; +namespace mobile_result = mobile_apis::Result; + +typedef SharedPtr GetVehicleDataRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class GetVehicleDataRequestTest + : public CommandRequestTest {}; + +class UnwrappedGetVehicleDataRequest : public GetVehicleDataRequest { + public: + UnwrappedGetVehicleDataRequest(const MessageSharedPtr& message, + am::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : GetVehicleDataRequest(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + + policy::RPCParams& get_disallowed_params() { + return removed_parameters_permissions_.disallowed_params; + } + + using GetVehicleDataRequest::on_event; +}; + +#ifdef HMI_DBUS_API +// HMI_DBUS_API currently not supported +#else + +TEST_F(GetVehicleDataRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + GetVehicleDataRequestPtr command(CreateCommand()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(GetVehicleDataRequestTest, Run_TooHighFrequency_UNSUCCESS) { + const mobile_apis::FunctionID::eType kFunctionId = + mobile_apis::FunctionID::GetVehicleDataID; + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::function_id] = kFunctionId; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + GetVehicleDataRequestPtr command( + CreateCommand(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL( + *app, + AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::CONFIG_FILE)) + .WillOnce(Return(true)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::REJECTED), _)); + + command->Run(); +} + +TEST_F(GetVehicleDataRequestTest, Run_EmptyMsgParams_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + GetVehicleDataRequestPtr command( + CreateCommand(command_msg)); + + const am::VehicleData kEmptyVehicleData; + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(kEmptyVehicleData)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(GetVehicleDataRequestTest, + Run_EmptyMsgParamsAndHasDisallowedParams_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + SharedPtr command( + CreateCommand(command_msg)); + + const am::VehicleData kEmptyVehicleData; + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillRepeatedly(ReturnRef(kEmptyVehicleData)); + + policy::RPCParams& disallowed_params = command->get_disallowed_params(); + disallowed_params.insert("test_param"); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::DISALLOWED), _)); + + command->Run(); +} + +TEST_F(GetVehicleDataRequestTest, Run_SUCCESS) { + const std::string kMsgParamKey("test_key"); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + + GetVehicleDataRequestPtr command( + CreateCommand(command_msg)); + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type( + kMsgParamKey, mobile_apis::VehicleDataType::VEHICLEDATA_SPEED)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VehicleInfo_GetVehicleData))); + + command->Run(); +} + +TEST_F(GetVehicleDataRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + SharedPtr command( + CreateCommand(command_msg)); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->on_event(event); +} + +TEST_F(GetVehicleDataRequestTest, OnEvent_DataNotAvailable_SUCCESS) { + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::DATA_NOT_AVAILABLE; + const mobile_result::eType mobile_response_code = + mobile_result::DATA_NOT_AVAILABLE; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + SharedPtr command( + CreateCommand(command_msg)); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; + (*event_msg)[am::strings::params][am::strings::error_msg] = "test_error"; + (*event_msg)[am::strings::msg_params][am::hmi_response::method] = 0; + + Event event(hmi_apis::FunctionID::VehicleInfo_GetVehicleData); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + command->on_event(event); +} + +#endif // HMI_DBUS_API + +} // namespace get_vehicle_data_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc new file mode 100644 index 0000000000..af071ae716 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include "gtest/gtest.h" +#include "mobile/on_vehicle_data_notification.h" +#include "utils/shared_ptr.h" +#include "utils/custom_string.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/message_helper.h" +#include "application_manager/mock_message_helper.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_vehicle_data_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +using am::commands::MessageSharedPtr; +using vehicle_info_plugin::commands::OnVehicleDataNotification; + +typedef ::utils::SharedPtr NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnVehicleDataNotificationTest + : public CommandsTest { + public: + OnVehicleDataNotificationTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand(command_msg_)) {} + + MessageSharedPtr command_msg_; + NotificationPtr command_; +}; + +MATCHER_P2(CheckMessageData, key, value, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + const bool kIsConnectionKeyCorrect = + (*arg)[am::strings::params][am::strings::connection_key].asUInt() == + kAppId; + + const bool kAreMsgParamsCorrect = + (*arg)[am::strings::msg_params][key].asInt() == value; + + using namespace helpers; + return Compare(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect, + kAreMsgParamsCorrect); +} + +TEST_F(OnVehicleDataNotificationTest, + Run_NotEmptyListOfAppsSubscribedForEvent_SUCCESS) { + am::VehicleData test_vehicle_data; + test_vehicle_data.insert(am::VehicleData::value_type( + am::strings::fuel_level, + mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL)); + + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(test_vehicle_data)); + + const int kFuelLevel = 100; + (*command_msg_)[am::strings::msg_params][am::strings::fuel_level] = + kFuelLevel; + + MockAppPtr mock_app(CreateMockApp()); + std::vector applications; + applications.push_back(mock_app); + + EXPECT_CALL( + app_mngr_, + IviInfoUpdated(mobile_apis::VehicleDataType::VEHICLEDATA_FUELLEVEL, + kFuelLevel)).WillOnce(Return(applications)); + + EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); + ::utils::custom_string::CustomString dummy_name("test_app"); + ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(dummy_name)); + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile( + CheckMessageData(am::strings::fuel_level, kFuelLevel), _)); + + command_->Run(); +} + +} // namespace on_vehicle_data_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc new file mode 100644 index 0000000000..e6649a14ad --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/read_did_request_test.cc @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "interfaces/MOBILE_API.h" +#include "interfaces/HMI_API.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace read_did_request { + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::SaveArg; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::ReadDIDRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using ::utils::SharedPtr; + +class ReadDIDRequestTest + : public CommandRequestTest {}; + +TEST_F(ReadDIDRequestTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + SharedPtr command(CreateCommand()); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->on_event(event); +} + +TEST_F(ReadDIDRequestTest, OnEvent_SUCCESS) { + Event event(Event::EventID::VehicleInfo_ReadDID); + + SharedPtr command(CreateCommand()); + + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::SUCCESS; + const mobile_apis::Result::eType mobile_response_code = + mobile_apis::Result::SUCCESS; + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; + (*event_msg)[am::strings::msg_params] = 0; + + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + command->on_event(event); +} + +TEST_F(ReadDIDRequestTest, Run_AppNotRegistered_UNSUCCESS) { + SharedPtr command(CreateCommand()); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(SharedPtr())); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(ReadDIDRequestTest, Run_CommandLimitsExceeded_UNSUCCESS) { + SharedPtr command(CreateCommand()); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(true)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::REJECTED, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(ReadDIDRequestTest, Run_EmptyDidLocation_UNSUCCESS) { + MockAppPtr app(CreateMockApp()); + SharedPtr command(CreateCommand()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(false)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::INVALID_DATA, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(ReadDIDRequestTest, Run_SUCCESS) { + MockAppPtr app(CreateMockApp()); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::msg_params][am::strings::did_location]["SomeData"] = 0; + SharedPtr command(CreateCommand(msg)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(*app, AreCommandLimitsExceeded(_, _)).WillByDefault(Return(false)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); + EXPECT_EQ(hmi_apis::FunctionID::VehicleInfo_ReadDID, + static_cast( + (*result_msg)[am::strings::params][am::strings::function_id] + .asInt())); +} + +} // namespace read_did_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc new file mode 100644 index 0000000000..10934a99fa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc @@ -0,0 +1,288 @@ +/* + Copyright (c) 2018, Ford Motor Company + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following + disclaimer in the documentation and/or other materials provided with the + distribution. + + Neither the name of the Ford Motor Company nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "mobile/unsubscribe_vehicle_data_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unsubscribe_vehicle_data_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; + +using vehicle_info_plugin::commands::UnsubscribeVehicleDataRequest; +using am::commands::MessageSharedPtr; + +typedef ::utils::SharedPtr CommandPtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const std::string kMsgParamKey = "test_key"; +const mobile_apis::VehicleDataType::eType kVehicleType = + mobile_apis::VehicleDataType::VEHICLEDATA_SPEED; +} // namespace + +class UnsubscribeVehicleRequestTest + : public CommandRequestTest { + protected: + void UnsubscribeSuccessfully(); + sync_primitives::Lock app_set_lock_; +}; + +TEST_F(UnsubscribeVehicleRequestTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand()); + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeVehicleRequestTest, + Run_DataToUnsubscribeIsNotExisted_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][am::strings::button_name] = + kVehicleType; + + am::VehicleData data; + EXPECT_CALL(mock_message_helper_, vehicle_data()).WillOnce(ReturnRef(data)); + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(UnsubscribeVehicleRequestTest, + Run_UnsubscribeNotSubscribedBeforeData_IGNORED) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = kVehicleType; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeVehicleRequestTest, + Run_UnsubscribeNotSubscribedBeforeData_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeDataDisabled_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +void UnsubscribeVehicleRequestTest::UnsubscribeSuccessfully() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + + am::VehicleData vehicle_data; + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + + am::ApplicationSet application_set_; + MockAppPtr mock_app(CreateMockApp()); + application_set_.insert(mock_app); + DataAccessor accessor(application_set_, app_set_lock_); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType)) + .WillRepeatedly(Return(true)); + + EXPECT_CALL(*mock_app, UnsubscribeFromIVI(kVehicleType)) + .WillRepeatedly(Return(true)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + CommandPtr command(CreateCommand(command_msg)); + command->Run(); +} + +TEST_F(UnsubscribeVehicleRequestTest, Run_UnsubscribeData_SUCCESS) { + UnsubscribeSuccessfully(); +} + +TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataNotSubscribed_IGNORED) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + CommandPtr command(CreateCommand(command_msg)); + + am::VehicleData vehicle_data; + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + vehicle_data.insert(am::VehicleData::value_type(kMsgParamKey, kVehicleType)); + EXPECT_CALL(mock_message_helper_, vehicle_data()) + .WillOnce(ReturnRef(vehicle_data)); + EXPECT_CALL(*mock_app, IsSubscribedToIVI(kVehicleType)) + .WillRepeatedly(Return(false)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + command->Init(); + command->Run(); + + am::event_engine::Event test_event( + hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData); + SmartObject message(smart_objects::SmartType_Map); + const hmi_apis::Common_Result::eType hmi_result = + hmi_apis::Common_Result::SUCCESS; + message[am::strings::params][am::hmi_response::code] = hmi_result; + message[am::strings::msg_params][kMsgParamKey] = true; + test_event.set_smart_object(message); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + EXPECT_CALL(*mock_app, UpdateHash()); + + command->on_event(test_event); +} + +TEST_F(UnsubscribeVehicleRequestTest, OnEvent_DataUnsubscribed_SUCCESS) { + UnsubscribeSuccessfully(); + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][kMsgParamKey] = true; + CommandPtr command(CreateCommand(command_msg)); + MockAppPtr mock_app(CreateMockApp()); + + am::event_engine::Event test_event( + hmi_apis::FunctionID::VehicleInfo_UnsubscribeVehicleData); + SmartObject message(smart_objects::SmartType_Map); + const hmi_apis::Common_Result::eType hmi_result = + hmi_apis::Common_Result::SUCCESS; + message[am::strings::params][am::hmi_response::code] = hmi_result; + message[am::strings::msg_params][kMsgParamKey] = true; + test_event.set_smart_object(message); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command->on_event(test_event); +} + +} // namespace unsubscribe_vehicle_data_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc new file mode 100644 index 0000000000..bed9cffeb2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "mobile/unsubscribe_vehicle_data_response.h" +#include +#include +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unsubscribe_vehicle_data_response { + +namespace commands = ::application_manager::commands; + +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; + +using vehicle_info_plugin::commands::UnsubscribeVehicleDataResponse; +using commands::MessageSharedPtr; +namespace am = ::application_manager; + +class UnsubscribeVehicleResponseTest + : public CommandsTest {}; + +MATCHER_P(ResultCodeIs, result_code, "") { + return result_code == + static_cast( + (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); +} + +TEST_F(UnsubscribeVehicleResponseTest, + Run_SendFalseResponseToMobile_SendInvalidEnum) { + MessageSharedPtr command_msg = + ::utils::MakeShared(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::success] = false; + + ::utils::SharedPtr command = + CreateCommand(command_msg); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(ResultCodeIs(mobile_apis::Result::INVALID_ENUM), _)); + command->Run(); +} + +TEST_F(UnsubscribeVehicleResponseTest, + Run_SendSuccessfulResponseToMobile_SUCCESS) { + MessageSharedPtr command_msg = + ::utils::MakeShared(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::success] = true; + ::utils::SharedPtr command = + CreateCommand(command_msg); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(ResultCodeIs(mobile_apis::Result::SUCCESS), _)); + command->Run(); +} + +TEST_F(UnsubscribeVehicleResponseTest, + Run_SendResponseToMobile_SendCodeToMobile) { + MessageSharedPtr command_msg = + ::utils::MakeShared(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::success] = true; + + mobile_apis::Result::eType result_type = mobile_apis::Result::WARNINGS; + (*command_msg)[am::strings::msg_params][am::strings::result_code] = + result_type; + ::utils::SharedPtr command = + CreateCommand(command_msg); + + command->Run(); +} + +} // namespace unsubscribe_vehicle_data_response +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test -- cgit v1.2.1