From 376c972ba76aa042fbd17f36cce9518d57d7b52d Mon Sep 17 00:00:00 2001 From: Valerii Date: Wed, 7 Feb 2018 16:42:01 +0200 Subject: Fix build with unit tests after commands factory refactoring - Change enum name from command origin to command source - Create Mock for command factory class - Fix mock_app_manager after refactoring - Fix failed unit test Fix unit test in progress Add asser in plugin manager getter Fixed UT Application manager impl -Add method "SetRPCService" into the class ApplicationManagerImpl Fixed UT Application manager impl -Add method "SetRPCService" into the class ApplicationManagerImpl Fixed UT Application manager impl -Add method "SetRPCService" into the class ApplicationManagerImpl Fixed UTs for hmi and mobile commands. --- src/components/application_manager/CMakeLists.txt | 2 +- .../application_manager/application_manager_impl.h | 5 + .../include/application_manager/rpc_service_impl.h | 2 +- .../hmi/mixing_audio_supported_response.cc | 3 +- .../src/commands/hmi/notification_from_hmi.cc | 111 -- .../src/commands/hmi/notification_to_hmi.cc | 75 - .../src/commands/hmi/response_from_hmi.cc | 116 -- .../src/commands/hmi/response_to_hmi.cc | 73 - .../rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt | 34 + .../test/commands/hmi/activate_app_request_test.cc | 125 ++ .../hmi/add_statistics_info_notification_test.cc | 85 + .../commands/hmi/allow_all_apps_response_test.cc | 76 + .../test/commands/hmi/allow_app_response_test.cc | 95 + .../hmi/button_get_capabilities_response_test.cc | 112 ++ .../test/commands/hmi/close_popup_response_test.cc | 74 + .../test/commands/hmi/dummy_hmi_commands_test.cc | 618 ++++++ .../commands/hmi/get_system_info_request_test.cc | 99 + .../commands/hmi/get_system_info_response_test.cc | 140 ++ .../test/commands/hmi/get_urls_response_test.cc | 90 + .../test/commands/hmi/get_urls_test.cc | 336 ++++ .../hmi_notifications/hmi_notifications_test.cc | 1918 +++++++++++++++++++ .../hmi/mixing_audio_supported_request_test.cc | 91 + .../hmi/mixing_audio_supported_response_test.cc | 102 + .../hmi/navi_audio_start_stream_request_test.cc | 121 ++ .../commands/hmi/navi_is_ready_request_test.cc | 135 ++ .../commands/hmi/navi_is_ready_response_test.cc | 76 + .../hmi/navi_set_video_config_request_test.cc | 216 +++ .../hmi/navi_set_video_config_response_test.cc | 79 + .../commands/hmi/navi_start_stream_request_test.cc | 120 ++ .../commands/hmi/navi_stop_stream_requests_test.cc | 105 ++ .../hmi/on_driver_distraction_notification_test.cc | 161 ++ .../hmi/rc_get_capabilities_response_test.cc | 177 ++ .../test/commands/hmi/rc_is_ready_request_test.cc | 168 ++ .../test/commands/hmi/rc_is_ready_response_test.cc | 79 + .../test/commands/hmi/response_from_hmi_test.cc | 134 ++ .../commands/hmi/sdl_activate_app_request_test.cc | 495 +++++ .../commands/hmi/sdl_activate_app_response_test.cc | 87 + .../sdl_get_list_of_permisssions_request_test.cc | 111 ++ .../hmi/sdl_get_status_update_request_test.cc | 79 + .../sdl_get_user_friendly_message_request_test.cc | 160 ++ .../test/commands/hmi/simple_notifications_test.cc | 77 + .../commands/hmi/simple_request_from_hmi_test.cc | 99 + .../commands/hmi/simple_requests_to_hmi_test.cc | 286 +++ .../commands/hmi/simple_response_from_hmi_test.cc | 374 ++++ .../commands/hmi/simple_response_to_hmi_test.cc | 105 ++ .../hmi/tts_get_capabilities_response_test.cc | 125 ++ .../commands/hmi/tts_get_language_response_test.cc | 103 + .../tts_get_supported_languages_response_test.cc | 130 ++ .../commands/hmi/tts_is_ready_response_test.cc | 99 + .../hmi/ui_get_capabilities_response_test.cc | 317 ++++ .../commands/hmi/ui_get_language_response_test.cc | 107 ++ .../ui_get_supported_languages_response_test.cc | 124 ++ .../test/commands/hmi/ui_is_ready_request_test.cc | 199 ++ .../test/commands/hmi/ui_is_ready_response_test.cc | 92 + .../hmi/update_device_list_request_test.cc | 173 ++ .../test/commands/hmi/update_sdl_request_test.cc | 88 + .../test/commands/hmi/update_sdl_response_test.cc | 86 + .../hmi/vi_get_vehicle_data_response_test.cc | 153 ++ .../test/commands/hmi/vi_is_ready_request_test.cc | 169 ++ .../hmi/vr_get_capabilities_response_test.cc | 108 ++ .../commands/hmi/vr_get_language_response_test.cc | 107 ++ .../vr_get_supported_languages_response_test.cc | 124 ++ .../test/commands/hmi/vr_is_ready_request_test.cc | 182 ++ .../test/commands/hmi/vr_is_ready_response_test.cc | 79 + .../commands/mobile/add_command_request_test.cc | 1112 +++++++++++ .../commands/mobile/add_sub_menu_request_test.cc | 121 ++ .../commands/mobile/alert_maneuver_request_test.cc | 256 +++ .../test/commands/mobile/alert_request_test.cc | 810 ++++++++ .../commands/mobile/change_registration_test.cc | 559 ++++++ .../mobile/create_interaction_choice_set_test.cc | 831 ++++++++ .../commands/mobile/delete_command_request_test.cc | 257 +++ .../test/commands/mobile/delete_file_test.cc | 250 +++ .../mobile/delete_interaction_choice_set_test.cc | 294 +++ .../test/commands/mobile/delete_sub_menu_test.cc | 365 ++++ .../mobile/diagnostic_message_request_test.cc | 185 ++ .../commands/mobile/dial_number_request_test.cc | 190 ++ .../commands/mobile/dummy_mobile_commands_test.cc | 341 ++++ .../mobile/end_audio_pass_thru_request_test.cc | 120 ++ .../test/commands/mobile/get_dtcs_request_test.cc | 143 ++ .../mobile/get_vehicle_data_request_test.cc | 262 +++ .../commands/mobile/get_way_points_request_test.cc | 282 +++ .../commands/mobile/list_files_request_test.cc | 145 ++ .../mobile/on_button_notification_commands_test.cc | 340 ++++ .../mobile/on_command_notification_test.cc | 138 ++ .../mobile/on_hash_change_notification_test.cc | 119 ++ .../on_hmi_status_notification_from_mobile_test.cc | 282 +++ .../mobile/on_hmi_status_notification_test.cc | 205 ++ .../on_hmi_status_notification_test.cc.autosave | 205 ++ .../mobile/on_keyboard_input_notification_test.cc | 165 ++ .../mobile/on_system_request_notification_test.cc | 283 +++ .../on_tbt_client_state_notification_test.cc | 138 ++ .../mobile/on_touch_event_notification_test.cc | 148 ++ .../mobile/on_vehicle_data_notification_test.cc | 148 ++ .../on_way_point_change_notification_test.cc | 115 ++ .../mobile/perform_audio_pass_thru_test.cc | 835 ++++++++ .../commands/mobile/perform_interaction_test.cc | 264 +++ .../test/commands/mobile/put_file_test.cc | 407 ++++ .../test/commands/mobile/read_did_request_test.cc | 165 ++ .../mobile/register_app_interface_request_test.cc | 523 +++++ .../mobile/reset_global_properties_test.cc | 576 ++++++ .../commands/mobile/scrollable_message_test.cc | 286 +++ .../test/commands/mobile/send_haptic_data_test.cc | 164 ++ .../commands/mobile/send_location_request_test.cc | 406 ++++ .../test/commands/mobile/set_app_icon_test.cc | 174 ++ .../commands/mobile/set_display_layout_test.cc | 250 +++ .../commands/mobile/set_global_properties_test.cc | 1241 ++++++++++++ .../commands/mobile/set_media_clock_timer_test.cc | 356 ++++ .../test/commands/mobile/show_test.cc | 921 +++++++++ .../mobile/simple_notification_commands_test.cc | 99 + .../mobile/simple_response_commands_test.cc | 199 ++ .../test/commands/mobile/slider_test.cc | 342 ++++ .../test/commands/mobile/speak_request_test.cc | 407 ++++ .../mobile/subscribe_button_request_test.cc | 202 ++ .../mobile/subscribe_way_points_request_test.cc | 130 ++ .../test/commands/mobile/system_request_test.cc | 237 +++ .../unregister_app_interface_request_test.cc | 118 ++ .../mobile/unsubscribe_button_request_test.cc | 150 ++ .../mobile/unsubscribe_vehicle_request_test.cc | 288 +++ .../mobile/unsubscribe_vehicle_response_test.cc | 114 ++ .../mobile/unsubscribe_way_points_request_test.cc | 171 ++ ...unsubscribe_way_points_request_test.cc.autosave | 168 ++ .../mobile/update_turn_list_request_test.cc | 292 +++ .../src/commands/notification_from_hmi.cc | 111 ++ .../src/commands/notification_to_hmi.cc | 75 + .../src/commands/response_from_hmi.cc | 116 ++ .../src/commands/response_to_hmi.cc | 73 + .../application_manager/src/rpc_service_impl.cc | 80 +- .../application_manager/test/CMakeLists.txt | 3 +- .../test/application_manager_impl_test.cc | 16 +- .../test/command_holder_test.cc | 18 +- .../test/commands/CMakeLists.txt | 29 +- .../test/commands/command_impl_test.cc | 11 +- .../test/commands/command_request_impl_test.cc | 60 +- .../test/commands/command_response_impl_test.cc | 20 +- .../test/commands/hmi/activate_app_request_test.cc | 126 -- .../hmi/add_statistics_info_notification_test.cc | 90 - .../commands/hmi/allow_all_apps_response_test.cc | 77 - .../test/commands/hmi/allow_app_response_test.cc | 95 - .../hmi/button_get_capabilities_response_test.cc | 116 -- .../test/commands/hmi/close_popup_response_test.cc | 73 - .../test/commands/hmi/dummy_hmi_commands_test.cc | 617 ------ .../commands/hmi/get_system_info_request_test.cc | 100 - .../commands/hmi/get_system_info_response_test.cc | 153 -- .../test/commands/hmi/get_urls_response_test.cc | 91 - .../test/commands/hmi/get_urls_test.cc | 346 ---- .../hmi_notifications/hmi_notifications_test.cc | 1994 -------------------- .../hmi/mixing_audio_supported_request_test.cc | 92 - .../hmi/mixing_audio_supported_response_test.cc | 106 -- .../hmi/navi_audio_start_stream_request_test.cc | 123 -- .../commands/hmi/navi_is_ready_request_test.cc | 138 -- .../commands/hmi/navi_is_ready_response_test.cc | 76 - .../hmi/navi_set_video_config_request_test.cc | 216 --- .../hmi/navi_set_video_config_response_test.cc | 79 - .../commands/hmi/navi_start_stream_request_test.cc | 123 -- .../commands/hmi/navi_stop_stream_requests_test.cc | 107 -- .../hmi/on_driver_distraction_notification_test.cc | 162 -- .../hmi/rc_get_capabilities_response_test.cc | 181 -- .../test/commands/hmi/rc_is_ready_request_test.cc | 175 -- .../test/commands/hmi/rc_is_ready_response_test.cc | 79 - .../test/commands/hmi/response_from_hmi_test.cc | 139 -- .../commands/hmi/sdl_activate_app_request_test.cc | 506 ----- .../commands/hmi/sdl_activate_app_response_test.cc | 88 - .../sdl_get_list_of_permisssions_request_test.cc | 116 -- .../hmi/sdl_get_status_update_request_test.cc | 82 - .../sdl_get_user_friendly_message_request_test.cc | 169 -- .../test/commands/hmi/simple_notifications_test.cc | 77 - .../commands/hmi/simple_request_from_hmi_test.cc | 100 - .../commands/hmi/simple_requests_to_hmi_test.cc | 290 --- .../commands/hmi/simple_response_from_hmi_test.cc | 374 ---- .../commands/hmi/simple_response_to_hmi_test.cc | 108 -- .../hmi/tts_get_capabilities_response_test.cc | 136 -- .../commands/hmi/tts_get_language_response_test.cc | 109 -- .../tts_get_supported_languages_response_test.cc | 134 -- .../commands/hmi/tts_is_ready_response_test.cc | 99 - .../hmi/ui_get_capabilities_response_test.cc | 348 ---- .../commands/hmi/ui_get_language_response_test.cc | 113 -- .../ui_get_supported_languages_response_test.cc | 128 -- .../test/commands/hmi/ui_is_ready_request_test.cc | 205 -- .../test/commands/hmi/ui_is_ready_response_test.cc | 92 - .../hmi/update_device_list_request_test.cc | 175 -- .../test/commands/hmi/update_sdl_request_test.cc | 91 - .../test/commands/hmi/update_sdl_response_test.cc | 87 - .../hmi/vi_get_vehicle_data_response_test.cc | 156 -- .../test/commands/hmi/vi_is_ready_request_test.cc | 176 -- .../hmi/vr_get_capabilities_response_test.cc | 112 -- .../commands/hmi/vr_get_language_response_test.cc | 113 -- .../vr_get_supported_languages_response_test.cc | 128 -- .../test/commands/hmi/vr_is_ready_request_test.cc | 196 -- .../test/commands/hmi/vr_is_ready_response_test.cc | 79 - .../commands/mobile/add_command_request_test.cc | 1125 ----------- .../commands/mobile/add_sub_menu_request_test.cc | 122 -- .../commands/mobile/alert_maneuver_request_test.cc | 266 --- .../test/commands/mobile/alert_request_test.cc | 828 -------- .../commands/mobile/change_registration_test.cc | 567 ------ .../mobile/create_interaction_choice_set_test.cc | 843 --------- .../commands/mobile/delete_command_request_test.cc | 257 --- .../test/commands/mobile/delete_file_test.cc | 250 --- .../mobile/delete_interaction_choice_set_test.cc | 296 --- .../test/commands/mobile/delete_sub_menu_test.cc | 365 ---- .../mobile/diagnostic_message_request_test.cc | 185 -- .../commands/mobile/dial_number_request_test.cc | 187 -- .../commands/mobile/dummy_mobile_commands_test.cc | 342 ---- .../mobile/end_audio_pass_thru_request_test.cc | 121 -- .../test/commands/mobile/get_dtcs_request_test.cc | 143 -- .../mobile/get_vehicle_data_request_test.cc | 255 --- .../commands/mobile/get_way_points_request_test.cc | 285 --- .../commands/mobile/list_files_request_test.cc | 145 -- .../mobile/on_button_notification_commands_test.cc | 357 ---- .../mobile/on_command_notification_test.cc | 137 -- .../mobile/on_hash_change_notification_test.cc | 119 -- .../on_hmi_status_notification_from_mobile_test.cc | 282 --- .../mobile/on_hmi_status_notification_test.cc | 207 -- .../mobile/on_keyboard_input_notification_test.cc | 165 -- .../mobile/on_system_request_notification_test.cc | 297 --- .../on_tbt_client_state_notification_test.cc | 140 -- .../mobile/on_touch_event_notification_test.cc | 150 -- .../mobile/on_vehicle_data_notification_test.cc | 149 -- .../on_way_point_change_notification_test.cc | 116 -- .../mobile/perform_audio_pass_thru_test.cc | 841 --------- .../commands/mobile/perform_interaction_test.cc | 264 --- .../test/commands/mobile/put_file_test.cc | 416 ---- .../test/commands/mobile/read_did_request_test.cc | 166 -- .../mobile/register_app_interface_request_test.cc | 533 ------ .../mobile/reset_global_properties_test.cc | 578 ------ .../commands/mobile/scrollable_message_test.cc | 292 --- .../test/commands/mobile/send_haptic_data_test.cc | 164 -- .../commands/mobile/send_location_request_test.cc | 405 ---- .../test/commands/mobile/set_app_icon_test.cc | 175 -- .../commands/mobile/set_display_layout_test.cc | 258 --- .../commands/mobile/set_global_properties_test.cc | 1250 ------------ .../commands/mobile/set_media_clock_timer_test.cc | 357 ---- .../test/commands/mobile/show_test.cc | 953 ---------- .../mobile/simple_notification_commands_test.cc | 101 - .../mobile/simple_response_commands_test.cc | 204 -- .../test/commands/mobile/slider_test.cc | 344 ---- .../test/commands/mobile/speak_request_test.cc | 414 ---- .../mobile/subscribe_button_request_test.cc | 208 -- .../mobile/subscribe_way_points_request_test.cc | 130 -- .../test/commands/mobile/system_request_test.cc | 240 --- .../unregister_app_interface_request_test.cc | 118 -- .../mobile/unsubscribe_button_request_test.cc | 158 -- .../mobile/unsubscribe_vehicle_request_test.cc | 288 --- .../mobile/unsubscribe_vehicle_response_test.cc | 114 -- .../mobile/unsubscribe_way_points_request_test.cc | 173 -- .../mobile/update_turn_list_request_test.cc | 305 --- .../test/hmi_capabilities_test.cc | 7 +- .../test/hmi_language_handler_test.cc | 12 +- .../commands/command_request_test.h | 13 +- .../application_manager/commands/commands_test.h | 23 +- .../application_manager/mock_command_factory.h | 61 + .../application_manager/mock_hmi_command_factory.h | 60 - .../test/message_helper/message_helper_test.cc | 14 +- .../test/mock_hmi_command_factory.cc | 11 +- .../test/policy_handler_test.cc | 10 +- .../test/state_controller/state_controller_test.cc | 10 +- .../application_manager/mock_application_manager.h | 7 +- .../test/application_manager/mock_rpc_service.h | 4 + .../policy_external/policy/mock_policy_manager.h | 9 +- src/components/protocol_handler/CMakeLists.txt | 2 +- 259 files changed, 28927 insertions(+), 29024 deletions(-) delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_from_hmi.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_to_hmi.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_from_hmi.cc delete mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_to_hmi.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc.autosave create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc create 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/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc.autosave create mode 100644 src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc create mode 100644 src/components/application_manager/src/commands/notification_from_hmi.cc create mode 100644 src/components/application_manager/src/commands/notification_to_hmi.cc create mode 100644 src/components/application_manager/src/commands/response_from_hmi.cc create mode 100644 src/components/application_manager/src/commands/response_to_hmi.cc delete mode 100644 src/components/application_manager/test/commands/hmi/activate_app_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/add_statistics_info_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/allow_all_apps_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/allow_app_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/button_get_capabilities_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/close_popup_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/dummy_hmi_commands_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/get_system_info_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/get_urls_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/get_urls_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/mixing_audio_supported_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/mixing_audio_supported_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_audio_start_stream_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_is_ready_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_is_ready_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_set_video_config_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_set_video_config_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_start_stream_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/navi_stop_stream_requests_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/rc_get_capabilities_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/rc_is_ready_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/response_from_hmi_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/sdl_activate_app_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/sdl_get_status_update_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/simple_notifications_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/simple_request_from_hmi_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/simple_response_to_hmi_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/tts_get_language_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/tts_get_supported_languages_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/tts_is_ready_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/ui_get_capabilities_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/ui_get_language_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/ui_get_supported_languages_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/ui_is_ready_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/update_device_list_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/update_sdl_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/update_sdl_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vi_get_vehicle_data_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vr_get_capabilities_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vr_get_language_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vr_get_supported_languages_response_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc delete mode 100644 src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/add_command_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/alert_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/change_registration_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/delete_command_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/delete_file_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/dial_number_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/dummy_mobile_commands_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/list_files_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_button_notification_commands_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_command_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_tbt_client_state_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_touch_event_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/on_way_point_change_notification_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/perform_interaction_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/put_file_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/read_did_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/scrollable_message_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/send_location_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/set_app_icon_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/set_display_layout_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/set_global_properties_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/show_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/simple_response_commands_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/slider_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/speak_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/system_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/unsubscribe_button_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_response_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc delete mode 100644 src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc create mode 100644 src/components/application_manager/test/include/application_manager/mock_command_factory.h delete mode 100644 src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h diff --git a/src/components/application_manager/CMakeLists.txt b/src/components/application_manager/CMakeLists.txt index b3af800987..0e45582bb6 100644 --- a/src/components/application_manager/CMakeLists.txt +++ b/src/components/application_manager/CMakeLists.txt @@ -188,7 +188,7 @@ if(ENABLE_LOG) list(APPEND LIBRARIES log4cxx -L${LOG4CXX_LIBS_DIRECTORY}) endif() -add_dependencies("ApplicationManager" libbson) +#add_dependencies("ApplicationManager" libbson) target_link_libraries("ApplicationManager" ${LIBRARIES}) if(BUILD_TESTS) diff --git a/src/components/application_manager/include/application_manager/application_manager_impl.h b/src/components/application_manager/include/application_manager/application_manager_impl.h index 7435ae72e4..b7477edc14 100644 --- a/src/components/application_manager/include/application_manager/application_manager_impl.h +++ b/src/components/application_manager/include/application_manager/application_manager_impl.h @@ -210,6 +210,7 @@ class ApplicationManagerImpl } virtual plugin_manager::RPCPluginManager& GetPluginManager() OVERRIDE { + DCHECK(plugin_manager_); return *plugin_manager_; } @@ -956,6 +957,10 @@ class ApplicationManagerImpl return *rpc_handler_; } + void SetRPCService(std::unique_ptr& rpc_service) { + rpc_service_ = std::move(rpc_service); + } + bool is_stopping() const OVERRIDE; bool is_audio_pass_thru_active() const OVERRIDE; diff --git a/src/components/application_manager/include/application_manager/rpc_service_impl.h b/src/components/application_manager/include/application_manager/rpc_service_impl.h index 25f415bd40..7543fafccc 100644 --- a/src/components/application_manager/include/application_manager/rpc_service_impl.h +++ b/src/components/application_manager/include/application_manager/rpc_service_impl.h @@ -31,7 +31,7 @@ */ #ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_IMPL_H -#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_H +#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_RPC_SERVICE_IMPL_H #include "application_manager/application_manager.h" #include "application_manager/rpc_service.h" diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/mixing_audio_supported_response.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/mixing_audio_supported_response.cc index c7ea91f7ca..c18a40476d 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/mixing_audio_supported_response.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/mixing_audio_supported_response.cc @@ -53,8 +53,7 @@ MixingAudioSupportedResponse::~MixingAudioSupportedResponse() {} void MixingAudioSupportedResponse::Run() { LOG4CXX_AUTO_TRACE(logger_); - HMICapabilities& hmi_capabilities = hmi_capabilities_; - hmi_capabilities.set_attenuated_supported( + hmi_capabilities_.set_attenuated_supported( (*message_)[strings::msg_params][hmi_response::attenuated_supported] .asBool()); } diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_from_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_from_hmi.cc deleted file mode 100644 index cdb938d5d7..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_from_hmi.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* - Copyright (c) 2013, 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 "application_manager/commands/notification_from_hmi.h" -#include "application_manager/application_manager.h" -#include "application_manager/rpc_service.h" -#include "smart_objects/smart_object.h" - -namespace sdl_rpc_plugin { -using namespace application_manager; - -namespace commands { - -NotificationFromHMI::NotificationFromHMI( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : CommandImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) { - // Replace HMI app id with Mobile connection id - ReplaceHMIWithMobileAppId(*message); -} - -NotificationFromHMI::~NotificationFromHMI() {} - -bool NotificationFromHMI::Init() { - return true; -} - -bool NotificationFromHMI::CleanUp() { - return true; -} - -void NotificationFromHMI::Run() {} - -void NotificationFromHMI::SendNotificationToMobile( - const application_manager::commands::MessageSharedPtr& message) { - (*message)[strings::params][strings::message_type] = - static_cast(application_manager::MessageType::kNotification); - rpc_service_.ManageMobileCommand(message, SOURCE_SDL); -} - -void NotificationFromHMI::CreateHMIRequest( - const hmi_apis::FunctionID::eType& function_id, - const smart_objects::SmartObject& msg_params) const { - smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; - if (!result) { - LOG4CXX_ERROR(logger_, "Memory allocation failed."); - return; - } - - // get hmi correlation id for chaining further request from this object - const uint32_t hmi_correlation_id_ = - application_manager_.GetNextHMICorrelationID(); - - NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; - request[strings::params][strings::message_type] = - static_cast(application_manager::MessageType::kRequest); - request[strings::params][strings::function_id] = - static_cast(function_id); - request[strings::params][strings::correlation_id] = hmi_correlation_id_; - request[strings::params][strings::protocol_version] = - CommandImpl::protocol_version_; - request[strings::params][strings::protocol_type] = - CommandImpl::hmi_protocol_type_; - - request[strings::msg_params] = msg_params; - - if (!rpc_service_.ManageHMICommand(result)) { - LOG4CXX_ERROR(logger_, "Unable to send request"); - return; - } -} - -} // namespace commands - -} // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_to_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_to_hmi.cc deleted file mode 100644 index 0c4e64ebdd..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/notification_to_hmi.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright (c) 2013, 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 "application_manager/commands/notification_to_hmi.h" -#include "application_manager/application_manager.h" -#include "application_manager/rpc_service.h" - -namespace sdl_rpc_plugin { -using namespace application_manager; - -namespace commands { - -NotificationToHMI::NotificationToHMI( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : CommandImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} - -NotificationToHMI::~NotificationToHMI() {} - -bool NotificationToHMI::Init() { - // Replace Mobile connection id with HMI app id - return ReplaceMobileWithHMIAppId(*message_); -} - -bool NotificationToHMI::CleanUp() { - return true; -} - -void NotificationToHMI::Run() {} - -void NotificationToHMI::SendNotification() { - (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; - (*message_)[strings::params][strings::protocol_version] = protocol_version_; - rpc_service_.SendMessageToHMI(message_); -} - -} // namespace commands - -} // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_from_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_from_hmi.cc deleted file mode 100644 index c158052b89..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_from_hmi.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - Copyright (c) 2013, 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 "application_manager/commands/response_from_hmi.h" -#include "application_manager/rpc_service.h" -#include "smart_objects/smart_object.h" - -namespace sdl_rpc_plugin { -using namespace application_manager; - -namespace commands { - -ResponseFromHMI::ResponseFromHMI( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : CommandImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) { - // If it is error response, shift info - if ((*message)[strings::params].keyExists(hmi_response::message)) { - (*message)[strings::msg_params][strings::info] = - (*message)[strings::params][hmi_response::message]; - } - - // Replace HMI app id with Mobile connection id - ReplaceHMIWithMobileAppId(*message); -} - -ResponseFromHMI::~ResponseFromHMI() {} - -bool ResponseFromHMI::Init() { - return true; -} - -bool ResponseFromHMI::CleanUp() { - return true; -} - -void ResponseFromHMI::Run() {} - -void ResponseFromHMI::SendResponseToMobile( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager) { - (*message)[strings::params][strings::message_type] = MessageType::kResponse; - - rpc_service_.ManageMobileCommand(message, SOURCE_SDL); -} - -void ResponseFromHMI::CreateHMIRequest( - const hmi_apis::FunctionID::eType& function_id, - const smart_objects::SmartObject& msg_params) const { - smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; - - if (!result) { - LOG4CXX_ERROR(logger_, "Memory allocation failed."); - return; - } - - // get hmi correlation id for chaining further request from this object - const uint32_t hmi_correlation_id_ = - application_manager_.GetNextHMICorrelationID(); - - NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; - request[strings::params][strings::message_type] = MessageType::kRequest; - request[strings::params][strings::function_id] = function_id; - request[strings::params][strings::correlation_id] = hmi_correlation_id_; - request[strings::params][strings::protocol_version] = - CommandImpl::protocol_version_; - request[strings::params][strings::protocol_type] = - CommandImpl::hmi_protocol_type_; - - request[strings::msg_params] = msg_params; - - if (!rpc_service_.ManageHMICommand(result)) { - LOG4CXX_ERROR(logger_, "Unable to send request"); - return; - } -} - -} // namespace commands - -} // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_to_hmi.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_to_hmi.cc deleted file mode 100644 index 7aeddf28e5..0000000000 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/hmi/response_to_hmi.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (c) 2013, 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 "application_manager/commands/response_to_hmi.h" -#include "application_manager/application_manager.h" -#include "application_manager/rpc_service.h" - -namespace sdl_rpc_plugin { -using namespace application_manager; - -namespace commands { - -ResponseToHMI::ResponseToHMI( - const application_manager::commands::MessageSharedPtr& message, - ApplicationManager& application_manager, - rpc_service::RPCService& rpc_service, - HMICapabilities& hmi_capabilities, - policy::PolicyHandlerInterface& policy_handle) - : CommandImpl(message, - application_manager, - rpc_service, - hmi_capabilities, - policy_handle) {} - -ResponseToHMI::~ResponseToHMI() {} - -bool ResponseToHMI::Init() { - // Replace Mobile connection id with HMI app id - return ReplaceMobileWithHMIAppId(*message_); -} - -bool ResponseToHMI::CleanUp() { - return true; -} - -void ResponseToHMI::Run() { - (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; - (*message_)[strings::params][strings::protocol_version] = protocol_version_; - - rpc_service_.SendMessageToHMI(message_); -} - -} // namespace commands -} // namespace application_manager diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt index e69de29bb2..8893be4923 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt @@ -0,0 +1,34 @@ +include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories( + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_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 + sdl_rpc_plugin + jsoncpp +) + +create_cotired_test("sdl_commands_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc new file mode 100644 index 0000000000..39f9eee3d9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/activate_app_request.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace activate_app_request { + +using ::testing::_; +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::ActivateAppRequest; +using am::commands::CommandImpl; + +using ::test::components::application_manager_test::MockApplication; + +typedef SharedPtr MockAppPtr; +typedef ::utils::SharedPtr ActivateAppRequestPtr; + +MATCHER_P(CheckMessage, level, "") { + return level == + static_cast( + (*arg)[strings::msg_params][strings::activate_app_hmi_level] + .asInt()); +} + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCorrelationId = 2u; +} // namespace + +class ActivateAppRequestTest : public CommandsTest { + public: + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::app_id] = kAppId; + msg_params[strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params] = msg_params; + (*msg)[strings::params][strings::app_id] = kAppId; + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::app_id] = kAppId; + return msg; + } +}; + +TEST_F(ActivateAppRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + MockAppPtr app = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId)); + +// TODO(OKozlov) Investigate and fix issue with using log +#ifdef ENABLE_LOG + (*msg)[strings::msg_params][strings::activate_app_hmi_level] = + mobile_apis::HMILevel::HMI_FULL; +#endif + ActivateAppRequestPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); +#ifdef ENABLE_LOG + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(CheckMessage(mobile_apis::HMILevel::HMI_FULL))); +#else + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(msg))); +#endif + command->Run(); + +#ifndef ENABLE_LOG + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +#endif +} + +} // namespace activate_app_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/hmi/add_statistics_info_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc new file mode 100644 index 0000000000..0b80565bd9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/add_statistics_info_notification.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/policies/policy_handler.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace add_statistics_info_notification { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_notification = ::application_manager::hmi_notification; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AddStatisticsInfoNotification; +using am::commands::CommandImpl; +using policy::PolicyHandler; +using policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef ::utils::SharedPtr NotificationPtr; + +namespace { +const uint32_t kStatisticType = 1u; +} // namespace + +class AddStatisticsInfoNotificationTest + : public CommandsTest {}; + +TEST_F(AddStatisticsInfoNotificationTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::msg_params][am::hmi_notification::statistic_type] = + kStatisticType; + NotificationPtr command(CreateCommand(msg)); + + EXPECT_CALL(mock_policy_handler_, AddStatisticsInfo(kStatisticType)); + + command->Run(); +} + +} // namespace add_statistics_info_notification +} // 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/allow_all_apps_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc new file mode 100644 index 0000000000..e176db124d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/allow_all_apps_response.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace allow_all_apps_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AllowAllAppsResponse; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef ::utils::SharedPtr ResponsePtr; + +namespace { +const bool kResponseIsAllowed = true; +} // + +class AllowAllAppsResponseTest + : public CommandsTest {}; + +TEST_F(AllowAllAppsResponseTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::allowed] = kResponseIsAllowed; + + ResponsePtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, SetAllAppsAllowed(kResponseIsAllowed)); + + command->Run(); +} + +} // namespace allow_all_apps_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/allow_app_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc new file mode 100644 index 0000000000..e91fb522c6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/allow_app_response.h" +#include "utils/shared_ptr.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace allow_app_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AllowAppResponse; +using ::testing::_; +using ::testing::Return; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const uint32_t kConnectionKey = 1u; +const bool kIsResponseAllowed = true; +} + +typedef ::utils::SharedPtr ResponsePtr; + +class AllowAppResponseTest : public CommandsTest {}; + +TEST_F(AllowAppResponseTest, Run_AppCreated_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; + + ResponsePtr command(CreateCommand(msg)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_app_allowed(kIsResponseAllowed)); + + command->Run(); +} + +TEST_F(AllowAppResponseTest, Run_AppNotCreated_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; + + ResponsePtr command(CreateCommand(msg)); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + + command->Run(); +} + +} // namespace allow_app_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/button_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc new file mode 100644 index 0000000000..ae25703995 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/button_get_capabilities_response.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace button_get_capabilities_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::ButtonGetCapabilitiesResponse; +using ::testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef ::utils::SharedPtr ResponsePtr; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +class ButtonGetCapabilitiesResponseTest + : public CommandsTest { + public: + MessageSharedPtr CreateMsgParams() { + capabilities_[strings::name] = hmi_apis::Common_ButtonName::OK; + preset_bank_capabilities_ = true; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::capabilities] = (capabilities_); + (*msg)[strings::msg_params][hmi_response::preset_bank_capabilities] = + (preset_bank_capabilities_); + + return msg; + } + + SmartObject capabilities_; + SmartObject preset_bank_capabilities_; +}; + +TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeSuccess_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + ResponsePtr command(CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)); + EXPECT_CALL(mock_hmi_capabilities_, + set_preset_bank_capabilities(preset_bank_capabilities_)); + + command->Run(); +} + +TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeAborted_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponsePtr command(CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)) + .Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + set_preset_bank_capabilities(preset_bank_capabilities_)).Times(0); + + command->Run(); +} + +} // namespace button_get_capabilities_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/close_popup_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc new file mode 100644 index 0000000000..245db49060 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/close_popup_response.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace close_popup_response { + +using ::utils::SharedPtr; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::ClosePopupResponse; +using am::commands::CommandImpl; + +typedef SharedPtr ResponseFromHMIPtr; + +class ClosePopupResponseTest : public CommandsTest { +}; + +TEST_F(ClosePopupResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + ResponseFromHMIPtr command(CreateCommand(command_msg)); + + command->Run(); +} + +} // namespace close_popup_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/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc new file mode 100644 index 0000000000..2ad1b77ce0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -0,0 +1,618 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/command_request_test.h" + +#include +#include +#include +#include "gtest/gtest.h" + +#include "hmi/allow_all_apps_request.h" +#include "hmi/allow_all_apps_response.h" +#include "hmi/allow_app_request.h" +#include "hmi/allow_app_response.h" +#include "hmi/navi_audio_start_stream_request.h" +#include "hmi/navi_audio_start_stream_response.h" +#include "hmi/navi_audio_stop_stream_request.h" +#include "hmi/navi_audio_stop_stream_response.h" +#include "hmi/update_device_list_request.h" +#include "hmi/update_device_list_response.h" +#include "hmi/on_update_device_list.h" +#include "hmi/on_start_device_discovery.h" +#include "hmi/update_app_list_request.h" +#include "hmi/update_app_list_response.h" +#include "hmi/on_find_applications.h" +#include "hmi/sdl_get_list_of_permissions_request.h" +#include "hmi/sdl_get_list_of_permissions_response.h" +#include "hmi/sdl_get_user_friendly_message_request.h" +#include "hmi/sdl_get_user_friendly_message_response.h" +#include "hmi/sdl_get_status_update_request.h" +#include "hmi/sdl_get_status_update_response.h" +#include "hmi/on_status_update_notification.h" +#include "hmi/update_sdl_request.h" +#include "hmi/update_sdl_response.h" +#include "hmi/activate_app_request.h" +#include "hmi/activate_app_response.h" +#include "hmi/mixing_audio_supported_request.h" +#include "hmi/mixing_audio_supported_response.h" +#include "hmi/on_allow_sdl_functionality_notification.h" +#include "hmi/on_app_permission_changed_notification.h" +#include "hmi/on_app_permission_consent_notification.h" +#include "hmi/on_app_activated_notification.h" +#include "hmi/on_audio_data_streaming_notification.h" +#include "hmi/on_video_data_streaming_notification.h" +#include "hmi/on_sdl_consent_needed_notification.h" +#include "hmi/on_exit_all_applications_notification.h" +#include "hmi/on_exit_application_notification.h" +#include "hmi/on_put_file_notification.h" +#include "hmi/on_resume_audio_source_notification.h" +#include "hmi/on_ignition_cycle_over_notification.h" +#include "hmi/on_system_info_changed_notification.h" +#include "hmi/get_system_info_request.h" +#include "hmi/get_system_info_response.h" +#include "hmi/close_popup_request.h" +#include "hmi/close_popup_response.h" +#include "hmi/button_get_capabilities_request.h" +#include "hmi/button_get_capabilities_response.h" +#include "hmi/ui_add_command_request.h" +#include "hmi/ui_add_command_response.h" +#include "hmi/ui_delete_command_request.h" +#include "hmi/ui_delete_command_response.h" +#include "hmi/ui_add_submenu_request.h" +#include "hmi/ui_add_submenu_response.h" +#include "hmi/ui_delete_submenu_request.h" +#include "hmi/ui_delete_submenu_response.h" +#include "hmi/ui_get_supported_languages_request.h" +#include "hmi/ui_get_supported_languages_response.h" +#include "hmi/ui_get_language_request.h" +#include "hmi/ui_get_language_response.h" +#include "hmi/ui_get_capabilities_request.h" +#include "hmi/ui_get_capabilities_response.h" +#include "hmi/ui_change_registration_request.h" +#include "hmi/ui_change_registration_response.h" +#include "hmi/ui_show_request.h" +#include "hmi/ui_show_response.h" +#include "hmi/ui_alert_request.h" +#include "hmi/ui_alert_response.h" +#include "hmi/ui_is_ready_request.h" +#include "hmi/ui_is_ready_response.h" +#include "hmi/ui_slider_request.h" +#include "hmi/ui_slider_response.h" +#include "hmi/ui_set_media_clock_timer_request.h" +#include "hmi/ui_set_media_clock_timer_response.h" +#include "hmi/ui_set_global_properties_request.h" +#include "hmi/ui_set_global_properties_response.h" +#include "hmi/ui_scrollable_message_request.h" +#include "hmi/ui_scrollable_message_response.h" +#include "hmi/ui_set_app_icon_request.h" +#include "hmi/ui_set_app_icon_response.h" +#include "hmi/ui_perform_audio_pass_thru_response.h" +#include "hmi/ui_perform_audio_pass_thru_request.h" +#include "hmi/ui_end_audio_pass_thru_request.h" +#include "hmi/ui_end_audio_pass_thru_response.h" +#include "hmi/ui_perform_interaction_request.h" +#include "hmi/ui_perform_interaction_response.h" +#include "hmi/vr_is_ready_request.h" +#include "hmi/vr_is_ready_response.h" +#include "hmi/vr_add_command_request.h" +#include "hmi/vr_add_command_response.h" +#include "hmi/vr_delete_command_request.h" +#include "hmi/vr_delete_command_response.h" +#include "hmi/vr_change_registration_request.h" +#include "hmi/vr_change_registration_response.h" +#include "hmi/vr_get_supported_languages_request.h" +#include "hmi/vr_get_supported_languages_response.h" +#include "hmi/vr_get_language_request.h" +#include "hmi/vr_get_language_response.h" +#include "hmi/vr_get_capabilities_request.h" +#include "hmi/vr_get_capabilities_response.h" +#include "hmi/tts_is_ready_request.h" +#include "hmi/tts_is_ready_response.h" +#include "hmi/tts_change_registration_request.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/tts_get_supported_languages_request.h" +#include "hmi/tts_get_supported_languages_response.h" +#include "hmi/tts_get_language_request.h" +#include "hmi/tts_get_language_response.h" +#include "hmi/tts_stop_speaking_request.h" +#include "hmi/tts_stop_speaking_response.h" +#include "hmi/tts_speak_request.h" +#include "hmi/tts_speak_response.h" +#include "hmi/tts_set_global_properties_request.h" +#include "hmi/tts_set_global_properties_response.h" +#include "hmi/tts_get_capabilities_request.h" +#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" +#include "hmi/navi_show_constant_tbt_request.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_is_ready_response.h" +#include "hmi/navi_alert_maneuver_request.h" +#include "hmi/navi_alert_maneuver_response.h" +#include "hmi/navi_update_turn_list_request.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/navi_subscribe_way_points_request.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/navi_unsubscribe_way_points_request.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_get_way_points_request.h" +#include "hmi/navi_get_way_points_response.h" +#include "hmi/on_ready_notification.h" +#include "hmi/on_device_chosen_notification.h" +#include "hmi/on_file_removed_notification.h" +#include "hmi/on_system_context_notification.h" +#include "hmi/on_app_registered_notification.h" +#include "hmi/on_app_unregistered_notification.h" +#include "hmi/on_driver_distraction_notification.h" +#include "hmi/on_tts_started_notification.h" +#include "hmi/on_tts_stopped_notification.h" +#include "hmi/on_vr_started_notification.h" +#include "hmi/on_vr_stopped_notification.h" +#include "hmi/on_vr_command_notification.h" +#include "hmi/on_ui_command_notification.h" +#include "hmi/on_app_deactivated_notification.h" +#include "hmi/on_ui_language_change_notification.h" +#include "hmi/on_vr_language_change_notification.h" +#include "hmi/on_tts_language_change_notification.h" +#include "hmi/on_navi_tbt_client_state_notification.h" +#include "hmi/on_navi_way_point_change_notification.h" +#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" +#include "hmi/navi_start_stream_request.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_stop_stream_request.h" +#include "hmi/navi_stop_stream_response.h" +#include "hmi/on_system_request_notification.h" +#include "hmi/ui_set_display_layout_request.h" +#include "hmi/ui_set_display_layout_response.h" +#include "hmi/on_sdl_close_notification.h" +#include "hmi/on_sdl_persistence_complete_notification.h" +#include "hmi/on_record_start_notification.h" +#include "hmi/add_statistics_info_notification.h" +#include "hmi/on_system_error_notification.h" +#include "hmi/basic_communication_system_request.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/sdl_policy_update.h" +#include "hmi/sdl_policy_update_response.h" +#include "hmi/on_received_policy_update.h" +#include "hmi/on_policy_update.h" +#include "hmi/get_urls.h" +#include "hmi/get_urls_response.h" +#include "hmi/on_device_state_changed_notification.h" +#include "hmi/navi_send_location_request.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/on_tts_reset_timeout_notification.h" +#include "hmi/dial_number_request.h" +#include "hmi/dial_number_response.h" +#include "hmi/on_vi_gps_data_notification.h" +#include "hmi/on_vi_speed_notification.h" +#include "hmi/on_vi_rpm_notification.h" +#include "hmi/on_vi_fuel_level_notification.h" +#include "hmi/on_vi_fuel_level_state_notification.h" +#include "hmi/on_vi_instant_fuel_consumption_notification.h" +#include "hmi/on_vi_external_temperature_notification.h" +#include "hmi/on_vi_vin_notification.h" +#include "hmi/on_vi_prndl_notification.h" +#include "hmi/on_vi_tire_pressure_notification.h" +#include "hmi/on_vi_odometer_notification.h" +#include "hmi/on_vi_belt_status_notification.h" +#include "hmi/on_vi_body_information_notification.h" +#include "hmi/on_vi_device_status_notification.h" +#include "hmi/on_vi_driver_braking_notification.h" +#include "hmi/on_vi_wiper_status_notification.h" +#include "hmi/on_vi_head_lamp_status_notification.h" +#include "hmi/on_vi_engine_torque_notification.h" +#include "hmi/on_vi_acc_pedal_position_notification.h" +#include "hmi/on_vi_steering_wheel_angle_notification.h" +#include "hmi/on_vi_my_key_notification.h" +#include "hmi/ui_set_icon_request.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace dummy_hmi_commands_test { + +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; +using application_manager::commands::MessageSharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; + +template +class HMICommandsTest : public components::commands_test::CommandRequestTest< + CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; + + void InitCommand(const uint32_t& timeout) OVERRIDE { + stream_retry_.first = 0; + stream_retry_.second = 0; + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(stream_retry_)); + } + + protected: + std::pair stream_retry_; +}; + +template +class HMICommandsTestFirst : public HMICommandsTest { + public: + using typename HMICommandsTest::CommandType; +}; + +template +class HMICommandsTestSecond : public HMICommandsTest { + public: + using typename HMICommandsTest::CommandType; +}; + +template +class HMICommandsTestThird : public HMICommandsTest { + public: + using typename HMICommandsTest::CommandType; +}; + +template +class HMICommandsTestFourth : public HMICommandsTest { + public: + using typename HMICommandsTest::CommandType; +}; + +template +class HMICommandsTestFifth : public HMICommandsTest { + public: + using typename HMICommandsTest::CommandType; +}; + +/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few + * TYPED_TEST_CASE for HMI and mobile commands + */ + +typedef Types HMICommandsListFirst; + +typedef Types HMICommandsListSecond; + +typedef Types HMICommandsListThird; + +typedef Types HMICommandsListFourth; + +typedef Types HMICommandsListFifth; + +TYPED_TEST_CASE(HMICommandsTestFirst, HMICommandsListFirst); +TYPED_TEST_CASE(HMICommandsTestSecond, HMICommandsListSecond); +TYPED_TEST_CASE(HMICommandsTestThird, HMICommandsListThird); +TYPED_TEST_CASE(HMICommandsTestFourth, HMICommandsListFourth); +TYPED_TEST_CASE(HMICommandsTestFifth, HMICommandsListFifth); + +TYPED_TEST(HMICommandsTestFirst, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestSecond, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} +TYPED_TEST(HMICommandsTestThird, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestFourth, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestFifth, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +} // namespace dummy_hmi_commands_test +} // 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/get_system_info_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc new file mode 100644 index 0000000000..fbc08b3b34 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/request_to_hmi.h" +#include "hmi/get_system_info_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_system_info_request { + +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::GetSystemInfoRequest; +using am::commands::CommandImpl; + +typedef SharedPtr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 1u; +} // namespace + +class GetSystemInfoRequestTest + : public CommandsTest {}; + +TEST_F(GetSystemInfoRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + + RequestToHMIPtr command(CreateCommand(command_msg)); + + const uint32_t kAppId = command->application_id(); + + EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::msg_params][strings::app_id].asUInt(), + kAppId); + EXPECT_EQ((*command_msg)[strings::params][strings::correlation_id].asUInt(), + kCorrelationId); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace get_system_info_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/hmi/get_system_info_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc new file mode 100644 index 0000000000..638593d4f6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc @@ -0,0 +1,140 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/get_system_info_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/commands_test.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_system_info_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::GetSystemInfoResponse; +using sdl_rpc_plugin::commands::SystemInfo; +using am::commands::CommandImpl; + +typedef SharedPtr ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string ccpu_version("4.1.3.B_EB355B"); +const std::string wers_country_code("WAEGB"); +const uint32_t lang_code = 0u; +const std::string kLanguage = ""; +} // namespace + +class GetSystemInfoResponseTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::msg_params]["ccpu_version"] = ccpu_version; + (*command_msg)[strings::msg_params]["wersCountryCode"] = wers_country_code; + (*command_msg)[strings::msg_params]["language"] = lang_code; + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand(command_msg)); + + std::string language; + EXPECT_CALL(mock_message_helper_, + CommonLanguageToString( + static_cast(lang_code))) + .WillOnce(Return(language)); + EXPECT_EQ(kLanguage, language); + + EXPECT_CALL(mock_policy_handler_, + OnGetSystemInfo(ccpu_version, wers_country_code, kLanguage)); + + command->Run(); +} + +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_message_helper_, + CommonLanguageToString( + static_cast(lang_code))) + .Times(0); + + EXPECT_CALL(mock_policy_handler_, OnGetSystemInfo("", "", "")); + + command->Run(); +} + +} // namespace get_system_info_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/get_urls_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc new file mode 100644 index 0000000000..7e81bf88a7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_to_hmi.h" +#include "hmi/get_urls_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_urls_response { + +using ::testing::_; +using ::testing::Return; +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::GetUrlsResponse; +using sdl_rpc_plugin::commands::ResponseToHMI; +using am::commands::CommandImpl; + +typedef SharedPtr ResponseToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class GetUrlResponseTest : public CommandsTest {}; + +TEST_F(GetUrlResponseTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + + ResponseToHMIPtr command(CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace get_urls_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/get_urls_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc new file mode 100644 index 0000000000..74f744eb65 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc @@ -0,0 +1,336 @@ +/* + * Copyright (c) 2016, 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/message.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "hmi/get_urls.h" +#include "application_manager/policies/policy_handler.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/request_from_hmi.h" +#include "policy/policy_external/policy/mock_policy_manager.h" +#include "application_manager/event_engine/event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_urls { + +using namespace hmi_apis; +using namespace policy; +using ::utils::SharedPtr; +using ::testing::NiceMock; +using ::testing::_; +using ::testing::SetArgReferee; +using ::test::components::application_manager_test::MockApplication; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestFromHMI; +using sdl_rpc_plugin::commands::GetUrls; +using am::commands::CommandImpl; +using policy::PolicyHandler; +using policy_test::MockPolicyHandlerInterface; + +typedef SharedPtr RequestFromHMIPtr; + +namespace { +const uint32_t kInvalidAppId_ = 0u; +const uint32_t kAppIdForSending = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kServiceType = 0u; +const std::string kInitialService = "0x0"; +const std::string kPolicyService = "7"; +const std::string kDefaultUrl = "URL is not found"; +const std::string kDefaultId = "default"; +const std::string kPolicyAppId = "policy_app_id"; +} // namespace + +class GetUrlsTest : public CommandRequestTest { + public: + MessageSharedPtr command_msg_; + RequestFromHMIPtr request_command_; + + GetUrlsTest() { + command_msg_ = + CreateMessage(NsSmartDeviceLink::NsSmartObjects::SmartType_Map); + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kInitialService; + + request_command_ = CreateCommand(command_msg_); + } +}; + +TEST_F(GetUrlsTest, RUN_SUCCESS) { + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + // EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(_, _)); + + request_command_->Run(); +} + +TEST_F(GetUrlsTest, RUN_PolicyNotEnabled_UNSUCCESS) { + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F(GetUrlsTest, RUN_EmptyEndpoints_UNSUCCESS) { + EndpointUrls endpoints_; + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +#ifdef EXTENDED_POLICY +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppIdForSending)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::SUCCESS, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); + + EXPECT_EQ(kAppIdForSending, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [strings::app_id].asInt()); + EXPECT_EQ(kDefaultUrl, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [strings::url].asString()); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_IncorrectIdForSending_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kInvalidAppId_)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, application(kInvalidAppId_)).Times(0); + + request_command_->Run(); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_ApplicationIsNotValid_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr invalid_mock_app; + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(invalid_mock_app)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_FoundURLForApplication_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + data.app_id = kPolicyAppId; + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(kPolicyAppId)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::SUCCESS, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} +#endif + +TEST_F(GetUrlsTest, DISABLED_ProcessServiceURLs_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = + kDefaultUrl; + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id] = "1"; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + data.app_id = "1"; + endpoints_.push_back(data); + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + EXPECT_EQ(kDefaultUrl, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::strings::url].asString()); + EXPECT_EQ(endpoints_[0].app_id, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id].asString()); +} + +TEST_F(GetUrlsTest, ProcessServiceURLs_PolicyDefaultId_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = + kDefaultUrl; + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id] = kDefaultId; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(_)) + .WillOnce(Return(mock_app)); + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + EXPECT_TRUE( + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + .keyExists(am::hmi_response::policy_app_id)); +} + +} // namespace get_urls +} // 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/hmi_notifications/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc new file mode 100644 index 0000000000..c7fd0391c1 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc @@ -0,0 +1,1918 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/commands_test.h" + +#include "application_manager/commands/hmi/on_button_event_notification.h" +#include "application_manager/commands/hmi/on_navi_tbt_client_state_notification.h" +#include "application_manager/commands/hmi/on_navi_way_point_change_notification.h" +#include "application_manager/commands/hmi/on_ui_command_notification.h" +#include "application_manager/commands/hmi/on_ui_keyboard_input_notification.h" +#include "application_manager/commands/hmi/on_ui_touch_event_notification.h" +#include "application_manager/commands/hmi/on_vi_acc_pedal_position_notification.h" +#include "application_manager/commands/hmi/on_vi_belt_status_notification.h" +#include "application_manager/commands/hmi/on_vi_body_information_notification.h" +#include "application_manager/commands/hmi/on_vi_device_status_notification.h" +#include "application_manager/commands/hmi/on_vi_driver_braking_notification.h" +#include "application_manager/commands/hmi/on_vi_engine_torque_notification.h" +#include "application_manager/commands/hmi/on_vi_external_temperature_notification.h" +#include "application_manager/commands/hmi/on_vi_fuel_level_notification.h" +#include "application_manager/commands/hmi/on_vi_fuel_level_state_notification.h" +#include "application_manager/commands/hmi/on_vi_gps_data_notification.h" +#include "application_manager/commands/hmi/on_vi_head_lamp_status_notification.h" +#include "application_manager/commands/hmi/on_vi_instant_fuel_consumption_notification.h" +#include "application_manager/commands/hmi/on_vi_my_key_notification.h" +#include "application_manager/commands/hmi/on_vi_odometer_notification.h" +#include "application_manager/commands/hmi/on_vi_prndl_notification.h" +#include "application_manager/commands/hmi/on_vi_rpm_notification.h" +#include "application_manager/commands/hmi/on_vi_speed_notification.h" +#include "application_manager/commands/hmi/on_vi_steering_wheel_angle_notification.h" +#include "application_manager/commands/hmi/on_vi_tire_pressure_notification.h" +#include "application_manager/commands/hmi/on_vi_vehicle_data_notification.h" +#include "application_manager/commands/hmi/on_vi_vin_notification.h" +#include "application_manager/commands/hmi/on_vi_wiper_status_notification.h" +#include "application_manager/commands/hmi/on_app_permission_changed_notification.h" +#include "application_manager/commands/hmi/on_app_registered_notification.h" +#include "application_manager/commands/hmi/on_audio_data_streaming_notification.h" +#include "application_manager/commands/hmi/on_button_subscription_notification.h" +#include "application_manager/commands/hmi/on_file_removed_notification.h" +#include "application_manager/commands/hmi/on_put_file_notification.h" +#include "application_manager/commands/hmi/on_resume_audio_source_notification.h" +#include "application_manager/commands/hmi/on_sdl_close_notification.h" +#include "application_manager/commands/hmi/on_sdl_consent_needed_notification.h" +#include "application_manager/commands/hmi/on_sdl_persistence_complete_notification.h" +#include "application_manager/commands/hmi/on_status_update_notification.h" +#include "application_manager/commands/hmi/on_video_data_streaming_notification.h" +#include "application_manager/commands/hmi/on_record_start_notification.h" +#include "application_manager/commands/hmi/on_app_activated_notification.h" +#include "application_manager/commands/hmi/on_app_deactivated_notification.h" +#include "application_manager/commands/hmi/on_app_unregistered_notification.h" +#include "application_manager/commands/hmi/on_button_press_notification.h" +#include "application_manager/commands/hmi/on_event_changed_notification.h" +#include "application_manager/commands/hmi/on_ready_notification.h" +#include "application_manager/commands/hmi/on_tts_reset_timeout_notification.h" +#include "application_manager/commands/hmi/on_tts_started_notification.h" +#include "application_manager/commands/hmi/on_tts_stopped_notification.h" +#include "application_manager/commands/hmi/on_ui_reset_timeout_notification.h" +#include "application_manager/commands/hmi/on_vr_started_notification.h" +#include "application_manager/commands/hmi/on_vr_stopped_notification.h" +#include "application_manager/commands/hmi/on_app_permission_consent_notification.h" +#include "application_manager/commands/hmi/on_ignition_cycle_over_notification.h" +#include "application_manager/commands/hmi/on_policy_update.h" +#include "application_manager/commands/hmi/on_received_policy_update.h" +#include "application_manager/commands/hmi/on_system_error_notification.h" +#include "application_manager/commands/hmi/on_system_info_changed_notification.h" +#include "application_manager/commands/hmi/on_allow_sdl_functionality_notification.h" +#include "application_manager/commands/hmi/on_device_state_changed_notification.h" +#include "application_manager/commands/hmi/on_exit_all_applications_notification.h" +#include "application_manager/commands/hmi/on_exit_application_notification.h" +#include "application_manager/commands/hmi/on_vr_command_notification.h" +#include "application_manager/commands/hmi/on_vr_language_change_notification.h" +#include "application_manager/commands/hmi/on_start_device_discovery.h" +#include "application_manager/commands/hmi/on_device_chosen_notification.h" +#include "application_manager/commands/hmi/on_system_context_notification.h" +#include "application_manager/commands/hmi/on_system_request_notification.h" +#include "application_manager/commands/hmi/on_tts_language_change_notification.h" +#include "application_manager/commands/hmi/on_ui_language_change_notification.h" +#include "application_manager/commands/hmi/on_driver_distraction_notification.h" + +#include "utils/lock.h" +#include "utils/data_accessor.h" +#include "utils/signals.h" +#include "utils/shared_ptr.h" +#include "utils/make_shared.h" +#include "utils/file_system.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_state_controller.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/hmi_capabilities_impl.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "transport_manager/mock_transport_manager.h" +#include "connection_handler/mock_connection_handler.h" +#include "connection_handler/mock_connection_handler_settings.h" +#include "test/application_manager/mock_application_manager_settings.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "protocol_handler/mock_session_observer.h" +#include "application_manager/mock_resume_ctrl.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace hmi_notifications_test { + +using ::testing::_; +using ::testing::Test; +using ::testing::Types; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::NiceMock; +using ::testing::InSequence; +using ::utils::SharedPtr; +using ::smart_objects::SmartObject; +using ::application_manager::commands::MessageSharedPtr; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::application_manager::MockMessageHelper; + +using namespace am::commands; + +typedef SharedPtr MockAppPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +#define MEDIA true +#define NOT_MEDIA false +#define VC true +#define NOT_VC false +#define NAVI true +#define NOT_NAVI false + +ACTION_P(GetEventId, event_id) { + *event_id = arg0.id(); +} +ACTION_P(GetArg, arg) { + *arg = arg0; +} + +ACTION_P(GetArg3, result) { + arg3 = *result; +} + +ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { + *connect_id = arg0; + std::vector::const_iterator it = + arg1.group_permissions.begin(); + for (; it != arg1.group_permissions.end(); ++it) { + consent->group_permissions.push_back(*it); + } + consent->consent_source = arg1.consent_source; +} +ACTION_P2(GetBoolValueAndString, value, str) { + *value = arg0; + *str = arg1; +} +ACTION_P(GetMessage, message) { + (*message)[am::strings::params][am::strings::function_id] = + (*arg0)[am::strings::params][am::strings::function_id].asInt(); + (*message)[am::strings::params][am::strings::message_type] = + (*arg0)[am::strings::params][am::strings::message_type].asInt(); + (*message)[am::strings::params][am::strings::correlation_id] = + (*arg0)[am::strings::params][am::strings::correlation_id].asInt(); + (*message)[am::strings::params][am::strings::connection_key] = + (*arg0)[am::strings::params][am::strings::connection_key].asInt(); + return (*message)[am::strings::params][am::strings::correlation_id].asInt(); +} + +namespace { +const uint32_t kCountCommandsManageMobile_ = 22u; +const uint32_t kCountCommandsToHmi_ = 12u; +const int32_t kHmiProtocolType_ = 1; +const int32_t kMobileProtocolType_ = 0; +const int32_t kProtocolVersion_ = 3; +const uint32_t kCorrelationId_ = 1939u; +const uint32_t kAppId_ = 2014u; +} // namespace + +class HMICommandsNotificationsTest + : public components::commands_test::CommandsTest< + CommandsTestMocks::kIsNice> { + public: + HMICommandsNotificationsTest() + : applications_(application_set_, applications_lock_), app_ptr_(NULL) {} + + ~HMICommandsNotificationsTest() { + // Fix DataAccessor release and WinQt crash + Mock::VerifyAndClearExpectations(&app_mngr_); + } + typedef Command CommandType; + + protected: + am::ApplicationSet application_set_; + sync_primitives::Lock applications_lock_; + DataAccessor applications_; + + NiceMock mock_event_dispatcher_; + NiceMock mock_policy_handler_; + + application_manager_test::MockStateController mock_state_controller_; + + am::ApplicationSharedPtr app_; + NiceMock* app_ptr_; + + typedef IsNiceMock::Result MockConnectionHandler; + + typedef IsNiceMock::Result MockSessionObserver; + + MockConnectionHandler mock_connection_handler_; + MockSessionObserver mock_session_observer_; + + void InitCommand(const uint32_t& default_timeout) OVERRIDE { + app_ = ConfigureApp(&app_ptr_, kAppId_, NOT_MEDIA, NOT_NAVI, NOT_VC); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(default_timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_)); + ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); + } + + am::ApplicationSharedPtr ConfigureApp(NiceMock** app_mock, + uint32_t app_id, + bool media, + bool navi, + bool vc) { + *app_mock = new NiceMock; + + Mock::AllowLeak(*app_mock); // WorkAround for gogletest bug + am::ApplicationSharedPtr app(*app_mock); + + ON_CALL(**app_mock, app_id()).WillByDefault(Return(app_id)); + ON_CALL(**app_mock, is_media_application()).WillByDefault(Return(media)); + ON_CALL(**app_mock, is_navi()).WillByDefault(Return(navi)); + ON_CALL(**app_mock, is_voice_communication_supported()) + .WillByDefault(Return(vc)); + ON_CALL(**app_mock, IsAudioApplication()) + .WillByDefault(Return(media || navi || vc)); + return app; + } +#if defined(OS_POSIX) + void SubscribeForSignal() { + sigset_t signal_set; + sigemptyset(&signal_set); + sigaddset(&signal_set, SIGINT); + sigaddset(&signal_set, SIGTERM); + pthread_sigmask(SIG_BLOCK, &signal_set, NULL); + } +#endif +}; + +namespace { +void sig_handler(int sig) { + switch (sig) { + case SIGINT: + break; + case SIGTERM: + break; + case SIGSEGV: + abort(); + default: + exit(EXIT_FAILURE); + } +} +} // namespace + +template +class HMIOnViNotifications : public commands_test::CommandsTest { + public: + typedef Command CommandType; +}; + +template +class HMIOnNotificationsListToHMI + : public commands_test::CommandsTest { + public: + typedef Command CommandType; +}; + +template +struct CommandPair { + typedef CommandT CommandType; + enum { kHMICommandId = kCommandId }; +}; + +template +class HMIOnNotificationsEventDispatcher + : public commands_test::CommandsTest { + public: + typedef Command CommandType; + NiceMock mock_event_dispatcher_; +}; + +typedef Types HMIOnViNotificationsTypes; + +typedef Types HMIOnNotificationsListToHMITypes; + +typedef Types< + CommandPair, + CommandPair, + CommandPair, + CommandPair, + CommandPair, + CommandPair, + CommandPair, + CommandPair, + CommandPair > + HMIOnNotificationsEventDispatcherTypes; + +TYPED_TEST_CASE(HMIOnViNotifications, HMIOnViNotificationsTypes); +TYPED_TEST_CASE(HMIOnNotificationsListToHMI, HMIOnNotificationsListToHMITypes); +TYPED_TEST_CASE(HMIOnNotificationsEventDispatcher, + HMIOnNotificationsEventDispatcherTypes); + +TYPED_TEST(HMIOnViNotifications, CommandsSendNotificationToMobile) { + MessageSharedPtr message = + commands_test::CommandsTest::CreateMessage(); + utils::SharedPtr command = + this->template CreateCommand(message); + EXPECT_CALL(commands_test::CommandsTest::mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ( + static_cast(mobile_apis::FunctionID::eType::OnVehicleDataID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TYPED_TEST(HMIOnNotificationsListToHMI, CommandsSendNotificationToHmi) { + MessageSharedPtr message = + commands_test::CommandsTest::CreateMessage(); + utils::SharedPtr command = + this->template CreateCommand(message); + EXPECT_CALL(commands_test::CommandsTest::mock_rpc_service_, + SendMessageToHMI(_)); + command->Run(); + EXPECT_EQ( + static_cast(kHmiProtocolType_), + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + static_cast(kProtocolVersion_), + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TYPED_TEST(HMIOnNotificationsEventDispatcher, + CommandsNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = + commands_test::CommandsTest::CreateMessage(); + utils::SharedPtr command = + this->template CreateCommand< + typename TestFixture::CommandType::CommandType>(message); + EXPECT_CALL(commands_test::CommandsTest::app_mngr_, + event_dispatcher()) + .WillOnce(ReturnRef(this->mock_event_dispatcher_)); + EXPECT_CALL(this->mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(TestFixture::CommandType::kHMICommandId, event_id); +} + +// notifications(SendNotificationToMobile) +TEST_F(HMICommandsNotificationsTest, OnButtonEventSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnButtonEventID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnNaviTBTClientSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnTBTClientStateID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnNaviWayPointChangeSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnWayPointChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUICommandSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnCommandID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(mobile_apis::TriggerSource::TS_MENU), + (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnUIKeyBoardInputSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnKeyboardInputID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUITouchEventSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnTouchEventID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppRegisteredNotificationSendNotificationToHmi) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), + event_id); + EXPECT_EQ( + kHmiProtocolType_, + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + kProtocolVersion_, + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppUnregisteredNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast( + hmi_apis::FunctionID::BasicCommunication_OnAppUnregistered), + event_id); + EXPECT_EQ( + kHmiProtocolType_, + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + kProtocolVersion_, + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnButtonPressNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast(hmi_apis::FunctionID::Buttons_OnButtonPress), + event_id); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnButtonPressID), + (*message)[am::strings::params][am::strings::function_id].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, OnHMIStartedCooperation()); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(hmi_apis::FunctionID::BasicCommunication_OnReady, event_id); +} + +// policy handler +TEST_F(HMICommandsNotificationsTest, + OnIgnitionCycleOverNotificationPolicyHandler) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_policy_handler_, OnIgnitionCycleOver()); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnPolicyUpdateNotificationPolicyHandler) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = CreateCommand(message); + + EXPECT_CALL(mock_policy_handler_, OnPTExchangeNeeded()); + command->Run(); +} + +#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE) +TEST_F(HMICommandsNotificationsTest, + OnReceivePolicyUpdateNotification_SUCCESS) { + const std::string kFile = "./test_file.txt"; + EXPECT_TRUE(file_system::CreateFile(kFile)); + uint8_t tmp[] = {1u, 2u, 3u, 4u}; + std::vector data(tmp, tmp + 4); + EXPECT_TRUE(file_system::WriteBinaryFile(kFile, data)); + + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); + (*message)[am::strings::msg_params][am::hmi_notification::policyfile] = kFile; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, GetPolicyHandler()); + EXPECT_CALL(mock_policy_handler_, ReceiveMessageFromSDK(kFile, data)); + command->Run(); + EXPECT_TRUE(file_system::DeleteFile(kFile)); +} +#endif + +TEST_F(HMICommandsNotificationsTest, + OnReceivePolicyUpdateNotification_UNSUCCESS) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_policy_handler_, ReceiveMessageFromSDK(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerNoAppId) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + SmartObject& applications = + (*message)[am::strings::msg_params]["consentedFunctions"]; + + smart_objects::SmartObject hmi_application_temp(smart_objects::SmartType_Map); + applications[0] = hmi_application_temp; + + utils::SharedPtr command = + CreateCommand(message); + + int32_t connection_id = -1; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce(GetArg(&connection_id)); + command->Run(); + EXPECT_EQ(0, connection_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerWithAppId) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + smart_objects::SmartObjectSPtr consented_function = + utils::MakeShared(); + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + utils::SharedPtr command = + CreateCommand(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; + EXPECT_CALL(app_mngr_, GetPolicyHandler()); +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast(kAppId_), connection_id); + std::vector::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(policy::kGroupUndefined, (*it).state); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowTrue) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["source"] = "test_content_source"; + + smart_objects::SmartObjectSPtr consented_function = + utils::MakeShared(); + (*consented_function)["allowed"] = true; + (*consented_function)[am::strings::id] = 999; + (*consented_function)[am::strings::name] = "test_group_alias"; + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + utils::SharedPtr command = + CreateCommand(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast(kAppId_), connection_id); + + std::vector::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(999, (*it).group_id); + EXPECT_EQ("test_group_alias", (*it).group_alias); + EXPECT_EQ(policy::kGroupAllowed, (*it).state); + } + EXPECT_EQ("test_content_source", permission_consent.consent_source); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowFalse) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["source"] = "test_content_source"; + + smart_objects::SmartObjectSPtr consented_function = + utils::MakeShared(); + (*consented_function)["allowed"] = false; + (*consented_function)[am::strings::id] = 999; + (*consented_function)[am::strings::name] = "test_group_alias"; + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + utils::SharedPtr command = + CreateCommand(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast(kAppId_), connection_id); + + std::vector::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(999, (*it).group_id); + EXPECT_EQ("test_group_alias", (*it).group_alias); + EXPECT_EQ(policy::kGroupDisallowed, (*it).state); + } + EXPECT_EQ("test_content_source", permission_consent.consent_source); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemErrorNotificationOnSystemErrorCode) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::error] = + hmi_apis::Common_SystemError::SYNC_REBOOTED; + + utils::SharedPtr command = + CreateCommand(message); + + int32_t code = hmi_apis::Common_SystemError::INVALID_ENUM; + EXPECT_CALL(mock_policy_handler_, OnSystemError(_)).WillOnce(GetArg(&code)); + command->Run(); + EXPECT_EQ(static_cast(hmi_apis::Common_SystemError::SYNC_REBOOTED), + code); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemInfoChangedNotificationCheckLanguage) { + const uint32_t kLangCode = 5u; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLangCode; + + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)); + EXPECT_CALL(mock_policy_handler_, OnSystemInfoChanged(_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnAllowSDLFunctionalityNotificationDeviceKeyNotExist) { + const std::string kDeviceId = ""; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; + utils::SharedPtr command = + CreateCommand(message); + + bool value = false; + std::string str; + EXPECT_CALL(mock_policy_handler_, OnAllowSDLFunctionalityNotification(_, _)) + .WillOnce(GetBoolValueAndString(&value, &str)); + command->Run(); + EXPECT_EQ(true, value); + EXPECT_EQ(kDeviceId, str); +} + +TEST_F(HMICommandsNotificationsTest, + OnAllowSDLFunctionalityNotificationDeviceKeyExist) { + const std::string kDeviceId = "device_id"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; + (*message)[am::strings::msg_params]["device"]["id"] = kDeviceId; + utils::SharedPtr command = + CreateCommand(message); + + bool value; + std::string str; + EXPECT_CALL(mock_policy_handler_, OnAllowSDLFunctionalityNotification(_, _)) + .WillOnce(GetBoolValueAndString(&value, &str)); + command->Run(); + EXPECT_EQ(true, value); + EXPECT_EQ(kDeviceId, str); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateNotUnpaired) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::INVALID_ENUM; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateUnpaired) { + // Random MAC adress for test. It must contain 12 symbols. + const std::string device_id = "AA15F2204D6B"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = device_id; + + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateEmptyDeviceId) { + const std::string empty_device_id = ""; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; + + utils::SharedPtr command = + CreateCommand(message); + + std::string device_id = "default_id"; + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)).WillOnce(GetArg(&device_id)); + command->Run(); + EXPECT_EQ(empty_device_id, device_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateDeviceIdFromId) { + const std::string empty_device_id = ""; + const std::string id = "id_string"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; + (*message)[am::strings::msg_params]["deviceId"]["id"] = id; + + utils::SharedPtr command = + CreateCommand(message); + + std::string device_id = "default_id"; + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)).WillOnce(GetArg(&device_id)); + command->Run(); + EXPECT_EQ(id, device_id); +} + +//~policy_handler +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonIgnitionOff) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::IGNITION_OFF; + + utils::SharedPtr command = + CreateCommand(message); +#if defined(OS_POSIX) + am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason; + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)) + .WillOnce(GetArg(&mob_reason)); + EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); + + SubscribeForSignal(); + command->Run(); + utils::WaitTerminationSignals(sig_handler); + + EXPECT_EQ(am::mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF, + mob_reason); +#endif +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonMasterResetAndFactoryDefaults) { + MessageSharedPtr message = CreateMessage(); + + std::vector reason_list; + reason_list.push_back(hmi_apis::Common_ApplicationsCloseReason::MASTER_RESET); + reason_list.push_back( + hmi_apis::Common_ApplicationsCloseReason::FACTORY_DEFAULTS); + + std::vector + mob_reason_list; + mob_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::MASTER_RESET); + mob_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS); + + std::vector::iterator + it_reason = reason_list.begin(); + std::vector::iterator + it_mob_reason = mob_reason_list.begin(); + + for (; it_reason != reason_list.end(); ++it_reason, ++it_mob_reason) { + (*message)[am::strings::msg_params][am::hmi_request::reason] = *it_reason; + + utils::SharedPtr command = + CreateCommand(message); +#if defined(OS_POSIX) + am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason = + *it_mob_reason; + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(mob_reason)); + EXPECT_CALL(app_mngr_, HeadUnitReset(mob_reason)); + + SubscribeForSignal(); + command->Run(); + utils::WaitTerminationSignals(sig_handler); +#endif + } +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonSuspend) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::SUSPEND; + + utils::SharedPtr command = + CreateCommand(message); + + MessageSharedPtr ethalon_message = + CreateMessage(smart_objects::SmartType_Map); + (*ethalon_message)[am::strings::params][am::strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete; + (*ethalon_message)[am::strings::params][am::strings::message_type] = + am::MessageType::kNotification; + (*ethalon_message)[am::strings::params][am::strings::correlation_id] = + kCorrelationId_; + MessageSharedPtr temp_message = CreateMessage(); + + resumprion_test::MockResumeCtrl mock_resume_ctrl; + EXPECT_CALL(app_mngr_, resume_controller()) + .WillOnce(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, OnSuspend()); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(GetMessage(temp_message)); + + command->Run(); + EXPECT_EQ( + static_cast( + hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete), + (*temp_message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(am::MessageType::kNotification), + (*temp_message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ(static_cast(kCorrelationId_), + (*temp_message)[am::strings::params][am::strings::correlation_id] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonInvalidEnum) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::INVALID_ENUM; + + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)).Times(0); + EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationManageMobileCommand) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + smart_objects::SmartObjectSPtr notification = + utils::MakeShared(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast( + mobile_apis::FunctionID::OnAppInterfaceUnregisteredID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + + std::vector reason_list; + reason_list.push_back(hmi_apis::Common_ApplicationExitReason:: + UNAUTHORIZED_TRANSPORT_REGISTRATION); + reason_list.push_back( + hmi_apis::Common_ApplicationExitReason::UNSUPPORTED_HMI_RESOURCE); + + std::vector + mobile_reason_list; + mobile_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED); + mobile_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::UNSUPPORTED_HMI_RESOURCE); + + std::vector::iterator + it_mobile_reason = mobile_reason_list.begin(); + std::vector::iterator + it_reason = reason_list.begin(); + + for (; it_reason != reason_list.end(); ++it_reason, ++it_mobile_reason) { + (*message)[am::strings::msg_params][am::strings::reason] = *it_reason; + utils::SharedPtr command = + CreateCommand(message); + + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast(*it_mobile_reason); + +#ifdef SDL_REMOTE_CONTROL + plugin_manager::RPCPluginManager plugin_mng; + EXPECT_CALL(app_mngr_, GetPluginManager()) + .WillRepeatedly(ReturnRef(plugin_mng)); +#endif // SDL_REMOTE_CONTROL + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, *it_mobile_reason)).WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationUnhandledReason) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::INVALID_ENUM; + + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnExitApplicationNotificationInvalidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + + utils::SharedPtr command = + CreateCommand(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + DISABLED_OnExitApplicationNotificationDriverDistractionValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::DRIVER_DISTRACTION_VIOLATION; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + false)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationrUserExitValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::USER_EXIT; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + false)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationSwitchedAndValidApp) { + const uint32_t cmd_id = 12u; + const uint32_t max_cmd_id = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = cmd_id; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, mobile_apis::HMILevel::HMI_FULL, true)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(max_cmd_id)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationSwitchedAndInvalidApp) { + const uint32_t kCmdId = 12u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + utils::SharedPtr command = + CreateCommand(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(invalid_app)); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationCmdIdEqualToMaxCmdId) { + const uint32_t kCmdId = 11u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationCmdIdLessMaxCmdIsInvalidApp) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + utils::SharedPtr command = + CreateCommand(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationActivePerformIteraction) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + const uint32_t kIsPerformInteractionActive = 1u; + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) + .WillOnce(Return(kIsPerformInteractionActive)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); + EXPECT_EQ(hmi_apis::FunctionID::VR_OnCommand, event_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationNotActivePerformIteraction) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + const uint32_t kIsPerformInteractionActive = 0u; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + (*message)[am::strings::msg_params][am::strings::function_id] = + mobile_apis::FunctionID::eType::OnCommandID; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) + .WillOnce(Return(kIsPerformInteractionActive)); + + EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnCommandID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(mobile_apis::TriggerSource::TS_VR), + (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnVRLanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRLanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRLanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + utils::MakeShared(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnStartDeviceDiscoveryRun) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, StartDevicesDiscovery()); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceChosenNotificationDeviceInfoExists) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::device_info] + [am::strings::id] = "2014"; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, + ConnectToDevice( + (*message)[am::strings::msg_params][am::strings::device_info] + [am::strings::id].asString())); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceChosenNotificationDeviceInfoNotExists) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, ConnectToDevice(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationValidActiveApplication) { + MessageSharedPtr message = CreateMessage(); + std::vector system_context_list; + system_context_list.push_back( + am::mobile_api::SystemContext::SYSCTXT_VRSESSION); + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MENU); + system_context_list.push_back( + am::mobile_api::SystemContext::SYSCTXT_HMI_OBSCURED); + + std::vector::iterator it = + system_context_list.begin(); + for (; it != system_context_list.end(); ++it) { + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + *it; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationInvalidActiveApplication) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::SYSCTXT_VRSESSION; + utils::SharedPtr command = + CreateCommand(message); + ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationInvalidSystemContext) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::INVALID_ENUM; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, active_application()).Times(0); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationValidApplication) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + std::vector system_context_list; + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_ALERT); + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MAIN); + + std::vector::iterator it = + system_context_list.begin(); + for (; it != system_context_list.end(); ++it) { + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + *it; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationAppIdDoesntExists) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::SYSCTXT_ALERT; + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdExistsAndValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + const int32_t device_id = 1; + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An(), NULL, NULL, _, NULL)) + .WillByDefault(Return(device_id)); + + EXPECT_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillOnce(Return(policy::kDeviceAllowed)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdExistsAndInvalidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + utils::SharedPtr command = + CreateCommand(message); + ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); + EXPECT_EQ( + static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdDoesntExistsAndValidApp) { + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppId_)); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + const int32_t device_id = 1; + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An(), NULL, NULL, _, NULL)) + .WillByDefault(Return(device_id)); + + EXPECT_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillOnce(Return(policy::kDeviceAllowed)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdDoesntExistsAndNullAppId) { + const uint32_t kNullApppId = 0u; + MessageSharedPtr message = CreateMessage(); + utils::SharedPtr command = + CreateCommand(message); + EXPECT_CALL(app_mngr_, GetPolicyHandler()); + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kNullApppId)); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnTTSLanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnTTSLanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnTTSLanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + utils::MakeShared(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUILanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, ui_language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnUILanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(kLang), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnUILanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + utils::MakeShared(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast(mobile_apis::Language::EN_US), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + utils::SharedPtr command = + CreateCommand(message); + + EXPECT_CALL(app_mngr_, set_driver_distraction(state)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDriverDistractionNotificationInvalidApp) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + utils::SharedPtr command = + CreateCommand(message); + + ApplicationSharedPtr invalid_app; + application_set_.insert(invalid_app); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::mobile_notification::state] = state; + utils::SharedPtr command = + CreateCommand(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(policy_interface_)); + EXPECT_CALL(policy_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) + .WillOnce(GetMessage(message)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + + command->Run(); + EXPECT_EQ( + static_cast(am::mobile_api::FunctionID::OnDriverDistractionID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +} // namespace hmi_notifications_test +} // 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/mixing_audio_supported_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc new file mode 100644 index 0000000000..8b49f6a781 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "hmi/mixing_audio_supported_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace mixing_audio_supported_request { + +using ::testing::_; +using ::testing::Return; +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::MixingAudioSupportedRequest; +using am::commands::CommandImpl; + +typedef SharedPtr RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class MixingAudioSupportedRequestTest + : public CommandsTest {}; + +TEST_F(MixingAudioSupportedRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command( + CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace mixing_audio_supported_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/hmi/mixing_audio_supported_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc new file mode 100644 index 0000000000..c93090fa42 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/response_from_hmi.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "hmi/mixing_audio_supported_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace mixing_audio_supported_response { + +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::NiceMock; +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::MixingAudioSupportedResponse; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using am::commands::CommandImpl; +using am::HMICapabilities; +namespace hmi_response = ::application_manager::hmi_response; + +typedef SharedPtr ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class MixingAudioSupportedResponseTest + : public CommandsTest {}; + +TEST_F(MixingAudioSupportedResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + const bool hmiResponse = + (*command_msg)[strings::msg_params][hmi_response::attenuated_supported] + .asBool(); + + EXPECT_CALL(mock_hmi_capabilities_, set_attenuated_supported(hmiResponse)); + + command->Run(); +} + +} // namespace mixing_audio_supported_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/navi_audio_start_stream_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc new file mode 100644 index 0000000000..20c439b88c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016, 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 "hmi/navi_audio_start_stream_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/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_audio_start_stream_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = am::commands; +using commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AudioStartStreamRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kHmiAppId = 13u; +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +class AudioStartStreamRequestTest + : public CommandRequestTest { + public: + AudioStartStreamRequestTest() { + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(start_stream_retry_amount_)); + msg_ = CreateMessage(); + command_ = CreateCommand(msg_); + } + + std::pair start_stream_retry_amount_; + MessageSharedPtr msg_; + SharedPtr command_; +}; + +TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(AudioStartStreamRequestTest, + Run_HmiInterfaceAvailableButNoApp_NoRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_audio_streaming_allowed(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg_)); + + command_->Run(); +} + +} // namespace navi_audio_start_stream_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/hmi/navi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc new file mode 100644 index 0000000000..6f083891c4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2016, 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/navi_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/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviIsReadyRequest; +using am::event_engine::Event; + +namespace { +const hmi_apis::FunctionID::eType kEventID = + hmi_apis::FunctionID::Navigation_IsReady; +} // namespace + +typedef SharedPtr NaviIsReadyRequestPtr; + +class NaviIsReadyRequestTest + : public CommandRequestTest { + public: + NaviIsReadyRequestTest() : command_(CreateCommand()) {} + + NaviIsReadyRequestPtr command_; +}; + +TEST_F(NaviIsReadyRequestTest, + OnEvent_HmiInterfaceIsAvailable_NaviCooperatingIsAvailable) { + const bool is_hmi_interface_available = true; + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::msg_params][am::strings::available] = + is_hmi_interface_available; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, + am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +TEST_F(NaviIsReadyRequestTest, + OnEvent_HmiInterfaceIsNotAvailable_NaviCooperatingIsNotAvailable) { + const bool is_hmi_interface_available = false; + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::msg_params][am::strings::available] = + is_hmi_interface_available; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, + am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +TEST_F(NaviIsReadyRequestTest, + OnEvent_AvailabilityFieldMissing_NaviCooperatingIsNotAvailable) { + const bool is_hmi_interface_available = false; + + MessageSharedPtr event_msg = CreateMessage(); + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +} // namespace navi_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/hmi/navi_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc new file mode 100644 index 0000000000..327c885ef9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "hmi/navi_is_ready_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_is_ready_responce { + +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::ReturnRef; +using ::utils::SharedPtr; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr ResponseFromHMIPtr; + +class NaviIsReadyResponseTest + : public CommandRequestTest {}; + +TEST_F(NaviIsReadyResponseTest, NaviIsReadyResponse_Run_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand()); + 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 navi_is_ready_responce +} // 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/navi_set_video_config_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc new file mode 100644 index 0000000000..2aafea2e01 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2017 Xevo Inc. + * 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 names of the copyright holders 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 "hmi/navi_set_video_config_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/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_set_video_config_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviSetVideoConfigRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kHmiAppId = 13u; +const hmi_apis::FunctionID::eType kEventID = + hmi_apis::FunctionID::Navigation_SetVideoConfig; +} // namespace + +typedef SharedPtr NaviSetVideoConfigRequestPtr; + +class NaviSetVideoConfigRequestTest + : public CommandRequestTest { + public: + NaviSetVideoConfigRequestTest() { + mock_app_ptr_ = CreateMockApp(); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_ptr_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_ptr_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + } + + MOCK(am::MockHmiInterfaces) mock_hmi_interfaces_; + MockAppPtr mock_app_ptr_; + MockEventDispatcher mock_event_dispatcher_; +}; + +TEST_F(NaviSetVideoConfigRequestTest, OnEventWithSuccessResponse) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, true, empty)) + .Times(1); + + command->on_event(event); +} + +static bool ValidateList(std::vector& expected, + std::vector& actual) { + std::sort(expected.begin(), expected.end()); + std::sort(actual.begin(), actual.end()); + return std::equal(expected.begin(), expected.end(), actual.begin()); +} + +TEST_F(NaviSetVideoConfigRequestTest, OnEventWithRejectedResponse) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*request_msg)[am::strings::msg_params][am::strings::config] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::protocol] = + hmi_apis::Common_VideoStreamingProtocol::RTP; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::codec] = + hmi_apis::Common_VideoStreamingCodec::H265; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::height] = 640; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::width] = 480; + + NaviSetVideoConfigRequestPtr command = + CreateCommand(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + + (*event_msg)[am::strings::msg_params][am::strings::rejected_params] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*event_msg)[am::strings::msg_params][am::strings::rejected_params][0] = + "codec"; + (*event_msg)[am::strings::msg_params][am::strings::rejected_params][1] = + "protocol"; + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector rejected_params; + EXPECT_CALL(app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, _)) + .WillOnce(SaveArg<3>(&rejected_params)); + + command->on_event(event); + + ASSERT_EQ(2u, rejected_params.size()); + std::vector expected_list; + expected_list.push_back(std::string("protocol")); + expected_list.push_back(std::string("codec")); + ASSERT_TRUE(ValidateList(expected_list, rejected_params)); +} + +TEST_F(NaviSetVideoConfigRequestTest, + OnEventWithRejectedResponseWithoutParams) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) + .WillOnce(Return()); + + command->on_event(event); +} + +TEST_F(NaviSetVideoConfigRequestTest, OnTimeout) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand(request_msg); + + std::vector empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) + .WillOnce(Return()); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(1); + + command->onTimeOut(); +} + +} // namespace navi_set_video_config_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/hmi/navi_set_video_config_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc new file mode 100644 index 0000000000..ab3285f565 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2017 Xevo Inc. + * 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 names of the copyright holders 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 "gtest/gtest.h" +#include "application_manager/commands/commands_test.h" +#include "hmi/navi_set_video_config_response.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_set_video_config_response { + +using utils::SharedPtr; +using sdl_rpc_plugin::commands::NaviSetVideoConfigResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +class NaviSetVideoConfigResponseTest + : public CommandsTest {}; + +TEST_F(NaviSetVideoConfigResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(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(); +} + +} // namespace navi_set_video_config_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/navi_start_stream_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc new file mode 100644 index 0000000000..362a03f8d3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016, 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 "hmi/navi_start_stream_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" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_start_stream_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = am::commands; +using commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviStartStreamRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kHmiAppId = 13u; +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +class NaviStartStreamRequestTest + : public CommandRequestTest { + public: + NaviStartStreamRequestTest() { + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(start_stream_retry_amount_)); + msg_ = CreateMessage(); + command_ = CreateCommand(msg_); + } + + std::pair start_stream_retry_amount_; + MessageSharedPtr msg_; + SharedPtr command_; +}; + +TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(NaviStartStreamRequestTest, + Run_HmiInterfaceAvailableButNoApp_NoRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_video_streaming_allowed(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg_)); + + command_->Run(); +} + +} // namespace navi_start_stream_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/hmi/navi_stop_stream_requests_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc new file mode 100644 index 0000000000..b953db97ab --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016, 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/navi_stop_stream_request.h" +#include "hmi/navi_audio_stop_stream_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" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_stop_stream_requests { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +namespace { +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +template +class NaviStopStreamRequestsTest + : public CommandRequestTest { + public: + NaviStopStreamRequestsTest() { + ON_CALL(this->app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + msg_ = CreateMessage(); + command_ = CreateCommand(msg_); + } + + MessageSharedPtr msg_; + SharedPtr command_; +}; + +typedef testing::Types RequestCommandsList; +TYPED_TEST_CASE(NaviStopStreamRequestsTest, RequestCommandsList); + +TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(TestFixture::mock_hmi_interfaces_, + GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(TestFixture::mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + TestFixture::command_->Run(); +} + +TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceAvailable_SentRequest) { + EXPECT_CALL(TestFixture::mock_hmi_interfaces_, + GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(TestFixture::mock_rpc_service_, + SendMessageToHMI(TestFixture::msg_)); + + TestFixture::command_->Run(); +} + +} // namespace navi_stop_stream_requests +} // 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/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc new file mode 100644 index 0000000000..3a7f0659d9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2016, 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 "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "utils/shared_ptr.h" +#include "utils/lock.h" +#include "utils/make_shared.h" +#include "utils/data_accessor.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/on_driver_distraction_notification.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_driver_distraction_notification { + +using ::testing::_; +using ::testing::Return; +using ::testing::Eq; +using ::utils::SharedPtr; + +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification; +using namespace am::commands; + +typedef ::utils::SharedPtr NotificationPtr; + +class HMIOnDriverDistractionNotificationTest + : public CommandsTest { + public: + ::sync_primitives::Lock app_set_lock_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; +}; + +MATCHER_P2(CheckNotificationParams, function_id, state, "") { + bool is_function_id_matched = + function_id == + static_cast( + (*arg)[am::strings::params][am::strings::function_id].asInt()); + bool is_state_matched = + state == + static_cast( + (*arg)[am::strings::msg_params][am::mobile_notification::state] + .asInt()); + return is_function_id_matched && is_state_matched; +} + +ACTION_P(GetArg3, result) { + arg3 = *result; +} + +TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + + NotificationPtr command( + CreateCommand(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + MockAppPtr mock_app = CreateMockApp(); + am::ApplicationSet app_set; + app_set.insert(mock_app); + + DataAccessor accessor(app_set, app_set_lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcDisallowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + + EXPECT_CALL(*mock_app, + PushMobileMessage(CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state))); + + command->Run(); +} + +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_SUCCESS) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + + NotificationPtr command( + CreateCommand(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + MockAppPtr mock_app = CreateMockApp(); + am::ApplicationSet app_set; + app_set.insert(mock_app); + + DataAccessor accessor(app_set, app_set_lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)); + + command->Run(); +} + +} // on_driver_distraction_notification +} // 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/rc_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc new file mode 100644 index 0000000000..724b1f6a3a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/rc_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_get_capabilities_response { + +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::RCGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef SharedPtr RCGetCapabilitiesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class RCGetCapabilitiesResponseTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][strings::rc_capability] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(RCGetCapabilitiesResponseTest, RUN_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::rc_capability] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject& remote_control_capability = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::rc_capability]; + + remote_control_capability["climateControlCapabilities"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability["climateControlCapabilities"][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& climate_control_capability = + remote_control_capability["climateControlCapabilities"][0]; + + climate_control_capability["moduleName"] = "Climate"; + climate_control_capability["fanSpeedAvailable"] = true; + climate_control_capability["desiredTemperatureAvailable"] = true; + climate_control_capability["acEnableAvailable"] = true; + climate_control_capability["acMaxEnableAvailable"] = true; + climate_control_capability["circulateAirEnableAvailable"] = true; + climate_control_capability["autoModeEnableAvailable"] = true; + climate_control_capability["dualModeEnableAvailable"] = true; + + climate_control_capability["defrostZoneAvailable"] = true; + climate_control_capability["defrostZone"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + climate_control_capability["defrostZone"][0] = "ALL"; + + climate_control_capability["ventilationModeAvailable"] = true; + climate_control_capability["ventilationMode"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + climate_control_capability["ventilationMode"][0] = "BOTH"; + + remote_control_capability["radioControlCapabilities"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability["radioControlCapabilities"][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& radio_control_capability = + remote_control_capability["radioControlCapabilities"][0]; + + radio_control_capability["moduleName"] = "Radio"; + radio_control_capability["radioEnableAvailable"] = true; + radio_control_capability["radioBandAvailable"] = true; + radio_control_capability["radioFrequencyAvailable"] = true; + radio_control_capability["hdChannelAvailable"] = true; + radio_control_capability["rdsDataAvailable"] = true; + radio_control_capability["availableHDsAvailable"] = true; + radio_control_capability["stateAvailable"] = true; + radio_control_capability["signalStrengthAvailable"] = true; + radio_control_capability["signalChangeThresholdAvailable"] = true; + + remote_control_capability[hmi_response::button_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability[hmi_response::button_capabilities][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& button_capability = + remote_control_capability[hmi_response::button_capabilities][0]; + + button_capability[strings::button_name] = "OK"; + button_capability["shortPressAvailable"] = true; + button_capability["longPressAvailable"] = true; + button_capability["upDownAvailable"] = true; + + RCGetCapabilitiesResponsePtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject rc_capability_so = + (*command_msg)[strings::msg_params][strings::rc_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, set_rc_capability(rc_capability_so)); + EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(true)); + + command->Run(); +} + +} // namespace rc_get_capabilities_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/rc_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc new file mode 100644 index 0000000000..b1108f3713 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2016, 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/rc_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/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::RCIsReadyRequest; +using am::event_engine::Event; + +typedef SharedPtr RCIsReadyRequestPtr; + +class RCIsReadyRequestTest + : public CommandRequestTest { + public: + RCIsReadyRequestTest() : command_(CreateCommand()) {} + + void SetUpExpectations(bool is_rc_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_rc_cooperating(is_rc_cooperating_available)); + if (!is_rc_cooperating_available) { + EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(false)); + } + + 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_RC, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_RC)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::RC_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_rc_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_rc_cooperating_available; + } + event.set_smart_object(*msg); + } + + RCIsReadyRequestPtr command_; + am::MockHmiInterfaces mock_hmi_interfaces_; +}; + +TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_rc_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_rc_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_rc_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event, is_rc_cooperating_available); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace rc_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/hmi/rc_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc new file mode 100644 index 0000000000..f8479b2737 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, 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/mock_hmi_capabilities.h" +#include "hmi/rc_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_is_ready_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::RCIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr RCIsReadyResponsePtr; + +class RCIsReadyResponseTest : public CommandsTest { +}; + +TEST_F(RCIsReadyResponseTest, RUN_SUCCESS) { + RCIsReadyResponsePtr command(CreateCommand()); + + 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 rc_is_ready_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/response_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc new file mode 100644 index 0000000000..8931547790 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" +#include "application_manager/commands/command.h" +#include "application_manager/test/include/application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/response_from_hmi.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace response_from_hmi { + +using ::testing::_; +using ::testing::Return; +using ::testing::SaveArg; +using ::testing::DoAll; + +using ::utils::SharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; + +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::ResponseFromHMI; + +typedef SharedPtr ResponseFromHMIPtr; + +class ResponseFromHMITest : public CommandsTest {}; + +TEST_F(ResponseFromHMITest, BasicMethodsOverloads_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(ResponseFromHMITest, SendResponseToMobile_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand()); + + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(msg, _)); + + command->SendResponseToMobile(msg, app_mngr_); + + const application_manager::MessageType received_message_tipe = + static_cast( + (*msg)[am::strings::params][am::strings::message_type].asInt()); + + EXPECT_EQ(application_manager::MessageType::kResponse, received_message_tipe); +} + +TEST_F(ResponseFromHMITest, CreateHMIRequest_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand()); + + MessageSharedPtr result_msg; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(true))); + + const hmi_apis::FunctionID::eType posted_function_id = + hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr dummy_msg_params = CreateMessage(); + command->CreateHMIRequest(posted_function_id, *dummy_msg_params); + + ASSERT_TRUE(result_msg); + + const application_manager::MessageType received_message_tipe = + static_cast( + (*result_msg)[am::strings::params][am::strings::message_type] + .asInt()); + + EXPECT_EQ(am::MessageType::kRequest, received_message_tipe); + + const hmi_apis::FunctionID::eType received_function_id = + static_cast( + (*result_msg)[am::strings::params][am::strings::function_id].asInt()); + + EXPECT_EQ(posted_function_id, received_function_id); +} + +TEST_F(ResponseFromHMITest, CreateHMIRequest_CantManageCommand_Covering) { + ResponseFromHMIPtr command(CreateCommand()); + + MessageSharedPtr result_msg; + ON_CALL(app_mngr_, GetNextHMICorrelationID()).WillByDefault(Return(1u)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(false))); + + const hmi_apis::FunctionID::eType posted_function_id = + hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr dummy_msg_params = CreateMessage(); + command->CreateHMIRequest(posted_function_id, *dummy_msg_params); +} + +} // namespace response_from_hmi +} // 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/sdl_activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc new file mode 100644 index 0000000000..52a8b1cad4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc @@ -0,0 +1,495 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/lock.h" +#include "utils/helpers.h" +#include "hmi/sdl_activate_app_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/application_manager.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_state_controller.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_activate_app_request { + +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLActivateAppRequest; +using am::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::ReturnRef; +using testing::Mock; +using ::testing::NiceMock; +using policy_test::MockPolicyHandlerInterface; +using am::event_engine::Event; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const uint32_t kAppIDFirst = 1u; +const connection_handler::DeviceHandle kHandle = 2u; +} // namespace + +MATCHER_P2(CheckMsgParams, result, corr_id, "") { + const bool is_func_id_valid = + hmi_apis::FunctionID::SDL_ActivateApp == + static_cast( + (*arg)[strings::params][strings::function_id].asInt()); + + const bool is_result_code_valid = + hmi_apis::Common_Result::APPLICATION_NOT_REGISTERED == + static_cast( + (*arg)[strings::msg_params][strings::result_code].asInt()); + + const bool is_result_valid = + result == (*arg)[strings::msg_params][strings::success].asBool(); + + const bool is_corr_id_valid = + corr_id == ((*arg)[strings::params][strings::correlation_id].asUInt()); + + using namespace helpers; + return Compare(true, + is_func_id_valid, + is_result_code_valid, + is_result_valid, + is_corr_id_valid); +} + +class SDLActivateAppRequestTest + : public CommandRequestTest { + protected: + ~SDLActivateAppRequestTest() { + // Fix DataAccessor release and WinQt crash + Mock::VerifyAndClearExpectations(&app_mngr_); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + MockAppPtr mock_app = CreateMockApp(); + CommandRequestTest::InitCommand(timeout); + ON_CALL((*mock_app), app_id()).WillByDefault(Return(kAppID)); + ON_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillByDefault(Return(mock_app)); + } + void SetCorrelationAndAppID(MessageSharedPtr msg) { + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + } + + ApplicationSet app_list_; + ::sync_primitives::Lock lock_; + application_manager_test::MockStateController mock_state_controller_; + NiceMock mock_event_dispatcher_; +}; + +#ifdef EXTERNAL_PROPRIETARY_MODE + +TEST_F(SDLActivateAppRequestTest, Run_ActivateApp_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, DISABLED_Run_DactivateApp_REJECTED) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + (*msg)[strings::msg_params][strings::function_id] = + hmi_apis::FunctionID::SDL_ActivateApp; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(true)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::SDL_ActivateApp))) + .WillOnce(Return(true)); + + command->Run(); +} +#else + +TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppID)).WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + ON_CALL(*mock_app, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + const std::string url = "url"; + ON_CALL(*mock_app_first, SchemaUrl()).WillByDefault(Return(url)); + const std::string package = "package"; + ON_CALL(*mock_app_first, PackageName()).WillByDefault(Return(package)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, AppIdNotFound_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kAppID)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, WaitingApplicationByID(kAppID)) + .WillOnce(Return(ApplicationSharedPtr())); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, DevicesAppsEmpty_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); + + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + app_list_ = accessor.GetData(); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + app_list_ = accessor.GetData(); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppIDFirst)) + .WillByDefault(Return(mock_app_first)); + + app_list_.insert(mock_app_first); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(true)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + + const std::string schema("schema"); + mock_app->SetShemaUrl(schema); + const std::string package_name("package_name"); + mock_app->SetPackageName(package_name); + + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, schema, package_name, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + DataAccessor accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + app_list_ = accessor.GetData(); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} +#endif + +TEST_F(SDLActivateAppRequestTest, OnTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + SharedPtr command( + CreateCommand(msg)); + ON_CALL(mock_event_dispatcher_, remove_observer(_, _)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->onTimeOut(); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::params][strings::correlation_id] = kCorrelationID; + + SharedPtr command( + CreateCommand()); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*event_msg); + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).Times(0); + + command->on_event(event); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidAppId_UNSUCCESS) { + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::msg_params][strings::application][strings::app_id] = + kAppID; + + SharedPtr command( + CreateCommand()); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); + event.set_smart_object(*event_msg); + + MockAppPtr invalid_mock_app; + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)) + .WillOnce(Return(invalid_mock_app)); + + command->on_event(event); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + SharedPtr command( + CreateCommand(msg)); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::msg_params][strings::application][strings::app_id] = + kAppID; + + Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); + event.set_smart_object(*event_msg); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppID)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->on_event(event); +} + +} // namespace sdl_activate_app_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/hmi/sdl_activate_app_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc new file mode 100644 index 0000000000..d808f42d9b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "hmi/sdl_activate_app_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_activate_app_response { + +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::SDLActivateAppResponse; +using am::commands::CommandImpl; + +typedef SharedPtr SDLActivateAppResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class SDLActivateAppResponseTest + : public CommandsTest {}; + +TEST_F(SDLActivateAppResponseTest, RUN_SendRequest_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; + + SDLActivateAppResponsePtr command( + CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace sdl_activate_app_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/sdl_get_list_of_permisssions_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc new file mode 100644 index 0000000000..ed4572eba3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/sdl_get_list_of_permissions_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_list_of_permissions_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetListOfPermissionsRequest; +using test::components::policy_test::MockPolicyHandlerInterface; +using smart_objects::SmartObject; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const uint32_t kConnectionKey = 0u; +} // namespace + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +class SDLGetListOfPermissionsRequestTest + : public CommandRequestTest { + protected: + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest::InitCommand(timeout); + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); + } + MockAppPtr mock_app_; +}; + +TEST_F(SDLGetListOfPermissionsRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillOnce(Return(mock_app_)); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_policy_handler_, + OnGetListOfPermissions(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetListOfPermissionsRequestTest, Run_KeyDoesntExist_SUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Binary); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_policy_handler_, + OnGetListOfPermissions(kConnectionKey, kCorrelationID)); + + command->Run(); +} + +} // namespace sdl_get_list_of_permissions_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/hmi/sdl_get_status_update_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc new file mode 100644 index 0000000000..736ae995d4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/sdl_get_status_update_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_status_update_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetStatusUpdateRequest; +using test::components::policy_test::MockPolicyHandlerInterface; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +} // namespace + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +class SDLGetStatusUpdateRequestTest + : public CommandRequestTest {}; + +TEST_F(SDLGetStatusUpdateRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_policy_handler_, OnGetStatusUpdate(kCorrelationID)); + + command->Run(); +} + +} // namespace sdl_get_status_update_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/hmi/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc new file mode 100644 index 0000000000..f280d8d80b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2016, 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 "hmi/sdl_get_user_friendly_message_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_state_controller.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_user_friendly_message_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetUserFriendlyMessageRequest; +using application_manager::MockMessageHelper; +using test::components::policy_test::MockPolicyHandlerInterface; +using test::components::application_manager_test::MockHMICapabilities; +using testing::_; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const std::string kLanguageDe = "de-de"; +const std::string kLanguageEn = "en-gb"; +const std::string kMessageCodes = "messageCodes"; +const hmi_apis::Common_Language::eType kLanguage = + hmi_apis::Common_Language::EN_GB; +} // namespace + +namespace strings = ::application_manager::strings; + +class SDLGetUserFriendlyMessageRequestTest + : public CommandRequestTest { + protected: + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest::InitCommand(timeout); + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillOnce(Return(mock_app_)); + } + MockAppPtr mock_app_; +}; + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + (*msg)[strings::msg_params][strings::language] = kLanguage; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) + .WillOnce(Return(kLanguageEn)); + std::vector msg_codes; + msg_codes.push_back(kLanguageDe); + msg_codes.push_back(kLanguageEn); + EXPECT_CALL(mock_policy_handler_, + OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(kLanguage)); + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) + .WillOnce(Return(kLanguageEn)); + std::vector msg_codes; + msg_codes.push_back(kLanguageDe); + msg_codes.push_back(kLanguageEn); + EXPECT_CALL(mock_policy_handler_, + OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_NoMsgCodes_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); + EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + + command->Run(); +} + +} // namespace sdl_get_user_friendly_message_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/hmi/simple_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc new file mode 100644 index 0000000000..2e68e21597 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" + +#include "application_manager/commands/commands_test.h" + +#include "application_manager/commands/notification_to_hmi.h" +#include "application_manager/commands/command_notification_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_notifications_test { + +using namespace application_manager; + +using ::testing::Types; +using sdl_rpc_plugin::commands::NotificationToHMI; +template +class SimpleNotificationsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +typedef Types + CommandsList; + +TYPED_TEST_CASE(SimpleNotificationsTest, CommandsList); + +TYPED_TEST(SimpleNotificationsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +} // namespace simple_notifications_test +} // 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/simple_request_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc new file mode 100644 index 0000000000..182d696f9a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016, 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 "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.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/request_from_hmi.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_requests_from_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; +using ::testing::NiceMock; + +using ::utils::SharedPtr; +namespace commands = ::application_manager::commands; +using commands::MessageSharedPtr; +using ::application_manager::event_engine::EventObserver; +using ::test::components::event_engine_test::MockEventDispatcher; + +class RequestFromHMITest : public CommandsTest { + protected: + void SetUp() OVERRIDE { + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + } + NiceMock mock_event_dispatcher_; +}; + +TEST_F(RequestFromHMITest, BasicMethodsOverloads_SUCCESS) { + SharedPtr command( + CreateCommand()); + application_manager::event_engine::Event event( + hmi_apis::FunctionID::BasicCommunication_ActivateApp); + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); + EXPECT_NO_THROW(command->Run()); + EXPECT_NO_THROW(command->on_event(event)); +} + +TEST_F(RequestFromHMITest, SendResponse_SUCCESS) { + SharedPtr command( + CreateCommand()); + + const bool success = false; + const uint32_t correlation_id = 1u; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(NotNull())); + + command->SendResponse(success, + correlation_id, + hmi_apis::FunctionID::BasicCommunication_ActivateApp, + hmi_apis::Common_Result::SUCCESS); +} + +} // namespace simple_requests_to_hmi_test +} // 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/simple_requests_to_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc new file mode 100644 index 0000000000..70c7411ec8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2016, Ford Motor Company + * All rights reserved. + * + * Copyright (c) 2017 Xevo Inc. + * 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 "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/commands/command.h" +#include "sdl_rpc_plugin/commands/hmi/allow_app_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_all_apps_request.h" +#include "sdl_rpc_plugin/commands/hmi/basic_communication_system_request.h" +#include "sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_alert_maneuver_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_audio_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_get_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_send_location_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_show_constant_tbt_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_subscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_unsubscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_update_turn_list_request.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h" +#include "sdl_rpc_plugin/commands/hmi/ui_scrollable_message_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_app_icon_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_display_layout_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_global_properties_request.h" +#include "application_manager/commands/request_to_hmi.h" +#include "sdl_rpc_plugin/commands/hmi/vi_get_vehicle_type_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_read_did_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_subscribe_vehicle_data_request.h" +#include "sdl_rpc_plugin/commands/hmi/dial_number_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_set_global_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_speak_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_stop_speaking_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/close_popup_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_add_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_add_submenu_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_alert_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_submenu_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_end_audio_pass_thru_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_perform_audio_pass_thru_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_perform_interaction_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_diagnostic_message_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_get_dtcs_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_get_vehicle_data_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_media_clock_timer_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_show_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_slider_request.h" +#include "sdl_rpc_plugin/commands/hmi/vi_unsubscribe_vehicle_data_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_add_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_delete_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_perform_interaction_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_all_apps_request.h" +#include "sdl_rpc_plugin/commands/hmi/basic_communication_system_request.h" +#include "sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_app_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_send_location_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_unsubscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_update_turn_list_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_show_constant_tbt_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_subscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_policy_update.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_icon_request.h" +#include "sdl_rpc_plugin/commands/hmi/dial_number_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_send_haptic_data_request.h" + +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_requests_to_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; + +using ::utils::SharedPtr; + +namespace am_commands = application_manager::commands; +using am_commands::MessageSharedPtr; +using event_engine_test::MockEventDispatcher; + +class RequestToHMITest : public CommandsTest {}; + +TEST_F(RequestToHMITest, BasicMethodsOverloads_SUCCESS) { + SharedPtr command( + CreateCommand()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(RequestToHMITest, SendRequest_SUCCESS) { + SharedPtr command( + CreateCommand()); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->SendRequest(); +} + +template +class RequestToHMICommandsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +template +class RequestToHMICommandsTest2 : public RequestToHMICommandsTest {}; + +template +class RequestToHMICommandsTest3 + : public CommandRequestTest { + public: + typedef Command CommandType; +}; + +typedef Types + RequestCommandsList; + +typedef Types + RequestCommandsList2; + +typedef Types RequestCommandsList3; + +TYPED_TEST_CASE(RequestToHMICommandsTest, RequestCommandsList); +TYPED_TEST_CASE(RequestToHMICommandsTest2, RequestCommandsList2); +TYPED_TEST_CASE(RequestToHMICommandsTest3, RequestCommandsList3); + +TYPED_TEST(RequestToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +TYPED_TEST(RequestToHMICommandsTest2, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +TYPED_TEST(RequestToHMICommandsTest3, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +} // namespace simple_requests_to_hmi_test +} // 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/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 new file mode 100644 index 0000000000..f36df1d922 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc @@ -0,0 +1,374 @@ +/* + * Copyright (c) 2016, Ford Motor Company + * All rights reserved. + * + * Copyright (c) 2017 Xevo Inc. + * 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 + +#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.h" +#include "hmi/activate_app_response.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/navi_alert_maneuver_response.h" +#include "hmi/navi_audio_start_stream_response.h" +#include "hmi/navi_audio_stop_stream_response.h" +#include "hmi/navi_get_way_points_response.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_stop_stream_response.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/ui_set_app_icon_response.h" +#include "hmi/ui_set_display_layout_response.h" +#include "hmi/ui_set_global_properties_response.h" +#include "hmi/ui_scrollable_message_response.h" +#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" +#include "hmi/tts_speak_response.h" +#include "hmi/tts_stop_speaking_response.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/ui_add_command_response.h" +#include "hmi/ui_add_submenu_response.h" +#include "hmi/ui_alert_response.h" +#include "hmi/ui_change_registration_response.h" +#include "hmi/ui_delete_command_response.h" +#include "hmi/ui_delete_submenu_response.h" +#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" +#include "hmi/vr_perform_interaction_response.h" +#include "hmi/activate_app_response.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/on_find_applications.h" +#include "hmi/on_update_device_list.h" +#include "hmi/sdl_policy_update_response.h" +#include "hmi/update_app_list_response.h" +#include "hmi/update_device_list_response.h" +#include "application_manager/commands/notification_from_hmi.h" +#include "hmi/ui_send_haptic_data_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_response_from_hmi_test { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::Types; +using ::testing::Eq; + +using ::utils::SharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; + +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; +using am::commands::MessageSharedPtr; +template +class ResponseFromHMICommandsTest + : public CommandsTest { + public: + typedef CommandD CommandData; + MockEventDispatcher event_dispatcher_; + + ResponseFromHMICommandsTest() { + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + } +}; + +template +class EmptyResponseFromHMICommandsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +template +struct CommandData { + typedef Command CommandType; + enum { kEventId = kExpectedEventId }; +}; + +typedef Types< + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData, + CommandData > ResponseCommandsList; + +typedef Types + EmptyResponseCommandsList; + +TYPED_TEST_CASE(ResponseFromHMICommandsTest, ResponseCommandsList); + +TYPED_TEST_CASE(EmptyResponseFromHMICommandsTest, EmptyResponseCommandsList); + +MATCHER_P(EventIdIsEqualTo, function_id, "") { + return static_cast(function_id) == arg.id(); +} + +TYPED_TEST(ResponseFromHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandData CommandData; + typedef typename CommandData::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + + EXPECT_CALL(this->event_dispatcher_, + raise_event(EventIdIsEqualTo(CommandData::kEventId))); + + command->Run(); +} + +TYPED_TEST(EmptyResponseFromHMICommandsTest, Run_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + + command->Run(); +} + +class OtherResponseFromHMICommandsTest + : public CommandsTest {}; + +MATCHER_P(VehicleTypeIsEqualTo, vehicle_type, "") { + return (*vehicle_type) == arg.asString(); +} + +TEST_F(OtherResponseFromHMICommandsTest, VIGetVehicleTypeResponse_Run_SUCCESS) { + const std::string kVehicleType = "Test"; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::hmi_response::vehicle_type] = + kVehicleType; + + SharedPtr command( + CreateCommand( + command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_vehicle_type(VehicleTypeIsEqualTo(&kVehicleType))); + + command->Run(); +} + +TEST_F(OtherResponseFromHMICommandsTest, VIIsReadyResponse_Run_SUCCESS) { + SharedPtr command( + CreateCommand()); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +MATCHER_P(CheckMsgType, msg_type, "") { + return msg_type == + static_cast( + (*arg)[am::strings::params][am::strings::message_type].asInt()); +} + +class NotificationFromHMITest + : public CommandsTest {}; + +TEST_F(NotificationFromHMITest, BasicMethodsOverloads_SUCCESS) { + SharedPtr command( + CreateCommand()); + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); + EXPECT_NO_THROW(command->Run()); +} + +TEST_F(NotificationFromHMITest, SendNotificationToMobile_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kNotification); + + SharedPtr command( + CreateCommand()); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMsgType(am::MessageType::kNotification), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command->SendNotificationToMobile(command_msg); +} + +TEST_F(NotificationFromHMITest, CreateHMIRequest_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params] = 0; + SharedPtr command( + CreateCommand( + command_msg)); + + const uint32_t correlation_id = 1u; + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(correlation_id)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(CheckMsgType(am::MessageType::kRequest))) + .WillOnce(Return(false)); + + command->CreateHMIRequest(hmi_apis::FunctionID::INVALID_ENUM, + (*command_msg)[am::strings::msg_params]); +} + +} // namespace simple_response_from_hmi_test +} // 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/simple_response_to_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc new file mode 100644 index 0000000000..69e59c0c1f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016, 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 "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.h" +#include "application_manager/commands/commands_test.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_response.h" +#include "application_manager/commands/response_to_hmi.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_response_to_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; +using ::utils::SharedPtr; + +namespace commands = sdl_rpc_plugin::commands; +using application_manager::commands::MessageSharedPtr; + +template +class ResponseToHMICommandsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +typedef Types ResponseCommandsList; + +TYPED_TEST_CASE(ResponseToHMICommandsTest, ResponseCommandsList); + +TYPED_TEST(ResponseToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + SharedPtr command = this->template CreateCommand(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +class ResponseToHMITest : public CommandsTest {}; + +TEST_F(ResponseToHMITest, BasicMethodsOverloads_SUCCESS) { + SharedPtr command( + CreateCommand()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(ResponseToHMITest, Run_SUCCESS) { + SharedPtr command( + CreateCommand()); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +} // namespace simple_response_to_hmi_test +} // 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/tts_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc new file mode 100644 index 0000000000..d1b05a294b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/tts_get_capabilities_response.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_capabilities_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::TTSGetCapabilitiesResponse; +using test::components::application_manager_test::MockHMICapabilities; +using utils::SharedPtr; +using testing::_; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const std::string kText = "TEXT"; +} + +class TTSGetCapabilitiesResponseTest + : public CommandsTest {}; + +TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; + (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = + kText; + + EXPECT_CALL(mock_hmi_capabilities_, + set_speech_capabilities(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + set_prerecorded_speech(SmartObject(kText))); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlySpeech_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; + + EXPECT_CALL(mock_hmi_capabilities_, + set_speech_capabilities(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlyPrerecorded_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = + kText; + + EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + set_prerecorded_speech(SmartObject(kText))); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_Nothing_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +} // namespace tts_get_capabilities_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/tts_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc new file mode 100644 index 0000000000..7b0c8aa5be --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/tts_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_language_response { + +using utils::SharedPtr; +using sdl_rpc_plugin::commands::TTSGetLanguageResponse; +using test::components::application_manager_test::MockHMICapabilities; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +namespace { +const Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class TTSGetLanguageResponseTest + : public CommandsTest {}; + +TEST_F(TTSGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(kLanguage)); + + 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(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_tts_language(Common_Language::INVALID_ENUM)); + + 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 tts_get_language_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/tts_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..7a6479f400 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/tts_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_supported_languages_response { + +using ::testing::_; +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesResponse; +using am::commands::CommandImpl; + +typedef SharedPtr ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class TTSGetSupportedLanguageResponseTest + : public CommandsTest { + public: + SmartObject capabilities_; +}; + +TEST_F(TTSGetSupportedLanguageResponseTest, RUN_SUCCESS) { + smart_objects::SmartObject supported_languages("EN_US"); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_tts_supported_languages(( + *command_msg)[strings::msg_params][hmi_response::languages])); + + command->Run(); +} +TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { + smart_objects::SmartObject supported_languages("EN_US"); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_tts_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace tts_get_supported_languages_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/tts_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc new file mode 100644 index 0000000000..238f2d023d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/tts_is_ready_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_is_ready_response { + +using ::testing::_; +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::TTSIsReadyResponse; +using am::commands::CommandImpl; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const bool kIsAvailable = true; +const bool kIsNotAvailable = false; +} // namespace + +class TTSIsReadyResponseTest : public CommandsTest { + public: + MockHMICapabilities mock_hmi_capabilities_; + SmartObject capabilities_; +}; + +TEST_F(TTSIsReadyResponseTest, RUN_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand()); + 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 tts_is_ready_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/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc new file mode 100644 index 0000000000..0f464d09c4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -0,0 +1,317 @@ +/* + * Copyright (c) 2016, Ford Motor Company + * All rights reserved. + * + * Copyright (c) 2017 Xevo Inc. + * 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 + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/ui_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_capabilities_response { + +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::UIGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef SharedPtr ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class UIGetCapabilitiesResponseTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(UIGetCapabilitiesResponseTest, RUN_SetDisplay_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] + [hmi_response::display_type] = "GEN2_8_DMA"; + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] + [hmi_response::display_name] = "GENERIC_DISPLAY"; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject display_capabilities_so = + (*command_msg)[strings::msg_params][hmi_response::display_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_display_capabilities(display_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetSoftButton_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] + [hmi_response::image_supported] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject soft_button_capabilities_so = (*command_msg) + [strings::msg_params][hmi_response::soft_button_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_soft_button_capabilities(soft_button_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities][0] = + "FRONT"; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject hmi_zone_capabilities_so = + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_hmi_zone_capabilities(hmi_zone_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::audio_pass_thru_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject audio_pass_thru_capabilities_so = (*command_msg) + [strings::msg_params][strings::audio_pass_thru_capabilities]; + EXPECT_CALL( + mock_hmi_capabilities_, + set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetNavigation_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::navigation] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_navigation_supported( + hmi_capabilities_so[strings::navigation].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetPhoneCall_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::phone_call] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_phone_call_supported( + hmi_capabilities_so[strings::phone_call].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreaming_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::video_streaming] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_video_streaming_supported( + hmi_capabilities_so[strings::video_streaming].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetNavigationCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]["sendLocationEnabled"] = true; + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]["getWayPointsEnabled"] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject navigation_capability_so = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_navigation_capability(navigation_capability_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetPhonenCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::phone_capability]["dialNumberEnabled"] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject phone_capability_so = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::phone_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_phone_capability(phone_capability_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::video_streaming_capability] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject& video_streaming_capability = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::video_streaming_capability]; + + video_streaming_capability[strings::preferred_resolution] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + video_streaming_capability[strings::preferred_resolution] + [strings::resolution_width] = 800; + video_streaming_capability[strings::preferred_resolution] + [strings::resolution_height] = 350; + + video_streaming_capability[strings::max_bitrate] = 10000; + + video_streaming_capability[strings::supported_formats] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + video_streaming_capability[strings::supported_formats][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + video_streaming_capability[strings::supported_formats][0][strings::protocol] = + hmi_apis::Common_VideoStreamingProtocol::RAW; + + video_streaming_capability[strings::supported_formats][0][strings::codec] = + hmi_apis::Common_VideoStreamingCodec::H264; + + video_streaming_capability[strings::haptic_spatial_data_supported] = true; + + ResponseFromHMIPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_video_streaming_capability(video_streaming_capability)); + + command->Run(); +} + +} // namespace ui_get_capabilities_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/ui_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc new file mode 100644 index 0000000000..e7746d69fa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/ui_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_language_response { + +using utils::SharedPtr; +using sdl_rpc_plugin::commands::UIGetLanguageResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class UIGetLanguageResponseTest + : public CommandsTest {}; + +TEST_F(UIGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(kLanguage)); + + 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(UIGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_ui_language(Common_Language::INVALID_ENUM)); + + 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 ui_get_language_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/ui_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..4a9f5de11b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "hmi/ui_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_supported_languages_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::UIGetSupportedLanguagesResponse; + +typedef SharedPtr + UIGetSupportedLanguagesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const std::string kLanguage = "EN_US"; +const smart_objects::SmartObject supported_languages(kLanguage); +} // namespace + +class UIGetSupportedLanguagesResponseTest + : public CommandsTest { + public: + SmartObject capabilities_; +}; + +TEST_F(UIGetSupportedLanguagesResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_ui_supported_languages((supported_languages))); + + command->Run(); +} +TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_ui_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace ui_get_supported_languages_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/ui_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc new file mode 100644 index 0000000000..deae819ae6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2016, 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/ui_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 ui_is_ready_request { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::UIIsReadyRequest; +using am::event_engine::Event; + +typedef SharedPtr UIIsReadyRequestPtr; + +class UIIsReadyRequestTest + : public CommandRequestTest { + public: + UIIsReadyRequestTest() : command_(CreateCommand()) {} + + void SetUpExpectations(bool is_ui_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + EXPECT_CALL(mock_hmi_capabilities_, + set_is_ui_cooperating(is_ui_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_UI, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(state)); + + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr get_language(CreateMessage()); + (*get_language)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kRequest); + (*get_language)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, _)) + .WillOnce(Return(get_language)); + + smart_objects::SmartObjectSPtr get_all_language(CreateMessage()); + (*get_all_language)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kRequest); + (*get_all_language)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetSupportedLanguages, _)) + .WillOnce(Return(get_all_language)); + + smart_objects::SmartObjectSPtr get_capabilities(CreateMessage()); + (*get_capabilities)[am::strings::params][am::strings::message_type] = + static_cast(am::MessageType::kRequest); + (*get_capabilities)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetCapabilities, _)) + .WillOnce(Return(get_capabilities)); + + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*get_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_all_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_ui_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_ui_cooperating_available; + } + event.set_smart_object(*msg); + } + + UIIsReadyRequestPtr command_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; +}; + +TEST_F(UIIsReadyRequestTest, + OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_ui_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, + OnEvent_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_ui_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_ui_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event, is_ui_cooperating_available); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace ui_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/hmi/ui_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc new file mode 100644 index 0000000000..419ab7ba67 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016, 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/mock_hmi_capabilities.h" +#include "hmi/ui_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_is_ready_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::UIIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr UIIsReadyResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const bool kIsAvailable = true; +const bool kIsNotAvailable = false; +} // namespace + +class UIIsReadyResponseTest : public CommandsTest { + public: + MockHMICapabilities mock_hmi_capabilities_; + SmartObject capabilities_; +}; + +TEST_F(UIIsReadyResponseTest, RUN_SUCCESS) { + UIIsReadyResponsePtr command(CreateCommand()); + + 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 ui_is_ready_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/update_device_list_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc new file mode 100644 index 0000000000..dffd4f3f9a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "interfaces/HMI_API.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/application_manager.h" +#include "application_manager/application_manager_impl.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/request_controller_settings.h" +#include "application_manager/mock_application_manager_settings.h" +#include "hmi/update_device_list_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_device_list_request { + +using ::utils::SharedPtr; +using testing::_; +using testing::ReturnRef; +using testing::Return; +using test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::UpdateDeviceListRequest; +using am::commands::CommandImpl; + +typedef SharedPtr UpdateDeviceListRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class UpdateDeviceListRequestTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + return command_msg; + } + + MockApplicationManagerSettings settings_; + MockEventDispatcher mock_event_dispatcher_; +}; + +TEST_F(UpdateDeviceListRequestTest, RUN_LaunchHMIReturnsFalse) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); + + EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(false)); + + EXPECT_CALL(app_mngr_, IsHMICooperating()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +TEST_F(UpdateDeviceListRequestTest, RUN_HMICooperatingReturnsTrue_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); + + EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, IsHMICooperating()).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +TEST_F(UpdateDeviceListRequestTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command(CreateCommand()); + + command->on_event(event); +} + +TEST_F(UpdateDeviceListRequestTest, OnEvent_SUCCESS) { + Event event(Event::EventID::BasicCommunication_OnReady); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_, _)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command(CreateCommand()); + + command->on_event(event); +} + +} // namespace update_device_list_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/hmi/update_sdl_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc new file mode 100644 index 0000000000..08c6844829 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/update_sdl_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_sdl_request { + +using ::utils::SharedPtr; +using ::testing::ReturnRef; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::UpdateSDLRequest; + +typedef SharedPtr UpdateSDLRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 1u; +const std::string kStrNumber = "123"; +} // namespace + +class UpdateSDLRequestTest : public CommandsTest {}; + +TEST_F(UpdateSDLRequestTest, 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::correlation_id] = kCorrelationId; + + UpdateSDLRequestPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_policy_handler_, PTExchangeAtUserRequest(kCorrelationId)); + + command->Run(); + + EXPECT_EQ(kCorrelationId, + (*command_msg)[strings::params][strings::correlation_id].asUInt()); +} + +} // namespace update_sdl_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/hmi/update_sdl_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc new file mode 100644 index 0000000000..4c9d522dd3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "hmi/update_sdl_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_sdl_response { + +using ::utils::SharedPtr; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::UpdateSDLResponse; +using am::commands::CommandImpl; + +typedef SharedPtr UpdateSDLResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class UpdateSDLResponseTest : public CommandsTest { +}; + +TEST_F(UpdateSDLResponseTest, RUN_SendRequest_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; + + UpdateSDLResponsePtr command(CreateCommand(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace update_sdl_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_get_vehicle_data_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc new file mode 100644 index 0000000000..83beda437c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_get_vehicle_data_response_test.cc @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2016, 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 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 new file mode 100644 index 0000000000..5eee0e370e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2016, 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/hmi/vr_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc new file mode 100644 index 0000000000..e28236274b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/vr_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_capabilities_response { + +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef SharedPtr VRGetCapabilitiesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class VRGetCapabilitiesResponseTest + : public CommandsTest { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(VRGetCapabilitiesResponseTest, RUN_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::vr_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][strings::vr_capabilities][0] = + "vrCapabilities"; + + VRGetCapabilitiesResponsePtr command( + CreateCommand(command_msg)); + + smart_objects::SmartObject vr_capabilities_so = + (*command_msg)[strings::msg_params][strings::vr_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, set_vr_capabilities(vr_capabilities_so)); + + command->Run(); +} + +} // namespace vr_get_capabilities_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/vr_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc new file mode 100644 index 0000000000..816b536875 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "hmi/vr_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_language_response { + +using utils::SharedPtr; +using sdl_rpc_plugin::commands::VRGetLanguageResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class VRGetLanguageResponseTest + : public CommandsTest {}; + +TEST_F(VRGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(kLanguage)); + + 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(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_vr_language(Common_Language::INVALID_ENUM)); + + 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 vr_get_language_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/vr_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..a23d77a32a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "hmi/vr_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_supported_languages_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRGetSupportedLanguagesResponse; + +typedef SharedPtr + VRGetSupportedLanguagesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const std::string kLanguage = "EN_US"; +const smart_objects::SmartObject supported_languages(kLanguage); +} // namespace + +class VRGetSupportedLanguagesResponseTest + : public CommandsTest { + public: + SmartObject capabilities_; +}; + +TEST_F(VRGetSupportedLanguagesResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_vr_supported_languages((supported_languages))); + + command->Run(); +} +TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_vr_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace vr_get_supported_languages_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/vr_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc new file mode 100644 index 0000000000..2442041206 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2016, 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/vr_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/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::VRIsReadyRequest; +using am::event_engine::Event; + +typedef SharedPtr VRIsReadyRequestPtr; + +class VRIsReadyRequestTest + : public CommandRequestTest { + public: + VRIsReadyRequestTest() : command_(CreateCommand()) {} + + void SetUpExpectations(bool is_vr_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + const bool is_send_message_by_timeout = false; + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(is_send_message_by_timeout); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_vr_cooperating(is_vr_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + smart_objects::SmartObjectSPtr language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(language)); + + smart_objects::SmartObjectSPtr support_language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(support_language)); + + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vr_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vr_cooperating_available; + } + event.set_smart_object(*msg); + } + + VRIsReadyRequestPtr command_; +}; + +TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vr_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + const bool is_send_message_by_timeout = true; + ExpectSendMessagesToHMI(is_send_message_by_timeout); + command_->onTimeOut(); +} + +} // namespace vr_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/hmi/vr_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc new file mode 100644 index 0000000000..a59be3332e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2016, 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/mock_hmi_capabilities.h" +#include "hmi/vr_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_is_ready_response { + +using ::testing::Return; +using ::utils::SharedPtr; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef SharedPtr VRIsReadyResponsePtr; + +class VRIsReadyResponseTest : public CommandsTest { +}; + +TEST_F(VRIsReadyResponseTest, RUN_SUCCESS) { + VRIsReadyResponsePtr command(CreateCommand()); + + 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 vr_is_ready_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/mobile/add_command_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc new file mode 100644 index 0000000000..20aec44c08 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc @@ -0,0 +1,1112 @@ +/* + * Copyright (c) 2016, 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 "mobile/add_command_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/helpers.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace add_command_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using ::testing::_; +using ::utils::SharedPtr; +using ::testing::Return; +using ::testing::InSequence; +using sdl_rpc_plugin::commands::AddCommandRequest; +using NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr; +using ::test::components::application_manager_test::MockApplication; +using am::event_engine::EventObserver; +using namespace smart_objects; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace mobile_result = mobile_apis::Result; +namespace hmi_response = ::application_manager::hmi_response; +namespace hmi_request = ::application_manager::hmi_request; +using namespace strings; + +namespace { +const hmi_apis::FunctionID::eType kInvalidFunctionId = + hmi_apis::FunctionID::INVALID_ENUM; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const std::string kMenuName = "LG"; +const uint32_t kFirstParentId = 10u; +const uint32_t kSecondParentId = 1u; +const std::string kErroredVRCommand = "l\namer"; +const std::string kFirstVrCommand = "lamer"; +const std::string kSecondVrCommand = "hacker"; +const uint32_t kFirstCommandId = 10u; +const uint32_t kSecondCommandId = 11u; +const int32_t kType = 34; +const int32_t kGrammarId = 12; +const int32_t kPosition = 10; +} // namespace + +class AddCommandRequestTest + : public CommandRequestTest { + public: + AddCommandRequestTest() + : msg_(CreateMessage()) + , default_app_name_("test_default_app_name_") + , mock_app_(CreateMockApp()) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + InitGetters(); + InitBasicMessage(); + } + + protected: + void InitBasicMessage() { + (*msg_)[params][connection_key] = kConnectionKey; + (*msg_)[msg_params][app_id] = kAppId; + (*msg_)[msg_params][app_name] = default_app_name_; + } + + void InitGetters() { + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, FindCommand(kCmdId)) + .WillByDefault(Return(so_ptr_.get())); + } + + void CreateBasicParamsUIRequest() { + SmartObject menu_params = SmartObject(SmartType_Map); + menu_params[position] = kPosition; + menu_params[menu_name] = kMenuName; + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[cmd_id] = kCmdId; + msg_params[strings::menu_params] = menu_params; + msg_params[cmd_icon] = 1; + msg_params[cmd_icon][value] = "10"; + msg_params[info] = "UI info"; + } + + void CreateBasicParamsVRRequest() { + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[cmd_id] = kCmdId; + msg_params[vr_commands] = SmartObject(SmartType_Array); + msg_params[vr_commands][0] = kFirstVrCommand; + msg_params[type] = kPosition; + msg_params[grammar_id] = kGrammarId; + msg_params[info] = "VR info"; + } + + const am::CommandsMap CreateCommandsMap(SmartObject& first_command, + SmartObject& second_command) { + second_command[menu_params] = SmartObject(SmartType_Map); + second_command[menu_params][hmi_request::parent_id] = kFirstParentId; + second_command[menu_params][menu_name] = kMenuName; + second_command[vr_commands] = SmartObject(SmartType_Array); + second_command[vr_commands][0] = kSecondVrCommand; + am::CommandsMap commands_map; + commands_map.insert(std::make_pair(kFirstCommandId, &first_command)); + commands_map.insert(std::make_pair(kSecondCommandId, &second_command)); + return commands_map; + } + + void CheckOnTimeOutCommandDeletion( + const hmi_apis::FunctionID::eType incoming_cmd, + const hmi_apis::FunctionID::eType cmd_to_delete) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)) + .WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor( + commands_map, lock_))); + so_ptr_ = utils::MakeShared(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + Event event(incoming_cmd); + event.set_smart_object(*msg_); + request_ptr->on_event(event); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(cmd_to_delete))) + + .WillOnce(Return(true)); + SmartObjectSPtr response = utils::MakeShared(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(response, + am::commands::Command::CommandSource::SOURCE_SDL)); + utils::SharedPtr base_class_request = + static_cast >(request_ptr); + base_class_request->onTimeOut(); + } + + MessageSharedPtr msg_; + SmartObjectSPtr so_ptr_; + const utils::custom_string::CustomString default_app_name_; + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +TEST_F(AddCommandRequestTest, Run_AppNotExisted_EXPECT_AppNotRegistered) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_ImageVerificationFailed_EXPECT_INVALID_DATA) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_MenuNameHasSyntaxError_EXPECT_INVALID_DATA) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; + const std::string errored_menu_name = "L\nG"; + msg_params[menu_params][menu_name] = errored_menu_name; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + SmartObject parent = SmartObject(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kFirstParentId)) + .WillOnce(Return(&parent)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_VRCommandsHaveSyntaxError_EXPECT_INVALID_DATA) { + CreateBasicParamsVRRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[vr_commands][0] = kErroredVRCommand; + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_CMDIconHasError_EXPECT_INVALID_DATA) { + MessageSharedPtr msg = CreateMessage(); + SmartObject& msg_params = (*msg)[strings::msg_params]; + (*msg)[params][connection_key] = kConnectionKey; + msg_params[cmd_id] = kCmdId; + msg_params[cmd_icon] = 1; + const std::string errored_cmd_icon_value = "1\n0"; + msg_params[cmd_icon][value] = errored_cmd_icon_value; + msg_params[vr_commands][0] = kFirstVrCommand; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_CommandIDAlreadyExists_EXPECT_INVALID_ID) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + so_ptr_ = utils::MakeShared(SmartType_Map); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CommandNameAlreadyExists_EXPECT_DUPLICATE_NAME) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsgParentIDsAreDifferentSubmenuNotExisted_EXPECT_INVALID_ID) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsgVrSynonymsAreTheSame_EXPECT_DUPLICATE_NAME) { + CreateBasicParamsVRRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + msg_params[vr_commands][0] = kSecondVrCommand; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + so_ptr_ = utils::MakeShared(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_MsgDataEmpty_EXPECT_INVALID_DATA) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[params][connection_key] = kConnectionKey; + SmartObject& msg_params = (*msg)[strings::msg_params]; + msg_params[app_id] = kAppId; + msg_params[cmd_id] = kCmdId; + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsg_UI_and_Vr_AreCorrect_EXPECT_VR_AND_UI_SENT) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + so_ptr_ = utils::MakeShared(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, GetRunMethods_SUCCESS) { + CreateBasicParamsUIRequest(); + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, OnEvent_UI_SUCCESS) { + CreateBasicParamsUIRequest(); + (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly( + Return(DataAccessor(commands_map, lock_))); + + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnEvent_VR_SUCCESS) { + CreateBasicParamsVRRequest(); + MessageSharedPtr msg = CreateMessage(SmartType_Map); + (*msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + (*msg)[msg_params][cmd_id] = kCmdId; + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly( + Return(DataAccessor(commands_map, lock_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_VR_DeleteCommand) { + CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::VR_AddCommand, + hmi_apis::FunctionID::VR_DeleteCommand); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_UI_DeleteCommand) { + CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::UI_AddCommand, + hmi_apis::FunctionID::UI_DeleteCommand); +} + +TEST_F(AddCommandRequestTest, OnEvent_BothSend_SUCCESS) { + MessageSharedPtr command_msg = CreateMessage(SmartType_Map); + (*command_msg)[params][connection_key] = kConnectionKey; + MessageSharedPtr event_msg = CreateMessage(SmartType_Map); + (*event_msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + (*event_msg)[msg_params][cmd_id] = kCmdId; + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*event_msg); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); + + utils::SharedPtr request_ptr = + CreateCommand(command_msg); + request_ptr->Run(); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnEvent_AppNotExisted_UNSUCCESS) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + Event event(hmi_apis::FunctionID::UI_AddCommand); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_HmiResponseCodeIsRejected_ExpectUICommandRemoved) { + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::REJECTED; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::REJECTED), _)); + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_HmiResponseCodeIsWarnings_ExpectCommandUpdated) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::WARNINGS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::WARNINGS), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_HmiResponseCodeIsGenericError_VR_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); + (*msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_vr)[msg_params][cmd_id] = kCmdId; + event_vr.set_smart_object(*msg_vr); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_VR_HmiResponseCodeIsGenericError_UI_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_vr); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); + (*msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_ui)[msg_params][cmd_id] = kCmdId; + event_ui.set_smart_object(*msg_ui); + request_ptr->on_event(event_ui); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_UI_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_VR_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_VR_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_UI_EventWithNotSuccesResponseCode_ExpectVRCommandDelete) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); + (*msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*msg_ui)[msg_params][cmd_id] = kCmdId; + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_ui); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, + OnEvent_UI_VR_Events_VRErrorPresent_ExpectRemoveCommand) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); + (*msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*msg_vr)[msg_params][cmd_id] = kCmdId; + event_vr.set_smart_object(*msg_vr); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, + OnTimeOut_AppNotExisted_NoAppRemoveCommandCalled) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); + SmartObjectSPtr response = utils::MakeShared(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + response, am::commands::Command::CommandSource::SOURCE_SDL)); + utils::SharedPtr base_class_request = + static_cast >( + CreateCommand(msg_)); + base_class_request->onTimeOut(); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_AppRemoveCommandCalled) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return( + DataAccessor(commands_map, lock_))); + so_ptr_ = utils::MakeShared(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + utils::SharedPtr request_ptr = + CreateCommand(msg_); + request_ptr->Run(); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + SmartObjectSPtr response = utils::MakeShared(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + response, am::commands::Command::CommandSource::SOURCE_SDL)); + utils::SharedPtr base_class_request = + static_cast >(request_ptr); + base_class_request->onTimeOut(); +} + +} // namespace add_command_test +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc new file mode 100644 index 0000000000..28441579af --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2016, 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 "mobile/add_sub_menu_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace add_sub_menu_request { + +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::AddSubMenuRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using ::testing::_; +using ::testing::Return; + +typedef SharedPtr AddSubMenuPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class AddSubMenuRequestTest + : public CommandRequestTest {}; + +TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + const uint32_t menu_id = 10u; + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::menu_id] = menu_id; + + utils::SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + EXPECT_CALL(*mock_app, AddSubMenu(menu_id, _)); + EXPECT_CALL(*mock_app, UpdateHash()); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_AddSubMenu); + event.set_smart_object(*ev_msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + command->Init(); + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace add_sub_menu_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/alert_maneuver_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc new file mode 100644 index 0000000000..984c567085 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc @@ -0,0 +1,256 @@ +/* + * Copyright (c) 2016, 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/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/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "mobile/alert_maneuver_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace alert_maneuver_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::AlertManeuverRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +typedef SharedPtr CommandPtr; + +class AlertManeuverRequestTest + : public CommandRequestTest { + public: + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = hmi_response; + (*response)[am::strings::msg_params][am::strings::info] = "test"; + + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*response); + + utils::SharedPtr command = + CreateCommand(response); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->on_event(event); + + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + success); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(mobile_response)); + } +}; + +TEST_F(AlertManeuverRequestTest, Run_RequiredFieldsDoesNotExist_UNSUCCESS) { + CommandPtr command(CreateCommand()); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + 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(AlertManeuverRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::tts_chunks] = 0; + + CommandPtr command(CreateCommand(msg)); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + + 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(AlertManeuverRequestTest, Run_ProcessingResult_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; + + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + const mobile_apis::Result::eType kProcessingResult = + mobile_apis::Result::ABORTED; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) + .WillOnce(Return(kProcessingResult)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(kProcessingResult, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, Run_IsWhiteSpaceExist_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::tts_chunks] = + SmartObject(smart_objects::SmartType_Array); + + SmartObject tts_chunk(smart_objects::SmartType_Map); + tts_chunk[am::strings::text] = "wrong chunk syntax\t\n"; + + (*msg)[am::strings::msg_params][am::strings::tts_chunks].asArray()->push_back( + tts_chunk); + + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + 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(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; + + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS)); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); + EXPECT_EQ(hmi_apis::FunctionID::Navigation_AlertManeuver, + static_cast( + (*result_msg)[am::strings::params][am::strings::function_id] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { + CommandPtr command(CreateCommand()); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event))); + EXPECT_EQ(mobile_apis::Result::INVALID_ENUM, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_SUCCESS) { + CheckExpectations(hmi_apis::Common_Result::SUCCESS, + mobile_apis::Result::SUCCESS, + am::HmiInterfaces::STATE_AVAILABLE, + true); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + false); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_WARNINGS) { + CheckExpectations(hmi_apis::Common_Result::WARNINGS, + mobile_apis::Result::WARNINGS, + am::HmiInterfaces::STATE_NOT_RESPONSE, + true); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_GENERIC_ERROR) { + CheckExpectations(hmi_apis::Common_Result::GENERIC_ERROR, + mobile_apis::Result::GENERIC_ERROR, + am::HmiInterfaces::STATE_NOT_RESPONSE, + false); +} + +} // namespace alert_maneuver_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/alert_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc new file mode 100644 index 0000000000..440c42ca8b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc @@ -0,0 +1,810 @@ +/* + * Copyright (c) 2016, 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 "mobile/alert_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace alert_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::AlertRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::utils::SharedPtr; +using am::event_engine::Event; +using policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef SharedPtr CommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kDefaultTimeout = 1000u; +const uint32_t kCorrelationId = 2u; +const mobile_apis::FunctionID::eType kFunctionId = + mobile_apis::FunctionID::AlertID; +} // namespace + +class AlertRequestTest : public CommandRequestTest { + public: + AlertRequestTest() : mock_app_(CreateMockApp()), msg_(CreateMessage()) {} + + protected: + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault( + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault( + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); + } + + void Expectations() { + (*msg_)[am::strings::params][am::strings::function_id] = kFunctionId; + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL( + *mock_app_, + AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); + } + + void AddAlertTextsToMsg() { + (*msg_)[am::strings::msg_params][am::strings::alert_text1] = "alert_text1"; + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = "alert_text2"; + (*msg_)[am::strings::msg_params][am::strings::alert_text3] = "alert_text3"; + } + void AddTTSChunkToMsg() { + (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "tts_chunk_text"; + } + + void ExpectCallHmiLevel(const mobile_apis::HMILevel::eType level) { + EXPECT_CALL(*mock_app_, hmi_level()).WillRepeatedly(Return(level)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + void ExpectManageHmiCommandTTSAndUI() { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Alert))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + } + sync_primitives::Lock lock_; + + MockAppPtr mock_app_; + MessageSharedPtr msg_; +}; + +TEST_F(AlertRequestTest, OnTimeout_GENERIC_ERROR) { + PreConditions(); + MessageSharedPtr command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*command_msg)[am::strings::msg_params][am::strings::success] = false; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + utils::SharedPtr command = CreateCommand(); + + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(command_msg)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->onTimeOut(); + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(AlertRequestTest, OnEvent_UI_HmiSendSuccess_UNSUPPORTED_RESOURCE) { + PreConditions(); + MessageSharedPtr command_msg = CreateFullParamsUISO(); + (*command_msg)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = 10u; + (*command_msg)[am::strings::msg_params][am::strings::menu_params] + [am::strings::menu_name] = "menu_name"; + + utils::SharedPtr command = + CreateCommand(command_msg); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + MessageSharedPtr msg_tts = CreateMessage(); + (*msg_tts)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::TTS_Speak); + event_vr.set_smart_object(*msg_tts); + + command->on_event(event_vr); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +class CallOnTimeOut { + public: + CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} + + void operator()() { + command_.onTimeOut(); + } + + CommandRequestImpl& command_; +}; + +TEST_F(AlertRequestTest, Init_DurationExists_SUCCESS) { + Expectations(); + (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + CommandPtr command(CreateCommand(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(AlertRequestTest, Init_DurationNotExists_SUCCESS) { + Expectations(); + CommandPtr command(CreateCommand(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(AlertRequestTest, OnTimeOut_SUCCESS) { + Expectations(); + MessageSharedPtr result_msg(CreateMessage(smart_objects::SmartType_Null)); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(result_msg)); + + CommandPtr command(CreateCommand()); + MessageSharedPtr received_result_msg( + CatchMobileCommandResult(CallOnTimeOut(*command))); + EXPECT_EQ(result_msg, received_result_msg); +} + +TEST_F(AlertRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + Expectations(); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + + CommandPtr command(CreateCommand(msg_)); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_AlertFrequencyIsTooHigh_UNSUCCESS) { + Expectations(); + EXPECT_CALL( + *mock_app_, + AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand(msg_)); + 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(AlertRequestTest, Run_FailToProcessSoftButtons_UNSUCCESS) { + Expectations(); + const mobile_apis::Result::eType result_code = + mobile_apis::Result::INVALID_ENUM; + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(result_code)); + + CommandPtr command(CreateCommand(msg_)); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(result_code, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertRequestTest, Run_MandatoryParametersAreMissed_UNSUCCESS) { + Expectations(); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_MandatoryParametersAreInvalid_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = + "invalid\t\nParam"; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + (*msg_)[am::strings::msg_params][am::strings::progress_indicator] = + "progress_indicator"; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageHmiCommandTTSAndUI(); + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + Expectations(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand(msg_)); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_UI_OnResetTimeout_SUCCESS) { + PreConditions(); + Expectations(); + AddAlertTextsToMsg(); + + (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; + + CommandPtr command(CreateCommand(msg_)); + EXPECT_TRUE(command->Init()); + + EXPECT_CALL( + app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_ENUM); + + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_UIAlertHasHmiResponsesToWait_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + CommandPtr command(CreateCommand(msg_)); + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageHmiCommandTTSAndUI(); + + command->Run(); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg_); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))); + + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarnings_SUCCESS) { + PreConditions(); + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSUnsupportedResource_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + PreConditions(); + + command->on_event(event); +} + +TEST_F(AlertRequestTest, + DISABLED_OnEvent_TTSUnsupportedResourceUiAlertSent_SUCCESS) { + PreConditions(); + + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_TTSUnsupportedResourceUiAlertSuccess_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_TTSSuccesUiAlertInvalidEnum_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_,, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::INVALID_ENUM; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSAbortedUiAlertNotSent_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::INVALID_ENUM; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarningUiAlertWarning_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, Run_InvalidAlert2_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = + "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_InvalidAlert3_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text3] = + "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_InvalidTTSChunk_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +} // namespace alert_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/change_registration_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc new file mode 100644 index 0000000000..7c17c999db --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc @@ -0,0 +1,559 @@ +/* + * Copyright (c) 2016, 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 "mobile/change_registration_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/helpers.h" +#include "utils/make_shared.h" +#include "utils/custom_string.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "policy/policy_regular/policy/usage_statistics/mock_statistics_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace change_registration_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::utils::SharedPtr; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SetArgPointee; +using sdl_rpc_plugin::commands::ChangeRegistrationRequest; +using policy_test::MockPolicyHandlerInterface; +using ::test::components::application_manager_test::MockApplication; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class ChangeRegistrationRequestTest + : public CommandRequestTest { + public: + ChangeRegistrationRequestTest() + : mock_app_(CreateMockApp()) + , supported_languages_(CreateMessage(smart_objects::SmartType_Array)) {} + + MessageSharedPtr CreateMsgFromMobile() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::hmi_display_language] = mobile_apis::Language::EN_US; + msg_params[strings::language] = mobile_apis::Language::EN_US; + (*msg)[strings::msg_params] = msg_params; + return msg; + } + void PrepareExpectationBeforeRun() { + (*supported_languages_)[0] = + static_cast(mobile_apis::Language::EN_US); + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success, + const hmi_apis::Common_Result::eType ui_hmi_response = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + const hmi_apis::Common_Result::eType vr_hmi_response = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor accessor(application_set, app_set_lock_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + PrepareExpectationBeforeRun(); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI(ui_response, ui_hmi_response, "ui_info"); + CreateResponseFromHMI(vr_response, vr_hmi_response, "unsupported_resource"); + + (*tts_response)[strings::params][hmi_response::code] = hmi_response; + (*tts_response)[strings::msg_params] = 0; + + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr( + hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_ui); + command->on_event(event_vr); + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + success); + EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] + .asInt(), + static_cast(mobile_response)); + } + + void CreateResponseFromHMI(MessageSharedPtr msg, + hmi_apis::Common_Result::eType result, + const std::string& info) { + (*msg)[strings::params][hmi_response::code] = static_cast(result); + (*msg)[strings::msg_params][strings::info] = info; + } + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ExpectationsHmiCapabilities( + smart_objects::SmartObjectSPtr supported_languages) { + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages.get())); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + typedef TypeIf, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + sync_primitives::Lock app_set_lock_; + MockAppPtr mock_app_; + MessageSharedPtr supported_languages_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +typedef ChangeRegistrationRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor accessor(application_set, app_set_lock_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + smart_objects::SmartObjectSPtr supported_languages( + CreateMessage(smart_objects::SmartType_Array)); + (*supported_languages)[0] = + static_cast(mobile_apis::Language::EN_US); + + ExpectationsHmiCapabilities(supported_languages); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI( + ui_response, hmi_apis::Common_Result::WARNINGS, "ui_info"); + CreateResponseFromHMI(vr_response, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*tts_response)[am::strings::msg_params][am::strings::app_id] = + kConnectionKey; + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_ui); + command->on_event(event_tts); + command->on_event(event_vr); + + ResultCommandExpectations(response_to_mobile, + "ui_info, VR is not supported by system, tts_info"); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + DataAccessor accessor(application_set, app_set_lock_); + application_set.insert(app); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + (*supported_languages_)[0] = + static_cast(mobile_apis::Language::EN_US); + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->Run(); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast(mobile_apis::Result::UNSUPPORTED_RESOURCE)); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_RESPONSE, + false); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + false); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_SUCCESS_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_SUCCESS_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::SUCCESS, + mobile_apis::Result::SUCCESS, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_WRONG_LANGUAGE_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::WRONG_LANGUAGE, + mobile_apis::Result::WRONG_LANGUAGE, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_INVALID_DATA_STATE_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::INVALID_DATA, + mobile_apis::Result::INVALID_DATA, + am::HmiInterfaces::STATE_AVAILABLE, + false, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor accessor(application_set, app_set_lock_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + smart_objects::SmartObjectSPtr supported_languages( + CreateMessage(smart_objects::SmartType_Array)); + (*supported_languages)[0] = + static_cast(mobile_apis::Language::EN_US); + + ExpectationsHmiCapabilities(supported_languages); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI(ui_response, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "unsupported_resource"); + CreateResponseFromHMI( + vr_response, hmi_apis::Common_Result::WARNINGS, "vr_info"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*tts_response)[am::strings::msg_params][am::strings::app_id] = + kConnectionKey; + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_tts); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "unsupported_resource, vr_info, tts_info"); +} + +} // namespace change_registration_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc new file mode 100644 index 0000000000..b1851d5c76 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -0,0 +1,831 @@ +/* + * Copyright (c) 2016, 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 "mobile/create_interaction_choice_set_request.h" +#include "mobile/create_interaction_choice_set_response.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/helpers.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace create_interaction_choice_set_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::utils::SharedPtr; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::AtLeast; +using sdl_rpc_plugin::commands::CreateInteractionChoiceSetRequest; +using sdl_rpc_plugin::commands::CreateInteractionChoiceSetResponse; +using ::test::components::application_manager_test::MockApplication; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef SharedPtr + CreateInteractionChoiceSetRequestPtr; +typedef SharedPtr + CreateInteractionChoiceSetResponsePtr; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::FunctionID::eType kInvalidFunctionId = + hmi_apis::FunctionID::INVALID_ENUM; +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +const uint32_t kGrammarId = 10u; +const int32_t kMenuId = 5; +const uint32_t kChoiceSetId = 1u; +const uint32_t kChoiceId1 = 2u; +const uint32_t kChoiceId2 = 3u; +const std::string kImage = "image"; +const std::string kSecondImage = "second_image"; +const std::string kVrCommands1 = "vr_commands_1"; +const std::string kVrCommands2 = "vr_commands_2"; +const std::string kMenuName = "menu_name"; + +} // namespace + +class CreateInteractionChoiceSetRequestTest + : public CommandRequestTest { + public: + CreateInteractionChoiceSetRequestTest() + : message_(CreateMessage()) + , command_(CreateCommand(message_)) + , mock_app_(CreateMockApp()) {} + + MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::cmd_id] = kCmdId; + msg_params[strings::vr_commands] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params[strings::vr_commands][0] = "lamer"; + msg_params[strings::type] = 34; + msg_params[strings::grammar_id] = 12; + msg_params[strings::app_id] = kAppId; + (*msg)[strings::msg_params] = msg_params; + + return msg; + } + + void FillMessageFieldsItem1(MessageSharedPtr message) { + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + } + void FillMessageFieldsItem2(MessageSharedPtr message) { + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands2; + (*message)[am::strings::msg_params] + [am::strings::interaction_choice_set_id] = kChoiceSetId; + } + + MessageSharedPtr message_; + CreateInteractionChoiceSetRequestPtr command_; + MockAppPtr mock_app_; + sync_primitives::Lock lock_; +}; + +class CreateInteractionChoiceSetResponseTest + : public CommandsTest {}; + +TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeout_GENERIC_ERROR) { + MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); + (*msg_vr)[strings::msg_params][strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*msg_vr)[strings::msg_params][strings::success] = false; + + utils::SharedPtr req_vr = + CreateCommand(); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, RemoveCommand(_)).WillByDefault(Return()); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + req_vr->onTimeOut(); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsVRSO(); + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = + 10; + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = + "menu_name"; + (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; + utils::SharedPtr req_vr = + CreateCommand(msg_vr); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + smart_objects::SmartObject* null_obj = NULL; + ON_CALL(*mock_app_, FindChoiceSet(_)).WillByDefault(Return(null_obj)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[strings::msg_params][strings::info] = "VR is not supported by system"; + (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; + + am::event_engine::Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg); + + smart_objects::SmartObject* ptr = NULL; + ON_CALL(*mock_app_, FindCommand(kCmdId)).WillByDefault(Return(ptr)); + EXPECT_EQ(NULL, ptr); + + am::CommandsMap commands_map; + ON_CALL(*mock_app_, commands_map()) + .WillByDefault( + Return(DataAccessor(commands_map, lock_))); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault( + Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + req_vr->Run(); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + req_vr->on_event(event); + + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::info].asString(), + (*msg)[strings::msg_params][strings::info].asString()); + } +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_VerifyImageFail_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image] = kSecondImage; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::INVALID_DATA)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* invalid_choice_set_id = + &((*message_)[am::strings::msg_params] + [am::strings::interaction_choice_set_id]); + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(invalid_choice_set_id)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_CheckChoiceSet_InvalidChoiceId_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + + FillMessageFieldsItem2(message_); + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][1] = " kVrCommands2\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands1; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_IsWhiteSpaceVRCommandsExist_InvalidMenuName_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = "menu_name\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_text] = "secondary_text\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::tertiary_text] = "tertiary_text\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = "image\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = + "second_image\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = "vr_commands_1\t"; + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillRepeatedly(Return(choice_set_id)); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::menu_name)) { + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::secondary_text)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::tertiary_text)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_text] = "secondary_text"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::vr_commands)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::tertiary_text] = "tertiary_text"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::image)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = "vr_commands"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::secondary_image)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_ValidAmountVrCommands_SUCCESS) { + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .Times(AtLeast(2)) + .WillOnce(Return(kConnectionKey)) + .WillOnce(Return(kConnectionKey)); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_EmptyAmountVrCommands_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands2; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InvalidEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InvalidVrCommand_UNSUCCESS) { + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + event.set_smart_object(*message_); + + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InValidVrNoError_UNSUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_DATA; + + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + event.set_smart_object(*message_); + + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_ValidVrNoErrorAndExpectedChoiceLessThanReceiveChoice_SUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + + FillMessageFieldsItem1(message_); + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + event.set_smart_object(*message_); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_InvalidErrorFromHMI_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), + am::commands::Command::SOURCE_SDL)); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_ValidErrorFromHMI_SUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_ENUM; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + command_->on_event(event); + + EXPECT_CALL(*mock_app_, RemoveChoiceSet(kChoiceSetId)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_ENUM; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(2); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + command_->on_event(event); + + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)).Times(0); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_SuccessfulResponseReceived_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + + command_->Run(); + + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + + command_->on_event(event); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)); + + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::success] = false; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::INVALID_ENUM; + CreateInteractionChoiceSetResponsePtr command( + CreateCommand(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, false)); + command->Run(); +} + +TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessTrue_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::success] = true; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + CreateInteractionChoiceSetResponsePtr command( + CreateCommand(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, false)); + command->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + FillMessageFieldsItem1(message_); + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillRepeatedly(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()) + .WillRepeatedly(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(2); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), + am::commands::Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + event.set_smart_object(*message_); + command_->on_event(event); + command_->Run(); +} + +} // namespace create_interaction_choice_set_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc new file mode 100644 index 0000000000..c70c384776 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc @@ -0,0 +1,257 @@ +/* + * Copyright (c) 2016, 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 "mobile/delete_command_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/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_command_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::DeleteCommandRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; +using am::MockHmiInterfaces; + +typedef SharedPtr DeleteCommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class DeleteCommandRequestTest + : public CommandRequestTest { + public: + DeleteCommandRequestTest() : mock_app_(CreateMockApp()) {} + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::vr_commands] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params[am::strings::vr_commands][0] = "lamer"; + msg_params[am::strings::type] = 34; + msg_params[am::strings::grammar_id] = 12; + msg_params[am::strings::app_id] = kAppId; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(hmi_interfaces_)); + + } + + NiceMock hmi_interfaces_; + MockAppPtr mock_app_; +}; + +TEST_F(DeleteCommandRequestTest, + OnEvent_VrHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr command_msg = CreateFullParamsVRSO(); + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DeleteCommandPtr command(CreateCommand(command_msg)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); + (*test_msg)[am::strings::vr_commands] = 0; + (*test_msg)[am::strings::menu_params] = 0; + + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(*mock_app_, FindCommand(kCommandId)) + .WillByDefault(Return(test_msg.get())); + ON_CALL(*mock_app_, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); + event_ui.set_smart_object(*msg); + command->Init(); + command->Run(); + command->on_event(event_ui); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::msg_params][am::strings::info] = + "VR is not supported by system"; + Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); + event_vr.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, RemoveCommand(kCommandId)); + + EXPECT_CALL(*mock_app_, UpdateHash()); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + command->on_event(event_vr); + + ResultCommandExpectations(vr_command_result, "VR is not supported by system"); +} + +TEST_F(DeleteCommandRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr command_msg = CreateFullParamsUISO(); + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DeleteCommandPtr command(CreateCommand(command_msg)); + + MockAppPtr app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); + (*test_msg)[am::strings::vr_commands] = 0; + (*test_msg)[am::strings::menu_params] = 0; + + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(*app, FindCommand(kCommandId)).WillByDefault(Return(test_msg.get())); + ON_CALL(*app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); + event_vr.set_smart_object(*msg); + + command->Init(); + command->Run(); + command->on_event(event_vr); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); + event_ui.set_smart_object(*event_msg); + + EXPECT_CALL(*app, RemoveCommand(kCommandId)); + + EXPECT_CALL(*app, UpdateHash()); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event_ui))); + + ASSERT_TRUE(result_msg); + + ResultCommandExpectations(result_msg, "UI is not supported by system"); +} + +} // namespace delete_command_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/delete_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc new file mode 100644 index 0000000000..5dcf911501 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2016, 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 + +#include "mobile/delete_file_request.h" +#include "mobile/delete_file_response.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/file_system.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/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_application_manager_settings.h" + +#include "interfaces/MOBILE_API.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/policies/policy_handler.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_file { + +using ::testing::_; +using ::testing::Test; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SetArgReferee; +using ::testing::AtLeast; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::DeleteFileRequest; +using sdl_rpc_plugin::commands::DeleteFileResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef SharedPtr DeleteFileRequestPtr; +typedef SharedPtr DeleteFileResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +ACTION_TEMPLATE(SetArgPointer, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_1_VALUE_PARAMS(vec)) { + *std::tr1::get(args) = *vec; +} + +MATCHER_P(CheckMessageResultCode, result_code, "") { + return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + result_code; +} + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kCorrelationId = 10u; +const int32_t kMenuId = 5; +} // namespace + +class DeleteFileRequestTest + : public CommandRequestTest { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand(message_); + mock_app_ = CreateMockApp(); + } + DeleteFileRequestPtr command_; + MessageSharedPtr message_; + MockAppPtr mock_app_; +}; + +class DeleteFileResponseTest : public CommandsTest { +}; + +TEST_F(DeleteFileRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, get_settings()).Times(0); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const uint32_t num = 0; + EXPECT_CALL(app_mngr_settings_, delete_file_in_none()) + .WillOnce(ReturnRef(num)); + EXPECT_CALL(*mock_app_, delete_file_in_none_count()).WillOnce(Return(1)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::REJECTED), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) { + const std::string file_name = "test_file.txt"; + EXPECT_TRUE(file_system::CreateFile(file_name)); + (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kFullFilePath)); + + am::AppFile file; + file.file_name = file_name; + file.file_type = mobile_apis::FileType::BINARY; + + EXPECT_CALL(*mock_app_, GetFile(_)).WillOnce(Return(&file)); + EXPECT_CALL(*mock_app_, DeleteFile(_)); + EXPECT_CALL(*mock_app_, increment_delete_file_in_none_count()); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::SUCCESS), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_InvalidFile_UNSUCCESS) { + const std::string file_name = "test_file.txt"; + (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kFullFilePath)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::REJECTED), + am::commands::Command::CommandSource::SOURCE_SDL)); + command_->Run(); +} + +TEST_F(DeleteFileResponseTest, Run_InvalidApp_UNSUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + DeleteFileResponsePtr command = CreateCommand(message); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(CheckMessageResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED), + false)); + + command->Run(); +} + +TEST_F(DeleteFileResponseTest, Run_ValidApp_SUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*message)[am::strings::msg_params][am::strings::success] = true; + + DeleteFileResponsePtr command = CreateCommand(message); + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + const uint32_t kAvailableDiskSpace = 10u; + EXPECT_CALL(*app, GetAvailableDiskSpace()) + .WillOnce(Return(kAvailableDiskSpace)); + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile( + CheckMessageResultCode(mobile_apis::Result::SUCCESS), _)); + + command->Run(); +} + +} // namespace delete_file +} // 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/delete_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc new file mode 100644 index 0000000000..f639bb96e8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2016, 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 "mobile/delete_interaction_choice_set_request.h" +#include "mobile/delete_interaction_choice_set_response.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/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_interaction_choice_set { + +using ::testing::_; +using ::testing::Return; +using ::testing::InSequence; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetRequest; +using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +typedef SharedPtr + DeleteInteractionChoiceSetRequestPtr; +typedef SharedPtr + DeleteInteractionChoiceSetResponsePtr; + +MATCHER_P(CheckMessageSuccess, success, "") { + return success == + (*arg)[am::strings::msg_params][am::strings::success].asBool(); +} + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kChoiceSetId = 11u; +const uint32_t kChoiceId = 110u; +const uint32_t kGrammarId = 101u; +} // namespace + +class DeleteInteractionChoiceSetRequestTest + : public CommandRequestTest { + public: + DeleteInteractionChoiceSetRequestTest() + : accessor_(choice_set_map_, performinteraction_choice_set_lock_) {} + + ~DeleteInteractionChoiceSetRequestTest() { + // Fix DataAccessor release and WinQt crash + Mock::VerifyAndClearExpectations(&app_mngr_); + } + + am::PerformChoiceSetMap choice_set_map_; + mutable sync_primitives::Lock performinteraction_choice_set_lock_; + DataAccessor accessor_; + + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand(message_); + app_ = CreateMockApp(); + } + + DeleteInteractionChoiceSetRequestPtr command_; + MessageSharedPtr message_; + MockAppPtr app_; +}; + +class DeleteInteractionChoiceSetResponseTest + : public CommandsTest { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand(message_); + app_ = CreateMockApp(); + } + DeleteInteractionChoiceSetResponsePtr command_; + MessageSharedPtr message_; + MockAppPtr app_; +}; + +TEST_F(DeleteInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_, FindChoiceSet(_)).Times(0); + command_->Run(); +} + +TEST_F(DeleteInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteInteractionChoiceSetRequestTest, Run_ChoiceSetInUse_SUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + + smart_objects::SmartObject* choice_set_id = + &((*message_)[am::strings::msg_params] + [am::strings::interaction_choice_set_id]); + + choice_set_map_[0].insert( + std::make_pair(kChoiceSetId, + &((*message_)[am::strings::msg_params] + [am::strings::interaction_choice_set_id]))); + + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(true)); + EXPECT_CALL(*app_, performinteraction_choice_set_map()) + .WillOnce(Return(accessor_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteInteractionChoiceSetRequestTest, + Run_SendVrDeleteCommand_PerformInteractionFalse_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + smart_objects::SmartObject* choice_set_id = + &((*message_)[am::strings::msg_params] + [am::strings::interaction_choice_set_id]); + smart_objects::SmartObject* invalid_choice_set_id = NULL; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(app_)); + + { + InSequence seq; + + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); + EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); + + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(invalid_choice_set_id)); + + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); + EXPECT_CALL(*app_, UpdateHash()); + } + + + DeleteInteractionChoiceSetRequestPtr command = + CreateCommand(message_); + + command->Init(); + command->Run(); +} + +TEST_F(DeleteInteractionChoiceSetRequestTest, Run_SendVrDeleteCommand_SUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + (*message_)[am::strings::msg_params][am::strings::grammar_id] = kGrammarId; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId; + smart_objects::SmartObject* choice_set_id = + &((*message_)[am::strings::msg_params]); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(app_)); + + { + InSequence seq; + + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); + EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); + + EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(*app_, app_id()) + .WillOnce(Return(kConnectionKey)) + .WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); + EXPECT_CALL(*app_, UpdateHash()); + } + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + DeleteInteractionChoiceSetRequestPtr command = + CreateCommand(message_); + + command->Init(); + command->Run(); +} + +TEST_F(DeleteInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::success] = false; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageSuccess(false), false)); + command_->Run(); +} + +TEST_F(DeleteInteractionChoiceSetResponseTest, Run_ValidResultCode_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::result_code] = + hmi_apis::Common_Result::SUCCESS; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageSuccess(true), false)); + command_->Run(); +} + +TEST_F(DeleteInteractionChoiceSetResponseTest, + Run_InvalidResultCode_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::result_code] = + hmi_apis::Common_Result::INVALID_ENUM; + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckMessageSuccess(false), false)); + command_->Run(); +} + +} // namespace delete_interaction_choice_set +} // 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/delete_sub_menu_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc new file mode 100644 index 0000000000..44668e18b2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc @@ -0,0 +1,365 @@ +/* + * Copyright (c) 2016, 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 "mobile/delete_sub_menu_request.h" +#include "mobile/delete_sub_menu_response.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_sub_menu_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::InSequence; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockHmiInterfaces; +using am::MockMessageHelper; + +using sdl_rpc_plugin::commands::DeleteSubMenuRequest; +using sdl_rpc_plugin::commands::DeleteSubMenuResponse; + +typedef SharedPtr DeleteSubMenuRequestPtr; +typedef SharedPtr DeleteSubMenuResponsePtr; + +MATCHER_P(CheckMessageResultCode, result_code, "") { + return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + result_code; +} + +MATCHER_P(CheckMessageConnectionKey, connection_key, "") { + return (*arg)[am::strings::msg_params][am::strings::connection_key].asInt() == + connection_key; +} + +ACTION_P(DeleteCommand, commands_map) { + am::CommandsMap::iterator it = (*commands_map).begin(); + if ((*commands_map).end() != it) { + (*commands_map).erase(it); + } +} + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +const uint32_t kMenuId = 100u; +const uint32_t kGrammarId = 101u; +const int32_t kCmdId = 102; +} // namespace + +class DeleteSubMenuRequestTest + : public CommandRequestTest { + public: + DeleteSubMenuRequestTest() + : accessor_(commands_map_, commands_lock_) + , message_(CreateMessage()) + , command_(CreateCommand(message_)) + , app_(CreateMockApp()) {} + + am::CommandsMap commands_map_; + mutable sync_primitives::Lock commands_lock_; + DataAccessor accessor_; + + MessageSharedPtr message_; + DeleteSubMenuRequestPtr command_; + MockAppPtr app_; +}; + +class DeleteSubMenuResponseTest + : public CommandsTest {}; + +TEST_F(DeleteSubMenuRequestTest, DISABLED_OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::menu_id] = 10u; + + utils::SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + EXPECT_CALL(*mock_app, RemoveSubMenu(_)); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + event.set_smart_object(*ev_msg); + + MockHmiInterfaces hmi_interfaces; + ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); + EXPECT_CALL(hmi_interfaces, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + am::CommandsMap commands_map; + smart_objects::SmartObject commands_msg(smart_objects::SmartType_Map); + commands_map.insert(std::pair(1u, &commands_msg)); + sync_primitives::Lock lock; + DataAccessor accessor(commands_map, lock); + EXPECT_CALL(*mock_app, commands_map()) + .WillOnce(Return(accessor)) + .WillOnce(Return(accessor)); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(DeleteSubMenuRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED), + am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_, FindSubMenu(_)).Times(0); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, Run_FindSubMenuFalse_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject* invalid_sub_menu = NULL; + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(invalid_sub_menu)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageResultCode(mobile_apis::Result::INVALID_ID), + am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_, app_id()).Times(0); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, Run_SendHMIRequest_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject* sub_menu = + &((*message_)[am::strings::msg_params][am::strings::menu_id]); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(sub_menu)); + + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteSubMenu))) + .WillOnce(Return(true)); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_UnknownEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_InvalidApp_UNSUCCESS) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + event.set_smart_object(*message_); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(*app_, RemoveSubMenu(_)).Times(0); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenu_SUCCESS) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::vr_commands] = + "vr_commands"; + (*message_)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + (*message_)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = kMenuId; + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*message_)[am::strings::params][am::hmi_response::code] = result_code; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + + InSequence seq; + EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, get_grammar_id()).WillOnce(Return(kGrammarId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveCommand(_)).WillOnce(DeleteCommand(&commands_map_)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*app_, RemoveSubMenu(_)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + EXPECT_CALL(*app_, UpdateHash()); + DeleteSubMenuRequestPtr command = + CreateCommand(message_); + + command->Init(); + command->on_event(event); +} + +TEST_F(DeleteSubMenuResponseTest, Run_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::connection_key] = + kConnectionKey; + DeleteSubMenuResponsePtr command( + CreateCommand(message)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(CheckMessageConnectionKey(kConnectionKey), _)); + command->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, + DeleteSubmenu_CommandhaventVrCommadsAndMenuParams_DontSendHMIRequest) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + am::mobile_api::Result::SUCCESS; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); + EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, + DeleteSubmenu_NotAChildOfMenupartam_DontSendHMIRequest) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = kMenuId + 1; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + am::mobile_api::Result::SUCCESS; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); + EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + command_->on_event(event); +} + +} // namespace delete_sub_menu_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/diagnostic_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc new file mode 100644 index 0000000000..54441a88a7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/diagnostic_message_request_test.cc @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2016, 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 "application_manager/mock_message_helper.h" +#include "mobile/diagnostic_message_request.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace diagnostic_message_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::DiagnosticMessageRequest; +using am::event_engine::Event; +namespace mobile_result = mobile_apis::Result; + +typedef SharedPtr DiagnosticMessageRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kDiagnosticMode = 5u; +} // namespace + +class DiagnosticMessageRequestTest + : public CommandRequestTest {}; + +TEST_F(DiagnosticMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DiagnosticMessageRequestPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(DiagnosticMessageRequestTest, Run_NotSupportedDiagnosticMode_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::message_data][0] = + kDiagnosticMode; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DiagnosticMessageRequestPtr command( + CreateCommand(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + + const std::vector empty_supported_diag_modes; + EXPECT_CALL(app_mngr_settings_, supported_diag_modes()) + .WillOnce(ReturnRef(empty_supported_diag_modes)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::REJECTED), _)); + + command->Run(); +} + +TEST_F(DiagnosticMessageRequestTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::message_data][0] = + kDiagnosticMode; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DiagnosticMessageRequestPtr command( + CreateCommand(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + + std::vector supported_diag_modes; + supported_diag_modes.push_back(kDiagnosticMode); + + EXPECT_CALL(app_mngr_settings_, supported_diag_modes()) + .WillOnce(ReturnRef(supported_diag_modes)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage))); + + command->Run(); +} + +TEST_F(DiagnosticMessageRequestTest, OnEvent_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + DiagnosticMessageRequestPtr command( + CreateCommand()); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->on_event(event); +} + +TEST_F(DiagnosticMessageRequestTest, OnEvent_SUCCESS) { + Event event(hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage); + + MessageSharedPtr event_message(CreateMessage(smart_objects::SmartType_Map)); + (*event_message)[am::strings::msg_params] = 0; + (*event_message)[am::strings::params][am::hmi_response::code] = + mobile_result::SUCCESS; + event.set_smart_object(*event_message); + + DiagnosticMessageRequestPtr command( + CreateCommand()); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command->on_event(event); +} + +} // namespace diagnostic_message_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/dial_number_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc new file mode 100644 index 0000000000..00f7fdd81e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2016, 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/dial_number_request.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace dial_number_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::DialNumberRequest; +using am::event_engine::Event; +namespace mobile_result = mobile_apis::Result; + +typedef SharedPtr DialNumberRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class DialNumberRequestTest + : public CommandRequestTest {}; + +TEST_F(DialNumberRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + DialNumberRequestPtr 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(DialNumberRequestTest, Run_InvalidNumber_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "\t\n"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand(command_msg)); + + 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(DialNumberRequestTest, Run_EmptyNumber_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "NotANumber"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand(command_msg)); + + 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(DialNumberRequestTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr 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::BasicCommunication_DialNumber))); + + command->Run(); +} + +TEST_F(DialNumberRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + // MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + // (*command_msg)[am::strings::params][am::strings::connection_key] = + // kConnectionKey; + + // DialNumberRequestPtr + // command(CreateCommand(command_msg)); + + // MockAppPtr app(CreateMockApp()); + // EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + // Event event(hmi_apis::FunctionID::INVALID_ENUM); + // EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + // command->on_event(event); +} + +TEST_F(DialNumberRequestTest, OnEvent_SUCCESS) { + // MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + // (*event_msg)[am::strings::params][am::hmi_response::code] = + // mobile_apis::Result::SUCCESS; + // (*event_msg)[am::strings::params][am::strings::info] = "test_info"; + + // Event event(hmi_apis::FunctionID::BasicCommunication_DialNumber); + // event.set_smart_object(*event_msg); + + // MockAppPtr app(CreateMockApp()); + // EXPECT_CALL(app_mngr_, application(kConnectionKey)) + // .WillRepeatedly(Return(app)); + // ON_CALL(app_mngr_, + // GetRPCService()).WillByDefault(ReturnRef(mock_rpc_service_)); + // EXPECT_CALL( + // mock_rpc_service_, + // ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + // _)); + + // MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + // (*command_msg)[am::strings::params][am::strings::connection_key] = + // kConnectionKey; + + // DialNumberRequestPtr + // command(CreateCommand(command_msg)); + // command->on_event(event); +} + +} // namespace dial_number_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/dummy_mobile_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc new file mode 100644 index 0000000000..8a51c4b35b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/command_request_test.h" + +#include +#include +#include +#include "gtest/gtest.h" + +#include "mobile/add_command_request.h" +#include "mobile/add_command_response.h" +#include "mobile/add_sub_menu_request.h" +#include "mobile/add_sub_menu_response.h" +#include "mobile/alert_maneuver_request.h" +#include "mobile/alert_maneuver_response.h" +#include "mobile/alert_request.h" +#include "mobile/alert_response.h" +#include "mobile/change_registration_request.h" +#include "mobile/change_registration_response.h" +#include "mobile/create_interaction_choice_set_request.h" +#include "mobile/create_interaction_choice_set_response.h" +#include "mobile/delete_command_request.h" +#include "mobile/delete_command_response.h" +#include "mobile/delete_file_request.h" +#include "mobile/delete_file_response.h" +#include "mobile/delete_interaction_choice_set_request.h" +#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" +#include "mobile/list_files_response.h" +#include "mobile/on_app_interface_unregistered_notification.h" +#include "mobile/on_audio_pass_thru_notification.h" +#include "mobile/on_button_event_notification.h" +#include "mobile/on_button_press_notification.h" +#include "mobile/on_command_notification.h" +#include "mobile/on_driver_distraction_notification.h" +#include "mobile/on_hash_change_notification.h" +#include "mobile/on_hmi_status_notification.h" +#include "mobile/on_hmi_status_notification_from_mobile.h" +#include "mobile/on_keyboard_input_notification.h" +#include "mobile/on_language_change_notification.h" +#include "mobile/on_permissions_change_notification.h" +#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" +#include "mobile/perform_interaction_request.h" +#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" +#include "mobile/reset_global_properties_response.h" +#include "mobile/scrollable_message_request.h" +#include "mobile/scrollable_message_response.h" +#include "mobile/send_location_request.h" +#include "mobile/send_location_response.h" +#include "mobile/set_app_icon_request.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/set_display_layout_request.h" +#include "mobile/set_display_layout_response.h" +#include "mobile/set_global_properties_request.h" +#include "mobile/set_global_properties_response.h" +#include "mobile/set_media_clock_timer_request.h" +#include "mobile/set_media_clock_timer_response.h" +#include "mobile/show_constant_tbt_request.h" +#include "mobile/show_constant_tbt_response.h" +#include "mobile/show_request.h" +#include "mobile/show_response.h" +#include "mobile/slider_request.h" +#include "mobile/slider_response.h" +#include "mobile/speak_request.h" +#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" +#include "mobile/unregister_app_interface_request.h" +#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" +#include "mobile/update_turn_list_response.h" + +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "test/application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace dummy_mobile_commands_test { + +namespace commands = sdl_rpc_plugin::commands; +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; +using am::commands::MessageSharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; + +namespace { +const std::string kEmptyString_ = ""; +} // namespace + +template +class MobileCommandsTest : public components::commands_test::CommandRequestTest< + CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; + + void InitCommand(const uint32_t& timeout) OVERRIDE { + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(kEmptyString_)); + } +}; + +template +class MobileCommandsTestFirst : public MobileCommandsTest { + public: + using typename MobileCommandsTest::CommandType; +}; + +template +class MobileCommandsTestSecond : public MobileCommandsTest { + public: + using typename MobileCommandsTest::CommandType; +}; + +template +class MobileCommandsTestThird : public MobileCommandsTest { + public: + using typename MobileCommandsTest::CommandType; +}; + +/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few + * TYPED_TEST_CASE for HMI and mobile commands + */ + +typedef Types + MobileCommandsListFirst; + +typedef Types MobileCommandsListSecond; + +typedef Types MobileCommandsListThird; + +TYPED_TEST_CASE(MobileCommandsTestFirst, MobileCommandsListFirst); +TYPED_TEST_CASE(MobileCommandsTestSecond, MobileCommandsListSecond); +TYPED_TEST_CASE(MobileCommandsTestThird, MobileCommandsListThird); + +TYPED_TEST(MobileCommandsTestFirst, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +TYPED_TEST(MobileCommandsTestSecond, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} +TYPED_TEST(MobileCommandsTestThird, CtorAndDtorCall) { + utils::SharedPtr command = + this->template CreateCommand(); + UNUSED(command); +} + +} // namespace dummy_mobile_commands_test +} // 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/end_audio_pass_thru_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc new file mode 100644 index 0000000000..31fe4a0793 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016, 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 "mobile/end_audio_pass_thru_request.h" + +#include "gtest/gtest.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/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace end_audio_pass_thru_request { + +namespace am = ::application_manager; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::EndAudioPassThruRequest; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef SharedPtr EndAudioPassThruRequestPtr; + +class EndAudioPassThruRequestTest + : public CommandRequestTest {}; + +TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { + const uint32_t kConnectionKey = 2u; + const uint32_t app_id = kConnectionKey; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EndAudioPassThruRequestPtr command( + CreateCommand(command_msg)); + + 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::UNSUPPORTED_RESOURCE; + + Event event(hmi_apis::FunctionID::UI_EndAudioPassThru); + event.set_smart_object(*event_msg); + + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace end_audio_pass_thru_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_dtcs_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc new file mode 100644 index 0000000000..28b576628d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_dtcs_request_test.cc @@ -0,0 +1,143 @@ +/* + * Copyright (c) 2016, 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 new file mode 100644 index 0000000000..60d1b3901a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_vehicle_data_request_test.cc @@ -0,0 +1,262 @@ +/* + * Copyright (c) 2016, 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/get_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc new file mode 100644 index 0000000000..c4c7eaa192 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "utils/shared_ptr.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 "mobile/get_way_points_request.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_message_helper.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace get_way_points_request { + +using namespace mobile_apis::Result; +using ::testing::Return; +using ::testing::_; +using sdl_rpc_plugin::commands::GetWayPointsRequest; +using application_manager::MockMessageHelper; +using application_manager::MockHmiInterfaces; + +typedef SharedPtr CommandPtr; +typedef mobile_apis::Result::eType MobileResult; +typedef hmi_apis::Common_Result::eType HmiResult; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 3u; +const uint32_t kConnectionKey = kAppId; +const std::string kMethodName = "Navigation.GetWayPoints"; +} + +class GetWayPointsRequestTest + : public CommandRequestTest { + public: + GetWayPointsRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + message_ = utils::MakeShared(::smart_objects::SmartType_Map); + (*message_)[am::strings::msg_params] = + ::smart_objects::SmartObject(::smart_objects::SmartType_Map); + + command_sptr_ = CreateCommand(message_); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + } + + MockAppPtr mock_app_; + MessageSharedPtr message_; + utils::SharedPtr command_sptr_; +}; + +class GetWayPointsRequestOnEventTest + : public CommandRequestTest { + public: + GetWayPointsRequestOnEventTest() : app_(CreateMockApp()) {} + + void CheckOnEventResponse(const std::string& wayPointsParam, + const HmiResult ResultCode, + const bool success) { + Event event(Event::EventID::Navigation_GetWayPoints); + CommandPtr command(CreateCommand()); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = ResultCode; + if ("0" == wayPointsParam) { + (*event_msg)[am::strings::msg_params] = 0; + } else { + (*event_msg)[am::strings::msg_params][am::strings::way_points][0]["123"] = + wayPointsParam; + } + + event.set_smart_object(*event_msg); + + const MobileResult mobile_result = static_cast(ResultCode); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event))); + EXPECT_EQ( + mobile_result, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); + EXPECT_EQ( + success, + (*result_msg)[am::strings::msg_params][am::strings::success].asBool()); + } + + protected: + MockAppPtr app_; + MockHmiInterfaces hmi_interfaces_; +}; + +TEST_F(GetWayPointsRequestTest, + Run_InvalidApp_ApplicationNotRegisteredResponce) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + utils::SharedPtr null_application_sptr; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(null_application_sptr)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, result); +} + +TEST_F(GetWayPointsRequestTest, Run_ApplicationRegistered_Success) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + MockAppPtr application_sptr = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + EXPECT_CALL(*application_sptr, app_id()).WillOnce(Return(1)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchHMICommandResult(caller); + + const hmi_apis::FunctionID::eType result_function_id = + static_cast( + (*result_message)[am::strings::params][am::strings::function_id] + .asInt()); + + EXPECT_EQ(hmi_apis::FunctionID::Navigation_GetWayPoints, result_function_id); + EXPECT_EQ(kCorrelationId, + (*result_message)[am::strings::params][am::strings::correlation_id] + .asUInt()); +} + +TEST_F(GetWayPointsRequestTest, + OnEvent_NavigationGetWayPointsEvent_SendResponse) { + am::event_engine::Event event(hmi_apis::FunctionID::Navigation_GetWayPoints); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + event.set_smart_object(*message_); + + CallOnEvent caller(*command_sptr_, event); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, result); +} + +TEST_F(GetWayPointsRequestTest, OnEvent_DefaultCase) { + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + + event.set_smart_object(*message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + CommandPtr command(CreateCommand()); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->on_event(event); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case1) { + CheckOnEventResponse("0", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case2) { + CheckOnEventResponse("", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case3) { + CheckOnEventResponse("test", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case1) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse(" ", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case2) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\t", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case3) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\n", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case4) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\t\n", HmiResult::GENERIC_ERROR, false); +} + +} // namespace get_way_points_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/list_files_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc new file mode 100644 index 0000000000..6cd5358b41 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2016, 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 "mobile/list_files_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace list_files_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::ListFilesRequest; +using am::commands::MessageSharedPtr; + +class ListFilesRequestTest + : public CommandRequestTest { + public: + ListFilesRequestTest() : kStoragePath_("storage"), kResponseSize_(1) {} + const std::string kStoragePath_; + const uint32_t kResponseSize_; +}; + +TEST_F(ListFilesRequestTest, 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(ListFilesRequestTest, Run_TooManyHmiNone_UNSUCCESS) { + MockAppPtr app(CreateMockApp()); + SharedPtr command(CreateCommand()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_NONE)); + + const uint32_t kListFilesInNoneAllowed = 1u; + const uint32_t kListFilesInNoneCount = 2u; + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, list_files_in_none()) + .WillByDefault(ReturnRef(kListFilesInNoneAllowed)); + ON_CALL(*app, list_files_in_none_count()) + .WillByDefault(Return(kListFilesInNoneCount)); + + 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(ListFilesRequestTest, Run_SUCCESS) { + MockAppPtr app(CreateMockApp()); + SharedPtr command(CreateCommand()); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillRepeatedly(ReturnRef(app_mngr_settings_)); + + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStoragePath_)); + + ON_CALL(app_mngr_settings_, list_files_response_size()) + .WillByDefault(ReturnRef(kResponseSize_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(*app, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + + ON_CALL(*app, increment_list_files_in_none_count()).WillByDefault(Return()); + + ON_CALL(*app, GetAvailableDiskSpace()).WillByDefault(Return(0)); + + am::AppFilesMap files_map; + ON_CALL(*app, getAppFiles()).WillByDefault(ReturnRef(files_map)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +} // namespace list_files_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_button_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc new file mode 100644 index 0000000000..3f6577855a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc @@ -0,0 +1,340 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" + +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" + +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "mobile/on_button_event_notification.h" +#include "mobile/on_button_press_notification.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_button_notification { + +namespace am = ::application_manager; +namespace commands = am::commands; +using sdl_rpc_plugin::commands::mobile::OnButtonEventNotification; +using sdl_rpc_plugin::commands::mobile::OnButtonPressNotification; +using ::testing::_; +using ::testing::Types; +using ::testing::Return; + +using ::utils::SharedPtr; +using am::commands::MessageSharedPtr; + +namespace { +const uint32_t kAppId = 5u; +const uint32_t kCustomButtonId = 3u; +const mobile_apis::ButtonName::eType kButtonName = mobile_apis::ButtonName::OK; +} // namespace + +template +struct NotificationData { + typedef NotificationT Notification; + enum { kFunctionId = kExpectedFunctionId }; +}; + +template +class OnButtonNotificationCommandsTest + : public CommandsTest, + public NotificationDataT {}; + +typedef Types, + NotificationData > + OnButtonNotificationCommandsList; + +MATCHER_P(CheckNotificationMessage, function_id, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + const bool kIsFunctionIdCorrect = + (*arg)[am::strings::params][am::strings::function_id].asInt() == + function_id; + + bool is_custom_button_id_correct = true; + if ((*arg)[am::strings::msg_params].keyExists( + am::hmi_response::custom_button_id)) { + is_custom_button_id_correct = + (*arg)[am::strings::msg_params][am::strings::custom_button_id] == + kCustomButtonId; + } + + return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && + kIsNotificationCorrect && kIsFunctionIdCorrect && + is_custom_button_id_correct; +} + +TYPED_TEST_CASE(OnButtonNotificationCommandsTest, + OnButtonNotificationCommandsList); + +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_CustomButton_NoAppId_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_CustomButton_NoCustomButtonId_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_CustomButton_AppNotRegistered_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*notification_msg)[am::strings::msg_params] + [am::hmi_response::custom_button_id] = kCustomButtonId; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + EXPECT_CALL(this->app_mngr_, application(kAppId)) + .WillOnce(Return(ApplicationSharedPtr())); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_CustomButton_AppNotSubscribedToCustomButtonId_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*notification_msg)[am::strings::msg_params] + [am::hmi_response::custom_button_id] = kCustomButtonId; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) + .WillOnce(Return(false)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + mobile_apis::ButtonName::CUSTOM_BUTTON; + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*notification_msg)[am::strings::msg_params] + [am::hmi_response::custom_button_id] = kCustomButtonId; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + ON_CALL(*mock_app, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) + .WillOnce(Return(true)); + EXPECT_CALL(this->mock_rpc_service_, + SendMessageToMobile( + CheckNotificationMessage(TestFixture::kFunctionId), _)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, Run_NoSubscribedApps_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + kButtonName; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + const std::vector empty_subscribed_apps_list; + EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) + .WillOnce(Return(empty_subscribed_apps_list)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, Run_InvalidHmiLevel_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + kButtonName; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector subscribed_apps_list; + subscribed_apps_list.push_back(mock_app); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); + + EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) + .WillOnce(Return(subscribed_apps_list)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, + Run_ButtonOkOnlyForHmiLevelFull_UNSUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + kButtonName; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector subscribed_apps_list; + subscribed_apps_list.push_back(mock_app); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED)); + + EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) + .WillOnce(Return(subscribed_apps_list)); + + command->Run(); +} + +TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { + typedef typename TestFixture::Notification Notification; + + MessageSharedPtr notification_msg( + this->CreateMessage(smart_objects::SmartType_Map)); + + (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = + kButtonName; + + SharedPtr command( + this->template CreateCommand(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector subscribed_apps_list; + subscribed_apps_list.push_back(mock_app); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); + + ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true)); + + EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) + .WillOnce(Return(subscribed_apps_list)); + EXPECT_CALL(this->mock_rpc_service_, + SendMessageToMobile( + CheckNotificationMessage(TestFixture::kFunctionId), _)); + + command->Run(); +} + +} // namespace on_button_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/on_command_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc new file mode 100644 index 0000000000..6097208bf2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "mobile/on_command_notification.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_command_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnCommandNotification; + +typedef ::utils::SharedPtr CommandPtr; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCommandId = 5u; +} // namespace + +class OnCommandNotificationTest + : public CommandsTest {}; + +TEST_F(OnCommandNotificationTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->Run(); +} + +TEST_F(OnCommandNotificationTest, Run_NoAppsForTheCommand_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, FindCommand(kCommandId)) + .WillOnce(Return(static_cast(NULL))); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->Run(); +} + +MATCHER(CheckNotificationMessage, "") { + 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; + + return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && + kIsNotificationCorrect; +} + +TEST_F(OnCommandNotificationTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + MessageSharedPtr dummy_msg(CreateMessage()); + EXPECT_CALL(*mock_app, FindCommand(kCommandId)) + .WillOnce(Return(dummy_msg.get())); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckNotificationMessage(), _)); + + + command->Run(); +} + +} // namespace on_command_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/on_hash_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc new file mode 100644 index 0000000000..8886e8f209 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_hash_change_notification.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hash_change_notification { + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::mobile::OnHashChangeNotification; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using testing::Mock; +using testing::Return; +using testing::ReturnRef; +using testing::_; + +class OnHashChangeNotificationTest + : public CommandsTest {}; + +TEST_F(OnHashChangeNotificationTest, Run_ValidApp_SUCCESS) { + const uint32_t kConnectionKey = 1u; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + + SharedPtr command = + CreateCommand(msg); + + std::string return_string = "1234"; + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, curHash()).WillOnce(ReturnRef(return_string)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + ASSERT_EQ(return_string, + (*msg)[strings::msg_params][strings::hash_id].asString()); +} + +TEST_F(OnHashChangeNotificationTest, Run_InvalidApp_NoNotification) { + const uint32_t kConnectionKey = 1u; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + + SharedPtr command = + CreateCommand(msg); + + std::string return_string; + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app, curHash()).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +} // namespace on_hash_change_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/on_hmi_status_notification_from_mobile_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc new file mode 100644 index 0000000000..3b547df43f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc @@ -0,0 +1,282 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_hmi_status_notification_from_mobile.h" +#include "application_manager/commands/commands_test.h" +#include +#include "application_manager/message.h" +#include "application_manager/application_manager.h" +#include "application_manager/mock_message_helper.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hmi_status_notification_from_mobile { + +namespace { +const uint32_t kConnectionKey = 1u; +const connection_handler::DeviceHandle kHandle = 2u; +} // namespace + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::OnHMIStatusNotificationFromMobile; +using protocol_handler::MajorProtocolVersion; +using application_manager::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnHMIStatusNotificationFromMobileTest + : public CommandsTest { + public: + MessageSharedPtr CreateMsgParams( + const mobile_apis::HMILevel::eType kHMIState) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; + return msg; + } + ApplicationSet app_set_; + sync_primitives::Lock lock_; +}; + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_CurrentStateForeground_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app, set_foreground(true)).Times(0); + + EXPECT_CALL(*mock_app, device()).Times(0); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).Times(0); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()).Times(0); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_CurrentStateNotForeground_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(false)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_ProtocolVersionKV3_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(false)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AppNotRequestedBeforeAndKV3_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AppNotRequestedBefore_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, is_foreground()).WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendQueryApps(kConnectionKey, _)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AnotherForegroundSDLApp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(false)); + + EXPECT_CALL(app_mngr_, MarkAppsGreyOut(kHandle, false)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +} // namespace on_hmi_status_notification_from_mobile +} // 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_hmi_status_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc new file mode 100644 index 0000000000..0a586b3fe7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_hmi_status_notification.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hmi_status_notification { + +namespace { +const uint32_t kConnectionKey = 1u; +} // namespace + +namespace strings = application_manager::strings; +using sdl_rpc_plugin::commands::OnHMIStatusNotification; +using protocol_handler::MajorProtocolVersion; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnHMIStatusNotificationTest + : public CommandsTest { + public: + MessageSharedPtr CreateMsgParams( + const mobile_apis::HMILevel::eType kHMIState) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; + return msg; + } + + void SetSendNotificationExpectations(MessageSharedPtr& msg) { + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + } + + void VerifySendNotificationData(MessageSharedPtr& msg) { + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + } +}; + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).Times(0); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(_)).Times(0); + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)) + .Times(0); + + command->Run(); +} + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidEnum_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::INVALID_ENUM); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndFalseProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + SetSendNotificationExpectations(msg); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(false)); + EXPECT_CALL(*mock_app, set_tts_properties_in_none(true)); + EXPECT_CALL(mock_message_helper_, SendTTSGlobalProperties(_, false, _)); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndTrueProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(true)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndFalseProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(false)); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(true)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndTrueProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(true)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +} // namespace on_hmi_status_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/on_hmi_status_notification_test.cc.autosave b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc.autosave new file mode 100644 index 0000000000..0a586b3fe7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc.autosave @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_hmi_status_notification.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hmi_status_notification { + +namespace { +const uint32_t kConnectionKey = 1u; +} // namespace + +namespace strings = application_manager::strings; +using sdl_rpc_plugin::commands::OnHMIStatusNotification; +using protocol_handler::MajorProtocolVersion; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnHMIStatusNotificationTest + : public CommandsTest { + public: + MessageSharedPtr CreateMsgParams( + const mobile_apis::HMILevel::eType kHMIState) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; + return msg; + } + + void SetSendNotificationExpectations(MessageSharedPtr& msg) { + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + } + + void VerifySendNotificationData(MessageSharedPtr& msg) { + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + } +}; + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).Times(0); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(_)).Times(0); + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)) + .Times(0); + + command->Run(); +} + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidEnum_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::INVALID_ENUM); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndFalseProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + SetSendNotificationExpectations(msg); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(false)); + EXPECT_CALL(*mock_app, set_tts_properties_in_none(true)); + EXPECT_CALL(mock_message_helper_, SendTTSGlobalProperties(_, false, _)); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndTrueProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(true)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndFalseProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(false)); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(true)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndTrueProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(true)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +} // namespace on_hmi_status_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/on_keyboard_input_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc new file mode 100644 index 0000000000..9864664e3f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_keyboard_input_notification.h" +#include "application_manager/commands/commands_test.h" +#include +#include "application_manager/message.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_keyboard_input_notification { + +namespace strings = application_manager::strings; + +namespace { +const uint32_t kConnectionKey = 1u; +} // namespace + +using sdl_rpc_plugin::commands::mobile::OnKeyBoardInputNotification; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using application_manager::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnKeyBoardInputNotificationTest + : public CommandsTest { + public: + void SetSendNotificationExpectations(MessageSharedPtr msg) { + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + } + + void SetSendNotificationVariables(MessageSharedPtr msg) { + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + } + + MockAppPtr InitAppSetDataAccessor(SharedPtr& app_set) { + app_set = (!app_set ? ::utils::MakeShared() : app_set); + MockAppPtr app(CreateMockApp()); + app_set->insert(app); + EXPECT_CALL(app_mngr_, applications()) + .WillOnce(Return(DataAccessor(*app_set, lock_))); + return app; + } + + SharedPtr app_set_; + sync_primitives::Lock lock_; +}; + +TEST_F(OnKeyBoardInputNotificationTest, Run_ActionActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()).WillOnce(Return(1)); + EXPECT_CALL(*mock_app, perform_interaction_layout()) + .WillOnce(Return(mobile_apis::LayoutMode::KEYBOARD)); + EXPECT_CALL(*mock_app, hmi_level()).Times(0); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + SetSendNotificationVariables(msg); + + ASSERT_EQ(kConnectionKey, + (*msg)[strings::params][strings::connection_key].asInt()); +} + +TEST_F(OnKeyBoardInputNotificationTest, Run_ActionNotActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_FULL)); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + SetSendNotificationVariables(msg); + + ASSERT_EQ(kConnectionKey, + (*msg)[strings::params][strings::connection_key].asInt()); +} + +TEST_F(OnKeyBoardInputNotificationTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_BACKGROUND)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); +} + +} // namespace on_keyboard_input_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/on_system_request_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc new file mode 100644 index 0000000000..1532607af3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc @@ -0,0 +1,283 @@ +/* + * Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/on_system_request_notification.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_system_request_notification { + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::mobile::OnSystemRequestNotification; +using application_manager::commands::CommandImpl; +using application_manager::MockMessageHelper; +using test::components::policy_test::MockPolicyHandlerInterface; +using namespace mobile_apis; +using testing::SaveArg; +using testing::Mock; +using testing::Return; +using testing::ReturnRef; +using testing::_; + +namespace { +const uint32_t kConnectionKey = 1u; +const std::string kPolicyAppId = "fake-app-id"; +} // namespace + +class OnSystemRequestNotificationTest + : public CommandsTest { + public: + OnSystemRequestNotificationTest() : mock_app_(CreateMockApp()) {} + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + + ON_CALL(app_mngr_, GetPolicyHandler()) + .WillByDefault(ReturnRef(mock_policy_handler_)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + } + + protected: + MockAppPtr mock_app_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::PROPRIETARY; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + std::string policy_app_id; + EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + .WillOnce(Return(true)); + +#ifdef PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, TimeoutExchangeSec()).WillOnce(Return(5u)); +#endif // PROPRIETARY_MODE + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(FileType::JSON, + (*msg)[strings::msg_params][strings::file_type].asInt()); + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + std::string policy_app_id; + EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(FileType::BINARY, + (*msg)[strings::msg_params][strings::file_type].asInt()); + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app, policy_app_id()).Times(0); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)).Times(0); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); +} + +TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + SharedPtr command = + CreateCommand(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + std::string policy_app_id; + EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + ; + + command->Run(); +} + +TEST_F( + OnSystemRequestNotificationTest, + Run_RequestTypeAllowedAndRequestSubTypeDisallowed_MessageNotSentToMobile) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + const auto request_type = mobile_apis::RequestType::HTTP; + (*msg)[strings::msg_params][strings::request_type] = request_type; + const std::string request_subtype = "fakeSubType"; + (*msg)[am::strings::msg_params][am::strings::request_subtype] = + request_subtype; + + PreConditions(); + + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kPolicyAppId, request_type)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_policy_handler_, + IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) + .WillOnce(Return(false)); + + EXPECT_CALL(app_mngr_, SendMessageToMobile(_, _)).Times(0); + + auto command = CreateCommand(msg); + + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(OnSystemRequestNotificationTest, + Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendMessageToMobile) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + const auto request_type = mobile_apis::RequestType::OEM_SPECIFIC; + (*msg)[strings::msg_params][strings::request_type] = request_type; + const std::string request_subtype = "fakeSubType"; + (*msg)[am::strings::msg_params][am::strings::request_subtype] = + request_subtype; + + PreConditions(); + + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kPolicyAppId, request_type)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_policy_handler_, + IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) + .WillOnce(Return(true)); + + smart_objects::SmartObjectSPtr result; + EXPECT_CALL(app_mngr_, SendMessageToMobile(_, _)) + .WillOnce((SaveArg<0>(&result))); + + auto command = CreateCommand(msg); + + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_EQ(application_manager::MessageType::kNotification, + (*result)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(request_type, + (*result)[strings::msg_params][strings::request_type].asInt()); + EXPECT_EQ( + request_subtype, + (*result)[strings::msg_params][strings::request_subtype].asString()); +} + +} // namespace on_system_request_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/on_tbt_client_state_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc new file mode 100644 index 0000000000..80ecea00a1 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2016, 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 "mobile/on_tbt_client_state_notification.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_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_tbt_client_state_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnTBTClientStateNotification; + +typedef ::utils::SharedPtr NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnTBTClientStateNotificationTest + : public CommandsTest { + public: + OnTBTClientStateNotificationTest() + : command_(CreateCommand()) {} + + NotificationPtr command_; +}; + +TEST_F(OnTBTClientStateNotificationTest, Run_HmiLevelNone_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector applications_with_navi; + applications_with_navi.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); + + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + command_->Run(); +} + +MATCHER(CheckMessageData, "") { + 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; + + using namespace helpers; + return Compare(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnTBTClientStateNotificationTest, + Run_NotEmptyListOfAppsWithNavi_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector applications_with_navi; + applications_with_navi.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + + command_->Run(); +} + +} // namespace on_tbt_client_state_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/on_touch_event_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc new file mode 100644 index 0000000000..e7dfce560e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2016, 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 "mobile/on_touch_event_notification.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_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_touch_event_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::mobile::OnTouchEventNotification; + +typedef ::utils::SharedPtr NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnTouchEventNotificationTest + : public CommandsTest { + public: + OnTouchEventNotificationTest() + : command_(CreateCommand()) {} + + NotificationPtr command_; +}; + +TEST_F(OnTouchEventNotificationTest, Run_AppIsNotFullscreen_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector applications_with_navi; + applications_with_navi.push_back(mock_app); + + std::vector applications_with_mobile_projection; + applications_with_mobile_projection.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) + .WillOnce(Return(applications_with_mobile_projection)); + + EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(false)); + + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + command_->Run(); +} + +MATCHER(CheckMessageData, "") { + 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; + + using namespace helpers; + return Compare(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnTouchEventNotificationTest, Run_NotEmptyListOfAppsWithNavi_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector applications_with_navi; + applications_with_navi.push_back(mock_app); + + std::vector applications_with_mobile_projection; + applications_with_mobile_projection.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) + .WillOnce(Return(applications_with_mobile_projection)); + + EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(true)); + + EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)) + .Times(2); + + command_->Run(); +} + +} // namespace on_touch_event_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/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 new file mode 100644 index 0000000000..b4d61d6677 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_vehicle_data_notification_test.cc @@ -0,0 +1,148 @@ +/* + * Copyright (c) 2016, 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/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc new file mode 100644 index 0000000000..ad0ebb7979 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2016, 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 "mobile/on_way_point_change_notification.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_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_way_point_change_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnWayPointChangeNotification; + +typedef ::utils::SharedPtr NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnWayPointChangeNotificationTest + : public CommandsTest { + public: + OnWayPointChangeNotificationTest() + : command_(CreateCommand()) {} + + NotificationPtr command_; +}; + +MATCHER(CheckMessageData, "") { + 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; + + using namespace helpers; + return Compare(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { + std::set apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kAppId); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + + command_->Run(); +} + +} // namespace on_way_point_change_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/perform_audio_pass_thru_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc new file mode 100644 index 0000000000..2757c0bc1a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc @@ -0,0 +1,835 @@ +/* + * Copyright (c) 2016, 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 "mobile/perform_audio_pass_thru_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace perform_audio_pass_thru_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::PerformAudioPassThruRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::InSequence; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 2u; +const std::string kCorrectPrompt = "CorrectPrompt"; +const std::string kCorrectType = "CorrectType"; +const std::string kCorrectDisplayText1 = "CorrectDisplayText1"; +const std::string kCorrectDisplayText2 = "CorrectDisplayText2"; +const std::string kFunctionId = "FunctionId"; +const uint32_t kTimeoutForTTSSpeak = 1u; +} // namespace + +class PerformAudioPassThruRequestTest + : public CommandRequestTest { + public: + PerformAudioPassThruRequestTest() + : mock_app_(CreateMockApp()) + , message_(utils::MakeShared(::smart_objects::SmartType_Map)) + , msg_params_((*message_)[am::strings::msg_params]) {} + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void TestWrongSyntaxInField(const std::string& field) { + if (field == am::strings::initial_prompt) { + msg_params_[field][0][am::strings::text] = "prompt\\n"; + } else { + msg_params_[field] = "prompt\\n"; + } + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(am::mobile_api::Result::INVALID_DATA, result); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + command_sptr_ = CreateCommand(message_); + + application_sptr_ = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(application_sptr_)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; + MessageSharedPtr message_; + ::smart_objects::SmartObject& msg_params_; + utils::SharedPtr command_sptr_; + MockAppPtr application_sptr_; +}; + +TEST_F(PerformAudioPassThruRequestTest, OnTimeout_GENERIC_ERROR) { + MessageSharedPtr msg_ui = CreateMessage(smart_objects::SmartType_Map); + (*msg_ui)[am::strings::msg_params][am::strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*msg_ui)[am::strings::msg_params][am::strings::success] = false; + + MessageSharedPtr message = + utils::MakeShared(::smart_objects::SmartType_Map); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + utils::SharedPtr command = + CreateCommand(message); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(msg_ui)); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + command->onTimeOut(); + EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(PerformAudioPassThruRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr mobile_request = CreateFullParamsUISO(); + (*mobile_request)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject initial_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + initial_prompt[0] = smart_objects::SmartObject(smart_objects::SmartType_Map); + initial_prompt[0][am::strings::text] = "tts chunk text"; + initial_prompt[0][am::strings::type] = 0; + (*mobile_request)[am::strings::msg_params][am::strings::initial_prompt] = + initial_prompt; + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + utils::SharedPtr command = + CreateCommand(mobile_request); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_msg_tts = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_tts)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response_msg_tts)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_msg_tts); + + MessageSharedPtr response_ui = CreateMessage(smart_objects::SmartType_Map); + (*response_ui)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_ui)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*response_ui)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_PerformAudioPassThru); + event_ui.set_smart_object(*response_ui); + + MessageSharedPtr response_to_mobile; + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillRepeatedly(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles((*mobile_request)[am::strings::msg_params] + [am::strings::initial_prompt], + _, + _)).WillOnce(Return(mobile_apis::Result::SUCCESS)); + + command->Run(); + command->on_event(event_tts); + command->on_event(event_ui); + + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::info] + .asString(), + "UI is not supported by system"); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InvalidApp_ApplicationNotRegisteredResponce) { + utils::SharedPtr null_application_sptr; + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(null_application_sptr)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + EXPECT_EQ(am::mobile_api::Result::APPLICATION_NOT_REGISTERED, result); +} + +TEST_F(PerformAudioPassThruRequestTest, Run_HmiLevelNone_Rejected) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + EXPECT_EQ(am::mobile_api::Result::REJECTED, result); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInInitialPrompt_InvalidData) { + TestWrongSyntaxInField(am::strings::initial_prompt); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInAudioPassDisplayText1_InvalidData) { + TestWrongSyntaxInField(am::strings::audio_pass_display_text1); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInAudioPassDisplayText2_InvalidData) { + TestWrongSyntaxInField(am::strings::audio_pass_display_text2); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_TTSSpeakIsAbsent) { + // First we need to call SendSpeakRequest() + // to enable the "is_active_tts_speak" key + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + // Send speak request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun run_caller(*command_sptr_); + run_caller(); + + const ::smart_objects::SmartObject& speak_msg_params = + (*speak_reqeust_result_msg)[am::strings::msg_params]; + + const std::string result_initial_prompt = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] + .asString(); + const std::string result_prompt_type = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] + .asString(); + + EXPECT_EQ(kCorrectPrompt, result_initial_prompt); + EXPECT_EQ(kCorrectType, result_prompt_type); + + // Now we recieve on_event() + + am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + event.set_smart_object(*message_); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_StopSpeaking)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + CallOnEvent on_event_caller(*command_sptr_, event); + MessageSharedPtr command_result = CatchHMICommandResult(on_event_caller); + + const hmi_apis::FunctionID::eType result_function_id = + static_cast( + (*command_result)[am::strings::params][am::strings::function_id] + .asInt()); + + EXPECT_EQ(hmi_apis::FunctionID::TTS_StopSpeaking, result_function_id); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteTrue) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + msg_params_[am::strings::audio_pass_display_text1] = kCorrectDisplayText1; + msg_params_[am::strings::audio_pass_display_text2] = kCorrectDisplayText2; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun caller(*command_sptr_); + caller(); + + const ::smart_objects::SmartObject& speak_msg_params = + (*speak_reqeust_result_msg)[am::strings::msg_params]; + const ::smart_objects::SmartObject& perform_msg_params = + (*perform_result_msg)[am::strings::msg_params]; + + const std::string result_initial_prompt = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] + .asString(); + const std::string result_prompt_type = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] + .asString(); + const std::string result_display_text_1 = + perform_msg_params[am::hmi_request::audio_pass_display_texts][0] + [am::hmi_request::field_text].asString(); + const std::string result_display_text_2 = + perform_msg_params[am::hmi_request::audio_pass_display_texts][1] + [am::hmi_request::field_text].asString(); + + EXPECT_EQ(kCorrectPrompt, result_initial_prompt); + EXPECT_EQ(kCorrectType, result_prompt_type); + EXPECT_EQ(kCorrectDisplayText1, result_display_text_1); + EXPECT_EQ(kCorrectDisplayText2, result_display_text_2); + + EXPECT_EQ(true, perform_msg_params[am::strings::mute_audio].asBool()); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteFalse) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + const bool muted = false; + + msg_params_[am::strings::mute_audio] = muted; + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun caller(*command_sptr_); + caller(); + + EXPECT_EQ( + muted, + (*perform_result_msg)[am::strings::msg_params][am::strings::mute_audio] + .asBool()); +} + +TEST_F( + PerformAudioPassThruRequestTest, + Run_InitPromptEmpty_PerformAndRecordStartNotificationsAndStartRecording) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + MessageSharedPtr start_record_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // Perform audio path thru request sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_OnRecordStart)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // Start recording notification sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&start_record_result_msg), Return(true))); + } + + // Start microphone recording cals + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); + EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); + + CallRun caller(*command_sptr_); + caller(); + + const hmi_apis::FunctionID::eType start_record_result_function_id = + static_cast( + (*start_record_result_msg)[am::strings::params] + [am::strings::function_id].asInt()); + EXPECT_EQ(hmi_apis::FunctionID::UI_OnRecordStart, + start_record_result_function_id); +} + +TEST_F(PerformAudioPassThruRequestTest, OnEvent_UIPAPT_Rejected) { + am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + event.set_smart_object(*message_); + + CallOnEvent caller(*command_sptr_, event); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result_code = + static_cast( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(am::mobile_api::Result::REJECTED, result_code); +} + +TEST_F(PerformAudioPassThruRequestTest, + OnEvent_TTSSpeakSuccess_UpdateRequestTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + event.set_smart_object(*message_); + + // Start recording notification sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + // Start microphone recording cals + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); + EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_PAPTunsupportedResource_CorrectInfo) { + const std::string return_info = "Unsupported phoneme type sent in a prompt"; + + am::event_engine::Event event_speak(hmi_apis::FunctionID::TTS_Speak); + am::event_engine::Event event_perform( + hmi_apis::FunctionID::UI_PerformAudioPassThru); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + event_speak.set_smart_object(*message_); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + event_perform.set_smart_object(*message_); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // First call on_event for setting result_tts_speak_ to UNSUPPORTED_RESOURCE + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + CallOnEvent caller_speak(*command_sptr_, event_speak); + caller_speak(); + + // Second call for test correct behavior of UI_PerformAudioPassThru event + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)).Times(0); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller_perform(*command_sptr_, event_perform); + + MessageSharedPtr perform_event_result = + CatchMobileCommandResult(caller_perform); + + EXPECT_EQ(return_info, + (*perform_event_result)[am::strings::msg_params][am::strings::info] + .asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_TTSSpeak_UpdateTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + + msg_params_[am::strings::connection_key] = kConnectionKey; + msg_params_[am::strings::function_id] = kFunctionId; + msg_params_[am::strings::correlation_id] = kCorrelationId; + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); + + EXPECT_CALL( + app_mngr_, + StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller(*command_sptr_, event); + caller(); + + EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); + EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_TTSOnResetTimeout_UpdateTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_OnResetTimeout); + + msg_params_[am::strings::connection_key] = kConnectionKey; + msg_params_[am::strings::function_id] = kFunctionId; + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); + + EXPECT_CALL( + app_mngr_, + StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller(*command_sptr_, event); + caller(); + + EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); + EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, OnEvent_DefaultCase) { + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).Times(0); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(PerformAudioPassThruRequestTest, Init_CorrectTimeout) { + const uint32_t kDefaultTimeout = command_sptr_->default_timeout(); + const uint32_t kMaxDuration = 10000u; + + msg_params_[am::strings::max_duration] = kMaxDuration; + + command_sptr_->Init(); + + EXPECT_EQ(kDefaultTimeout + kMaxDuration, command_sptr_->default_timeout()); +} + +TEST_F(PerformAudioPassThruRequestTest, + onTimeOut_ttsSpeakNotActive_DontSendHMIReqeust) { + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + // For setting current_state_ -> kCompleted + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + command_sptr_->onTimeOut(); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_onTimeOut_ttsSpeakActive_SendHMIReqeust) { + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(msg)); + + // For setting is_active_tts_speak -> true + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .Times(2) + .WillRepeatedly(Return(false)); + CallRun caller(*command_sptr_); + caller(); + + // For setting current_state_ -> kCompleted + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)); + command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(false)); + + command_sptr_->onTimeOut(); +} + +} // namespace perform_audio_pass_thru_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc new file mode 100644 index 0000000000..ba4860ffa6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2016, 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 "mobile/perform_interaction_request.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/helpers.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace perform_interaction_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::utils::SharedPtr; +using ::testing::Return; +using ::testing::ReturnRef; +using sdl_rpc_plugin::commands::PerformInteractionRequest; +using ::test::components::application_manager_test::MockApplication; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class PerformInteractionRequestTest + : public CommandRequestTest { + public: + PerformInteractionRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + static_cast(hmi_apis::Common_Result::SUCCESS); + (*response_msg_vr)[strings::msg_params][strings::info] = "info"; + MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); + (*request_msg)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::BOTH; + utils::SharedPtr command = + CreateCommand(request_msg); + MockAppPtr mock_app; + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + Event event(hmi_apis::FunctionID::VR_PerformInteraction); + event.set_smart_object(*response_msg_vr); + + command->Init(); + command->on_event(event); + MessageSharedPtr response_to_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*response_to_mobile)[strings::msg_params][strings::result_code] = + static_cast(am::mobile_api::Result::GENERIC_ERROR); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(response_to_mobile)); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + command->onTimeOut(); + + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(PerformInteractionRequestTest, + OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::VR_ONLY; + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + command->Init(); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_vr)[am::strings::msg_params][am::strings::info] = + "VR is not supported by system"; + + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "VR is not supported by system"); +} + +TEST_F(PerformInteractionRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::VR_ONLY; + utils::SharedPtr command = + CreateCommand(msg_from_mobile); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_msg_ui)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_ui)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + + EXPECT_CALL(*mock_app_, is_perform_interaction_active()) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app_, DeletePerformInteractionChoiceSet(_)); + + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "UI is not supported by system"); +} + +} // namespace perform_interaction_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc new file mode 100644 index 0000000000..100981720c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc @@ -0,0 +1,407 @@ +/* + * Copyright (c) 2016, 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 "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" + +#include "mobile/put_file_response.h" +#include "mobile/put_file_request.h" + +#include "utils/make_shared.h" +#include "utils/file_system.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/application.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace put_file { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::AtLeast; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::PutFileRequest; +using sdl_rpc_plugin::commands::PutFileResponse; +using am::commands::MessageSharedPtr; +using policy_test::MockPolicyHandlerInterface; + +typedef SharedPtr PutFileRequestPtr; +typedef SharedPtr PutFileResponsePtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const std::string kFileName = "sync_file_name.txt"; +const int64_t kOffset = 10u; +const int64_t kZeroOffset = 0u; +const std::string kStorageFolder = "./storage"; +const std::string kFolder = "folder"; +const std::string kAppFolder = "app_folder"; +} + +class PutFileRequestTest + : public CommandRequestTest { + public: + PutFileRequestTest() + : msg_(CreateMessage(::smart_objects::SmartType_Map)) + , mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + binary_data_.push_back(1u); + + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::sync_file_name] = kFileName; + (*msg_)[am::strings::msg_params][am::strings::persistent_file] = true; + (*msg_)[am::strings::msg_params][am::strings::file_type] = + mobile_apis::FileType::JSON; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + } + + void ExpectReceiveMessageFromSDK() { + EXPECT_CALL(mock_policy_handler_, + ReceiveMessageFromSDK(kFileName, binary_data_)) + .WillOnce(Return(false)); + } + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; + std::vector binary_data_; +}; + +class PutFileResponceTest : public CommandsTest { + public: + PutFileResponceTest() : message_(CreateMessage()) {} + + void SetUp() OVERRIDE { + command_sptr_ = CreateCommand(message_); + } + + MessageSharedPtr message_; + SharedPtr command_sptr_; +}; + +TEST_F(PutFileResponceTest, Run_InvalidApp_ApplicationNotRegisteredResponce) { + ::smart_objects::SmartObject& message_ref = *message_; + + message_ref[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + utils::SharedPtr null_application_sptr; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(null_application_sptr)); + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile( + MobileResultCodeIs(mobile_apis::Result::APPLICATION_NOT_REGISTERED), + _)); + command_sptr_->Run(); +} + +TEST_F(PutFileResponceTest, Run_ApplicationRegistered_Success) { + ::smart_objects::SmartObject& message_ref = *message_; + + message_ref[am::strings::params][am::strings::connection_key] = + kConnectionKey; + message_ref[am::strings::msg_params][am::strings::success] = true; + + utils::SharedPtr application_sptr = + utils::MakeShared(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + command_sptr_->Run(); +} + +TEST_F(PutFileRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_HmiLevelNone_UNSUCCESS) { + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); + + const uint32_t settings_put_file_in_none = 1u; + const uint32_t app_put_file_in_none_count = 2u; + EXPECT_CALL(app_mngr_settings_, put_file_in_none()) + .WillOnce(ReturnRef(settings_put_file_in_none)); + EXPECT_CALL(*mock_app_, put_file_in_none_count()) + .WillOnce(Return(app_put_file_in_none_count)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_BinaryDataDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::params].erase(am::strings::binary_data); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_SyncFileNameDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::msg_params].erase(am::strings::sync_file_name); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_FileTypeDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::msg_params].erase(am::strings::file_type); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_BinaryDataGreaterThanAvaliableSpace_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 0u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::OUT_OF_MEMORY); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_IvalidCreationDirectory_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + + const std::string storage_folder = "/storage"; + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(storage_folder)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::GENERIC_ERROR); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_IvalidUpdateFile_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 2u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)) + .WillOnce(Return(avaliable_space)); + + const std::string file_path = kStorageFolder + "/" + kAppFolder; + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(false)); + EXPECT_CALL(*mock_app_, UpdateFile(_)).WillOnce(Return(false)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_AddFile_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 2u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)) + .WillOnce(Return(avaliable_space)); + + const std::string file_path = kStorageFolder + "/" + kAppFolder; + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(true)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_SendOnPutFileNotification_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnPutFile))) + .WillOnce(Return(true)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_InvalidPutFile_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_CrcSumEqual_SendSuccessResponse) { + binary_data_ = {1u}; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + const uint32_t correct_crc_sum = + 2768625435u; // calculated using the GetCrc32CheckSum method + (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = + correct_crc_sum; + + ExpectReceiveMessageFromSDK(); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStorageFolder)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); + const size_t available_space = binary_data_.size() + 1; + ON_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillByDefault(Return(available_space)); + ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); + + const std::string file_path = kStorageFolder + "/" + kFolder; + EXPECT_CALL(app_mngr_, SaveBinary(binary_data_, file_path, kFileName, 0u)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, increment_put_file_in_none_count()); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + PutFileRequestPtr command(CreateCommand(msg_)); + ASSERT_TRUE(command->Init()); + command->Run(); + // The folder was created in the "Run" method + EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); +} + +TEST_F(PutFileRequestTest, Run_CrcSumUnequal_SendCorruptedDataResponse) { + binary_data_ = {1u}; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + const uint32_t incorrect_crc_sum = 0u; + (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = + incorrect_crc_sum; + + ExpectReceiveMessageFromSDK(); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStorageFolder)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); + const size_t available_space = binary_data_.size() + 1; + ON_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillByDefault(Return(available_space)); + ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::CORRUPTED_DATA); + EXPECT_CALL(app_mngr_, SaveBinary(_, _, _, _)).Times(0); + PutFileRequestPtr command(CreateCommand(msg_)); + ASSERT_TRUE(command->Init()); + command->Run(); + // The folder was created in the "Run" method + EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); +} + +} // namespace put_file +} // 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 new file mode 100644 index 0000000000..7b3e1843fe --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/read_did_request_test.cc @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2016, 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/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc new file mode 100644 index 0000000000..0da04db993 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -0,0 +1,523 @@ +/* + * Copyright (c) 2016, 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/register_app_interface_request.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_application_helper.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "protocol_handler/mock_session_observer.h" +#include "connection_handler/mock_connection_handler.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_resume_ctrl.h" +#include "application_manager/mock_hmi_interface.h" +#include "utils/data_accessor.h" +#include "utils/custom_string.h" +#include "utils/lock.h" +#include "utils/macro.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace register_app_interface_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; + +namespace am = ::application_manager; + +using ::utils::SharedPtr; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::RegisterAppInterfaceRequest; + +namespace { +const uint32_t kConnectionKey = 1u; +const hmi_apis::Common_Language::eType kHmiLanguage = + hmi_apis::Common_Language::EN_US; +const mobile_apis::Language::eType kMobileLanguage = + mobile_apis::Language::EN_US; +const std::string kMacAddress = "test_mac_address"; +const std::string kAppId = "test_app_id"; +const std::string kDummyString = "test_string"; +const std::vector kDummyDiagModes; +} // namespace + +class RegisterAppInterfaceRequestTest + : public CommandRequestTest { + public: + RegisterAppInterfaceRequestTest() + : msg_(CreateMessage()) + , command_(CreateCommand(msg_)) + , app_name_("test_app_name_") + , mock_application_helper_( + application_manager_test::MockApplicationHelper:: + application_helper_mock()) { + InitGetters(); + InitLanguage(); + } + + void SetUp() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + + void TearDown() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + + void InitBasicMessage() { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::app_name] = app_name_; + (*msg_)[am::strings::msg_params][am::strings::language_desired] = + kHmiLanguage; + (*msg_)[am::strings::msg_params] + [am::strings::hmi_display_language_desired] = kHmiLanguage; + } + + MockAppPtr CreateBasicMockedApp() { + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(app_name_)); + ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); + ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); + return mock_app; + } + + void InitLanguage( + hmi_apis::Common_Language::eType ui_language = kHmiLanguage, + hmi_apis::Common_Language::eType vr_language = kHmiLanguage, + hmi_apis::Common_Language::eType tts_language = kHmiLanguage) { + ON_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillByDefault(Return(vr_language)); + ON_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillByDefault(Return(ui_language)); + ON_CALL(mock_hmi_capabilities_, active_tts_language()) + .WillByDefault(Return(tts_language)); + } + + void InitGetters() { + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(true)); + ON_CALL(app_mngr_, resume_controller()) + .WillByDefault(ReturnRef(mock_resume_crt_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + ON_CALL(app_mngr_settings_, sdl_version()) + .WillByDefault(ReturnRef(kDummyString)); + ON_CALL(mock_hmi_capabilities_, ccpu_version()) + .WillByDefault(ReturnRef(kDummyString)); + ON_CALL(app_mngr_settings_, supported_diag_modes()) + .WillByDefault(ReturnRef(kDummyDiagModes)); + ON_CALL(mock_policy_handler_, GetAppRequestTypes(_)) + .WillByDefault(Return(std::vector())); + ON_CALL(mock_policy_handler_, GetAppRequestTypeState(_)) + .WillByDefault(Return(policy::RequestType::State::EMPTY)); + ON_CALL(mock_policy_handler_, GetAppRequestSubTypes(_)) + .WillByDefault(Return(std::vector())); + ON_CALL(mock_policy_handler_, GetAppRequestSubTypeState(_)) + .WillByDefault(Return(policy::RequestSubType::State::EMPTY)); + ON_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); + ON_CALL(app_mngr_, GetDeviceTransportType(_)) + .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); + ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); + ON_CALL(app_mngr_, application_by_policy_id(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + } + + void SetCommonExpectionsOnSwitchedApplication( + MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { + EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(response_result_code), _)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_ChangeRegistration))).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_ChangeRegistration))).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VR_ChangeRegistration))).Times(0); + + EXPECT_CALL( + app_mngr_, + OnApplicationSwitched( + MockAppPtr::static_pointer_cast( + mock_app))); + } + + MessageSharedPtr msg_; + SharedPtr command_; + + const utils::custom_string::CustomString app_name_; + sync_primitives::Lock lock_; + am::ApplicationSet app_set_; + + typedef IsNiceMock::Result MockPolicyHandlerInterface; + + typedef IsNiceMock::Result + MockResumeCtrl; + + typedef IsNiceMock::Result MockConnectionHandler; + + typedef IsNiceMock::Result MockSessionObserver; + + typedef IsNiceMock::Result MockHMICapabilities; + + MockResumeCtrl mock_resume_crt_; + MockConnectionHandler mock_connection_handler_; + MockSessionObserver mock_session_observer_; + application_manager_test::MockApplicationHelper& mock_application_helper_; +}; + +TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { + EXPECT_TRUE(command_->Init()); +} + +TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { + InitBasicMessage(); + (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId; + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())) + .WillRepeatedly(Return(mock_app)); + + ON_CALL(app_mngr_, applications()) + .WillByDefault(Return(DataAccessor(app_set_, lock_))); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + utils::MakeShared(); + ON_CALL(mock_policy_handler_, AddApplication(_, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + command_->Run(); +} + +MATCHER_P(CheckHMIInterfacesRealtedData, expected_data, "") { + const bool is_result_id_correct = + mobile_apis::Result::SUCCESS == + static_cast( + (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); + + const bool are_ui_related_data_exist = + (*arg)[am::strings::msg_params].keyExists( + am::hmi_response::display_capabilities); + + const bool are_vi_related_data_exist = + (*arg)[am::strings::msg_params][am::hmi_response::vehicle_type] == + (*expected_data)[am::hmi_response::vehicle_type]; + + const bool are_vr_related_data_exist = + (*arg)[am::strings::msg_params][am::strings::vr_capabilities] == + (*expected_data)[am::strings::vr_capabilities]; + + return is_result_id_correct && are_ui_related_data_exist && + are_vi_related_data_exist && are_vr_related_data_exist; +} + +TEST_F(RegisterAppInterfaceRequestTest, + Run_HmiInterfacesStateAvailable_SUCCESS) { + InitBasicMessage(); + + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())) + .WillRepeatedly(Return(mock_app)); + + MessageSharedPtr expected_message = + CreateMessage(smart_objects::SmartType_Map); + + (*expected_message)[am::hmi_response::vehicle_type] = "test_vehicle_type"; + (*expected_message)[am::strings::vr_capabilities] = "test_vr_capabilities"; + (*expected_message)[am::hmi_response::display_capabilities] = 0; + SmartObject& display_capabilities = + (*expected_message)[am::hmi_response::display_capabilities]; + display_capabilities[am::hmi_response::display_type] = "test_display_type"; + display_capabilities[am::hmi_response::display_name] = "GENERIC_DISPLAY"; + display_capabilities[am::hmi_response::text_fields] = "test_text_fields"; + display_capabilities[am::hmi_response::image_fields] = "test_image_fields"; + display_capabilities[am::hmi_response::media_clock_formats] = + "test_media_clock_formats"; + display_capabilities[am::hmi_response::num_custom_presets_available] = + "test_num_custom_presets_available"; + display_capabilities[am::hmi_response::graphic_supported] = + "test_graphic_supported"; + display_capabilities[am::hmi_response::templates_available] = + "test_templates_available"; + display_capabilities[am::hmi_response::screen_params] = "test_screen_params"; + + ON_CALL(mock_hmi_capabilities_, vehicle_type()) + .WillByDefault( + Return(&(*expected_message)[am::hmi_response::vehicle_type])); + ON_CALL(mock_hmi_capabilities_, vr_capabilities()) + .WillByDefault( + Return(&(*expected_message)[am::strings::vr_capabilities])); + ON_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillByDefault( + Return(&(*expected_message)[am::hmi_response::display_capabilities])); + + ON_CALL(app_mngr_, applications()) + .WillByDefault(Return(DataAccessor(app_set_, lock_))); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + utils::MakeShared(); + ON_CALL(mock_policy_handler_, AddApplication(_, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_CorrectHash_ExpectNoCleanupSuccess) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + MockAppPtr::static_pointer_cast( + mock_app), + request_hash_id)).WillOnce(Return(true)); + + EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0); + + EXPECT_CALL(mock_application_helper_, RecallApplicationData(_, _)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::SUCCESS); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_WrongHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + MockAppPtr::static_pointer_cast( + mock_app), + request_hash_id)).WillOnce(Return(false)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + MockAppPtr::static_pointer_cast( + mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_NoHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + MockAppPtr::static_pointer_cast( + mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + +} // namespace register_app_interface_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/reset_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc new file mode 100644 index 0000000000..e494ca7663 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc @@ -0,0 +1,576 @@ +/* + * Copyright (c) 2016, 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 "mobile/reset_global_properties_request.h" +#include "mobile/reset_global_properties_response.h" + +#include "gtest/gtest.h" +#include "utils/shared_ptr.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.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/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace reset_global_properties { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::ResetGlobalPropertiesRequest; +using sdl_rpc_plugin::commands::ResetGlobalPropertiesResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef SharedPtr ResetGlobalPropertiesRequestPtr; +typedef SharedPtr + ResetGlobalPropertiesResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +} // namespace + +class ResetGlobalPropertiesRequestTest + : public CommandRequestTest { + protected: + ResetGlobalPropertiesRequestTest() + : msg_(CreateMessage()), mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + command_ = CreateCommand(msg_); + + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; + ResetGlobalPropertiesRequestPtr command_; +}; + +class ResetGlobalPropertiesResponseTest + : public CommandsTest {}; + +TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + MessageSharedPtr command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); + + command_->Run(); + EXPECT_EQ( + (*command_result)[am::strings::msg_params][am::strings::success].asBool(), + false); + EXPECT_EQ( + (*command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(mobile_apis::Result::APPLICATION_NOT_REGISTERED)); +} + +TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::HELPPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][2] = + mobile_apis::GlobalProperty::VRHELPTITLE; + (*msg_)[am::strings::msg_params][am::strings::properties][3] = + mobile_apis::GlobalProperty::MENUNAME; + (*msg_)[am::strings::msg_params][am::strings::properties][4] = + mobile_apis::GlobalProperty::MENUICON; + (*msg_)[am::strings::msg_params][am::strings::properties][5] = + mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + smart_objects::SmartObject so_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + smart_objects::SmartObject timeout_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + timeout_prompt[am::strings::text] = time_out_prompt[0]; + timeout_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + + smart_objects::SmartObject so_time_out_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + so_time_out_prompt[0] = timeout_prompt; + + EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help; // = NULL; + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + command_->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::HELPPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][2] = + mobile_apis::GlobalProperty::VRHELPTITLE; + (*msg_)[am::strings::msg_params][am::strings::properties][3] = + mobile_apis::GlobalProperty::MENUNAME; + (*msg_)[am::strings::msg_params][am::strings::properties][4] = + mobile_apis::GlobalProperty::MENUICON; + (*msg_)[am::strings::msg_params][am::strings::properties][5] = + mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + smart_objects::SmartObject so_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + smart_objects::SmartObject timeout_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + timeout_prompt[am::strings::text] = time_out_prompt[0]; + timeout_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + + smart_objects::SmartObject so_time_out_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + so_time_out_prompt[0] = timeout_prompt; + + EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help = + ::utils::MakeShared( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::hmi_request::menu_title] = ""; + + EXPECT_CALL(*mock_app_, + set_menu_title(msg_params[am::hmi_request::menu_title])); + + const smart_objects::SmartObjectSPtr so_help_prompt = + ::utils::MakeShared( + smart_objects::SmartType_Map); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(so_help_prompt.get())); + EXPECT_CALL(*mock_app_, timeout_prompt()) + .WillOnce(Return(so_help_prompt.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_UI_SetGlobalProperties_SUCCESS) { + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*msg_)[am::strings::params][am::hmi_response::code] = result_code; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::VRHELPTITLE; + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help = + ::utils::MakeShared( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + + event.set_smart_object(*msg_); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_TTS_SetGlobalProperties_SUCCESS) { + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + MessageSharedPtr ui_msg = CreateMessage(); + (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*ui_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); + ui_event.set_smart_object(*ui_msg); + + command_->Run(); + command_->on_event(ui_event); + event.set_smart_object(*msg_); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::WARNINGS), + am::commands::Command::SOURCE_SDL)); + + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + ResetGlobalPropertiesResponsePtr command( + CreateCommand(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _)); + command->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::VRHELPTITLE; + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + smart_objects::SmartObjectSPtr vr_help = + ::utils::MakeShared( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + ResetGlobalPropertiesRequestPtr command = + CreateCommand(msg_); + command->Run(); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitTTS_Timeout_GENERIC_ERROR_TTSNotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + ResetGlobalPropertiesRequestPtr command = + CreateCommand(msg_); + command->Run(); + + // Received response only from UI + MessageSharedPtr ui_msg = CreateMessage(); + (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*ui_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*ui_msg)[am::strings::msg_params] = + SmartObject(smart_objects::SmartType_Map); + Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); + ui_event.set_smart_object(*ui_msg); + command->on_event(ui_event); + + // TTS doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + utils::MakeShared(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + const std::string info = "TTS component does not respond"; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUI_Timeout_GENERIC_ERROR_UINotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + + // Received response only from TTS + MessageSharedPtr tts_msg = CreateMessage(); + (*tts_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*tts_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + Event tts_event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + tts_event.set_smart_object(*tts_msg); + command_->on_event(tts_event); + + // UI doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + utils::MakeShared(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + + const std::string info = "UI component does not respond"; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command_->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUIAndTTS_Timeout_GENERIC_ERROR_TTSAndUINotRespond) { + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + utils::MakeShared(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + // TTS and UI don't respond, so timeout should send generic error + std::string info = "TTS, UI component does not respond"; + smart_objects::SmartObjectSPtr response = + utils::MakeShared(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command_->onTimeOut(); +} + +} // namespace reset_global_properties +} // 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/scrollable_message_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc new file mode 100644 index 0000000000..eec1642883 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2016, 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 "mobile/scrollable_message_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace scrollable_message_request { + +namespace am = application_manager; +namespace hmi_response = am::hmi_response; +namespace mobile_result = mobile_apis::Result; +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::ScrollableMessageRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Eq; +using ::testing::Ref; +using ::testing::Return; +using ::testing::ReturnRef; + +using namespace am::strings; +using test::components::policy_test::MockPolicyHandlerInterface; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kTimeOut = 30000u; +const uint32_t kCorrelationId = 10u; +const uint32_t kFunctionID = 3u; +} // namespace + +class ScrollableMessageRequestTest + : public CommandRequestTest { + public: + typedef TypeIf, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + sync_primitives::Lock lock_; + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + command_ = CreateCommand(msg_); + } + + MockAppPtr mock_app_; + MessageSharedPtr msg_; + SharedPtr command_; +}; + +typedef ScrollableMessageRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(ScrollableMessageRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + utils::SharedPtr command = + CreateCommand(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info1"; + + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { + (*msg_)[msg_params][timeout] = kTimeOut; + (*msg_)[msg_params][interaction_mode] = + mobile_apis::InteractionMode::MANUAL_ONLY; + EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + command_->Init(); + EXPECT_EQ(kTimeOut, command_->default_timeout()); +} + +TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { + (*msg_)[msg_params][interaction_mode] = + mobile_apis::InteractionMode::MANUAL_ONLY; + EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + command_->Init(); + EXPECT_EQ(kTimeOut, command_->default_timeout()); +} + +TEST_F(ScrollableMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + command_->Run(); +} + +TEST_F(ScrollableMessageRequestTest, + Run_SoftButtonProcessingResultWrogParameters_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + const mobile_apis::Result::eType processing_result = + mobile_apis::Result::ABORTED; + smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; + EXPECT_CALL( + mock_message_helper_, + ProcessSoftButtons( + msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) + .WillOnce(Return(processing_result)); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command_))); + EXPECT_EQ(processing_result, + static_cast( + (*result_msg)[am::strings::msg_params][result_code].asInt())); +} + +TEST_F(ScrollableMessageRequestTest, Run_SoftButtonProcessingResult_SUCCESS) { + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; + (*msg_)[am::strings::params][am::strings::function_id] = kFunctionID; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::soft_button_id] = 0; + EXPECT_CALL( + mock_message_helper_, + ProcessSoftButtons( + msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); + EXPECT_EQ(hmi_apis::FunctionID::UI_ScrollableMessage, + static_cast( + (*result_msg)[params][function_id].asInt())); +} + +TEST_F(ScrollableMessageRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + OnEvent_ReceivedUIOnResetTimeoutEvent_SUCCESS) { + (*msg_)[params][connection_key] = kConnectionKey; + (*msg_)[params][correlation_id] = kCorrelationId; + EXPECT_CALL( + app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout_)); + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + DISABLED_OnEvent_ReceivedUIScrollableMessage_SUCCESS) { + (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + DISABLED_OnEvent_UnsupportedRCAndUICoop_SUCCESS) { + (*msg_)[params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +} // namespace scrollable_message_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc new file mode 100644 index 0000000000..1b0dcf02ba --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2017 Xevo Inc. + * 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 Xevo Inc. 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 "gtest/gtest.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" + +#include "mobile/send_haptic_data_request.h" +#include "mobile/send_haptic_data_response.h" + +#include "interfaces/MOBILE_API.h" +#include "application_manager/application.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace send_haptic_data { + +using ::testing::_; +using ::testing::Return; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::SendHapticDataRequest; +using sdl_rpc_plugin::commands::SendHapticDataResponse; +using am::commands::MessageSharedPtr; + +typedef SharedPtr SendHapticDataRequestPtr; +typedef SharedPtr SendHapticDataResponsePtr; + +namespace { +const uint32_t kConnectionKey = 1u; +} + +class SendHapticDataRequestTest + : public CommandRequestTest { + public: + SendHapticDataRequestTest() + : msg_(CreateMessage(::smart_objects::SmartType_Map)) + , mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; +}; + +class SendHapticDataResponseTest + : public CommandsTest { + public: + SendHapticDataResponseTest() : message_(CreateMessage()) {} + + void SetUp() OVERRIDE { + command_sptr_ = CreateCommand(message_); + } + + MessageSharedPtr message_; + SharedPtr command_sptr_; +}; + +TEST_F(SendHapticDataRequestTest, Run_SUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_SendHapticData))) + .WillOnce(Return(true)); + + SendHapticDataRequestPtr command(CreateCommand(msg_)); + + command->Init(); + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, Run_DISALLOWED) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(false)); + + EXPECT_CALL(*mock_app_, mobile_projection_enabled()).WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(Return(true)); + + SendHapticDataRequestPtr command(CreateCommand(msg_)); + + command->Init(); + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, OnEvent_SUCCESS) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + (*msg_)[am::strings::msg_params] = 0; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + Event event(hmi_apis::FunctionID::UI_SendHapticData); + event.set_smart_object(*msg_); + SendHapticDataRequestPtr command(CreateCommand(msg_)); + + command->Init(); + command->on_event(event); +} + +TEST_F(SendHapticDataResponseTest, Run_Success) { + ::smart_objects::SmartObject& message_ref = *message_; + message_ref[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + command_sptr_->Init(); + command_sptr_->Run(); +} + +} // namespace send_haptic_data +} // 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/send_location_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc new file mode 100644 index 0000000000..300c9835e5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc @@ -0,0 +1,406 @@ +/* + * Copyright (c) 2016, 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 "mobile/send_location_request.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "utils/shared_ptr.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace send_location_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SendLocationRequest; +using application_manager::MockMessageHelper; +using test::components::application_manager_test::MockHMICapabilities; +using smart_objects::SmartObject; +using utils::SharedPtr; +using testing::_; +using testing::Return; +using testing::ReturnRef; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +namespace Common_TextFieldName = hmi_apis::Common_TextFieldName; + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kFunctionID = 2u; +const uint32_t kAppID = 3u; +const double kLongitudeDegrees = 13.4; +const std::string kLocationDescription = "Location_Description"; +const std::string kNewLine = "\\n"; +const std::string kAddressLine = "Address_Line"; +const std::string kPhoneNumber = "Phone_number"; +const std::string kCorrectAddress = "Correct address"; +const std::string kEmptyAddress = ""; +const std::string kAddressWithWrongSyntax = "Wrong Syntax\\n"; +} // namespace + +class SendLocationRequestTest + : public CommandRequestTest { + public: + class UnwrappedSendLocationRequest : public SendLocationRequest { + public: + UnwrappedSendLocationRequest( + const MessageSharedPtr& message, + application_manager::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : SendLocationRequest(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + ::application_manager::CommandParametersPermissions& + get_parameters_permissions() { + return parameters_permissions_; + } + }; + + typedef SharedPtr CommandSPrt; + + SendLocationRequestTest() { + mock_app_ = CreateMockApp(); + disp_cap_ = utils::MakeShared(smart_objects::SmartType_Map); + message_ = CreateMessage(); + command_ = CreateCommand(message_); + } + + void InitialSetup(MessageSharedPtr message_) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + (*message_)[strings::params][strings::function_id] = kFunctionID; + (*message_)[strings::msg_params] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::address] = kCorrectAddress; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + AllowMandatoryFields(); + } + + void HMICapabilitiesSetupHelper() { + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + } + + void HMICapabilitiesSetupWithArguments( + Common_TextFieldName::eType field_name) { + HMICapabilitiesSetupHelper(); + (*disp_cap_)[hmi_response::text_fields] = + SmartObject(smart_objects::SmartType_Array); + (*disp_cap_)[hmi_response::text_fields][0] = + SmartObject(smart_objects::SmartType_Map); + (*disp_cap_)[hmi_response::text_fields][0][strings::name] = field_name; + EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) + .Times(2) + .WillRepeatedly(Return(disp_cap_.get())); + } + + void FinishSetup() { + EXPECT_CALL(*mock_app_, hmi_app_id()).WillOnce(Return(kAppID)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Navigation_SendLocation))); + } + + void FinishSetupCancelled(mobile_apis::Result::eType result) { + EXPECT_CALL(*mock_app_, hmi_app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(result), _)); + } + + void AllowMandatoryFields() { + application_manager::CommandParametersPermissions& permissions = + command_->get_parameters_permissions(); + permissions.allowed_params.insert(strings::longitude_degrees); + permissions.allowed_params.insert(strings::latitude_degrees); + } + + MockAppPtr mock_app_; + SharedPtr disp_cap_; + MessageSharedPtr message_; + CommandSPrt command_; +}; + +TEST_F(SendLocationRequestTest, Run_InvalidApp_Success) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + FinishSetupCancelled(mobile_apis::Result::APPLICATION_NOT_REGISTERED); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_DeliveryMode_Success) { + InitialSetup(message_); + SmartObject msg_params = (*message_)[strings::msg_params]; + msg_params[strings::delivery_mode] = SmartObject(); + (*message_)[strings::msg_params] = msg_params; + msg_params.erase(strings::delivery_mode); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name\\n"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesAreAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesAreNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = + kAddressLine + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = + kPhoneNumber + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressesContainWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address]["Address 1"] = + kCorrectAddress; + (*message_)[strings::msg_params][strings::address]["Address 2"] = + kAddressWithWrongSyntax; + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationImageValid_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_image] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::location_image][strings::value] = + "1"; + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*message_)[strings::msg_params][strings::location_image], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationImageInvalid_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_image] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::location_image][strings::value] = + "1"; + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*message_)[strings::msg_params][strings::location_image], _, _)) + .WillOnce(Return(mobile_apis::Result::ABORTED)); + FinishSetupCancelled(mobile_apis::Result::ABORTED); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_HMIUINotCoop_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + (*disp_cap_)[hmi_response::text_fields] = + SmartObject(smart_objects::SmartType_Array); + (*disp_cap_)[hmi_response::text_fields][0] = + SmartObject(smart_objects::SmartType_Map); + (*disp_cap_)[hmi_response::text_fields][0][strings::name] = + Common_TextFieldName::phoneNumber; + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(false)); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, OnEvent_Success) { + mobile_apis::Result::eType response_code = mobile_apis::Result::SUCCESS; + (*message_)[strings::params][hmi_response::code] = response_code; + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + + Event event(hmi_apis::FunctionID::Navigation_SendLocation); + event.set_smart_object(*message_); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .WillOnce(Return(false)); + command_->on_event(event); +} + +TEST_F(SendLocationRequestTest, OnEvent_Cancelled) { + (*message_)[strings::params][hmi_response::code] = + mobile_apis::Result::SUCCESS; + Event event(hmi_apis::FunctionID::Navigation_OnWayPointChange); + event.set_smart_object(*message_); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .Times(0); + command_->on_event(event); +} + +TEST_F(SendLocationRequestTest, Run_MandatoryParamsDisallowed_InvalidData) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + (*message_)[strings::params][strings::function_id] = kFunctionID; + (*message_)[strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::address] = kCorrectAddress; + (*message_)[strings::msg_params][strings::longitude_degrees] = + kLongitudeDegrees; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + application_manager::CommandParametersPermissions& permissions = + command_->get_parameters_permissions(); + // 1st one allowed + permissions.allowed_params.insert(strings::longitude_degrees); + // 2nd one disallowed + permissions.disallowed_params.insert(strings::latitude_degrees); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + command_->Run(); +} + +} // namespace send_location_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/set_app_icon_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc new file mode 100644 index 0000000000..028247710b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2016, 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 "mobile/set_app_icon_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "protocol_handler/mock_protocol_handler.h" +#include "protocol_handler/mock_protocol_handler_settings.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_app_icon_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SetAppIconRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using am::MockHmiInterfaces; +using test::components::protocol_handler_test::MockProtocolHandler; +using test::components::protocol_handler_test::MockProtocolHandlerSettings; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class SetAppIconRequestTest + : public CommandRequestTest { + public: + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + NiceMock hmi_interfaces_; + protocol_handler_test::MockProtocolHandler mock_protocol_handler_; + protocol_handler_test::MockProtocolHandlerSettings + mock_protocol_handler_settings_; +}; + +TEST_F(SetAppIconRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + const std::string file_path = "file_path"; + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_vr)[am::strings::msg_params][am::strings::sync_file_name] + [am::strings::value] = file_path; + + const std::string dir_path = "./"; + ON_CALL(app_mngr_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(dir_path)); + + utils::SharedPtr req_vr = + CreateCommand(msg_vr); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(hmi_interfaces_)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(app_mngr_, protocol_handler()) + .WillByDefault(ReturnRef(mock_protocol_handler_)); + ON_CALL(mock_protocol_handler_, get_settings()) + .WillByDefault(ReturnRef(mock_protocol_handler_settings_)); + + ON_CALL(mock_protocol_handler_settings_, max_supported_protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, set_app_icon_path(_)).WillByDefault(Return(true)); + ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(file_path)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info1"; + + Event event(hmi_apis::FunctionID::UI_SetAppIcon); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + req_vr->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace set_app_icon_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc new file mode 100644 index 0000000000..f5514be245 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc @@ -0,0 +1,250 @@ +/* + * Copyright (c) 2016, 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 "mobile/set_display_layout_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_display_layout_request { + +namespace am = application_manager; +namespace mobile_result = mobile_apis::Result; +using sdl_rpc_plugin::commands::SetDisplayLayoutRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef ::utils::SharedPtr CommandPtr; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationKey = 2u; +const std::string kLayout = "media"; +} // namespace + +MATCHER_P(CheckMshCorrId, corr_id, "") { + return (*arg)[am::strings::params][am::strings::correlation_id].asUInt() == + corr_id; +} + +class SetDisplayLayoutRequestTest + : public CommandRequestTest { + public: + SetDisplayLayoutRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + typedef TypeIf, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + false); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +typedef SetDisplayLayoutRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(SetDisplayLayoutRequestTest, + OnEvent_UIHmiUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + utils::SharedPtr command = + CreateCommand(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); + event.set_smart_object(*msg); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetDisplayLayoutRequestTest, Run_InvalidApp_UNSUCCESS) { + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand(msg)); + + MockAppPtr invalid_mock_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_mock_app)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command->Run(); +} + +TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, display_layout()).WillOnce(ReturnRef(kLayout)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationKey)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetDisplayLayout)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(CheckMshCorrId(kCorrelationKey))) + .WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + CommandPtr command(CreateCommand()); + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + SmartObject msg(smart_objects::SmartType_Map); + + event.set_smart_object(msg); + + command->on_event(event); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { + am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); + MessageSharedPtr msg = CreateMessage(); + + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params][am::hmi_response::display_capabilities] = 0; + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + event.set_smart_object(*msg); + + MessageSharedPtr dispaly_capabilities_msg = CreateMessage(); + (*dispaly_capabilities_msg)[am::hmi_response::templates_available] = + "templates_available"; + + EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillOnce(Return(dispaly_capabilities_msg.get())); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), + am::commands::Command::CommandSource::SOURCE_SDL)); + + CommandPtr command(CreateCommand(msg)); + command->on_event(event); +} + +} // namespace set_display_layout_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc new file mode 100644 index 0000000000..4ed7580f87 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc @@ -0,0 +1,1241 @@ +/* + * Copyright (c) 2016, 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 "mobile/set_global_properties_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_global_properties_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SetGlobalPropertiesRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using am::CommandsMap; +using utils::custom_string::CustomString; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 1u; +const std::string kText = "one"; +const uint32_t kPosition = 1u; +} // namespace + +class SetGlobalPropertiesRequestTest + : public CommandRequestTest { + public: + SetGlobalPropertiesRequestTest() : mock_app_(CreateMockApp()) {} + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + msg_params[am::strings::vr_help_title] = "vr_help_title"; + msg_params[am::strings::vr_help][0][am::strings::text] = "vr_help"; + msg_params[am::strings::vr_help][0][am::strings::position] = 1u; + msg_params[am::strings::help_prompt][0][am::strings::text] = "help_promt"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + return msg; + } + + void VRArraySetupHelper(MessageSharedPtr msg, + SmartObject& vr_help_title, + SmartObject& vr_help_array) { + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + } + + void OnEventUISetupHelper(MessageSharedPtr msg, + SharedPtr command) { + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + EXPECT_CALL(mock_message_helper_, + VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, + RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + command->Run(); + } + + void OnEventTTSSetupHelper(MessageSharedPtr msg, + SharedPtr command) { + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = + timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, + RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title("title"); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + command->Run(); + } + + void EmptyExpectationsSetupHelper() { + EXPECT_CALL(*mock_app_, set_vr_help_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_vr_help(_)).Times(0); + EXPECT_CALL(*mock_app_, vr_help_title()).Times(0); + EXPECT_CALL(*mock_app_, vr_help()).Times(0); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + } + + void ExpectInvalidData() { + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), + am::commands::Command::SOURCE_SDL)); + } + + void ExpectVerifyImageVrHelpSuccess(SmartObject& smart_obj) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(smart_obj, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void ExpectVerifyImageVrHelpUnsuccess() { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void ExpectVerifyImageSuccess(SmartObject& smart_obj) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(smart_obj, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void ExpectationsHmiInterface_Run() { + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::msg_params][am::strings::vr_commands][0] = + "vr_command"; + + utils::SharedPtr command = + CreateCommand(msg_vr); + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + const smart_objects::SmartObject* vr_help_title = + &((*msg_vr)[am::strings::msg_params][am::strings::vr_help_title]); + const smart_objects::SmartObject* vr_help = + &((*msg_vr)[am::strings::msg_params][am::strings::vr_help]); + const smart_objects::SmartObject* vr_help_prompt = + &((*msg_vr)[am::strings::msg_params][am::strings::help_prompt]); + ON_CALL(*mock_app_, vr_help_title()).WillByDefault(Return(vr_help_title)); + ON_CALL(*mock_app_, vr_help()).WillByDefault(Return(vr_help)); + ON_CALL(*mock_app_, help_prompt()).WillByDefault(Return(vr_help_prompt)); + + ExpectationsHmiInterface_Run(); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + ON_CALL(mock_message_helper_, + VerifyImageVrHelpItems( + (*msg_vr)[am::strings::msg_params][am::strings::vr_help], _, _)) + .WillByDefault(Return(mobile_apis::Result::SUCCESS)); + + ON_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillByDefault(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_vr)[am::strings::msg_params][am::strings::help_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + (*msg_vr)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event_vr.set_smart_object(*msg_vr); + + command->Run(); + command->on_event(event_vr); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_SUCCESS_Expect_MessageNotSend) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response)[am::strings::msg_params][am::strings::info] = "test"; + + am::event_engine::Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*response); + + utils::SharedPtr command = + CreateCommand(response); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .Times(0); + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_Expect_false) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*response)[am::strings::msg_params][am::strings::info] = "qwe"; + + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_SetGlobalProperties); + event_tts.set_smart_object(*response); + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_SetGlobalProperties); + event_tts.set_smart_object(*response); + utils::SharedPtr command = + CreateCommand(response); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->Run(); + command->on_event(event_ui); + command->on_event(event_tts); + + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(mobile_apis::Result::INVALID_DATA)); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRNoMenuAndKeyboard_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command( + CreateCommand(msg)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + OnEventUISetupHelper(msg, command); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRWithMenuAndKeyboard_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenMenuIcon_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::ABORTED))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenVRHelp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::ABORTED))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRIncorrectSyntax_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + SmartObject vr_help_title("wrong syntax string\\n"); + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingTitle_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_array(smart_objects::SmartType_Array); + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingArray_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRWrongOrder_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + vr_help_array[1] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[1][am::strings::text] = "two"; + vr_help_array[1][am::strings::position] = 3u; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVR_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title("Menu_Title"); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRCouldNotGenerate_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject* vr_help_title = NULL; + CommandsMap commands_map; + SmartObject empty_msg(smart_objects::SmartType_Map); + commands_map.insert(std::pair(1u, &empty_msg)); + DataAccessor accessor(commands_map, lock_); + EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(vr_help_title)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + + SharedPtr command( + CreateCommand(msg)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), + am::commands::Command::SOURCE_SDL)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataNoDefault_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title(smart_objects::SmartType_Null); + EXPECT_CALL(*mock_app_, vr_help_title()) + .WillOnce(Return(&vr_help_title)) + .WillOnce(Return(&vr_help_title)); + + CommandsMap commands_map; + DataAccessor accessor(commands_map, lock_); + EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); + const CustomString name("name"); + EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); + EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)); + EXPECT_CALL(*mock_app_, app_id()); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataDefaultCreated_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title(smart_objects::SmartType_Null); + EXPECT_CALL(*mock_app_, vr_help_title()) + .Times(2) + .WillRepeatedly(Return(&vr_help_title)); + + CommandsMap commands_map; + SmartObject command_text(smart_objects::SmartType_Map); + commands_map[0] = &command_text; + (*commands_map[0])[am::strings::vr_commands] = SmartObject("one"); + DataAccessor accessor(commands_map, lock_); + EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); + EXPECT_CALL(*mock_app_, set_vr_help(_)); + const CustomString name("name"); + EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); + EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); + SmartObject vr_help_array(smart_objects::SmartType_Array); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataFromSynonyms_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title(smart_objects::SmartType_Null); + EXPECT_CALL(*mock_app_, vr_help_title()) + .Times(2) + .WillRepeatedly(Return(&vr_help_title)); + + CommandsMap commands_map; + DataAccessor accessor(commands_map, lock_); + EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); + SmartObject vr_help_array(smart_objects::SmartType_Array); + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + SmartObject vr_synonyms(smart_objects::SmartType_Array); + vr_synonyms[0] = vr_help_array; + const CustomString name("name"); + EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); + EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title("title"); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyHelp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title("title"); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)).Times(0); + EXPECT_CALL(*mock_app_, timeout_prompt()).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + SmartObject vr_help_title("title"); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, set_help_prompt(_)).Times(0); + EXPECT_CALL(*mock_app_, help_prompt()).Times(0); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSIncorrectSyntax_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One\\n"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidHelpPromptText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = + "invalid help prompt text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidVrHelpText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help(smart_objects::SmartType_Array); + vr_help[0][am::strings::text] = + "invalid vr_help text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; + + ExpectVerifyImageVrHelpSuccess(vr_help); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidImageValue_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help(smart_objects::SmartType_Array); + vr_help[0][am::strings::text] = "vr_help"; + vr_help[0][am::strings::image][am::strings::value] = + "invalid value text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; + + ExpectVerifyImageVrHelpSuccess(vr_help); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuIcon_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject menu_icon(smart_objects::SmartType_Array); + menu_icon[am::strings::value] = + "invalid menu icon text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::menu_icon] = menu_icon; + + ExpectVerifyImageSuccess(menu_icon); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuTitle_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject menu_title(smart_objects::SmartType_Array); + menu_title = "invalid menu title text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::menu_title] = menu_title; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, + Run_InvalidLimitedCharacterList_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject limited_character_list(smart_objects::SmartType_Array); + limited_character_list[0] = + "invalid limited character list text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::keyboard_properties] + [am::strings::limited_character_list] = limited_character_list; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, + Run_InvalidAutoCompleteText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject auto_complete_text(smart_objects::SmartType_Array); + auto_complete_text = + "invalid auto completetext with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::keyboard_properties] + [am::strings::auto_complete_text] = auto_complete_text; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoData_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + ExpectVerifyImageVrHelpUnsuccess(); + + EmptyExpectationsSetupHelper(); + + SharedPtr command( + CreateCommand(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_PendingRequest_UNSUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + SharedPtr command( + CreateCommand(msg)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndSuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + SharedPtr command( + CreateCommand(msg)); + OnEventUISetupHelper(msg, command); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndWarningResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + SharedPtr command( + CreateCommand(msg)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + OnEventUISetupHelper(msg, command); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + OnEventUISetupHelper(msg, command); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(MockAppPtr())); + + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidEventID_Canceled) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)).Times(0); + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + Event event(hmi_apis::FunctionID::TTS_Stopped); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_TTSAndSuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + OnEventTTSSetupHelper(msg, command); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_TTSAndWarningsResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + const hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + SharedPtr command( + CreateCommand(msg)); + + OnEventTTSSetupHelper(msg, command); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::WARNINGS)); +} + +} // namespace set_global_properties_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc new file mode 100644 index 0000000000..f96e8c3efa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc @@ -0,0 +1,356 @@ +/* + * Copyright (c) 2016, 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 "mobile/set_media_clock_timer_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_media_clock_timer_request { + +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SetMediaClockRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace UpdateMode = mobile_apis::UpdateMode; + +typedef SharedPtr SetMediaClockRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 2u; +const uint32_t kAppID = 2u; +const uint32_t kHours = 2u; +const uint32_t kMinutes = 26u; +const uint32_t kSeconds = 1u; +} // namespace + +class SetMediaClockRequestTest + : public CommandRequestTest { + public: + SetMediaClockRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + return msg; + } + + void ExpectationsSetupHelper(bool is_media) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(is_media)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(SetMediaClockRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + utils::SharedPtr command = + CreateCommand(msg); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*ev_msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); + event.set_smart_object(*ev_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountUp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTUP; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = + kSeconds; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountDown_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::seconds] = kSeconds; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountUpWrongTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTUP; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::seconds] = kSeconds; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + + SharedPtr command( + CreateCommand(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountDownWrongTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = + kSeconds; + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NoStartTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + + SharedPtr command( + CreateCommand(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NoUpdateMode_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NotMediaApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command( + CreateCommand(msg)); + + ExpectationsSetupHelper(false); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command( + CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app_, is_media_application()).Times(0); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, OnEvent_Success) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Null); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); + event.set_smart_object(*msg); + SharedPtr command( + CreateCommand(msg)); + command->on_event(event); +} + +TEST_F(SetMediaClockRequestTest, OnEvent_Canceled) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command( + CreateCommand(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg); + + command->on_event(event); +} + +} // namespace set_media_clock_timer_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/show_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc new file mode 100644 index 0000000000..88dee7e474 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc @@ -0,0 +1,921 @@ +/* + * Copyright (c) 2016, 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 "mobile/show_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace show_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::ShowRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using test::components::policy_test::MockPolicyHandlerInterface; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kFunctionID = 3u; +} // namespace + +class ShowRequestTest : public CommandRequestTest { + public: + ShowRequestTest() { + mock_app_ = CreateMockApp(); + } + sync_primitives::Lock lock_; + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + return msg; + } + + void TestSetupHelper(MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + msg_params[field] = text_field_; + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params.erase(field); + msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_name] = + static_cast(field_name); + msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_text] = + text_field_; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + } + + void TestSetupHelperWrongSyntax( + MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + msg_params[field] = text_field_; + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + } + + void TestSetupHelperWithMetadata( + MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field, + size_t num_tags, + int32_t* field_tags, + bool set_field_text = true) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + if (set_field_text) { + msg_params[field] = text_field_; + } + msg_params[am::strings::metadata_tags][field] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + for (size_t i = 0; i < num_tags; ++i) { + const int32_t current_tag = field_tags[i]; + msg_params[am::strings::metadata_tags][field][i] = current_tag; + } + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_EQ((*msg)[am::strings::msg_params], msg_params); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params.erase(field); + msg_params.erase(am::strings::metadata_tags); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + if (set_field_text) { + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_name] = + static_cast(field_name); + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_text] = text_field_; + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_types] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + for (size_t i = 0; i < num_tags; ++i) { + const int32_t current_tag = field_tags[i]; + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_types][i] = current_tag; + } + } + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + } + + MockAppPtr mock_app_; + std::string text_field_; +}; + +TEST_F(ShowRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = 10u; + (*msg_vr)[am::strings::msg_params][am::strings::menu_params] + [am::strings::menu_name] = "menu_name"; + + utils::SharedPtr command = CreateCommand(msg_vr); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*vr_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*vr_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*vr_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = "Soft_Buttons"; + (*msg)[am::strings::msg_params] = msg_params; + SmartObject creation_msg_params(msg_params); + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL( + mock_message_helper_, + SubscribeApplicationToSoftButton(creation_msg_params, _, kFunctionID)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SoftButtonNotExists_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = ""; + (*msg)[am::strings::msg_params] = msg_params; + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(*mock_app_, UnsubscribeFromSoftButtons(kFunctionID)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = "Soft_Buttons"; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) + .WillOnce(Return(mobile_apis::Result::ABORTED)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)) + .Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::ABORTED)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "\\n"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::ABORTED)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = ""; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_1"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_1\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_2"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_2\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_3"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_3\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_4"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_4\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MultipleMetadataTags) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 5; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaTitle, + hmi_apis::Common_MetadataType::mediaArtist, + hmi_apis::Common_MetadataType::rating, + hmi_apis::Common_MetadataType::humidity, + hmi_apis::Common_MetadataType::currentTemperature}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_2"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_3"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_4"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags, + false); + command->Run(); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*ev_msg)[am::strings::msg_params][am::strings::info] = ""; + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*ev_msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(mobile_apis::Result::WARNINGS)); +} + +TEST_F(ShowRequestTest, Run_MediaClock_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Media_Clock"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mediaClock, + am::strings::media_clock); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaClock_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Media_Clock\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mediaClock, + am::strings::media_clock); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaTrack_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Media_Track"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mediaTrack, + am::strings::media_track); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaTrack_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Media_Track\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mediaTrack, + am::strings::media_track); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_StatusBar_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Status_Bar"; + TestSetupHelper( + msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_StatusBar_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + SharedPtr command(CreateCommand(msg)); + + text_field_ = "Status_Bar\\n"; + TestSetupHelperWrongSyntax( + msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Alignment_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::alignment] = "Alignment"; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_CustomPresets_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject custom_presets(smart_objects::SmartType_Array); + custom_presets[0] = "Custom_Presets"; + msg_params[am::strings::custom_presets] = custom_presets; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_CustomPresets_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject custom_presets(smart_objects::SmartType_Array); + custom_presets[0] = "Custom_Presets\\t"; + msg_params[am::strings::custom_presets] = custom_presets; + (*msg)[am::strings::msg_params] = msg_params; + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_EmptyParams_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SharedPtr command(CreateCommand(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + SharedPtr command(CreateCommand(msg)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), _)); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, OnEvent_WarningsResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::message] = "Response Info"; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + SharedPtr command(CreateCommand(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, OnEvent_WrongFunctionID_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::SUCCESS; + + SharedPtr command(CreateCommand(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg); + + command->on_event(event); +} + +} // namespace show_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc new file mode 100644 index 0000000000..032da752b4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2016, 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/smart_object_keys.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "mobile/on_app_interface_unregistered_notification.h" +#include "mobile/on_audio_pass_thru_notification.h" +#include "mobile/on_driver_distraction_notification.h" +#include "mobile/on_language_change_notification.h" +#include "mobile/on_permissions_change_notification.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace simple_notification_commands_test { + +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::_; +using ::testing::Types; +using ::testing::Return; + +template +class MobileNotificationCommandsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +typedef Types + NotificationCommandsList; + +MATCHER(CheckNotificationMessage, "") { + return (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_ && + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_ && + (*arg)[am::strings::params][am::strings::message_type].asInt() == + application_manager::MessageType::kNotification; +} + +TYPED_TEST_CASE(MobileNotificationCommandsTest, NotificationCommandsList); + +TYPED_TEST(MobileNotificationCommandsTest, Run_SendMessageToMobile_SUCCESS) { + ::utils::SharedPtr command = + this->template CreateCommand(); + EXPECT_CALL(this->mock_rpc_service_, + SendMessageToMobile(CheckNotificationMessage(), _)); + command->Run(); +} + +} // namespace simple_notification_commands_test +} // 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 new file mode 100644 index 0000000000..28628dd7a4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2016, 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/helpers.h" +#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" +#include "mobile/perform_interaction_response.h" +#include "mobile/perform_audio_pass_thru_response.h" +#include "mobile/set_global_properties_response.h" +#include "mobile/set_media_clock_timer_response.h" +#include "mobile/show_constant_tbt_response.h" +#include "mobile/show_response.h" +#include "mobile/add_command_response.h" +#include "mobile/send_location_response.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/set_display_layout_response.h" +#include "mobile/generic_response.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/scrollable_message_response.h" +#include "mobile/change_registration_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace simple_response_commands_test { + +namespace commands = sdl_rpc_plugin::commands; +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; + +using am::commands::MessageSharedPtr; + +template +class MobileResponseCommandsTest + : public CommandsTest { + public: + typedef Command CommandType; +}; + +typedef Types ResponseCommandsList; + +TYPED_TEST_CASE(MobileResponseCommandsTest, ResponseCommandsList); + +TYPED_TEST(MobileResponseCommandsTest, Run_SendResponseToMobile_SUCCESS) { + ::utils::SharedPtr command = + this->template CreateCommand(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToMobile(NotNull(), _)); + command->Run(); +} + +class GenericResponseFromHMICommandsTest + : public CommandsTest {}; + +MATCHER_P2(CheckMessageParams, success, result, "") { + const bool is_msg_type_correct = + (am::MessageType::kResponse) == + static_cast( + (*arg)[am::strings::params][am::strings::message_type].asInt()); + const bool is_success_correct = + success == (*arg)[am::strings::msg_params][am::strings::success].asBool(); + const bool is_result_code_correct = + result == + static_cast( + (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); + + using namespace helpers; + return Compare( + true, is_msg_type_correct, is_success_correct, is_result_code_correct); +} + +TEST_F(GenericResponseFromHMICommandsTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + + SharedPtr command( + CreateCommand(command_msg)); + + EXPECT_CALL( + this->mock_rpc_service_, + SendMessageToMobile( + CheckMessageParams(false, mobile_apis::Result::INVALID_DATA), false)); + + command->Run(); +} + +class ScrollableMessageResponseTest + : public CommandsTest {}; + +TEST_F(ScrollableMessageResponseTest, Run_SUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + MockAppPtr app(CreateMockApp()); + + SharedPtr command( + CreateCommand(message)); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app)); + EXPECT_CALL(*app, UnsubscribeFromSoftButtons(_)); + command->Run(); +} + +} // namespace simple_response_commands_test +} // 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/slider_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc new file mode 100644 index 0000000000..50bac7655d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc @@ -0,0 +1,342 @@ +/* + * Copyright (c) 2016, 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 "mobile/slider_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace slider_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SliderRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using policy_test::MockPolicyHandlerInterface; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef SharedPtr CommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kDefaultTimeout = 1000u; +const uint32_t kCorrelationId = 2u; +const uint32_t kFunctionId = 3u; +const uint32_t kNumTicks = 2u; +const uint32_t kPositionGreaterTicks = 3u; +const uint32_t kPositionLessTicks = 1u; +} // namespace + +class SliderRequestTest + : public CommandRequestTest { + public: + SliderRequestTest() + : mock_app_(CreateMockApp()) + , msg_(CreateMessage(smart_objects::SmartType_Map)) {} + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void PreConditions() { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::num_ticks] = kNumTicks; + (*msg_)[am::strings::msg_params][am::strings::position] = + kPositionLessTicks; + (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = + "slider_footer1"; + (*msg_)[am::strings::msg_params][am::strings::slider_footer][1] = + "slider_footer2"; + (*msg_)[am::strings::msg_params][am::strings::slider_header] = + "slider_header"; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + sync_primitives::Lock lock_; + + MockAppPtr mock_app_; + MessageSharedPtr msg_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +TEST_F(SliderRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + utils::SharedPtr command = + CreateCommand(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +class CallOnTimeOut { + public: + CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} + + void operator()() { + command_.onTimeOut(); + } + + CommandRequestImpl& command_; +}; + +TEST_F(SliderRequestTest, Init_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + + CommandPtr command(CreateCommand(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(SliderRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + PreConditions(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(ApplicationSharedPtr())); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_PositionGreaterTicks_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::position] = + kPositionGreaterTicks; + + CommandPtr command(CreateCommand(msg_)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_SliderFooterNotEqToNumticks_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_footer][2] = + "slider_footer3"; + CommandPtr command(CreateCommand(msg_)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_InvalidSliderHeader_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_header] = + "invalid_test_with_empty_str\\n"; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_InvalidSliderFooter_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = + "invalid_test_with_empty_str\\n"; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_SUCCESS) { + PreConditions(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Slider))); + + CommandPtr command(CreateCommand(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + CommandPtr command(CreateCommand(msg_)); + EXPECT_TRUE(command->Init()); + + EXPECT_CALL(app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, _)); + + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UI_UnknownEventId_UNSUCCESS) { + PreConditions(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand(msg_)); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UISliderPositionExists_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::TIMED_OUT; + (*msg_)[am::strings::params][am::strings::data] + [am::strings::slider_position] = "position"; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::TIMED_OUT); + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand(msg_)); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UISliderAborted_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand(msg_)); + command->on_event(event); +} + +} // namespace slider_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc new file mode 100644 index 0000000000..79f2d08c2d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc @@ -0,0 +1,407 @@ +/* + + Copyright (c) 2016, 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 "gtest/gtest.h" +#include "mobile/speak_request.h" +#include "utils/shared_ptr.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "utils/shared_ptr.h" +#include "utils/helpers.h" +#include "utils/make_shared.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/application.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace speak_request { + +namespace am = application_manager; +namespace mobile_result = mobile_apis::Result; +namespace hmi_response = ::application_manager::hmi_response; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::utils::SharedPtr; +using ::testing::Return; +using ::testing::ReturnRef; +using sdl_rpc_plugin::commands::SpeakRequest; +using ::test::components::application_manager_test::MockApplication; + +typedef SharedPtr CommandPtr; + +namespace { +const uint32_t kAppId = 10u; +const uint32_t kConnectionKey = 5u; +} + +class SpeakRequestTest : public CommandRequestTest { + public: + SpeakRequestTest() + : request_(CreateMessage(smart_objects::SmartType_Map)) + , response_(CreateMessage(smart_objects::SmartType_Map)) + , app_(CreateMockApp()) {} + + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success) { + utils::SharedPtr command = + CreateCommand(request_); + + (*response_)[strings::params][hmi_response::code] = hmi_response; + (*response_)[strings::msg_params] = 0; + + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + success); + EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] + .asInt(), + static_cast(mobile_response)); + } + + MessageSharedPtr request_; + MessageSharedPtr response_; + MockAppPtr app_; +}; + +TEST_F(SpeakRequestTest, OnEvent_SUCCESS_Expect_true) { + utils::SharedPtr command = + CreateCommand(request_); + + (*response_)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response_)[strings::msg_params] = 0; + + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + true); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast(mobile_apis::Result::SUCCESS)); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + true); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_AVAILABLE, + false); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_RESPONSE, + true); +} + +TEST_F(SpeakRequestTest, Run_ApplicationIsNotRegistered) { + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithWhiteSpace_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = " "; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar1_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\\t"; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar2_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\\n"; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar3_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\tdf"; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar4_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\n rer"; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectCharInfirstPlace_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "\n"; + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithEmptyString_Success) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = ""; + CommandPtr command(CreateCommand(request_)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgCorrect_Success) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "asda"; + CommandPtr command(CreateCommand(request_)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); + + command->Run(); +} + +TEST_F(SpeakRequestTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + CommandPtr command(CreateCommand()); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_Speak_SUCCESS) { + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "1234"; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_SpeakWithWarning_WarningWithSuccess) { + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::WARNINGS; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "asda"; + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::WARNINGS), _)); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_OnResetTimeout_UpdateTimeout) { + Event event(Event::EventID::TTS_OnResetTimeout); + (*request_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*request_)[am::strings::params][am::strings::correlation_id] = kAppId; + CommandPtr command(CreateCommand(request_)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey, kAppId, _)); + + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) { + const hmi_apis::Common_Result::eType hmi_result = + hmi_apis::Common_Result::SUCCESS; + + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "text"; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand(request_)); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + command->on_event(event); +} + +} // namespace speak_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace component +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc new file mode 100644 index 0000000000..94c08287da --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2016, 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_hmi_capabilities.h" +#include "mobile/subscribe_button_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace subscribe_button_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SubscribeButtonRequest; +using am::commands::MessageSharedPtr; + +typedef SharedPtr CommandPtr; + +class SubscribeButtonRequestTest + : public CommandRequestTest { + public: + typedef TypeIf, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; +}; + +typedef SubscribeButtonRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(SubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr 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(SubscribeButtonRequestTest, Run_SubscriptionNotAllowed_UNSUCCESS) { + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = + mobile_apis::ButtonName::SEEKLEFT; + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(false)); + + 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(SubscribeButtonRequestTest, Run_UiIsNotSupported_UNSUCCESS) { + CommandPtr command(CreateCommand()); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(false)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) { + const mobile_apis::ButtonName::eType kButtonName = + mobile_apis::ButtonName::SEEKLEFT; + + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; + + ON_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillByDefault(Return(button_caps_ptr.get())); + + ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(true)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::IGNORED, + static_cast( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) { + const mobile_apis::ButtonName::eType kButtonName = + mobile_apis::ButtonName::SEEKLEFT; + + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; + CommandPtr command(CreateCommand(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; + + ON_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillByDefault(Return(button_caps_ptr.get())); + + ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); + + MessageSharedPtr hmi_result_msg; + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); + + MessageSharedPtr mobile_result_msg; + EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + static_cast( + (*hmi_result_msg)[am::strings::params][am::strings::function_id] + .asInt())); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast( + (*mobile_result_msg)[am::strings::msg_params] + [am::strings::result_code].asInt())); +} + +} // namespace subscribe_button_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/subscribe_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc new file mode 100644 index 0000000000..aa353d2f39 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016, 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 "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_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "mobile/subscribe_way_points_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace subscribe_way_points_request { + +using ::testing::_; +using ::testing::A; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +using ::testing::InSequence; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SubscribeWayPointsRequest; +using am::commands::MessageSharedPtr; + +typedef SharedPtr CommandPtr; + +class SubscribeWayPointsRequestTest + : public CommandRequestTest {}; + +TEST_F(SubscribeWayPointsRequestTest, Run_SUCCESS) { + CommandPtr command(CreateCommand()); + MockAppPtr app(CreateMockApp()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(A())) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(true)); + + { + InSequence dummy; + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A())); + EXPECT_CALL(*app, UpdateHash()); + } + + command->Init(); + MessageSharedPtr mobile_result_msg( + CatchMobileCommandResult(CallRun(*command))); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast( + (*mobile_result_msg)[am::strings::msg_params] + [am::strings::result_code].asInt())); +} + +TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { + CommandPtr command(CreateCommand()); + MockAppPtr app(CreateMockApp()); + Event event(hmi_apis::FunctionID::Navigation_SubscribeWayPoints); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*event_msg)[am::strings::params][am::hmi_response::code] = result_code; + (*event_msg)[am::strings::msg_params] = 0; + + event.set_smart_object(*event_msg); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + { + InSequence dummy; + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A())); + EXPECT_CALL(mock_message_helper_, HMIToMobileResult(result_code)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*app, UpdateHash()); + } + + command->Init(); + command->on_event(event); +} + +} // namespace subscribe_way_points_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/system_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc new file mode 100644 index 0000000000..3a3c549ee0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc @@ -0,0 +1,237 @@ +/* + * Copyright (c) 2017, 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/system_request.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace system_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SystemRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockHmiInterfaces; +using am::event_engine::Event; +using am::MessageType; +using policy_test::MockPolicyHandlerInterface; +using ::utils::SharedPtr; +using ::testing::_; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SaveArg; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kAppPolicyId = "fake-app-id"; +const uint32_t kDefaultTimeout = 1000u; +const std::string kAppFolderName = "fake-app-name"; +const std::string kAppStorageFolder = "fake-storage"; +const std::string kSystemFilesPath = "/fake/system/files"; +const std::string kFileName = "Filename"; +const uint32_t kHmiAppId = 3u; +} // namespace + +class SystemRequestTest + : public CommandRequestTest { + public: + SystemRequestTest() : mock_app_(CreateMockApp()) {} + + protected: + MessageSharedPtr CreateIVSUMessage() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::HTTP; + (*msg)[am::strings::msg_params][am::strings::file_name] = kFileName; + return msg; + } + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kAppPolicyId)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kAppFolderName)); + ON_CALL(*mock_app_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + + ON_CALL(app_mngr_settings_, system_files_path()) + .WillByDefault(ReturnRef(kSystemFilesPath)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kAppStorageFolder)); + + ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) + .WillByDefault(Return(true)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(SystemRequestTest, Run_HTTP_FileName_no_binary_data_REJECTED) { + PreConditions(); + MessageSharedPtr msg = CreateIVSUMessage(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); + + SharedPtr command(CreateCommand(msg)); + command->Run(); +} + +TEST_F(SystemRequestTest, + Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendHMIRequest) { + MessageSharedPtr msg = CreateIVSUMessage(); + + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::OEM_SPECIFIC; + + const std::string request_subtype = "fakeSubType"; + (*msg)[am::strings::msg_params][am::strings::request_subtype] = + request_subtype; + + const std::vector binary_data = {1u, 2u}; + (*msg)[am::strings::params][am::strings::binary_data] = binary_data; + + PreConditions(); + + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kAppPolicyId, + mobile_apis::RequestType::OEM_SPECIFIC)) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_policy_handler_, + IsRequestSubTypeAllowed(kAppPolicyId, request_subtype)) + .WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data, kSystemFilesPath, kFileName, 0u)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObjectSPtr result; + EXPECT_CALL(app_mngr_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); + + SharedPtr command(CreateCommand(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_EQ(MessageType::kRequest, + (*result)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + mobile_apis::RequestType::OEM_SPECIFIC, + (*result)[am::strings::msg_params][am::strings::request_type].asInt()); + EXPECT_EQ( + request_subtype, + (*msg)[am::strings::msg_params][am::strings::request_subtype].asString()); +} + +TEST_F( + SystemRequestTest, + Run_RequestTypeAllowedAndRequestSubTypeDisallowed_SendDisallowedResponse) { + MessageSharedPtr msg = CreateIVSUMessage(); + + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::OEM_SPECIFIC; + + const std::string request_subtype = "fakeSubType2"; + (*msg)[am::strings::msg_params][am::strings::request_subtype] = + request_subtype; + + PreConditions(); + + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kAppPolicyId, + mobile_apis::RequestType::OEM_SPECIFIC)) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_policy_handler_, + IsRequestSubTypeAllowed(kAppPolicyId, request_subtype)) + .WillOnce(Return(false)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); + EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); + + SharedPtr command(CreateCommand(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +TEST_F(SystemRequestTest, Run_RequestTypeDisallowed_SendDisallowedResponse) { + MessageSharedPtr msg = CreateIVSUMessage(); + + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::OEM_SPECIFIC; + + PreConditions(); + + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kAppPolicyId, + mobile_apis::RequestType::OEM_SPECIFIC)) + .WillOnce(Return(false)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); + EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); + + SharedPtr command(CreateCommand(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace system_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/unregister_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc new file mode 100644 index 0000000000..40ccd2ebca --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2016, 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/unregister_app_interface_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unregister_app_interface_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; + +using sdl_rpc_plugin::commands::UnregisterAppInterfaceRequest; +using am::commands::MessageSharedPtr; + +typedef ::utils::SharedPtr CommandPtr; + +class UnregisterAppInterfaceRequestTest + : public CommandRequestTest {}; + +TEST_F(UnregisterAppInterfaceRequestTest, 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(UnregisterAppInterfaceRequestTest, Run_SUCCESS) { + const uint32_t kConnectionKey = 1u; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + const mobile_apis::AppInterfaceUnregisteredReason::eType kUnregisterReason = + mobile_apis::AppInterfaceUnregisteredReason::INVALID_ENUM; + + MessageSharedPtr dummy_msg(CreateMessage()); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kConnectionKey, kUnregisterReason)) + .WillOnce(Return(dummy_msg)); + { + ::testing::InSequence sequence; + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(dummy_msg, _)); + + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kConnectionKey, mobile_apis::Result::SUCCESS, _, _)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + } + + command->Run(); +} + +} // namespace unregister_app_interface_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_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc new file mode 100644 index 0000000000..439e94b94f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc @@ -0,0 +1,150 @@ +#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 "application_manager/mock_hmi_capabilities.h" +#include "mobile/unsubscribe_button_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unsubscribe_button_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; + +using sdl_rpc_plugin::commands::UnsubscribeButtonRequest; +using am::commands::MessageSharedPtr; + +typedef ::utils::SharedPtr CommandPtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const mobile_apis::ButtonName::eType kButtonId = mobile_apis::ButtonName::OK; +} // namespace + +class UnsubscribeButtonRequestTest + : public CommandRequestTest { + public: + typedef TypeIf, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; +}; + +TEST_F(UnsubscribeButtonRequestTest, 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(UnsubscribeButtonRequestTest, + Run_UnsubscribeNotSubscribedButton_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] = kButtonId; + + CommandPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) + .WillOnce(Return(false)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeButtonRequestTest, + Run_UnsubscribeNotAllowedByHmiCapabilities_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] = kButtonId; + CommandPtr command(CreateCommand(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::UNSUPPORTED_RESOURCE), _)); + + command->Run(); +} + +TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) { + 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] = kButtonId; + + CommandPtr command(CreateCommand(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + EXPECT_CALL(*mock_app, UpdateHash()); + command->Init(); + command->Run(); +} + +} // namespace unsubscribe_button_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_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc new file mode 100644 index 0000000000..d3a9f52f99 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_request_test.cc @@ -0,0 +1,288 @@ +/* + Copyright (c) 2016, 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 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 new file mode 100644 index 0000000000..284022f2e7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_vehicle_response_test.cc @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016, 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/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc new file mode 100644 index 0000000000..465d67d427 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2016, 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 "mobile/unsubscribe_way_points_request.h" +#include "interfaces/MOBILE_API.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 "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 unsubscribe_way_points_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; +using ::testing::Return; + +using sdl_rpc_plugin::commands::UnSubscribeWayPointsRequest; +using am::commands::MessageSharedPtr; + +namespace { +const uint32_t kConnectionKey = 3u; +const uint32_t kAppId = 5u; +} // namespace + +class UnSubscribeWayPointsRequestTest + : public CommandRequestTest { + public: + UnSubscribeWayPointsRequestTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand(command_msg_)) { + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + } + + MessageSharedPtr command_msg_; + ::utils::SharedPtr command_; +}; + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_AppIsNotSubscribedForWayPoints_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher(mock_app))) + .WillOnce(Return(false)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher(mock_app))) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints))); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + command_->on_event(event); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + OnEvent_ReceivedNavigationUnSubscribeWayPointsEvent_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + 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_result::SUCCESS; + Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); + event.set_smart_object(*event_msg); + + EXPECT_CALL(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher(mock_app))); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command_->on_event(event); +} + +} // namespace unsubscribe_way_points_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_way_points_request_test.cc.autosave b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc.autosave new file mode 100644 index 0000000000..5e7948b92a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc.autosave @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2016, 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 "mobile/unsubscribe_way_points_request.h" +#include "interfaces/MOBILE_API.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 "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 unsubscribe_way_points_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; +using ::testing::Return; + +using sdl_rpc_plugin::commands::UnSubscribeWayPointsRequest; +using am::commands::MessageSharedPtr; + +namespace { +const uint32_t kConnectionKey = 3u; +const uint32_t kAppId = 5u; +} // namespace + +class UnSubscribeWayPointsRequestTest + : public CommandRequestTest { + public: + UnSubscribeWayPointsRequestTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand(command_msg_)) { + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + } + + MessageSharedPtr command_msg_; + ::utils::SharedPtr command_; +}; + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_AppIsNotSubscribedForWayPoints_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher(mock_app))) + .WillOnce(Return(false)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher(mock_app))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints))); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + command_->on_event(event); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + OnEvent_ReceivedNavigationUnSubscribeWayPointsEvent_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + 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_result::SUCCESS; + Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); + event.set_smart_object(*event_msg); + + EXPECT_CALL(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher(mock_app))); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command_->on_event(event); +} + +} // namespace unsubscribe_way_points_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/update_turn_list_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc new file mode 100644 index 0000000000..2cf943bcfe --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc @@ -0,0 +1,292 @@ +/* + * Copyright (c) 2016, 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 "mobile/update_turn_list_request.h" +#include "interfaces/MOBILE_API.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 "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.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 update_turn_list_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::Ref; +using ::testing::Eq; + +using sdl_rpc_plugin::commands::UpdateTurnListRequest; +using am::commands::MessageSharedPtr; +using application_manager_test::MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 3u; +const hmi_apis::FunctionID::eType kFunctionId = + hmi_apis::FunctionID::Buttons_OnButtonEvent; +const uint32_t kAppId = 5u; +} // namespace + +class UpdateTurnListRequestTest + : public CommandRequestTest { + public: + UpdateTurnListRequestTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand(command_msg_)) { + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg_)[am::strings::params][am::strings::function_id] = + kFunctionId; + } + + MessageSharedPtr command_msg_; + ::utils::SharedPtr command_; +}; + +TEST_F(UpdateTurnListRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_InvalidNavigationText_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "invalid_navigation_text\t\n"; + + 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(UpdateTurnListRequestTest, Run_InvalidTurnIcon_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "valid_navigation_text"; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "invalid_turn_icon\t\n"; + + 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(UpdateTurnListRequestTest, + Run_ProcessSoftButtonsNotSucceeded_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "valid_navigation_text"; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "valid_turn_icon"; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + const mobile_result::eType kExpectedResult = mobile_result::INVALID_ENUM; + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(kExpectedResult)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(kExpectedResult), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_NoTurnList_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_ValidTurnList_SUCCESS) { + const std::string kNavigationText = "valid_navigation_text"; + + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = kNavigationText; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "valid_turn_icon"; + (*command_msg_)[am::strings::msg_params][am::strings::soft_buttons] = 0; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon], + Eq(mock_app), + Ref(app_mngr_))).WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton(_, _, kFunctionId)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); + ASSERT_TRUE(result_msg); + EXPECT_EQ( + hmi_apis::FunctionID::Navigation_UpdateTurnList, + (*result_msg)[am::strings::params][am::strings::function_id].asInt()); + + ASSERT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + .keyExists(am::hmi_request::navi_text)); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_name)); + EXPECT_EQ( + hmi_apis::Common_TextFieldName::turnText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_name] + .asInt()); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_text)); + EXPECT_EQ( + kNavigationText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_text] + .asString()); +} + +TEST_F(UpdateTurnListRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command_->on_event(event); +} + +TEST_F(UpdateTurnListRequestTest, OnEvent_UnsupportedResource_SUCCESS) { + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + const mobile_result::eType mobile_response_code = + mobile_result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; + (*event_msg)[am::strings::msg_params] = 0; + + Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + command_->on_event(event); +} + +TEST_F(UpdateTurnListRequestTest, + OnEvent_ReceivedNavigationUpdateTurnListEvent_SUCCESS) { + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::SUCCESS; + const mobile_result::eType mobile_response_code = mobile_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 event(hmi_apis::FunctionID::Navigation_UpdateTurnList); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + command_->on_event(event); +} + +} // namespace update_turn_list_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/src/commands/notification_from_hmi.cc b/src/components/application_manager/src/commands/notification_from_hmi.cc new file mode 100644 index 0000000000..cdb938d5d7 --- /dev/null +++ b/src/components/application_manager/src/commands/notification_from_hmi.cc @@ -0,0 +1,111 @@ +/* + Copyright (c) 2013, 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 "application_manager/commands/notification_from_hmi.h" +#include "application_manager/application_manager.h" +#include "application_manager/rpc_service.h" +#include "smart_objects/smart_object.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +NotificationFromHMI::NotificationFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : CommandImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) { + // Replace HMI app id with Mobile connection id + ReplaceHMIWithMobileAppId(*message); +} + +NotificationFromHMI::~NotificationFromHMI() {} + +bool NotificationFromHMI::Init() { + return true; +} + +bool NotificationFromHMI::CleanUp() { + return true; +} + +void NotificationFromHMI::Run() {} + +void NotificationFromHMI::SendNotificationToMobile( + const application_manager::commands::MessageSharedPtr& message) { + (*message)[strings::params][strings::message_type] = + static_cast(application_manager::MessageType::kNotification); + rpc_service_.ManageMobileCommand(message, SOURCE_SDL); +} + +void NotificationFromHMI::CreateHMIRequest( + const hmi_apis::FunctionID::eType& function_id, + const smart_objects::SmartObject& msg_params) const { + smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; + if (!result) { + LOG4CXX_ERROR(logger_, "Memory allocation failed."); + return; + } + + // get hmi correlation id for chaining further request from this object + const uint32_t hmi_correlation_id_ = + application_manager_.GetNextHMICorrelationID(); + + NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; + request[strings::params][strings::message_type] = + static_cast(application_manager::MessageType::kRequest); + request[strings::params][strings::function_id] = + static_cast(function_id); + request[strings::params][strings::correlation_id] = hmi_correlation_id_; + request[strings::params][strings::protocol_version] = + CommandImpl::protocol_version_; + request[strings::params][strings::protocol_type] = + CommandImpl::hmi_protocol_type_; + + request[strings::msg_params] = msg_params; + + if (!rpc_service_.ManageHMICommand(result)) { + LOG4CXX_ERROR(logger_, "Unable to send request"); + return; + } +} + +} // namespace commands + +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/notification_to_hmi.cc b/src/components/application_manager/src/commands/notification_to_hmi.cc new file mode 100644 index 0000000000..0c4e64ebdd --- /dev/null +++ b/src/components/application_manager/src/commands/notification_to_hmi.cc @@ -0,0 +1,75 @@ +/* + Copyright (c) 2013, 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 "application_manager/commands/notification_to_hmi.h" +#include "application_manager/application_manager.h" +#include "application_manager/rpc_service.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +NotificationToHMI::NotificationToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : CommandImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +NotificationToHMI::~NotificationToHMI() {} + +bool NotificationToHMI::Init() { + // Replace Mobile connection id with HMI app id + return ReplaceMobileWithHMIAppId(*message_); +} + +bool NotificationToHMI::CleanUp() { + return true; +} + +void NotificationToHMI::Run() {} + +void NotificationToHMI::SendNotification() { + (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; + (*message_)[strings::params][strings::protocol_version] = protocol_version_; + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands + +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/response_from_hmi.cc b/src/components/application_manager/src/commands/response_from_hmi.cc new file mode 100644 index 0000000000..c158052b89 --- /dev/null +++ b/src/components/application_manager/src/commands/response_from_hmi.cc @@ -0,0 +1,116 @@ +/* + Copyright (c) 2013, 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 "application_manager/commands/response_from_hmi.h" +#include "application_manager/rpc_service.h" +#include "smart_objects/smart_object.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +ResponseFromHMI::ResponseFromHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : CommandImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) { + // If it is error response, shift info + if ((*message)[strings::params].keyExists(hmi_response::message)) { + (*message)[strings::msg_params][strings::info] = + (*message)[strings::params][hmi_response::message]; + } + + // Replace HMI app id with Mobile connection id + ReplaceHMIWithMobileAppId(*message); +} + +ResponseFromHMI::~ResponseFromHMI() {} + +bool ResponseFromHMI::Init() { + return true; +} + +bool ResponseFromHMI::CleanUp() { + return true; +} + +void ResponseFromHMI::Run() {} + +void ResponseFromHMI::SendResponseToMobile( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager) { + (*message)[strings::params][strings::message_type] = MessageType::kResponse; + + rpc_service_.ManageMobileCommand(message, SOURCE_SDL); +} + +void ResponseFromHMI::CreateHMIRequest( + const hmi_apis::FunctionID::eType& function_id, + const smart_objects::SmartObject& msg_params) const { + smart_objects::SmartObjectSPtr result = new smart_objects::SmartObject; + + if (!result) { + LOG4CXX_ERROR(logger_, "Memory allocation failed."); + return; + } + + // get hmi correlation id for chaining further request from this object + const uint32_t hmi_correlation_id_ = + application_manager_.GetNextHMICorrelationID(); + + NsSmartDeviceLink::NsSmartObjects::SmartObject& request = *result; + request[strings::params][strings::message_type] = MessageType::kRequest; + request[strings::params][strings::function_id] = function_id; + request[strings::params][strings::correlation_id] = hmi_correlation_id_; + request[strings::params][strings::protocol_version] = + CommandImpl::protocol_version_; + request[strings::params][strings::protocol_type] = + CommandImpl::hmi_protocol_type_; + + request[strings::msg_params] = msg_params; + + if (!rpc_service_.ManageHMICommand(result)) { + LOG4CXX_ERROR(logger_, "Unable to send request"); + return; + } +} + +} // namespace commands + +} // namespace application_manager diff --git a/src/components/application_manager/src/commands/response_to_hmi.cc b/src/components/application_manager/src/commands/response_to_hmi.cc new file mode 100644 index 0000000000..7aeddf28e5 --- /dev/null +++ b/src/components/application_manager/src/commands/response_to_hmi.cc @@ -0,0 +1,73 @@ +/* + Copyright (c) 2013, 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 "application_manager/commands/response_to_hmi.h" +#include "application_manager/application_manager.h" +#include "application_manager/rpc_service.h" + +namespace sdl_rpc_plugin { +using namespace application_manager; + +namespace commands { + +ResponseToHMI::ResponseToHMI( + const application_manager::commands::MessageSharedPtr& message, + ApplicationManager& application_manager, + rpc_service::RPCService& rpc_service, + HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handle) + : CommandImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handle) {} + +ResponseToHMI::~ResponseToHMI() {} + +bool ResponseToHMI::Init() { + // Replace Mobile connection id with HMI app id + return ReplaceMobileWithHMIAppId(*message_); +} + +bool ResponseToHMI::CleanUp() { + return true; +} + +void ResponseToHMI::Run() { + (*message_)[strings::params][strings::protocol_type] = hmi_protocol_type_; + (*message_)[strings::params][strings::protocol_version] = protocol_version_; + + rpc_service_.SendMessageToHMI(message_); +} + +} // namespace commands +} // namespace application_manager diff --git a/src/components/application_manager/src/rpc_service_impl.cc b/src/components/application_manager/src/rpc_service_impl.cc index 62e7f5775f..fad844aaa3 100644 --- a/src/components/application_manager/src/rpc_service_impl.cc +++ b/src/components/application_manager/src/rpc_service_impl.cc @@ -126,11 +126,7 @@ bool RPCServiceImpl::ManageMobileCommand( LOG4CXX_WARN(logger_, "Filed to find plugin : " << plugin.error()); return false; } -<<<<<<< 7ee50284ab58ece63d8b7fdc3eb48b0effa11858 application_manager::CommandFactory& factory = (*plugin).GetCommandFactory(); -======= - auto factory = plugin->GetCommandFactory(); ->>>>>>> Remove commands includes auto command = factory.CreateCommand(message, source); if (!command) { @@ -263,7 +259,6 @@ bool RPCServiceImpl::ManageHMICommand( MessageHelper::PrintSmartObject(*message); const int32_t function_id = (*(message.get()))[strings::params][strings::function_id].asInt(); -<<<<<<< 7ee50284ab58ece63d8b7fdc3eb48b0effa11858 auto plugin = app_manager_.GetPluginManager().FindPluginToProcess( function_id, commands::Command::SOURCE_HMI); if (!plugin) { @@ -276,59 +271,42 @@ bool RPCServiceImpl::ManageHMICommand( if (!command) { LOG4CXX_WARN(logger_, "Failed to create command from smart object"); -======= - auto plugin = - app_manager_.GetPluginManager().FindPluginToProcess(function_id, source); - if (!plugin) { - LOG4CXX_WARN(logger_, "Filed to find plugin : " << plugin.error()); ->>>>>>> Remove commands includes return false; } - auto factory = plugin->GetCommandFactory(); - auto command = factory.CreateCommand(message, source); + if ((*message).keyExists(strings::msg_params) && + (*message)[strings::msg_params].keyExists(strings::app_id)) { + const auto connection_key = + (*message)[strings::msg_params][strings::app_id].asUInt(); - message, commands::Command::SOURCE_HMI); - if (!command) { - LOG4CXX_WARN(logger_, "Failed to create command from smart object"); - return false; - } - - if ((*message).keyExists(strings::msg_params) && - (*message)[strings::msg_params].keyExists(strings::app_id)) { - const auto connection_key = - (*message)[strings::msg_params][strings::app_id].asUInt(); - - auto app = - app_manager_.application(static_cast(connection_key)); - if (app && app_manager_.IsAppInReconnectMode(app->policy_app_id())) { - commands_holder_.Suspend( - app, CommandHolder::CommandType::kHmiCommand, message); - return true; - } - } + auto app = app_manager_.application(static_cast(connection_key)); + if (app && app_manager_.IsAppInReconnectMode(app->policy_app_id())) { + commands_holder_.Suspend( + app, CommandHolder::CommandType::kHmiCommand, message); + return true; + } + } - int32_t message_type = - (*(message.get()))[strings::params][strings::message_type].asInt(); + int32_t message_type = + (*(message.get()))[strings::params][strings::message_type].asInt(); - if (kRequest == message_type) { - LOG4CXX_DEBUG(logger_, "ManageHMICommand"); - request_ctrl_.addHMIRequest(command); - } + if (kRequest == message_type) { + LOG4CXX_DEBUG(logger_, "ManageHMICommand"); + request_ctrl_.addHMIRequest(command); + } - if (command->Init()) { - command->Run(); - if (kResponse == message_type) { - const uint32_t correlation_id = - (*(message.get()))[strings::params][strings::correlation_id] - .asUInt(); - const int32_t function_id = - (*(message.get()))[strings::params][strings::function_id].asInt(); - request_ctrl_.OnHMIResponse(correlation_id, function_id); - } - return true; - } - return false; + if (command->Init()) { + command->Run(); + if (kResponse == message_type) { + const uint32_t correlation_id = + (*(message.get()))[strings::params][strings::correlation_id].asUInt(); + const int32_t function_id = + (*(message.get()))[strings::params][strings::function_id].asInt(); + request_ctrl_.OnHMIResponse(correlation_id, function_id); + } + return true; + } + return false; } void RPCServiceImpl::Handle(const impl::MessageToHmi message) { diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index 90059e4d98..2110e68b27 100644 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -70,7 +70,6 @@ set(testSources set(testSourcesMockHmi ${AM_SOURCE_DIR}/src/message_helper/message_helper.cc ${AM_TEST_DIR}/application_manager_impl_mock_hmi_test.cc - ${AM_TEST_DIR}/mock_hmi_command_factory.cc ) if(REMOTE_CONTROL) @@ -134,7 +133,7 @@ set(CMAKE_EXE_LINKER_FLAGS ) create_test("application_manager_test" "${testSources}" "${LIBRARIES}") create_test("application_manager_mock_hmi_test" "${testSourcesMockHmi}" "${LIBRARIES}") -add_dependencies("application_manager_test" libbson) +#add_dependencies("application_manager_test" libbson) create_test("request_controller_test" "${RequestController_SOURCES}" "${LIBRARIES}") diff --git a/src/components/application_manager/test/application_manager_impl_test.cc b/src/components/application_manager/test/application_manager_impl_test.cc index c7bf7139ff..19ba8bbc78 100644 --- a/src/components/application_manager/test/application_manager_impl_test.cc +++ b/src/components/application_manager/test/application_manager_impl_test.cc @@ -99,12 +99,15 @@ const std::string kAppName = "appName"; class ApplicationManagerImplTest : public ::testing::Test { public: ApplicationManagerImplTest() - : mock_storage_( + : app_id_(0u) + , mock_storage_( ::utils::MakeShared >( mock_app_mngr_)) + , mock_rpc_service_(new MockRPCService) , mock_message_helper_( application_manager::MockMessageHelper::message_helper_mock()) - , app_id_(0u) { + + { logger::create_log_message_loop_thread(); Mock::VerifyAndClearExpectations(&mock_message_helper_); } @@ -119,7 +122,7 @@ class ApplicationManagerImplTest : public ::testing::Test { .WillByDefault(DoAll(SetArgPointee<3u>(app_id_), Return(0))); ON_CALL(mock_connection_handler_, get_session_observer()) .WillByDefault(ReturnRef(mock_session_observer_)); - + app_manager_impl_->SetRPCService(mock_rpc_service_); app_manager_impl_->resume_controller().set_resumption_storage( mock_storage_); app_manager_impl_->set_connection_handler(&mock_connection_handler_); @@ -181,17 +184,19 @@ class ApplicationManagerImplTest : public ::testing::Test { SetArgPointee<4u>(connection_type), Return(0))); } - + uint32_t app_id_; NiceMock mock_policy_settings_; utils::SharedPtr > mock_storage_; + + std::unique_ptr mock_rpc_service_; NiceMock mock_connection_handler_; NiceMock mock_session_observer_; NiceMock mock_application_manager_settings_; application_manager_test::MockApplicationManager mock_app_mngr_; std::auto_ptr app_manager_impl_; application_manager::MockMessageHelper* mock_message_helper_; - uint32_t app_id_; + utils::SharedPtr mock_app_ptr_; NiceMock mock_protocol_handler_; }; @@ -200,7 +205,6 @@ TEST_F(ApplicationManagerImplTest, ProcessQueryApp_ExpectSuccess) { using namespace NsSmartDeviceLink::NsSmartObjects; SmartObject app_data; const uint32_t connection_key = 65537u; - app_data[am::json::name] = "application_manager_test"; app_data[am::json::appId] = app_id_; app_data[am::json::android] = "bucket"; diff --git a/src/components/application_manager/test/command_holder_test.cc b/src/components/application_manager/test/command_holder_test.cc index 484af75798..9227fd8fcb 100644 --- a/src/components/application_manager/test/command_holder_test.cc +++ b/src/components/application_manager/test/command_holder_test.cc @@ -68,7 +68,7 @@ class CommandHolderImplTest : public testing::Test { ON_CALL(*mock_app_ptr_, policy_app_id()) .WillByDefault(Return(kPolicyAppId_)); ON_CALL(mock_app_manager_, GetRPCService()) - .WillByDefault(ReturnRef(rpc_service_)); + .WillByDefault(ReturnRef(mock_rpc_service_)); } MockApplicationManager mock_app_manager_; @@ -77,7 +77,7 @@ class CommandHolderImplTest : public testing::Test { const uint32_t kConnectionKey_; utils::SharedPtr cmd_ptr_; utils::SharedPtr mock_app_ptr_; - application_manager_test::MockRPCService rpc_service_; + application_manager_test::MockRPCService mock_rpc_service_; }; TEST_F(CommandHolderImplTest, HoldOne_ExpectReleaseOne) { @@ -86,7 +86,7 @@ TEST_F(CommandHolderImplTest, HoldOne_ExpectReleaseOne) { mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand, cmd_ptr_); // Act - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)); cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); } @@ -101,7 +101,7 @@ TEST_F(CommandHolderImplTest, HoldMany_ExpectReleaseSame) { } while (iterations < 5); // Act - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)).Times(iterations); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)).Times(iterations); cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); } @@ -114,7 +114,7 @@ TEST_F(CommandHolderImplTest, Hold_Drop_ExpectNoReleased) { // Act cmd_holder.Clear(mock_app_ptr_); - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)).Times(0); cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); } @@ -129,7 +129,7 @@ TEST_F(CommandHolderImplTest, Hold_ReleaseAnotherId_ExpectNoReleased) { utils::SharedPtr another_app = utils::MakeShared(); - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)).Times(0); cmd_holder.Resume(another_app, am::CommandHolder::CommandType::kHmiCommand); } @@ -148,7 +148,7 @@ TEST_F(CommandHolderImplTest, Hold_DropAnotherId_ExpectReleased) { utils::MakeShared(); cmd_holder.Clear(another_app); - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)).Times(iterations); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)).Times(iterations); cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); } @@ -162,11 +162,11 @@ TEST_F(CommandHolderImplTest, Hold_Mobile_and_HMI_commands_ExpectReleased) { mock_app_ptr_, am::CommandHolder::CommandType::kMobileCommand, cmd_ptr_); // Act - EXPECT_CALL(rpc_service_, ManageHMICommand(cmd_ptr_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(cmd_ptr_)); cmd_holder.Resume(mock_app_ptr_, am::CommandHolder::CommandType::kHmiCommand); EXPECT_CALL( - rpc_service_, + mock_rpc_service_, ManageMobileCommand(cmd_ptr_, am::commands::Command::CommandSource::SOURCE_MOBILE)); cmd_holder.Resume(mock_app_ptr_, diff --git a/src/components/application_manager/test/commands/CMakeLists.txt b/src/components/application_manager/test/commands/CMakeLists.txt index be236fdb49..ab412c7e4e 100644 --- a/src/components/application_manager/test/commands/CMakeLists.txt +++ b/src/components/application_manager/test/commands/CMakeLists.txt @@ -35,11 +35,10 @@ include_directories( ${COMPONENTS_DIR}/application_manager/include/ ${COMPONENTS_DIR}/application_manager/include/application_manager/ ${COMPONENTS_DIR}/application_manager/include/application_manager/commands/ - ${COMPONENTS_DIR}/application_manager/include/application_manager/commands/hmi/ - ${COMPONENTS_DIR}/application_manager/include/application_manager/commands/mobile/ - ${COMPONENTS_DIR}/application_manager/test/include/ - ${COMPONENTS_DIR}/application_manager/test/include/application_manager/ ) +#${COMPONENTS_DIR}/application_manager/test/include/ +#${COMPONENTS_DIR}/application_manager/test/include/application_manager/ +#${COMPONENTS_DIR}/application_manager/src/commands/ set(COMMANDS_TEST_DIR ${AM_TEST_DIR}/commands) @@ -47,25 +46,29 @@ file(GLOB SOURCES ${COMMANDS_TEST_DIR}/* ${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 - ${COMPONENTS_DIR}/application_manager/src/message.cc - ${COMMANDS_TEST_DIR}/hmi/* - ${COMMANDS_TEST_DIR}/hmi/hmi_notifications/* - ${COMMANDS_TEST_DIR}/mobile/* + ${COMPONENTS_DIR}/application_manager/test/commands/command_imp_test.cc + ${COMPONENTS_DIR}/application_manager/test/commands/command_request_impl_test.cc + ${COMPONENTS_DIR}/application_manager/test/commands/command_response_impl_test.cc ) +#${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc +#${COMPONENTS_DIR}/application_manager/src/message.cc set(LIBRARIES gmock Utils SmartObjects HMI_API MOBILE_API - ApplicationManager - AMHMICommandsLibrary - AMMobileCommandsLibrary connectionHandler + ApplicationManager jsoncpp Policy ) -create_cotired_test("commands_test" "${SOURCES}" "${LIBRARIES}" ) +create_test("commands_test" "${SOURCES}" "${LIBRARIES}") +#${COMMANDS_TEST_DIR}/hmi/* +#${COMMANDS_TEST_DIR}/hmi/hmi_notifications/* +#${COMMANDS_TEST_DIR}/mobile/* +#ApplicationManager +#AMHMICommandsLibrary +#AMMobileCommandsLibrary diff --git a/src/components/application_manager/test/commands/command_impl_test.cc b/src/components/application_manager/test/commands/command_impl_test.cc index ff9634cbb1..b50d94f824 100644 --- a/src/components/application_manager/test/commands/command_impl_test.cc +++ b/src/components/application_manager/test/commands/command_impl_test.cc @@ -87,8 +87,15 @@ class CommandImplTest : public CommandsTest { using CommandImpl::ReplaceHMIWithMobileAppId; UnwrappedCommandImpl(const MessageSharedPtr& message, - ApplicationManager& application_manager) - : CommandImpl(message, application_manager) {} + ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandImpl(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} }; // Create `SmartObject` which handle array of `SmartObjects` diff --git a/src/components/application_manager/test/commands/command_request_impl_test.cc b/src/components/application_manager/test/commands/command_request_impl_test.cc index f2a00e2785..556d1c85d4 100644 --- a/src/components/application_manager/test/commands/command_request_impl_test.cc +++ b/src/components/application_manager/test/commands/command_request_impl_test.cc @@ -104,8 +104,12 @@ class CommandRequestImplTest using CommandRequestImpl::HasDisallowedParams; UnwrappedCommandRequestImpl(const MessageSharedPtr& message, - ApplicationManager& am) - : CommandRequestImpl(message, am) {} + ApplicationManager& am, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : CommandRequestImpl( + message, am, rpc_service, hmi_capabilities, policy_handler) {} const RequestState current_state() const { return current_state_; @@ -150,8 +154,8 @@ TEST_F(CommandRequestImplTest, OnTimeOut_StateCompleted_UNSUCCESS) { // First -- on `onTimeOut` method call // Second -- on destruction; EXPECT_CALL(event_dispatcher_, remove_observer(_)).Times(2); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); // If `command` already done, then state should change to `kCompleted`. command->set_current_state(RequestState::kCompleted); @@ -172,9 +176,9 @@ TEST_F(CommandRequestImplTest, OnTimeOut_StateAwaitingHMIResponse_SUCCESS) { MessageSharedPtr dummy_msg(CreateMessage()); EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) .WillOnce(Return(dummy_msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); + EXPECT_CALL( - rpc_service_, + mock_rpc_service_, ManageMobileCommand(dummy_msg, Command::CommandSource::SOURCE_SDL)); command->onTimeOut(); @@ -251,8 +255,8 @@ TEST_F(CommandRequestImplTest, CreateHMINotification_SUCCESS) { (*msg_params)[kTestParamsKey] = 0; MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); command->CreateHMINotification(kInvalidFunctionId, *msg_params); @@ -273,8 +277,8 @@ TEST_F(CommandRequestImplTest, SendHMIRequest_NoUseEvent_SUCCESS) { EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); // Return `true` prevents call of `SendResponse` method; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); EXPECT_EQ(kCorrelationId, command->SendHMIRequest(kInvalidFunctionId, NULL, false)); @@ -291,8 +295,8 @@ TEST_F(CommandRequestImplTest, SendHMIRequest_UseEvent_SUCCESS) { EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); // Return `true` prevents call of `SendResponse` method; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); EXPECT_CALL(event_dispatcher_, add_observer(_, _, _)); EXPECT_EQ(kCorrelationId, @@ -388,8 +392,8 @@ TEST_F(CommandRequestImplTest, EXPECT_CALL(mock_message_helper_, CreateBlockedByPoliciesResponse(_, _, _, _)) .WillOnce(Return(smart_objects::SmartObjectSPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(_, _)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)); EXPECT_FALSE(command->CheckPermissions()); } @@ -440,8 +444,8 @@ TEST_F(CommandRequestImplTest, SendResponse_TimedOut_UNSUCCESS) { CommandPtr command = CreateCommand(); command->set_current_state(RequestState::kTimedOut); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); // Args do not affect on anything in this case; command->SendResponse(true, kMobResultSuccess, NULL, NULL); @@ -456,8 +460,8 @@ TEST_F(CommandRequestImplTest, SendResponse_SUCCESS) { EXPECT_TRUE(smart_objects::SmartType_Null == (*msg).getType()); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); // Args do not affect on anything in this case; @@ -487,8 +491,8 @@ TEST_F(CommandRequestImplTest, kDisallowedParam1); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); command->SendResponse(true, kMobResultSuccess, NULL, NULL); @@ -506,8 +510,8 @@ TEST_F(CommandRequestImplTest, HashUpdateAllowed_UpdateExpected) { command->SetHashUpdateMode(CommandRequestImpl::HashUpdateMode::kDoHashUpdate); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const bool is_succedeed = true; @@ -527,8 +531,8 @@ TEST_F(CommandRequestImplTest, HashUpdateDisallowed_HashUpdateNotExpected) { CommandRequestImpl::HashUpdateMode::kSkipHashUpdate); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const bool is_succedeed = true; @@ -546,8 +550,8 @@ TEST_F(CommandRequestImplTest, RequestFailed_HashUpdateNotExpected) { command->SetHashUpdateMode(CommandRequestImpl::HashUpdateMode::kDoHashUpdate); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const bool is_succedeed = false; @@ -565,8 +569,8 @@ TEST_F(CommandRequestImplTest, AppNotFound_HashUpdateNotExpected) { command->SetHashUpdateMode(CommandRequestImpl::HashUpdateMode::kDoHashUpdate); MessageSharedPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)) + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const bool is_succedeed = true; diff --git a/src/components/application_manager/test/commands/command_response_impl_test.cc b/src/components/application_manager/test/commands/command_response_impl_test.cc index 07398d2132..bd7499ce8f 100644 --- a/src/components/application_manager/test/commands/command_response_impl_test.cc +++ b/src/components/application_manager/test/commands/command_response_impl_test.cc @@ -77,8 +77,8 @@ TEST_F(CommandResponseImplTest, SendResponse_MessageWithResultCode_SUCCESS) { // If `msg_params->result_code` exist in message, // then send message to mobile. (*msg)[strings::msg_params][strings::result_code] = kResultCode; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, kFinalResponse)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, kFinalResponse)); command->SendResponse(kSuccess, kResultCode, kFinalResponse); } @@ -93,8 +93,8 @@ TEST_F(CommandResponseImplTest, const mobile_apis::Result::eType kResultCode = mobile_apis::Result::eType::SUCCESS; const bool kFinalResponse = true; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, kFinalResponse)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, kFinalResponse)); // If `msg_params->result_code` does not exist in message // and arg `result_code` not equals `INVALID_ENUM`, @@ -121,8 +121,8 @@ TEST_F(CommandResponseImplTest, // then if `params->hmi_response::code` exist in message, // then set it to `msg_params->result_code` and send message to mobile. (*msg)[strings::params][hmi_response::code] = mobile_apis::Result::SUCCESS; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, kFinalResponse)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, kFinalResponse)); command->SendResponse(kSuccess, kResultCode, kFinalResponse); @@ -146,8 +146,8 @@ TEST_F(CommandResponseImplTest, // then if `kSuccess` equals `true`, // then `msg_params->result_code` will be `SUCCESS` const bool kSuccess = true; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, kFinalResponse)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, kFinalResponse)); command->SendResponse(kSuccess, kResultCode, kFinalResponse); @@ -171,8 +171,8 @@ TEST_F(CommandResponseImplTest, // then if `kSuccess` equals `false`, // then `msg_params->result_code` will be `INVALID_ENUM` const bool kSuccess = false; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, kFinalResponse)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, kFinalResponse)); command->SendResponse(kSuccess, kResultCode, kFinalResponse); diff --git a/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc b/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc deleted file mode 100644 index a582a692ad..0000000000 --- a/src/components/application_manager/test/commands/hmi/activate_app_request_test.cc +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/activate_app_request.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/commands/command_impl.h" -#include "commands/commands_test.h" -#include "application_manager/mock_application.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace activate_app_request { - -using ::testing::_; -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::MessageSharedPtr; -using am::commands::ActivateAppRequest; -using am::commands::CommandImpl; - -using ::test::components::application_manager_test::MockApplication; - -typedef SharedPtr MockAppPtr; -typedef ::utils::SharedPtr ActivateAppRequestPtr; - -MATCHER_P(CheckMessage, level, "") { - return level == - static_cast( - (*arg)[strings::msg_params][strings::activate_app_hmi_level] - .asInt()); -} - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCorrelationId = 2u; -} // namespace - -class ActivateAppRequestTest : public CommandsTest { - public: - MessageSharedPtr CreateMsgParams() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::app_id] = kAppId; - msg_params[strings::correlation_id] = kCorrelationId; - (*msg)[strings::msg_params] = msg_params; - (*msg)[strings::params][strings::app_id] = kAppId; - (*msg)[strings::params][strings::correlation_id] = kCorrelationId; - (*msg)[strings::app_id] = kAppId; - return msg; - } -}; - -TEST_F(ActivateAppRequestTest, Run_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - MockAppPtr app = CreateMockApp(); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - - ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId)); - -// TODO(OKozlov) Investigate and fix issue with using log -#ifdef ENABLE_LOG - (*msg)[strings::msg_params][strings::activate_app_hmi_level] = - mobile_apis::HMILevel::HMI_FULL; -#endif - ActivateAppRequestPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); -#ifdef ENABLE_LOG - EXPECT_CALL(rpc_service_, - SendMessageToHMI(CheckMessage(mobile_apis::HMILevel::HMI_FULL))); -#else - EXPECT_CALL(rpc_service_, - SendMessageToHMI(msg)); -#endif - command->Run(); - -#ifndef ENABLE_LOG - EXPECT_EQ(CommandImpl::hmi_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - EXPECT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); -#endif -} - -} // namespace activate_app_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/add_statistics_info_notification_test.cc b/src/components/application_manager/test/commands/hmi/add_statistics_info_notification_test.cc deleted file mode 100644 index 88efc61816..0000000000 --- a/src/components/application_manager/test/commands/hmi/add_statistics_info_notification_test.cc +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/add_statistics_info_notification.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/mock_application.h" -#include "application_manager/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/policies/policy_handler.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace add_statistics_info_notification { - -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_notification = ::application_manager::hmi_notification; -using am::commands::MessageSharedPtr; -using am::commands::AddStatisticsInfoNotification; -using am::commands::CommandImpl; -using policy::PolicyHandler; -using policy_test::MockPolicyHandlerInterface; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -typedef ::utils::SharedPtr NotificationPtr; - -namespace { -const uint32_t kStatisticType = 1u; -} // namespace - -class AddStatisticsInfoNotificationTest - : public CommandsTest { - protected: - MockPolicyHandlerInterface policy_handler_; -}; - -TEST_F(AddStatisticsInfoNotificationTest, Run_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::msg_params][am::hmi_notification::statistic_type] = - kStatisticType; - NotificationPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler_)); - EXPECT_CALL(policy_handler_, AddStatisticsInfo(kStatisticType)); - - command->Run(); -} - -} // namespace add_statistics_info_notification -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/allow_all_apps_response_test.cc b/src/components/application_manager/test/commands/hmi/allow_all_apps_response_test.cc deleted file mode 100644 index 60eced4830..0000000000 --- a/src/components/application_manager/test/commands/hmi/allow_all_apps_response_test.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/allow_all_apps_response.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/mock_application.h" -#include "application_manager/commands/command_impl.h" -#include "commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace allow_all_apps_response { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::AllowAllAppsResponse; - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -typedef ::utils::SharedPtr ResponsePtr; - -namespace { -const bool kResponseIsAllowed = true; -} // - -class AllowAllAppsResponseTest - : public CommandsTest {}; - -TEST_F(AllowAllAppsResponseTest, Run_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::allowed] = kResponseIsAllowed; - - ResponsePtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, SetAllAppsAllowed(kResponseIsAllowed)); - - command->Run(); -} - -} // namespace allow_all_apps_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/allow_app_response_test.cc b/src/components/application_manager/test/commands/hmi/allow_app_response_test.cc deleted file mode 100644 index 69b4abe39d..0000000000 --- a/src/components/application_manager/test/commands/hmi/allow_app_response_test.cc +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/allow_app_response.h" -#include "utils/shared_ptr.h" -#include "application_manager/mock_application.h" -#include "commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace allow_app_response { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::AllowAppResponse; -using ::testing::_; -using ::testing::Return; - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -namespace { -const uint32_t kConnectionKey = 1u; -const bool kIsResponseAllowed = true; -} - -typedef ::utils::SharedPtr ResponsePtr; - -class AllowAppResponseTest : public CommandsTest {}; - -TEST_F(AllowAppResponseTest, Run_AppCreated_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; - - ResponsePtr command(CreateCommand(msg)); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_app_allowed(kIsResponseAllowed)); - - command->Run(); -} - -TEST_F(AllowAppResponseTest, Run_AppNotCreated_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; - - ResponsePtr command(CreateCommand(msg)); - - MockAppPtr mock_app; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - - command->Run(); -} - -} // namespace allow_app_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/button_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/button_get_capabilities_response_test.cc deleted file mode 100644 index b2a8f0858a..0000000000 --- a/src/components/application_manager/test/commands/hmi/button_get_capabilities_response_test.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/button_get_capabilities_response.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace button_get_capabilities_response { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::ButtonGetCapabilitiesResponse; -using ::testing::ReturnRef; -using ::testing::NiceMock; - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -typedef ::utils::SharedPtr ResponsePtr; - -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -class ButtonGetCapabilitiesResponseTest - : public CommandsTest { - public: - MessageSharedPtr CreateMsgParams() { - capabilities_[strings::name] = hmi_apis::Common_ButtonName::OK; - preset_bank_capabilities_ = true; - - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::capabilities] = (capabilities_); - (*msg)[strings::msg_params][hmi_response::preset_bank_capabilities] = - (preset_bank_capabilities_); - - return msg; - } - - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; - SmartObject preset_bank_capabilities_; -}; - -TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeSuccess_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - ResponsePtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, - set_preset_bank_capabilities(preset_bank_capabilities_)); - - command->Run(); -} - -TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeAborted_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::ABORTED; - - ResponsePtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()).Times(0); - EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)) - .Times(0); - EXPECT_CALL(mock_hmi_capabilities_, - set_preset_bank_capabilities(preset_bank_capabilities_)).Times(0); - - command->Run(); -} - -} // namespace button_get_capabilities_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/close_popup_response_test.cc b/src/components/application_manager/test/commands/hmi/close_popup_response_test.cc deleted file mode 100644 index b4a6ea272a..0000000000 --- a/src/components/application_manager/test/commands/hmi/close_popup_response_test.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/commands/command.h" -#include "commands/commands_test.h" -#include "application_manager/commands/hmi/response_from_hmi.h" -#include "application_manager/commands/hmi/close_popup_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace close_popup_response { - -using ::utils::SharedPtr; -namespace am = ::application_manager; -using am::commands::ResponseFromHMI; -using am::commands::ClosePopupResponse; -using am::commands::CommandImpl; - -typedef SharedPtr ResponseFromHMIPtr; - -class ClosePopupResponseTest : public CommandsTest { -}; - -TEST_F(ClosePopupResponseTest, RUN_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - ResponseFromHMIPtr command(CreateCommand(command_msg)); - - command->Run(); -} - -} // namespace close_popup_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/test/commands/hmi/dummy_hmi_commands_test.cc deleted file mode 100644 index 7c95a4ca2f..0000000000 --- a/src/components/application_manager/test/commands/hmi/dummy_hmi_commands_test.cc +++ /dev/null @@ -1,617 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/command_request_test.h" - -#include -#include -#include -#include "gtest/gtest.h" - -#include "application_manager/commands/hmi/allow_all_apps_request.h" -#include "application_manager/commands/hmi/allow_all_apps_response.h" -#include "application_manager/commands/hmi/allow_app_request.h" -#include "application_manager/commands/hmi/allow_app_response.h" -#include "application_manager/commands/hmi/navi_audio_start_stream_request.h" -#include "application_manager/commands/hmi/navi_audio_start_stream_response.h" -#include "application_manager/commands/hmi/navi_audio_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_audio_stop_stream_response.h" -#include "application_manager/commands/hmi/update_device_list_request.h" -#include "application_manager/commands/hmi/update_device_list_response.h" -#include "application_manager/commands/hmi/on_update_device_list.h" -#include "application_manager/commands/hmi/on_start_device_discovery.h" -#include "application_manager/commands/hmi/update_app_list_request.h" -#include "application_manager/commands/hmi/update_app_list_response.h" -#include "application_manager/commands/hmi/on_find_applications.h" -#include "application_manager/commands/hmi/sdl_get_list_of_permissions_request.h" -#include "application_manager/commands/hmi/sdl_get_list_of_permissions_response.h" -#include "application_manager/commands/hmi/sdl_get_user_friendly_message_request.h" -#include "application_manager/commands/hmi/sdl_get_user_friendly_message_response.h" -#include "application_manager/commands/hmi/sdl_get_status_update_request.h" -#include "application_manager/commands/hmi/sdl_get_status_update_response.h" -#include "application_manager/commands/hmi/on_status_update_notification.h" -#include "application_manager/commands/hmi/update_sdl_request.h" -#include "application_manager/commands/hmi/update_sdl_response.h" -#include "application_manager/commands/hmi/activate_app_request.h" -#include "application_manager/commands/hmi/activate_app_response.h" -#include "application_manager/commands/hmi/mixing_audio_supported_request.h" -#include "application_manager/commands/hmi/mixing_audio_supported_response.h" -#include "application_manager/commands/hmi/on_allow_sdl_functionality_notification.h" -#include "application_manager/commands/hmi/on_app_permission_changed_notification.h" -#include "application_manager/commands/hmi/on_app_permission_consent_notification.h" -#include "application_manager/commands/hmi/on_app_activated_notification.h" -#include "application_manager/commands/hmi/on_audio_data_streaming_notification.h" -#include "application_manager/commands/hmi/on_video_data_streaming_notification.h" -#include "application_manager/commands/hmi/on_sdl_consent_needed_notification.h" -#include "application_manager/commands/hmi/on_exit_all_applications_notification.h" -#include "application_manager/commands/hmi/on_exit_application_notification.h" -#include "application_manager/commands/hmi/on_put_file_notification.h" -#include "application_manager/commands/hmi/on_resume_audio_source_notification.h" -#include "application_manager/commands/hmi/on_ignition_cycle_over_notification.h" -#include "application_manager/commands/hmi/on_system_info_changed_notification.h" -#include "application_manager/commands/hmi/get_system_info_request.h" -#include "application_manager/commands/hmi/get_system_info_response.h" -#include "application_manager/commands/hmi/close_popup_request.h" -#include "application_manager/commands/hmi/close_popup_response.h" -#include "application_manager/commands/hmi/button_get_capabilities_request.h" -#include "application_manager/commands/hmi/button_get_capabilities_response.h" -#include "application_manager/commands/hmi/ui_add_command_request.h" -#include "application_manager/commands/hmi/ui_add_command_response.h" -#include "application_manager/commands/hmi/ui_delete_command_request.h" -#include "application_manager/commands/hmi/ui_delete_command_response.h" -#include "application_manager/commands/hmi/ui_add_submenu_request.h" -#include "application_manager/commands/hmi/ui_add_submenu_response.h" -#include "application_manager/commands/hmi/ui_delete_submenu_request.h" -#include "application_manager/commands/hmi/ui_delete_submenu_response.h" -#include "application_manager/commands/hmi/ui_get_supported_languages_request.h" -#include "application_manager/commands/hmi/ui_get_supported_languages_response.h" -#include "application_manager/commands/hmi/ui_get_language_request.h" -#include "application_manager/commands/hmi/ui_get_language_response.h" -#include "application_manager/commands/hmi/ui_get_capabilities_request.h" -#include "application_manager/commands/hmi/ui_get_capabilities_response.h" -#include "application_manager/commands/hmi/ui_change_registration_request.h" -#include "application_manager/commands/hmi/ui_change_registration_response.h" -#include "application_manager/commands/hmi/ui_show_request.h" -#include "application_manager/commands/hmi/ui_show_response.h" -#include "application_manager/commands/hmi/ui_alert_request.h" -#include "application_manager/commands/hmi/ui_alert_response.h" -#include "application_manager/commands/hmi/ui_is_ready_request.h" -#include "application_manager/commands/hmi/ui_is_ready_response.h" -#include "application_manager/commands/hmi/ui_slider_request.h" -#include "application_manager/commands/hmi/ui_slider_response.h" -#include "application_manager/commands/hmi/ui_set_media_clock_timer_request.h" -#include "application_manager/commands/hmi/ui_set_media_clock_timer_response.h" -#include "application_manager/commands/hmi/ui_set_global_properties_request.h" -#include "application_manager/commands/hmi/ui_set_global_properties_response.h" -#include "application_manager/commands/hmi/ui_scrollable_message_request.h" -#include "application_manager/commands/hmi/ui_scrollable_message_response.h" -#include "application_manager/commands/hmi/ui_set_app_icon_request.h" -#include "application_manager/commands/hmi/ui_set_app_icon_response.h" -#include "application_manager/commands/hmi/ui_perform_audio_pass_thru_response.h" -#include "application_manager/commands/hmi/ui_perform_audio_pass_thru_request.h" -#include "application_manager/commands/hmi/ui_end_audio_pass_thru_request.h" -#include "application_manager/commands/hmi/ui_end_audio_pass_thru_response.h" -#include "application_manager/commands/hmi/ui_perform_interaction_request.h" -#include "application_manager/commands/hmi/ui_perform_interaction_response.h" -#include "application_manager/commands/hmi/vr_is_ready_request.h" -#include "application_manager/commands/hmi/vr_is_ready_response.h" -#include "application_manager/commands/hmi/vr_add_command_request.h" -#include "application_manager/commands/hmi/vr_add_command_response.h" -#include "application_manager/commands/hmi/vr_delete_command_request.h" -#include "application_manager/commands/hmi/vr_delete_command_response.h" -#include "application_manager/commands/hmi/vr_change_registration_request.h" -#include "application_manager/commands/hmi/vr_change_registration_response.h" -#include "application_manager/commands/hmi/vr_get_supported_languages_request.h" -#include "application_manager/commands/hmi/vr_get_supported_languages_response.h" -#include "application_manager/commands/hmi/vr_get_language_request.h" -#include "application_manager/commands/hmi/vr_get_language_response.h" -#include "application_manager/commands/hmi/vr_get_capabilities_request.h" -#include "application_manager/commands/hmi/vr_get_capabilities_response.h" -#include "application_manager/commands/hmi/tts_is_ready_request.h" -#include "application_manager/commands/hmi/tts_is_ready_response.h" -#include "application_manager/commands/hmi/tts_change_registration_request.h" -#include "application_manager/commands/hmi/tts_change_registration_response.h" -#include "application_manager/commands/hmi/tts_get_supported_languages_request.h" -#include "application_manager/commands/hmi/tts_get_supported_languages_response.h" -#include "application_manager/commands/hmi/tts_get_language_request.h" -#include "application_manager/commands/hmi/tts_get_language_response.h" -#include "application_manager/commands/hmi/tts_stop_speaking_request.h" -#include "application_manager/commands/hmi/tts_stop_speaking_response.h" -#include "application_manager/commands/hmi/tts_speak_request.h" -#include "application_manager/commands/hmi/tts_speak_response.h" -#include "application_manager/commands/hmi/tts_set_global_properties_request.h" -#include "application_manager/commands/hmi/tts_set_global_properties_response.h" -#include "application_manager/commands/hmi/tts_get_capabilities_request.h" -#include "application_manager/commands/hmi/tts_get_capabilities_response.h" -#include "application_manager/commands/hmi/vr_perform_interaction_request.h" -#include "application_manager/commands/hmi/vr_perform_interaction_response.h" -#include "application_manager/commands/hmi/vi_is_ready_request.h" -#include "application_manager/commands/hmi/vi_is_ready_response.h" -#include "application_manager/commands/hmi/vi_read_did_request.h" -#include "application_manager/commands/hmi/vi_read_did_response.h" -#include "application_manager/commands/hmi/sdl_activate_app_request.h" -#include "application_manager/commands/hmi/sdl_activate_app_response.h" -#include "application_manager/commands/hmi/on_app_permission_changed_notification.h" -#include "application_manager/commands/hmi/on_event_changed_notification.h" -#include "application_manager/commands/hmi/vi_get_vehicle_data_request.h" -#include "application_manager/commands/hmi/vi_get_vehicle_data_response.h" -#include "application_manager/commands/hmi/on_vi_vehicle_data_notification.h" -#include "application_manager/commands/hmi/vi_subscribe_vehicle_data_request.h" -#include "application_manager/commands/hmi/vi_subscribe_vehicle_data_response.h" -#include "application_manager/commands/hmi/vi_unsubscribe_vehicle_data_request.h" -#include "application_manager/commands/hmi/vi_unsubscribe_vehicle_data_response.h" -#include "application_manager/commands/hmi/vi_get_dtcs_request.h" -#include "application_manager/commands/hmi/vi_get_dtcs_response.h" -#include "application_manager/commands/hmi/vi_diagnostic_message_request.h" -#include "application_manager/commands/hmi/vi_diagnostic_message_response.h" -#include "application_manager/commands/hmi/vi_get_vehicle_type_request.h" -#include "application_manager/commands/hmi/vi_get_vehicle_type_response.h" -#include "application_manager/commands/hmi/navi_is_ready_request.h" -#include "application_manager/commands/hmi/navi_show_constant_tbt_request.h" -#include "application_manager/commands/hmi/navi_show_constant_tbt_response.h" -#include "application_manager/commands/hmi/navi_is_ready_response.h" -#include "application_manager/commands/hmi/navi_alert_maneuver_request.h" -#include "application_manager/commands/hmi/navi_alert_maneuver_response.h" -#include "application_manager/commands/hmi/navi_update_turn_list_request.h" -#include "application_manager/commands/hmi/navi_update_turn_list_response.h" -#include "application_manager/commands/hmi/navi_subscribe_way_points_request.h" -#include "application_manager/commands/hmi/navi_subscribe_way_points_response.h" -#include "application_manager/commands/hmi/navi_unsubscribe_way_points_request.h" -#include "application_manager/commands/hmi/navi_unsubscribe_way_points_response.h" -#include "application_manager/commands/hmi/navi_get_way_points_request.h" -#include "application_manager/commands/hmi/navi_get_way_points_response.h" -#include "application_manager/commands/hmi/on_ready_notification.h" -#include "application_manager/commands/hmi/on_device_chosen_notification.h" -#include "application_manager/commands/hmi/on_file_removed_notification.h" -#include "application_manager/commands/hmi/on_system_context_notification.h" -#include "application_manager/commands/hmi/on_app_registered_notification.h" -#include "application_manager/commands/hmi/on_app_unregistered_notification.h" -#include "application_manager/commands/hmi/on_driver_distraction_notification.h" -#include "application_manager/commands/hmi/on_tts_started_notification.h" -#include "application_manager/commands/hmi/on_tts_stopped_notification.h" -#include "application_manager/commands/hmi/on_vr_started_notification.h" -#include "application_manager/commands/hmi/on_vr_stopped_notification.h" -#include "application_manager/commands/hmi/on_vr_command_notification.h" -#include "application_manager/commands/hmi/on_ui_command_notification.h" -#include "application_manager/commands/hmi/on_app_deactivated_notification.h" -#include "application_manager/commands/hmi/on_ui_language_change_notification.h" -#include "application_manager/commands/hmi/on_vr_language_change_notification.h" -#include "application_manager/commands/hmi/on_tts_language_change_notification.h" -#include "application_manager/commands/hmi/on_navi_tbt_client_state_notification.h" -#include "application_manager/commands/hmi/on_navi_way_point_change_notification.h" -#include "application_manager/commands/hmi/on_button_event_notification.h" -#include "application_manager/commands/hmi/on_button_press_notification.h" -#include "application_manager/commands/hmi/on_button_subscription_notification.h" -#include "application_manager/commands/hmi/on_vi_vehicle_data_notification.h" -#include "application_manager/commands/hmi/on_ui_keyboard_input_notification.h" -#include "application_manager/commands/hmi/on_ui_touch_event_notification.h" -#include "application_manager/commands/hmi/on_ui_reset_timeout_notification.h" -#include "application_manager/commands/hmi/navi_start_stream_request.h" -#include "application_manager/commands/hmi/navi_start_stream_response.h" -#include "application_manager/commands/hmi/navi_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_stop_stream_response.h" -#include "application_manager/commands/hmi/on_system_request_notification.h" -#include "application_manager/commands/hmi/ui_set_display_layout_request.h" -#include "application_manager/commands/hmi/ui_set_display_layout_response.h" -#include "application_manager/commands/hmi/on_sdl_close_notification.h" -#include "application_manager/commands/hmi/on_sdl_persistence_complete_notification.h" -#include "application_manager/commands/hmi/on_record_start_notification.h" -#include "application_manager/commands/hmi/add_statistics_info_notification.h" -#include "application_manager/commands/hmi/on_system_error_notification.h" -#include "application_manager/commands/hmi/basic_communication_system_request.h" -#include "application_manager/commands/hmi/basic_communication_system_response.h" -#include "application_manager/commands/hmi/sdl_policy_update.h" -#include "application_manager/commands/hmi/sdl_policy_update_response.h" -#include "application_manager/commands/hmi/on_received_policy_update.h" -#include "application_manager/commands/hmi/on_policy_update.h" -#include "application_manager/commands/hmi/get_urls.h" -#include "application_manager/commands/hmi/get_urls_response.h" -#include "application_manager/commands/hmi/on_device_state_changed_notification.h" -#include "application_manager/commands/hmi/navi_send_location_request.h" -#include "application_manager/commands/hmi/navi_send_location_response.h" -#include "application_manager/commands/hmi/on_tts_reset_timeout_notification.h" -#include "application_manager/commands/hmi/dial_number_request.h" -#include "application_manager/commands/hmi/dial_number_response.h" -#include "application_manager/commands/hmi/on_vi_gps_data_notification.h" -#include "application_manager/commands/hmi/on_vi_speed_notification.h" -#include "application_manager/commands/hmi/on_vi_rpm_notification.h" -#include "application_manager/commands/hmi/on_vi_fuel_level_notification.h" -#include "application_manager/commands/hmi/on_vi_fuel_level_state_notification.h" -#include "application_manager/commands/hmi/on_vi_instant_fuel_consumption_notification.h" -#include "application_manager/commands/hmi/on_vi_external_temperature_notification.h" -#include "application_manager/commands/hmi/on_vi_vin_notification.h" -#include "application_manager/commands/hmi/on_vi_prndl_notification.h" -#include "application_manager/commands/hmi/on_vi_tire_pressure_notification.h" -#include "application_manager/commands/hmi/on_vi_odometer_notification.h" -#include "application_manager/commands/hmi/on_vi_belt_status_notification.h" -#include "application_manager/commands/hmi/on_vi_body_information_notification.h" -#include "application_manager/commands/hmi/on_vi_device_status_notification.h" -#include "application_manager/commands/hmi/on_vi_driver_braking_notification.h" -#include "application_manager/commands/hmi/on_vi_wiper_status_notification.h" -#include "application_manager/commands/hmi/on_vi_head_lamp_status_notification.h" -#include "application_manager/commands/hmi/on_vi_engine_torque_notification.h" -#include "application_manager/commands/hmi/on_vi_acc_pedal_position_notification.h" -#include "application_manager/commands/hmi/on_vi_steering_wheel_angle_notification.h" -#include "application_manager/commands/hmi/on_vi_my_key_notification.h" -#include "application_manager/commands/hmi/ui_set_icon_request.h" - -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "test/application_manager/mock_application_manager_settings.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace am = application_manager; - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace dummy_hmi_commands_test { - -namespace commands = ::application_manager::commands; - -using ::testing::_; -using ::testing::NotNull; -using ::testing::Types; -using commands::MessageSharedPtr; -using ::test::components::event_engine_test::MockEventDispatcher; -using ::test::components::application_manager_test::MockApplicationManager; -using ::test::components::application_manager_test:: - MockApplicationManagerSettings; -using ::application_manager::ApplicationSharedPtr; -using ::test::components::application_manager_test::MockApplication; - -template -class HMICommandsTest : public components::commands_test::CommandRequestTest< - CommandsTestMocks::kIsNice> { - public: - typedef Command CommandType; - - void InitCommand(const uint32_t& timeout) OVERRIDE { - stream_retry_.first = 0; - stream_retry_.second = 0; - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); - ON_CALL(app_mngr_settings_, start_stream_retry_amount()) - .WillByDefault(ReturnRef(stream_retry_)); - } - - protected: - std::pair stream_retry_; -}; - -template -class HMICommandsTestFirst : public HMICommandsTest { - public: - using typename HMICommandsTest::CommandType; -}; - -template -class HMICommandsTestSecond : public HMICommandsTest { - public: - using typename HMICommandsTest::CommandType; -}; - -template -class HMICommandsTestThird : public HMICommandsTest { - public: - using typename HMICommandsTest::CommandType; -}; - -template -class HMICommandsTestFourth : public HMICommandsTest { - public: - using typename HMICommandsTest::CommandType; -}; - -template -class HMICommandsTestFifth : public HMICommandsTest { - public: - using typename HMICommandsTest::CommandType; -}; - -/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few - * TYPED_TEST_CASE for HMI and mobile commands - */ - -typedef Types HMICommandsListFirst; - -typedef Types HMICommandsListSecond; - -typedef Types HMICommandsListThird; - -typedef Types HMICommandsListFourth; - -typedef Types HMICommandsListFifth; - -TYPED_TEST_CASE(HMICommandsTestFirst, HMICommandsListFirst); -TYPED_TEST_CASE(HMICommandsTestSecond, HMICommandsListSecond); -TYPED_TEST_CASE(HMICommandsTestThird, HMICommandsListThird); -TYPED_TEST_CASE(HMICommandsTestFourth, HMICommandsListFourth); -TYPED_TEST_CASE(HMICommandsTestFifth, HMICommandsListFifth); - -TYPED_TEST(HMICommandsTestFirst, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -TYPED_TEST(HMICommandsTestSecond, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} -TYPED_TEST(HMICommandsTestThird, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -TYPED_TEST(HMICommandsTestFourth, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -TYPED_TEST(HMICommandsTestFifth, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -} // namespace dummy_hmi_commands_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/get_system_info_request_test.cc b/src/components/application_manager/test/commands/hmi/get_system_info_request_test.cc deleted file mode 100644 index 1db2b817b3..0000000000 --- a/src/components/application_manager/test/commands/hmi/get_system_info_request_test.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/request_to_hmi.h" -#include "application_manager/commands/hmi/get_system_info_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace get_system_info_request { - -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::RequestToHMI; -using am::commands::GetSystemInfoRequest; -using am::commands::CommandImpl; - -typedef SharedPtr RequestToHMIPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 1u; -} // namespace - -class GetSystemInfoRequestTest - : public CommandsTest {}; - -TEST_F(GetSystemInfoRequestTest, RUN_SendRequest_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; - - RequestToHMIPtr command(CreateCommand(command_msg)); - - const uint32_t kAppId = command->application_id(); - - EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::msg_params][strings::app_id].asUInt(), - kAppId); - EXPECT_EQ((*command_msg)[strings::params][strings::correlation_id].asUInt(), - kCorrelationId); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -} // namespace get_system_info_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc b/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc deleted file mode 100644 index 980b6e0e9d..0000000000 --- a/src/components/application_manager/test/commands/hmi/get_system_info_response_test.cc +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/response_from_hmi.h" -#include "application_manager/commands/hmi/get_system_info_response.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace get_system_info_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::ResponseFromHMI; -using am::commands::GetSystemInfoResponse; -using am::commands::CommandImpl; -using am::commands::SystemInfo; - -typedef SharedPtr ResponseFromHMIPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string ccpu_version("4.1.3.B_EB355B"); -const std::string wers_country_code("WAEGB"); -const uint32_t lang_code = 0u; -const std::string kLanguage = ""; -} // namespace - -class GetSystemInfoResponseTest - : public CommandsTest { - public: - MessageSharedPtr CreateCommandMsg() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::msg_params]["ccpu_version"] = ccpu_version; - (*command_msg)[strings::msg_params]["wersCountryCode"] = wers_country_code; - (*command_msg)[strings::msg_params]["language"] = lang_code; - - return command_msg; - } - - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(GetSystemInfoResponseTest, GetSystemInfo_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - ResponseFromHMIPtr command(CreateCommand(command_msg)); - policy_test::MockPolicyHandlerInterface policy_handler; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - std::string language; - EXPECT_CALL(mock_message_helper_, - CommonLanguageToString( - static_cast(lang_code))) - .WillOnce(Return(language)); - EXPECT_EQ(kLanguage, language); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(policy_handler, - OnGetSystemInfo(ccpu_version, wers_country_code, kLanguage)); - - command->Run(); -} - -TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WRONG_LANGUAGE; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - ResponseFromHMIPtr command(CreateCommand(command_msg)); - policy_test::MockPolicyHandlerInterface policy_handler; - - EXPECT_CALL(app_mngr_, hmi_capabilities()).Times(0); - - EXPECT_CALL(mock_message_helper_, - CommonLanguageToString( - static_cast(lang_code))) - .Times(0); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(policy_handler, OnGetSystemInfo("", "", "")); - - command->Run(); -} - -} // namespace get_system_info_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/get_urls_response_test.cc b/src/components/application_manager/test/commands/hmi/get_urls_response_test.cc deleted file mode 100644 index 24f4ab1aa3..0000000000 --- a/src/components/application_manager/test/commands/hmi/get_urls_response_test.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/commands/command.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/response_to_hmi.h" -#include "application_manager/commands/hmi/get_urls_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace get_urls_response { - -using ::testing::_; -using ::testing::Return; -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::ResponseToHMI; -using am::commands::GetUrlsResponse; -using am::commands::CommandImpl; - -typedef SharedPtr ResponseToHMIPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class GetUrlResponseTest : public CommandsTest {}; - -TEST_F(GetUrlResponseTest, RUN_SendRequest_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - - ResponseToHMIPtr command(CreateCommand(command_msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -} // namespace get_urls_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/get_urls_test.cc b/src/components/application_manager/test/commands/hmi/get_urls_test.cc deleted file mode 100644 index 4344e03256..0000000000 --- a/src/components/application_manager/test/commands/hmi/get_urls_test.cc +++ /dev/null @@ -1,346 +0,0 @@ -/* - * Copyright (c) 2016, 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/message.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/command.h" -#include "application_manager/commands/hmi/get_urls.h" -#include "application_manager/policies/policy_handler.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "commands/commands_test.h" -#include "commands/command_request_test.h" -#include "hmi/request_from_hmi.h" -#include "policy/mock_policy_manager.h" -#include "application_manager/event_engine/event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace get_urls { - -using namespace hmi_apis; -using namespace policy; -using ::utils::SharedPtr; -using ::testing::NiceMock; -using ::testing::SetArgReferee; -using ::test::components::application_manager_test::MockApplication; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::RequestFromHMI; -using am::commands::GetUrls; -using am::commands::CommandImpl; -using policy::PolicyHandler; -using policy_test::MockPolicyHandlerInterface; - -typedef SharedPtr RequestFromHMIPtr; - -namespace { -const uint32_t kInvalidAppId_ = 0u; -const uint32_t kAppIdForSending = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kServiceType = 0u; -const std::string kInitialService = "0x0"; -const std::string kPolicyService = "7"; -const std::string kDefaultUrl = "URL is not found"; -const std::string kDefaultId = "default"; -const std::string kPolicyAppId = "policy_app_id"; -} // namespace - -class GetUrlsTest : public CommandRequestTest { - public: - policy_test::MockPolicyHandlerInterface mock_policy_handler_; - MessageSharedPtr command_msg_; - RequestFromHMIPtr request_command_; - - GetUrlsTest() { - command_msg_ = - CreateMessage(NsSmartDeviceLink::NsSmartObjects::SmartType_Map); - (*command_msg_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kInitialService; - - request_command_ = CreateCommand(command_msg_); - - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - } -}; - -TEST_F(GetUrlsTest, RUN_SUCCESS) { - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - request_command_->Run(); -} - -TEST_F(GetUrlsTest, RUN_PolicyNotEnabled_UNSUCCESS) { - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(false)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -TEST_F(GetUrlsTest, RUN_EmptyEndpoints_UNSUCCESS) { - EndpointUrls endpoints_; - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -#ifdef EXTENDED_POLICY -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr mock_app = CreateMockApp(); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppIdForSending)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::SUCCESS, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); - - EXPECT_EQ(kAppIdForSending, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [strings::app_id].asInt()); - EXPECT_EQ(kDefaultUrl, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [strings::url].asString()); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_IncorrectIdForSending_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kInvalidAppId_)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, application(kInvalidAppId_)).Times(0); - - request_command_->Run(); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_ApplicationIsNotValid_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr invalid_mock_app; - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(invalid_mock_app)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_));); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} - -TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_FoundURLForApplication_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = - kPolicyService; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - data.app_id = kPolicyAppId; - endpoints_.push_back(data); - - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - MockAppPtr mock_app = CreateMockApp(); - - EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) - .WillOnce(Return(kAppIdForSending)); - - EXPECT_CALL(app_mngr_, application(kAppIdForSending)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(kPolicyAppId)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(command_msg_)) - .WillOnce(Return(true)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - - EXPECT_EQ(am::MessageType::kResponse, - (*command_msg_)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(Common_Result::SUCCESS, - (*command_msg_)[strings::params][am::hmi_response::code].asInt()); -} -#endif - -TEST_F(GetUrlsTest, DISABLED_ProcessServiceURLs_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = - kDefaultUrl; - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id] = "1"; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - data.app_id = "1"; - endpoints_.push_back(data); - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - EXPECT_EQ(kDefaultUrl, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::strings::url].asString()); - EXPECT_EQ(endpoints_[0].app_id, - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id].asString()); -} - -TEST_F(GetUrlsTest, ProcessServiceURLs_PolicyDefaultId_SUCCESS) { - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = - kDefaultUrl; - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - [am::hmi_response::policy_app_id] = kDefaultId; - - EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); - EndpointUrls endpoints_; - EndpointData data(kDefaultUrl); - endpoints_.push_back(data); - EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) - .WillOnce(SetArgReferee<1>(endpoints_)); - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(_)) - .WillOnce(Return(mock_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - request_command_->Run(); - - EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( - am::hmi_request::service)); - EXPECT_TRUE( - (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] - .keyExists(am::hmi_response::policy_app_id)); -} - -} // namespace get_urls -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc b/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc deleted file mode 100644 index 628f0d9434..0000000000 --- a/src/components/application_manager/test/commands/hmi/hmi_notifications/hmi_notifications_test.cc +++ /dev/null @@ -1,1994 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/commands_test.h" - -#include "application_manager/commands/hmi/on_button_event_notification.h" -#include "application_manager/commands/hmi/on_navi_tbt_client_state_notification.h" -#include "application_manager/commands/hmi/on_navi_way_point_change_notification.h" -#include "application_manager/commands/hmi/on_ui_command_notification.h" -#include "application_manager/commands/hmi/on_ui_keyboard_input_notification.h" -#include "application_manager/commands/hmi/on_ui_touch_event_notification.h" -#include "application_manager/commands/hmi/on_vi_acc_pedal_position_notification.h" -#include "application_manager/commands/hmi/on_vi_belt_status_notification.h" -#include "application_manager/commands/hmi/on_vi_body_information_notification.h" -#include "application_manager/commands/hmi/on_vi_device_status_notification.h" -#include "application_manager/commands/hmi/on_vi_driver_braking_notification.h" -#include "application_manager/commands/hmi/on_vi_engine_torque_notification.h" -#include "application_manager/commands/hmi/on_vi_external_temperature_notification.h" -#include "application_manager/commands/hmi/on_vi_fuel_level_notification.h" -#include "application_manager/commands/hmi/on_vi_fuel_level_state_notification.h" -#include "application_manager/commands/hmi/on_vi_gps_data_notification.h" -#include "application_manager/commands/hmi/on_vi_head_lamp_status_notification.h" -#include "application_manager/commands/hmi/on_vi_instant_fuel_consumption_notification.h" -#include "application_manager/commands/hmi/on_vi_my_key_notification.h" -#include "application_manager/commands/hmi/on_vi_odometer_notification.h" -#include "application_manager/commands/hmi/on_vi_prndl_notification.h" -#include "application_manager/commands/hmi/on_vi_rpm_notification.h" -#include "application_manager/commands/hmi/on_vi_speed_notification.h" -#include "application_manager/commands/hmi/on_vi_steering_wheel_angle_notification.h" -#include "application_manager/commands/hmi/on_vi_tire_pressure_notification.h" -#include "application_manager/commands/hmi/on_vi_vehicle_data_notification.h" -#include "application_manager/commands/hmi/on_vi_vin_notification.h" -#include "application_manager/commands/hmi/on_vi_wiper_status_notification.h" -#include "application_manager/commands/hmi/on_app_permission_changed_notification.h" -#include "application_manager/commands/hmi/on_app_registered_notification.h" -#include "application_manager/commands/hmi/on_audio_data_streaming_notification.h" -#include "application_manager/commands/hmi/on_button_subscription_notification.h" -#include "application_manager/commands/hmi/on_file_removed_notification.h" -#include "application_manager/commands/hmi/on_put_file_notification.h" -#include "application_manager/commands/hmi/on_resume_audio_source_notification.h" -#include "application_manager/commands/hmi/on_sdl_close_notification.h" -#include "application_manager/commands/hmi/on_sdl_consent_needed_notification.h" -#include "application_manager/commands/hmi/on_sdl_persistence_complete_notification.h" -#include "application_manager/commands/hmi/on_status_update_notification.h" -#include "application_manager/commands/hmi/on_video_data_streaming_notification.h" -#include "application_manager/commands/hmi/on_record_start_notification.h" -#include "application_manager/commands/hmi/on_app_activated_notification.h" -#include "application_manager/commands/hmi/on_app_deactivated_notification.h" -#include "application_manager/commands/hmi/on_app_unregistered_notification.h" -#include "application_manager/commands/hmi/on_button_press_notification.h" -#include "application_manager/commands/hmi/on_event_changed_notification.h" -#include "application_manager/commands/hmi/on_ready_notification.h" -#include "application_manager/commands/hmi/on_tts_reset_timeout_notification.h" -#include "application_manager/commands/hmi/on_tts_started_notification.h" -#include "application_manager/commands/hmi/on_tts_stopped_notification.h" -#include "application_manager/commands/hmi/on_ui_reset_timeout_notification.h" -#include "application_manager/commands/hmi/on_vr_started_notification.h" -#include "application_manager/commands/hmi/on_vr_stopped_notification.h" -#include "application_manager/commands/hmi/on_app_permission_consent_notification.h" -#include "application_manager/commands/hmi/on_ignition_cycle_over_notification.h" -#include "application_manager/commands/hmi/on_policy_update.h" -#include "application_manager/commands/hmi/on_received_policy_update.h" -#include "application_manager/commands/hmi/on_system_error_notification.h" -#include "application_manager/commands/hmi/on_system_info_changed_notification.h" -#include "application_manager/commands/hmi/on_allow_sdl_functionality_notification.h" -#include "application_manager/commands/hmi/on_device_state_changed_notification.h" -#include "application_manager/commands/hmi/on_exit_all_applications_notification.h" -#include "application_manager/commands/hmi/on_exit_application_notification.h" -#include "application_manager/commands/hmi/on_vr_command_notification.h" -#include "application_manager/commands/hmi/on_vr_language_change_notification.h" -#include "application_manager/commands/hmi/on_start_device_discovery.h" -#include "application_manager/commands/hmi/on_device_chosen_notification.h" -#include "application_manager/commands/hmi/on_system_context_notification.h" -#include "application_manager/commands/hmi/on_system_request_notification.h" -#include "application_manager/commands/hmi/on_tts_language_change_notification.h" -#include "application_manager/commands/hmi/on_ui_language_change_notification.h" -#include "application_manager/commands/hmi/on_driver_distraction_notification.h" - -#include "utils/lock.h" -#include "utils/data_accessor.h" -#include "utils/signals.h" -#include "utils/shared_ptr.h" -#include "utils/make_shared.h" -#include "utils/file_system.h" -#include "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_state_controller.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/hmi_capabilities_impl.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "transport_manager/mock_transport_manager.h" -#include "connection_handler/mock_connection_handler.h" -#include "connection_handler/mock_connection_handler_settings.h" -#include "test/application_manager/mock_application_manager_settings.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_message_helper.h" -#include "protocol_handler/mock_session_observer.h" -#include "application_manager/mock_resume_ctrl.h" - -namespace am = application_manager; - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace hmi_notifications_test { - -using ::testing::_; -using ::testing::Test; -using ::testing::Types; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::NiceMock; -using ::testing::InSequence; -using ::utils::SharedPtr; -using ::smart_objects::SmartObject; -using ::application_manager::commands::MessageSharedPtr; -using ::test::components::application_manager_test::MockApplicationManager; -using ::test::components::application_manager_test:: - MockApplicationManagerSettings; -using ::application_manager::ApplicationSharedPtr; -using ::test::components::application_manager_test::MockApplication; -using ::test::components::event_engine_test::MockEventDispatcher; -using ::application_manager::MockMessageHelper; - -using namespace am::commands; - -typedef SharedPtr MockAppPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -#define MEDIA true -#define NOT_MEDIA false -#define VC true -#define NOT_VC false -#define NAVI true -#define NOT_NAVI false - -ACTION_P(GetEventId, event_id) { - *event_id = arg0.id(); -} -ACTION_P(GetArg, arg) { - *arg = arg0; -} - -ACTION_P(GetArg3, result) { - arg3 = *result; -} - -ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { - *connect_id = arg0; - std::vector::const_iterator it = - arg1.group_permissions.begin(); - for (; it != arg1.group_permissions.end(); ++it) { - consent->group_permissions.push_back(*it); - } - consent->consent_source = arg1.consent_source; -} -ACTION_P2(GetBoolValueAndString, value, str) { - *value = arg0; - *str = arg1; -} -ACTION_P(GetMessage, message) { - (*message)[am::strings::params][am::strings::function_id] = - (*arg0)[am::strings::params][am::strings::function_id].asInt(); - (*message)[am::strings::params][am::strings::message_type] = - (*arg0)[am::strings::params][am::strings::message_type].asInt(); - (*message)[am::strings::params][am::strings::correlation_id] = - (*arg0)[am::strings::params][am::strings::correlation_id].asInt(); - (*message)[am::strings::params][am::strings::connection_key] = - (*arg0)[am::strings::params][am::strings::connection_key].asInt(); - return (*message)[am::strings::params][am::strings::correlation_id].asInt(); -} - -namespace { -const uint32_t kCountCommandsManageMobile_ = 22u; -const uint32_t kCountCommandsToHmi_ = 12u; -const int32_t kHmiProtocolType_ = 1; -const int32_t kMobileProtocolType_ = 0; -const int32_t kProtocolVersion_ = 3; -const uint32_t kCorrelationId_ = 1939u; -const uint32_t kAppId_ = 2014u; -} // namespace - -class HMICommandsNotificationsTest - : public components::commands_test::CommandsTest< - CommandsTestMocks::kIsNice> { - public: - HMICommandsNotificationsTest() - : applications_(application_set_, applications_lock_), app_ptr_(NULL) {} - - ~HMICommandsNotificationsTest() { - // Fix DataAccessor release and WinQt crash - Mock::VerifyAndClearExpectations(&app_mngr_); - } - typedef Command CommandType; - - protected: - am::ApplicationSet application_set_; - sync_primitives::Lock applications_lock_; - DataAccessor applications_; - MockHMICapabilities mock_hmi_capabilities_; - - NiceMock mock_event_dispatcher_; - NiceMock policy_interface_; - - application_manager_test::MockStateController mock_state_controller_; - - am::ApplicationSharedPtr app_; - NiceMock* app_ptr_; - - typedef IsNiceMock::Result MockConnectionHandler; - - typedef IsNiceMock::Result MockSessionObserver; - - MockConnectionHandler mock_connection_handler_; - MockSessionObserver mock_session_observer_; - - void InitCommand(const uint32_t& default_timeout) OVERRIDE { - app_ = ConfigureApp(&app_ptr_, kAppId_, NOT_MEDIA, NOT_NAVI, NOT_VC); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(default_timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(mock_event_dispatcher_)); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(policy_interface_)); - ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_)); - ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); - } - - am::ApplicationSharedPtr ConfigureApp(NiceMock** app_mock, - uint32_t app_id, - bool media, - bool navi, - bool vc) { - *app_mock = new NiceMock; - - Mock::AllowLeak(*app_mock); // WorkAround for gogletest bug - am::ApplicationSharedPtr app(*app_mock); - - ON_CALL(**app_mock, app_id()).WillByDefault(Return(app_id)); - ON_CALL(**app_mock, is_media_application()).WillByDefault(Return(media)); - ON_CALL(**app_mock, is_navi()).WillByDefault(Return(navi)); - ON_CALL(**app_mock, is_voice_communication_supported()) - .WillByDefault(Return(vc)); - ON_CALL(**app_mock, IsAudioApplication()) - .WillByDefault(Return(media || navi || vc)); - return app; - } -#if defined(OS_POSIX) - void SubscribeForSignal() { - sigset_t signal_set; - sigemptyset(&signal_set); - sigaddset(&signal_set, SIGINT); - sigaddset(&signal_set, SIGTERM); - pthread_sigmask(SIG_BLOCK, &signal_set, NULL); - } -#endif -}; - -namespace { -void sig_handler(int sig) { - switch (sig) { - case SIGINT: - break; - case SIGTERM: - break; - case SIGSEGV: - abort(); - default: - exit(EXIT_FAILURE); - } -} -} // namespace - -template -class HMIOnViNotifications : public commands_test::CommandsTest { - public: - typedef Command CommandType; -}; - -template -class HMIOnNotificationsListToHMI - : public commands_test::CommandsTest { - public: - typedef Command CommandType; -}; - -template -struct CommandPair { - typedef CommandT CommandType; - enum { kHMICommandId = kCommandId }; -}; - -template -class HMIOnNotificationsEventDispatcher - : public commands_test::CommandsTest { - public: - typedef Command CommandType; - NiceMock mock_event_dispatcher_; -}; - -typedef Types HMIOnViNotificationsTypes; - -typedef Types HMIOnNotificationsListToHMITypes; - -typedef Types< - CommandPair, - CommandPair, - CommandPair, - CommandPair, - CommandPair, - CommandPair, - CommandPair, - CommandPair, - CommandPair > - HMIOnNotificationsEventDispatcherTypes; - -TYPED_TEST_CASE(HMIOnViNotifications, HMIOnViNotificationsTypes); -TYPED_TEST_CASE(HMIOnNotificationsListToHMI, HMIOnNotificationsListToHMITypes); -TYPED_TEST_CASE(HMIOnNotificationsEventDispatcher, - HMIOnNotificationsEventDispatcherTypes); - -TYPED_TEST(HMIOnViNotifications, CommandsSendNotificationToMobile) { - MessageSharedPtr message = - commands_test::CommandsTest::CreateMessage(); - utils::SharedPtr command = - this->template CreateCommand(message); - EXPECT_CALL(commands_test::CommandsTest::app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(commands_test::CommandsTest::rpc_service_)); - EXPECT_CALL(commands_test::CommandsTest::rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ( - static_cast(mobile_apis::FunctionID::eType::OnVehicleDataID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TYPED_TEST(HMIOnNotificationsListToHMI, CommandsSendNotificationToHmi) { - MessageSharedPtr message = - commands_test::CommandsTest::CreateMessage(); - utils::SharedPtr command = - this->template CreateCommand(message); - EXPECT_CALL(commands_test::CommandsTest::app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(commands_test::CommandsTest::rpc_service_)); - EXPECT_CALL(commands_test::CommandsTest::rpc_service_, - SendMessageToHMI(_)); - command->Run(); - EXPECT_EQ( - static_cast(kHmiProtocolType_), - (*message)[am::strings::params][am::strings::protocol_type].asInt()); - EXPECT_EQ( - static_cast(kProtocolVersion_), - (*message)[am::strings::params][am::strings::protocol_version].asInt()); -} - -TYPED_TEST(HMIOnNotificationsEventDispatcher, - CommandsNotificationEventDispatcher) { - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = - commands_test::CommandsTest::CreateMessage(); - utils::SharedPtr command = - this->template CreateCommand< - typename TestFixture::CommandType::CommandType>(message); - EXPECT_CALL(commands_test::CommandsTest::app_mngr_, - event_dispatcher()) - .WillOnce(ReturnRef(this->mock_event_dispatcher_)); - EXPECT_CALL(this->mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - command->Run(); - EXPECT_EQ(TestFixture::CommandType::kHMICommandId, event_id); -} - -// notifications(SendNotificationToMobile) -TEST_F(HMICommandsNotificationsTest, OnButtonEventSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnButtonEventID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnNaviTBTClientSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnTBTClientStateID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnNaviWayPointChangeSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnWayPointChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnUICommandSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnCommandID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(mobile_apis::TriggerSource::TS_MENU), - (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnUIKeyBoardInputSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnKeyboardInputID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnUITouchEventSendNotificationToMobile) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnTouchEventID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnAppRegisteredNotificationSendNotificationToHmi) { - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)); - EXPECT_CALL(app_mngr_, event_dispatcher()); - EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - command->Run(); - EXPECT_EQ(static_cast( - hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), - event_id); - EXPECT_EQ( - kHmiProtocolType_, - (*message)[am::strings::params][am::strings::protocol_type].asInt()); - EXPECT_EQ( - kProtocolVersion_, - (*message)[am::strings::params][am::strings::protocol_version].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnAppUnregisteredNotificationEventDispatcher) { - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)); - EXPECT_CALL(app_mngr_, event_dispatcher()); - EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - command->Run(); - EXPECT_EQ(static_cast( - hmi_apis::FunctionID::BasicCommunication_OnAppUnregistered), - event_id); - EXPECT_EQ( - kHmiProtocolType_, - (*message)[am::strings::params][am::strings::protocol_type].asInt()); - EXPECT_EQ( - kProtocolVersion_, - (*message)[am::strings::params][am::strings::protocol_version].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnButtonPressNotificationEventDispatcher) { - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, event_dispatcher()); - EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - command->Run(); - EXPECT_EQ(static_cast(hmi_apis::FunctionID::Buttons_OnButtonPress), - event_id); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnButtonPressID), - (*message)[am::strings::params][am::strings::function_id].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, OnHMIStartedCooperation()); - EXPECT_CALL(app_mngr_, event_dispatcher()); - EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - command->Run(); - EXPECT_EQ(hmi_apis::FunctionID::BasicCommunication_OnReady, event_id); -} - -// policy handler -TEST_F(HMICommandsNotificationsTest, - OnIgnitionCycleOverNotificationPolicyHandler) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnIgnitionCycleOver()); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, OnPolicyUpdateNotificationPolicyHandler) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnPTExchangeNeeded()); - command->Run(); -} - -#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE) -TEST_F(HMICommandsNotificationsTest, - OnReceivePolicyUpdateNotification_SUCCESS) { - const std::string kFile = "./test_file.txt"; - EXPECT_TRUE(file_system::CreateFile(kFile)); - uint8_t tmp[] = {1u, 2u, 3u, 4u}; - std::vector data(tmp, tmp + 4); - EXPECT_TRUE(file_system::WriteBinaryFile(kFile, data)); - - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); - (*message)[am::strings::msg_params][am::hmi_notification::policyfile] = kFile; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, ReceiveMessageFromSDK(kFile, data)); - command->Run(); - EXPECT_TRUE(file_system::DeleteFile(kFile)); -} -#endif - -TEST_F(HMICommandsNotificationsTest, - OnReceivePolicyUpdateNotification_UNSUCCESS) { - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - EXPECT_CALL(policy_interface_, ReceiveMessageFromSDK(_, _)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnAppPermissionConsentNotificationPolicyHandlerNoAppId) { - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); - (*message)[am::strings::msg_params]["consentedFunctions"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - SmartObject& applications = - (*message)[am::strings::msg_params]["consentedFunctions"]; - - smart_objects::SmartObject hmi_application_temp(smart_objects::SmartType_Map); - applications[0] = hmi_application_temp; - - utils::SharedPtr command = - CreateCommand(message); - - int32_t connection_id = -1; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); -#ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _, _)) -#else - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _)) -#endif - .WillOnce(GetArg(&connection_id)); - command->Run(); - EXPECT_EQ(0, connection_id); -} - -TEST_F(HMICommandsNotificationsTest, - OnAppPermissionConsentNotificationPolicyHandlerWithAppId) { - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - (*message)[am::strings::msg_params]["consentedFunctions"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - smart_objects::SmartObjectSPtr consented_function = - utils::MakeShared(); - (*message)[am::strings::msg_params]["consentedFunctions"][0] = - *consented_function; - - utils::SharedPtr command = - CreateCommand(message); - - int32_t connection_id = -1; - policy::PermissionConsent permission_consent; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); -#ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _, _)) -#else - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _)) -#endif - .WillOnce( - GetConnectIdPermissionConsent(&connection_id, &permission_consent)); - command->Run(); - EXPECT_EQ(static_cast(kAppId_), connection_id); - std::vector::const_iterator it = - permission_consent.group_permissions.begin(); - for (; it != permission_consent.group_permissions.end(); ++it) { - EXPECT_EQ(policy::kGroupUndefined, (*it).state); - } -} - -TEST_F(HMICommandsNotificationsTest, - OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowTrue) { - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); - (*message)[am::strings::msg_params]["consentedFunctions"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - (*message)[am::strings::msg_params]["source"] = "test_content_source"; - - smart_objects::SmartObjectSPtr consented_function = - utils::MakeShared(); - (*consented_function)["allowed"] = true; - (*consented_function)[am::strings::id] = 999; - (*consented_function)[am::strings::name] = "test_group_alias"; - (*message)[am::strings::msg_params]["consentedFunctions"][0] = - *consented_function; - - utils::SharedPtr command = - CreateCommand(message); - - int32_t connection_id = -1; - policy::PermissionConsent permission_consent; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); -#ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _, _)) -#else - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _)) -#endif - .WillOnce( - GetConnectIdPermissionConsent(&connection_id, &permission_consent)); - command->Run(); - EXPECT_EQ(static_cast(kAppId_), connection_id); - - std::vector::const_iterator it = - permission_consent.group_permissions.begin(); - for (; it != permission_consent.group_permissions.end(); ++it) { - EXPECT_EQ(999, (*it).group_id); - EXPECT_EQ("test_group_alias", (*it).group_alias); - EXPECT_EQ(policy::kGroupAllowed, (*it).state); - } - EXPECT_EQ("test_content_source", permission_consent.consent_source); -} - -TEST_F(HMICommandsNotificationsTest, - OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowFalse) { - MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); - (*message)[am::strings::msg_params]["consentedFunctions"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - (*message)[am::strings::msg_params]["source"] = "test_content_source"; - - smart_objects::SmartObjectSPtr consented_function = - utils::MakeShared(); - (*consented_function)["allowed"] = false; - (*consented_function)[am::strings::id] = 999; - (*consented_function)[am::strings::name] = "test_group_alias"; - (*message)[am::strings::msg_params]["consentedFunctions"][0] = - *consented_function; - - utils::SharedPtr command = - CreateCommand(message); - - int32_t connection_id = -1; - policy::PermissionConsent permission_consent; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); -#ifdef EXTERNAL_PROPRIETARY_MODE - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _, _)) -#else - EXPECT_CALL(policy_interface_, OnAppPermissionConsent(_, _)) -#endif - .WillOnce( - GetConnectIdPermissionConsent(&connection_id, &permission_consent)); - command->Run(); - EXPECT_EQ(static_cast(kAppId_), connection_id); - - std::vector::const_iterator it = - permission_consent.group_permissions.begin(); - for (; it != permission_consent.group_permissions.end(); ++it) { - EXPECT_EQ(999, (*it).group_id); - EXPECT_EQ("test_group_alias", (*it).group_alias); - EXPECT_EQ(policy::kGroupDisallowed, (*it).state); - } - EXPECT_EQ("test_content_source", permission_consent.consent_source); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemErrorNotificationOnSystemErrorCode) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::error] = - hmi_apis::Common_SystemError::SYNC_REBOOTED; - - utils::SharedPtr command = - CreateCommand(message); - - int32_t code = hmi_apis::Common_SystemError::INVALID_ENUM; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnSystemError(_)).WillOnce(GetArg(&code)); - command->Run(); - EXPECT_EQ(static_cast(hmi_apis::Common_SystemError::SYNC_REBOOTED), - code); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemInfoChangedNotificationCheckLanguage) { - const uint32_t kLangCode = 5u; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLangCode; - - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)); - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnSystemInfoChanged(_)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnAllowSDLFunctionalityNotificationDeviceKeyNotExist) { - const std::string kDeviceId = ""; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; - utils::SharedPtr command = - CreateCommand(message); - - bool value = false; - std::string str; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnAllowSDLFunctionalityNotification(_, _)) - .WillOnce(GetBoolValueAndString(&value, &str)); - command->Run(); - EXPECT_EQ(true, value); - EXPECT_EQ(kDeviceId, str); -} - -TEST_F(HMICommandsNotificationsTest, - OnAllowSDLFunctionalityNotificationDeviceKeyExist) { - const std::string kDeviceId = "device_id"; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; - (*message)[am::strings::msg_params]["device"]["id"] = kDeviceId; - utils::SharedPtr command = - CreateCommand(message); - - bool value; - std::string str; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, OnAllowSDLFunctionalityNotification(_, _)) - .WillOnce(GetBoolValueAndString(&value, &str)); - command->Run(); - EXPECT_EQ(true, value); - EXPECT_EQ(kDeviceId, str); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceStateChangedNotificationDeviceStateNotUnpaired) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params]["deviceState"] = - hmi_apis::Common_DeviceState::INVALID_ENUM; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - EXPECT_CALL(policy_interface_, RemoveDevice(_)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceStateChangedNotificationDeviceStateUnpaired) { - // Random MAC adress for test. It must contain 12 symbols. - const std::string device_id = "AA15F2204D6B"; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params]["deviceState"] = - hmi_apis::Common_DeviceState::UNPAIRED; - (*message)[am::strings::msg_params]["deviceInternalId"] = device_id; - - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, RemoveDevice(_)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceStateChangedNotificationDeviceStateEmptyDeviceId) { - const std::string empty_device_id = ""; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params]["deviceState"] = - hmi_apis::Common_DeviceState::UNPAIRED; - (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; - - utils::SharedPtr command = - CreateCommand(message); - - std::string device_id = "default_id"; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, RemoveDevice(_)).WillOnce(GetArg(&device_id)); - command->Run(); - EXPECT_EQ(empty_device_id, device_id); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceStateChangedNotificationDeviceStateDeviceIdFromId) { - const std::string empty_device_id = ""; - const std::string id = "id_string"; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params]["deviceState"] = - hmi_apis::Common_DeviceState::UNPAIRED; - (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; - (*message)[am::strings::msg_params]["deviceId"]["id"] = id; - - utils::SharedPtr command = - CreateCommand(message); - - std::string device_id = "default_id"; - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, RemoveDevice(_)).WillOnce(GetArg(&device_id)); - command->Run(); - EXPECT_EQ(id, device_id); -} - -//~policy_handler -TEST_F(HMICommandsNotificationsTest, - OnExitAllApplicationsNotificationReasonIgnitionOff) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_request::reason] = - hmi_apis::Common_ApplicationsCloseReason::IGNITION_OFF; - - utils::SharedPtr command = - CreateCommand(message); -#if defined(OS_POSIX) - am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason; - - EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)) - .WillOnce(GetArg(&mob_reason)); - EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); - - SubscribeForSignal(); - command->Run(); - utils::WaitTerminationSignals(sig_handler); - - EXPECT_EQ(am::mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF, - mob_reason); -#endif -} - -TEST_F(HMICommandsNotificationsTest, - OnExitAllApplicationsNotificationReasonMasterResetAndFactoryDefaults) { - MessageSharedPtr message = CreateMessage(); - - std::vector reason_list; - reason_list.push_back(hmi_apis::Common_ApplicationsCloseReason::MASTER_RESET); - reason_list.push_back( - hmi_apis::Common_ApplicationsCloseReason::FACTORY_DEFAULTS); - - std::vector - mob_reason_list; - mob_reason_list.push_back( - mobile_apis::AppInterfaceUnregisteredReason::MASTER_RESET); - mob_reason_list.push_back( - mobile_apis::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS); - - std::vector::iterator - it_reason = reason_list.begin(); - std::vector::iterator - it_mob_reason = mob_reason_list.begin(); - - for (; it_reason != reason_list.end(); ++it_reason, ++it_mob_reason) { - (*message)[am::strings::msg_params][am::hmi_request::reason] = *it_reason; - - utils::SharedPtr command = - CreateCommand(message); -#if defined(OS_POSIX) - am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason = - *it_mob_reason; - - EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(mob_reason)); - EXPECT_CALL(app_mngr_, HeadUnitReset(mob_reason)); - - SubscribeForSignal(); - command->Run(); - utils::WaitTerminationSignals(sig_handler); -#endif - } -} - -TEST_F(HMICommandsNotificationsTest, - OnExitAllApplicationsNotificationReasonSuspend) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_request::reason] = - hmi_apis::Common_ApplicationsCloseReason::SUSPEND; - - utils::SharedPtr command = - CreateCommand(message); - - MessageSharedPtr ethalon_message = - CreateMessage(smart_objects::SmartType_Map); - (*ethalon_message)[am::strings::params][am::strings::function_id] = - hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete; - (*ethalon_message)[am::strings::params][am::strings::message_type] = - am::MessageType::kNotification; - (*ethalon_message)[am::strings::params][am::strings::correlation_id] = - kCorrelationId_; - MessageSharedPtr temp_message = CreateMessage(); - - resumprion_test::MockResumeCtrl mock_resume_ctrl; - EXPECT_CALL(app_mngr_, resume_controller()) - .WillOnce(ReturnRef(mock_resume_ctrl)); - EXPECT_CALL(mock_resume_ctrl, OnSuspend()); - - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(GetMessage(temp_message)); - - command->Run(); - EXPECT_EQ( - static_cast( - hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete), - (*temp_message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(am::MessageType::kNotification), - (*temp_message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ(static_cast(kCorrelationId_), - (*temp_message)[am::strings::params][am::strings::correlation_id] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnExitAllApplicationsNotificationReasonInvalidEnum) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_request::reason] = - hmi_apis::Common_ApplicationsCloseReason::INVALID_ENUM; - - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)).Times(0); - EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnExitApplicationNotificationManageMobileCommand) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - smart_objects::SmartObjectSPtr notification = - utils::MakeShared(); - (*notification)[am::strings::params][am::strings::function_id] = - static_cast( - mobile_apis::FunctionID::OnAppInterfaceUnregisteredID); - (*notification)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kNotification); - (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; - - std::vector reason_list; - reason_list.push_back(hmi_apis::Common_ApplicationExitReason:: - UNAUTHORIZED_TRANSPORT_REGISTRATION); - reason_list.push_back( - hmi_apis::Common_ApplicationExitReason::UNSUPPORTED_HMI_RESOURCE); - - std::vector - mobile_reason_list; - mobile_reason_list.push_back( - mobile_apis::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED); - mobile_reason_list.push_back( - mobile_apis::AppInterfaceUnregisteredReason::UNSUPPORTED_HMI_RESOURCE); - - std::vector::iterator - it_mobile_reason = mobile_reason_list.begin(); - std::vector::iterator - it_reason = reason_list.begin(); - - for (; it_reason != reason_list.end(); ++it_reason, ++it_mobile_reason) { - (*message)[am::strings::msg_params][am::strings::reason] = *it_reason; - utils::SharedPtr command = - CreateCommand(message); - - (*notification)[am::strings::msg_params][am::strings::reason] = - static_cast(*it_mobile_reason); - -#ifdef SDL_REMOTE_CONTROL - plugin_manager::RPCPluginManager plugin_mng; - EXPECT_CALL(app_mngr_, GetPluginManager()) - .WillRepeatedly(ReturnRef(plugin_mng)); -#endif // SDL_REMOTE_CONTROL - - EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(mock_message_helper_, - GetOnAppInterfaceUnregisteredNotificationToMobile( - kAppId_, *it_mobile_reason)).WillOnce(Return(notification)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(notification, Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, - UnregisterApplication( - kAppId_, mobile_apis::Result::SUCCESS, false, false)); - command->Run(); - } -} - -TEST_F(HMICommandsNotificationsTest, - OnExitApplicationNotificationUnhandledReason) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - - (*message)[am::strings::msg_params][am::strings::reason] = - hmi_apis::Common_ApplicationExitReason::INVALID_ENUM; - - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, OnExitApplicationNotificationInvalidApp) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - - utils::SharedPtr command = - CreateCommand(message); - - am::ApplicationSharedPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - DISABLED_OnExitApplicationNotificationDriverDistractionValidApp) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - (*message)[am::strings::msg_params][am::strings::reason] = - hmi_apis::Common_ApplicationExitReason::DRIVER_DISTRACTION_VIOLATION; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); - - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, - mobile_apis::HMILevel::HMI_NONE, - mobile_apis::AudioStreamingState::NOT_AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - false)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnExitApplicationNotificationrUserExitValidApp) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - (*message)[am::strings::msg_params][am::strings::reason] = - hmi_apis::Common_ApplicationExitReason::USER_EXIT; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, - mobile_apis::HMILevel::HMI_NONE, - mobile_apis::AudioStreamingState::NOT_AUDIBLE, - mobile_apis::VideoStreamingState::NOT_STREAMABLE, - false)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationSwitchedAndValidApp) { - const uint32_t cmd_id = 12u; - const uint32_t max_cmd_id = 10u; - - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = cmd_id; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(_, mobile_apis::HMILevel::HMI_FULL, true)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(max_cmd_id)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationSwitchedAndInvalidApp) { - const uint32_t kCmdId = 12u; - const uint32_t kMaxCmdId = 10u; - - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - utils::SharedPtr command = - CreateCommand(message); - - am::ApplicationSharedPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(invalid_app)); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationCmdIdEqualToMaxCmdId) { - const uint32_t kCmdId = 11u; - const uint32_t kMaxCmdId = 10u; - - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationCmdIdLessMaxCmdIsInvalidApp) { - const uint32_t kCmdId = 8u; - const uint32_t kMaxCmdId = 10u; - - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - utils::SharedPtr command = - CreateCommand(message); - - am::ApplicationSharedPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationActivePerformIteraction) { - const uint32_t kCmdId = 8u; - const uint32_t kMaxCmdId = 10u; - const uint32_t kIsPerformInteractionActive = 1u; - int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) - .WillOnce(Return(kIsPerformInteractionActive)); - EXPECT_CALL(app_mngr_, event_dispatcher()); - EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) - .WillOnce(GetEventId(&event_id)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->Run(); - EXPECT_EQ(hmi_apis::FunctionID::VR_OnCommand, event_id); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRCommandNotificationNotActivePerformIteraction) { - const uint32_t kCmdId = 8u; - const uint32_t kMaxCmdId = 10u; - const uint32_t kIsPerformInteractionActive = 0u; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - (*message)[am::strings::msg_params][am::strings::function_id] = - mobile_apis::FunctionID::eType::OnCommandID; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); - EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) - .WillOnce(Return(kIsPerformInteractionActive)); - - EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::eType::OnCommandID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(mobile_apis::TriggerSource::TS_VR), - (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnVRLanguageChangeNotificationEmptyData) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - EXPECT_CALL(*app_ptr_, language()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRLanguageChangeNotificationAppLangEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); - - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(hmi_apis::Common_Language::EN_AU), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnVRLanguageChangeNotificationAppLangNotEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = - mobile_apis::Language::EN_US; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - smart_objects::SmartObjectSPtr notification = - utils::MakeShared(); - (*notification)[am::strings::params][am::strings::function_id] = - static_cast(mobile_apis::FunctionID::OnLanguageChangeID); - (*notification)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kNotification); - (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; - (*notification)[am::strings::msg_params][am::strings::reason] = - static_cast( - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); - EXPECT_CALL(mock_message_helper_, - GetOnAppInterfaceUnregisteredNotificationToMobile( - kAppId_, - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) - .WillOnce(Return(notification)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(notification, Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, - UnregisterApplication( - kAppId_, mobile_apis::Result::SUCCESS, false, false)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(hmi_apis::Common_Language::EN_AU), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnStartDeviceDiscoveryRun) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, StartDevicesDiscovery()); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceChosenNotificationDeviceInfoExists) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::device_info] - [am::strings::id] = "2014"; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, - ConnectToDevice( - (*message)[am::strings::msg_params][am::strings::device_info] - [am::strings::id].asString())); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnDeviceChosenNotificationDeviceInfoNotExists) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, ConnectToDevice(_)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemContextNotificationValidActiveApplication) { - MessageSharedPtr message = CreateMessage(); - std::vector system_context_list; - system_context_list.push_back( - am::mobile_api::SystemContext::SYSCTXT_VRSESSION); - system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MENU); - system_context_list.push_back( - am::mobile_api::SystemContext::SYSCTXT_HMI_OBSCURED); - - std::vector::iterator it = - system_context_list.begin(); - for (; it != system_context_list.end(); ++it) { - (*message)[am::strings::msg_params][am::hmi_notification::system_context] = - *it; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(app_)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); - command->Run(); - } -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemContextNotificationInvalidActiveApplication) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::system_context] = - am::mobile_api::SystemContext::SYSCTXT_VRSESSION; - utils::SharedPtr command = - CreateCommand(message); - ApplicationSharedPtr invalid_app; - EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(invalid_app)); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemContextNotificationInvalidSystemContext) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::system_context] = - am::mobile_api::SystemContext::INVALID_ENUM; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, active_application()).Times(0); - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemContextNotificationValidApplication) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - std::vector system_context_list; - system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_ALERT); - system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MAIN); - - std::vector::iterator it = - system_context_list.begin(); - for (; it != system_context_list.end(); ++it) { - (*message)[am::strings::msg_params][am::hmi_notification::system_context] = - *it; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); - command->Run(); - } -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemContextNotificationAppIdDoesntExists) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::system_context] = - am::mobile_api::SystemContext::SYSCTXT_ALERT; - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_, state_controller()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemRequestNotificationAppIdExistsAndValidApp) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); - ON_CALL(app_mngr_, connection_handler()) - .WillByDefault(ReturnRef(mock_connection_handler_)); - ON_CALL(mock_connection_handler_, get_session_observer()) - .WillByDefault(ReturnRef(mock_session_observer_)); - const int32_t device_id = 1; - ON_CALL( - mock_session_observer_, - GetDataOnDeviceID( - testing::An(), NULL, NULL, _, NULL)) - .WillByDefault(Return(device_id)); - - EXPECT_CALL(policy_interface_, GetUserConsentForDevice(_)) - .WillOnce(Return(policy::kDeviceAllowed)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemRequestNotificationAppIdExistsAndInvalidApp) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; - utils::SharedPtr command = - CreateCommand(message); - ApplicationSharedPtr invalid_app; - EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->Run(); - EXPECT_EQ( - static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), - (*message)[am::strings::params][am::strings::function_id].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemRequestNotificationAppIdDoesntExistsAndValidApp) { - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(policy_interface_)); - EXPECT_CALL(policy_interface_, GetAppIdForSending()) - .WillOnce(Return(kAppId_)); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); - ON_CALL(app_mngr_, connection_handler()) - .WillByDefault(ReturnRef(mock_connection_handler_)); - ON_CALL(mock_connection_handler_, get_session_observer()) - .WillByDefault(ReturnRef(mock_session_observer_)); - const int32_t device_id = 1; - ON_CALL( - mock_session_observer_, - GetDataOnDeviceID( - testing::An(), NULL, NULL, _, NULL)) - .WillByDefault(Return(device_id)); - - EXPECT_CALL(policy_interface_, GetUserConsentForDevice(_)) - .WillOnce(Return(policy::kDeviceAllowed)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - command->Run(); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(mobile_apis::FunctionID::eType::OnSystemRequestID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnSystemRequestNotificationAppIdDoesntExistsAndNullAppId) { - const uint32_t kNullApppId = 0u; - MessageSharedPtr message = CreateMessage(); - utils::SharedPtr command = - CreateCommand(message); - EXPECT_CALL(app_mngr_, GetPolicyHandler()); - EXPECT_CALL(policy_interface_, GetAppIdForSending()) - .WillOnce(Return(kNullApppId)); - EXPECT_CALL(app_mngr_, application(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, OnTTSLanguageChangeNotificationEmptyData) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - EXPECT_CALL(*app_ptr_, language()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnTTSLanguageChangeNotificationAppLangEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); - - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(hmi_apis::Common_Language::EN_AU), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnTTSLanguageChangeNotificationAppLangNotEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = - mobile_apis::Language::EN_US; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - smart_objects::SmartObjectSPtr notification = - utils::MakeShared(); - (*notification)[am::strings::params][am::strings::function_id] = - static_cast(mobile_apis::FunctionID::OnLanguageChangeID); - (*notification)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kNotification); - (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; - (*notification)[am::strings::msg_params][am::strings::reason] = - static_cast( - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); - EXPECT_CALL(mock_message_helper_, - GetOnAppInterfaceUnregisteredNotificationToMobile( - kAppId_, - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) - .WillOnce(Return(notification)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(notification, Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, - UnregisterApplication( - kAppId_, mobile_apis::Result::SUCCESS, false, false)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(hmi_apis::Common_Language::EN_AU), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnUILanguageChangeNotificationEmptyData) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); - EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - EXPECT_CALL(*app_ptr_, ui_language()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnUILanguageChangeNotificationAppLangEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = kLang; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); - - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(kLang), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, - OnUILanguageChangeNotificationAppLangNotEqualMessageLang) { - const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::language] = - mobile_apis::Language::EN_US; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - smart_objects::SmartObjectSPtr notification = - utils::MakeShared(); - (*notification)[am::strings::params][am::strings::function_id] = - static_cast(mobile_apis::FunctionID::OnLanguageChangeID); - (*notification)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kNotification); - (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; - (*notification)[am::strings::msg_params][am::strings::reason] = - static_cast( - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) - .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); - EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); - EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); - EXPECT_CALL(mock_message_helper_, - GetOnAppInterfaceUnregisteredNotificationToMobile( - kAppId_, - mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) - .WillOnce(Return(notification)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(notification, Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, - UnregisterApplication( - kAppId_, mobile_apis::Result::SUCCESS, false, false)); - command->Run(); - EXPECT_EQ(static_cast(mobile_apis::FunctionID::OnLanguageChangeID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - static_cast(mobile_apis::Language::EN_US), - (*message)[am::strings::msg_params][am::strings::hmi_display_language] - .asInt()); -} - -TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::state] = state; - utils::SharedPtr command = - CreateCommand(message); - - EXPECT_CALL(app_mngr_, set_driver_distraction(state)); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, - OnDriverDistractionNotificationInvalidApp) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::hmi_notification::state] = state; - utils::SharedPtr command = - CreateCommand(message); - - ApplicationSharedPtr invalid_app; - application_set_.insert(invalid_app); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(*app_ptr_, app_id()).Times(0); - command->Run(); -} - -TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::mobile_notification::state] = state; - utils::SharedPtr command = - CreateCommand(message); - - application_set_.insert(app_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); - policy::CheckPermissionResult result; - result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_interface_)); - EXPECT_CALL(policy_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) - .WillOnce(GetMessage(message)); - EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); - - command->Run(); - EXPECT_EQ( - static_cast(am::mobile_api::FunctionID::OnDriverDistractionID), - (*message)[am::strings::params][am::strings::function_id].asInt()); - EXPECT_EQ( - static_cast(kAppId_), - (*message)[am::strings::params][am::strings::connection_key].asInt()); - EXPECT_EQ(static_cast(am::MessageType::kNotification), - (*message)[am::strings::params][am::strings::message_type].asInt()); -} - -} // namespace hmi_notifications_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/mixing_audio_supported_request_test.cc b/src/components/application_manager/test/commands/hmi/mixing_audio_supported_request_test.cc deleted file mode 100644 index 015fc5d7ca..0000000000 --- a/src/components/application_manager/test/commands/hmi/mixing_audio_supported_request_test.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "commands/command_request_test.h" -#include "hmi/request_to_hmi.h" -#include "application_manager/commands/hmi/mixing_audio_supported_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace mixing_audio_supported_request { - -using ::testing::_; -using ::testing::Return; -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::RequestToHMI; -using am::commands::MixingAudioSupportedRequest; -using am::commands::CommandImpl; - -typedef SharedPtr RequestToHMIPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class MixingAudioSupportedRequestTest - : public CommandsTest {}; - -TEST_F(MixingAudioSupportedRequestTest, RUN_SendRequest_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - RequestToHMIPtr command( - CreateCommand(command_msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -} // namespace mixing_audio_supported_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/mixing_audio_supported_response_test.cc b/src/components/application_manager/test/commands/hmi/mixing_audio_supported_response_test.cc deleted file mode 100644 index 89ba6c8bdb..0000000000 --- a/src/components/application_manager/test/commands/hmi/mixing_audio_supported_response_test.cc +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/commands/command.h" -#include "commands/commands_test.h" -#include "commands/command_request_test.h" -#include "application_manager/commands/hmi/response_from_hmi.h" -#include "interfaces/HMI_API.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/commands/hmi/mixing_audio_supported_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace mixing_audio_supported_response { - -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::NiceMock; -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::ResponseFromHMI; -using am::commands::MixingAudioSupportedResponse; -using am::commands::CommandImpl; -using am::HMICapabilities; -namespace hmi_response = ::application_manager::hmi_response; - -typedef SharedPtr ResponseFromHMIPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class MixingAudioSupportedResponseTest - : public CommandsTest {}; - -TEST_F(MixingAudioSupportedResponseTest, RUN_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - MockHMICapabilities mock_hmi_capabilities; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - - const bool hmiResponse = - (*command_msg)[strings::msg_params][hmi_response::attenuated_supported] - .asBool(); - - EXPECT_CALL(mock_hmi_capabilities, set_attenuated_supported(hmiResponse)); - - command->Run(); -} - -} // namespace mixing_audio_supported_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_audio_start_stream_request_test.cc b/src/components/application_manager/test/commands/hmi/navi_audio_start_stream_request_test.cc deleted file mode 100644 index 96397e56c3..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_audio_start_stream_request_test.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/navi_audio_start_stream_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" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_audio_start_stream_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -namespace commands = am::commands; -using commands::MessageSharedPtr; -using commands::AudioStartStreamRequest; -using am::event_engine::Event; - -namespace { -const uint32_t kHmiAppId = 13u; -const am::HmiInterfaces::InterfaceID kHmiInterface = - am::HmiInterfaces::HMI_INTERFACE_Navigation; -} // namespace - -class AudioStartStreamRequestTest - : public CommandRequestTest { - public: - AudioStartStreamRequestTest() { - ON_CALL(app_mngr_settings_, start_stream_retry_amount()) - .WillByDefault(ReturnRef(start_stream_retry_amount_)); - msg_ = CreateMessage(); - command_ = CreateCommand(msg_); - } - - std::pair start_stream_retry_amount_; - MessageSharedPtr msg_; - SharedPtr command_; -}; - -TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)).Times(0); - - command_->Run(); -} - -TEST_F(AudioStartStreamRequestTest, - Run_HmiInterfaceAvailableButNoApp_NoRequest) { - (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)).Times(0); - - command_->Run(); -} - -TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { - (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_audio_streaming_allowed(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(msg_)); - - command_->Run(); -} - -} // namespace navi_audio_start_stream_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/navi_is_ready_request_test.cc deleted file mode 100644 index 825cca9185..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_is_ready_request_test.cc +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/navi_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/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_is_ready_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::NaviIsReadyRequest; -using am::event_engine::Event; - -namespace { -const hmi_apis::FunctionID::eType kEventID = - hmi_apis::FunctionID::Navigation_IsReady; -} // namespace - -typedef SharedPtr NaviIsReadyRequestPtr; - -class NaviIsReadyRequestTest - : public CommandRequestTest { - public: - NaviIsReadyRequestTest() : command_(CreateCommand()) { - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(mock_hmi_capabilities_)); - } - - NaviIsReadyRequestPtr command_; - MOCK(application_manager_test::MockHMICapabilities) mock_hmi_capabilities_; -}; - -TEST_F(NaviIsReadyRequestTest, - OnEvent_HmiInterfaceIsAvailable_NaviCooperatingIsAvailable) { - const bool is_hmi_interface_available = true; - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::msg_params][am::strings::available] = - is_hmi_interface_available; - - Event event(kEventID); - event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, - am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_is_navi_cooperating(is_hmi_interface_available)); - - command_->on_event(event); -} - -TEST_F(NaviIsReadyRequestTest, - OnEvent_HmiInterfaceIsNotAvailable_NaviCooperatingIsNotAvailable) { - const bool is_hmi_interface_available = false; - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::msg_params][am::strings::available] = - is_hmi_interface_available; - - Event event(kEventID); - event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, - am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_is_navi_cooperating(is_hmi_interface_available)); - - command_->on_event(event); -} - -TEST_F(NaviIsReadyRequestTest, - OnEvent_AvailabilityFieldMissing_NaviCooperatingIsNotAvailable) { - const bool is_hmi_interface_available = false; - - MessageSharedPtr event_msg = CreateMessage(); - Event event(kEventID); - event.set_smart_object(*event_msg); - - EXPECT_CALL(mock_hmi_capabilities_, - set_is_navi_cooperating(is_hmi_interface_available)); - - command_->on_event(event); -} - -} // namespace navi_is_ready_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/navi_is_ready_response_test.cc deleted file mode 100644 index 7185a5f7ed..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_is_ready_response_test.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/commands/hmi/navi_is_ready_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_is_ready_responce { - -namespace am = ::application_manager; -namespace commands = am::commands; - -using ::testing::ReturnRef; -using ::utils::SharedPtr; -using commands::ResponseFromHMI; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr ResponseFromHMIPtr; - -class NaviIsReadyResponseTest - : public CommandRequestTest {}; - -TEST_F(NaviIsReadyResponseTest, NaviIsReadyResponse_Run_SUCCESS) { - ResponseFromHMIPtr command(CreateCommand()); - 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 navi_is_ready_responce -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_set_video_config_request_test.cc b/src/components/application_manager/test/commands/hmi/navi_set_video_config_request_test.cc deleted file mode 100644 index 7c04aa724c..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_set_video_config_request_test.cc +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2017 Xevo Inc. - * 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 names of the copyright holders 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 "application_manager/commands/hmi/navi_set_video_config_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/event_engine/event.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_set_video_config_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::NaviSetVideoConfigRequest; -using am::event_engine::Event; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kHmiAppId = 13u; -const hmi_apis::FunctionID::eType kEventID = - hmi_apis::FunctionID::Navigation_SetVideoConfig; -} // namespace - -typedef SharedPtr NaviSetVideoConfigRequestPtr; - -class NaviSetVideoConfigRequestTest - : public CommandRequestTest { - public: - NaviSetVideoConfigRequestTest() { - mock_app_ptr_ = CreateMockApp(); - ON_CALL(app_mngr_, hmi_interfaces()) - .WillByDefault(ReturnRef(mock_hmi_interfaces_)); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_ptr_)); - ON_CALL(app_mngr_, application_by_hmi_app(_)) - .WillByDefault(Return(mock_app_ptr_)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(mock_event_dispatcher_)); - ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kAppId)); - ON_CALL(*mock_app_ptr_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); - } - - MOCK(am::MockHmiInterfaces) mock_hmi_interfaces_; - MockAppPtr mock_app_ptr_; - MockEventDispatcher mock_event_dispatcher_; -}; - -TEST_F(NaviSetVideoConfigRequestTest, OnEventWithSuccessResponse) { - MessageSharedPtr request_msg = CreateMessage(); - (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - - NaviSetVideoConfigRequestPtr command = - CreateCommand(request_msg); - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - Event event(kEventID); - event.set_smart_object(*event_msg); - - std::vector empty; - EXPECT_CALL( - app_mngr_, - OnStreamingConfigured( - kAppId, protocol_handler::ServiceType::kMobileNav, true, empty)) - .Times(1); - - command->on_event(event); -} - -static bool ValidateList(std::vector& expected, - std::vector& actual) { - std::sort(expected.begin(), expected.end()); - std::sort(actual.begin(), actual.end()); - return std::equal(expected.begin(), expected.end(), actual.begin()); -} - -TEST_F(NaviSetVideoConfigRequestTest, OnEventWithRejectedResponse) { - MessageSharedPtr request_msg = CreateMessage(); - (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*request_msg)[am::strings::msg_params][am::strings::config] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*request_msg)[am::strings::msg_params][am::strings::config] - [am::strings::protocol] = - hmi_apis::Common_VideoStreamingProtocol::RTP; - (*request_msg)[am::strings::msg_params][am::strings::config] - [am::strings::codec] = - hmi_apis::Common_VideoStreamingCodec::H265; - (*request_msg)[am::strings::msg_params][am::strings::config] - [am::strings::height] = 640; - (*request_msg)[am::strings::msg_params][am::strings::config] - [am::strings::width] = 480; - - NaviSetVideoConfigRequestPtr command = - CreateCommand(request_msg); - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::REJECTED; - - (*event_msg)[am::strings::msg_params][am::strings::rejected_params] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*event_msg)[am::strings::msg_params][am::strings::rejected_params][0] = - "codec"; - (*event_msg)[am::strings::msg_params][am::strings::rejected_params][1] = - "protocol"; - Event event(kEventID); - event.set_smart_object(*event_msg); - - std::vector rejected_params; - EXPECT_CALL(app_mngr_, - OnStreamingConfigured( - kAppId, protocol_handler::ServiceType::kMobileNav, false, _)) - .WillOnce(SaveArg<3>(&rejected_params)); - - command->on_event(event); - - ASSERT_EQ(2u, rejected_params.size()); - std::vector expected_list; - expected_list.push_back(std::string("protocol")); - expected_list.push_back(std::string("codec")); - ASSERT_TRUE(ValidateList(expected_list, rejected_params)); -} - -TEST_F(NaviSetVideoConfigRequestTest, - OnEventWithRejectedResponseWithoutParams) { - MessageSharedPtr request_msg = CreateMessage(); - (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - - NaviSetVideoConfigRequestPtr command = - CreateCommand(request_msg); - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::REJECTED; - - Event event(kEventID); - event.set_smart_object(*event_msg); - - std::vector empty; - EXPECT_CALL( - app_mngr_, - OnStreamingConfigured( - kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) - .WillOnce(Return()); - - command->on_event(event); -} - -TEST_F(NaviSetVideoConfigRequestTest, OnTimeout) { - MessageSharedPtr request_msg = CreateMessage(); - (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - - NaviSetVideoConfigRequestPtr command = - CreateCommand(request_msg); - - std::vector empty; - EXPECT_CALL( - app_mngr_, - OnStreamingConfigured( - kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) - .WillOnce(Return()); - - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(1); - - command->onTimeOut(); -} - -} // namespace navi_set_video_config_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_set_video_config_response_test.cc b/src/components/application_manager/test/commands/hmi/navi_set_video_config_response_test.cc deleted file mode 100644 index 753c2a9179..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_set_video_config_response_test.cc +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2017 Xevo Inc. - * 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 names of the copyright holders 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 "gtest/gtest.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/hmi/navi_set_video_config_response.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/smart_object_keys.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_set_video_config_response { - -using utils::SharedPtr; -using application_manager::commands::NaviSetVideoConfigResponse; -using test::components::event_engine_test::MockEventDispatcher; -using testing::_; -using testing::ReturnRef; -using ::testing::NiceMock; - -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -class NaviSetVideoConfigResponseTest - : public CommandsTest {}; - -TEST_F(NaviSetVideoConfigResponseTest, RUN_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(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(); -} - -} // namespace navi_set_video_config_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_start_stream_request_test.cc b/src/components/application_manager/test/commands/hmi/navi_start_stream_request_test.cc deleted file mode 100644 index e1597fa8fb..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_start_stream_request_test.cc +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/navi_start_stream_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" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_start_stream_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -namespace commands = am::commands; -using commands::MessageSharedPtr; -using commands::NaviStartStreamRequest; -using am::event_engine::Event; - -namespace { -const uint32_t kHmiAppId = 13u; -const am::HmiInterfaces::InterfaceID kHmiInterface = - am::HmiInterfaces::HMI_INTERFACE_Navigation; -} // namespace - -class NaviStartStreamRequestTest - : public CommandRequestTest { - public: - NaviStartStreamRequestTest() { - ON_CALL(app_mngr_settings_, start_stream_retry_amount()) - .WillByDefault(ReturnRef(start_stream_retry_amount_)); - msg_ = CreateMessage(); - command_ = CreateCommand(msg_); - } - - std::pair start_stream_retry_amount_; - MessageSharedPtr msg_; - SharedPtr command_; -}; - -TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)).Times(0); - - command_->Run(); -} - -TEST_F(NaviStartStreamRequestTest, - Run_HmiInterfaceAvailableButNoApp_NoRequest) { - (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToHMI(_)).Times(0); - - command_->Run(); -} - -TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { - (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_video_streaming_allowed(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(msg_)); - - command_->Run(); -} - -} // namespace navi_start_stream_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/navi_stop_stream_requests_test.cc b/src/components/application_manager/test/commands/hmi/navi_stop_stream_requests_test.cc deleted file mode 100644 index 8419fc8d76..0000000000 --- a/src/components/application_manager/test/commands/hmi/navi_stop_stream_requests_test.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/navi_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_audio_stop_stream_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" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace navi_stop_stream_requests { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -namespace commands = am::commands; -using commands::MessageSharedPtr; -using am::event_engine::Event; - -namespace { -const am::HmiInterfaces::InterfaceID kHmiInterface = - am::HmiInterfaces::HMI_INTERFACE_Navigation; -} // namespace - -template -class NaviStopStreamRequestsTest - : public CommandRequestTest { - public: - NaviStopStreamRequestsTest() { - ON_CALL(this->app_mngr_, hmi_interfaces()) - .WillByDefault(ReturnRef(mock_hmi_interfaces_)); - msg_ = CreateMessage(); - command_ = CreateCommand(msg_); - } - - MessageSharedPtr msg_; - SharedPtr command_; -}; - -typedef testing::Types RequestCommandsList; -TYPED_TEST_CASE(NaviStopStreamRequestsTest, RequestCommandsList); - -TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceNotAvailable_NoRequest) { - EXPECT_CALL(TestFixture::mock_hmi_interfaces_, - GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(TestFixture::app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(TestFixture::rpc_service_, SendMessageToHMI(_)).Times(0); - - TestFixture::command_->Run(); -} - -TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceAvailable_SentRequest) { - EXPECT_CALL(TestFixture::mock_hmi_interfaces_, - GetInterfaceState(kHmiInterface)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(TestFixture::app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(TestFixture::rpc_service_)); - EXPECT_CALL(TestFixture::rpc_service_, SendMessageToHMI(TestFixture::msg_)); - - TestFixture::command_->Run(); -} - -} // namespace navi_stop_stream_requests -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc deleted file mode 100644 index 78de8b86ba..0000000000 --- a/src/components/application_manager/test/commands/hmi/on_driver_distraction_notification_test.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (c) 2016, 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 "smart_objects/smart_object.h" -#include "application_manager/smart_object_keys.h" -#include "utils/shared_ptr.h" -#include "utils/lock.h" -#include "utils/make_shared.h" -#include "utils/data_accessor.h" -#include "commands/commands_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "hmi/on_driver_distraction_notification.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace on_driver_distraction_notification { - -using ::testing::_; -using ::testing::Return; -using ::testing::Eq; -using ::utils::SharedPtr; - -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::hmi::OnDriverDistractionNotification; -using namespace am::commands; - -typedef ::utils::SharedPtr NotificationPtr; - -class HMIOnDriverDistractionNotificationTest - : public CommandsTest { - public: - ::sync_primitives::Lock app_set_lock_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; -}; - -MATCHER_P2(CheckNotificationParams, function_id, state, "") { - bool is_function_id_matched = - function_id == - static_cast( - (*arg)[am::strings::params][am::strings::function_id].asInt()); - bool is_state_matched = - state == - static_cast( - (*arg)[am::strings::msg_params][am::mobile_notification::state] - .asInt()); - return is_function_id_matched && is_state_matched; -} - -ACTION_P(GetArg3, result) { - arg3 = *result; -} - -TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; - MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); - (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; - - NotificationPtr command( - CreateCommand(commands_msg)); - - EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); - - MockAppPtr mock_app = CreateMockApp(); - am::ApplicationSet app_set; - app_set.insert(mock_app); - - DataAccessor accessor(app_set, app_set_lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - policy::CheckPermissionResult result; - result.hmi_level_permitted = policy::kRpcDisallowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); - - EXPECT_CALL(*mock_app, - PushMobileMessage(CheckNotificationParams( - am::mobile_api::FunctionID::OnDriverDistractionID, state))); - - command->Run(); -} - -TEST_F(HMIOnDriverDistractionNotificationTest, - Run_SendNotificationToMobile_SUCCESS) { - const hmi_apis::Common_DriverDistractionState::eType state = - hmi_apis::Common_DriverDistractionState::DD_ON; - MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); - (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; - - NotificationPtr command( - CreateCommand(commands_msg)); - - EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); - - MockAppPtr mock_app = CreateMockApp(); - am::ApplicationSet app_set; - app_set.insert(mock_app); - - DataAccessor accessor(app_set, app_set_lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - policy::CheckPermissionResult result; - result.hmi_level_permitted = policy::kRpcAllowed; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) - .WillOnce(GetArg3(&result)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - CheckNotificationParams( - am::mobile_api::FunctionID::OnDriverDistractionID, state), - Command::CommandSource::SOURCE_SDL)); - - command->Run(); -} - -} // on_driver_distraction_notification -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/rc_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/rc_get_capabilities_response_test.cc deleted file mode 100644 index 90be018e74..0000000000 --- a/src/components/application_manager/test/commands/hmi/rc_get_capabilities_response_test.cc +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/mock_hmi_capabilities.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/commands/hmi/rc_get_capabilities_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace rc_get_capabilities_response { - -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = am::strings; -namespace hmi_response = am::hmi_response; -using am::commands::RCGetCapabilitiesResponse; -using am::commands::CommandImpl; - -typedef SharedPtr RCGetCapabilitiesResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class RCGetCapabilitiesResponseTest - : public CommandsTest { - public: - MessageSharedPtr CreateCommandMsg() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][strings::rc_capability] = - (capabilities_); - - return command_msg; - } - - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(RCGetCapabilitiesResponseTest, RUN_SUCCESSS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - - (*command_msg)[strings::msg_params][strings::system_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::rc_capability] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - smart_objects::SmartObject& remote_control_capability = - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::rc_capability]; - - remote_control_capability["climateControlCapabilities"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - remote_control_capability["climateControlCapabilities"][0] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - smart_objects::SmartObject& climate_control_capability = - remote_control_capability["climateControlCapabilities"][0]; - - climate_control_capability["moduleName"] = "Climate"; - climate_control_capability["fanSpeedAvailable"] = true; - climate_control_capability["desiredTemperatureAvailable"] = true; - climate_control_capability["acEnableAvailable"] = true; - climate_control_capability["acMaxEnableAvailable"] = true; - climate_control_capability["circulateAirEnableAvailable"] = true; - climate_control_capability["autoModeEnableAvailable"] = true; - climate_control_capability["dualModeEnableAvailable"] = true; - - climate_control_capability["defrostZoneAvailable"] = true; - climate_control_capability["defrostZone"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - climate_control_capability["defrostZone"][0] = "ALL"; - - climate_control_capability["ventilationModeAvailable"] = true; - climate_control_capability["ventilationMode"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - climate_control_capability["ventilationMode"][0] = "BOTH"; - - remote_control_capability["radioControlCapabilities"] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - remote_control_capability["radioControlCapabilities"][0] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - smart_objects::SmartObject& radio_control_capability = - remote_control_capability["radioControlCapabilities"][0]; - - radio_control_capability["moduleName"] = "Radio"; - radio_control_capability["radioEnableAvailable"] = true; - radio_control_capability["radioBandAvailable"] = true; - radio_control_capability["radioFrequencyAvailable"] = true; - radio_control_capability["hdChannelAvailable"] = true; - radio_control_capability["rdsDataAvailable"] = true; - radio_control_capability["availableHDsAvailable"] = true; - radio_control_capability["stateAvailable"] = true; - radio_control_capability["signalStrengthAvailable"] = true; - radio_control_capability["signalChangeThresholdAvailable"] = true; - - remote_control_capability[hmi_response::button_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - remote_control_capability[hmi_response::button_capabilities][0] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - smart_objects::SmartObject& button_capability = - remote_control_capability[hmi_response::button_capabilities][0]; - - button_capability[strings::button_name] = "OK"; - button_capability["shortPressAvailable"] = true; - button_capability["longPressAvailable"] = true; - button_capability["upDownAvailable"] = true; - - RCGetCapabilitiesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject rc_capability_so = - (*command_msg)[strings::msg_params][strings::rc_capability]; - - EXPECT_CALL(mock_hmi_capabilities_, set_rc_capability(rc_capability_so)); - EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(true)); - - command->Run(); -} - -} // namespace rc_get_capabilities_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc deleted file mode 100644 index 8dbb6c7046..0000000000 --- a/src/components/application_manager/test/commands/hmi/rc_is_ready_request_test.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/rc_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/mock_message_helper.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace rc_is_ready_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::RCIsReadyRequest; -using am::event_engine::Event; - -typedef SharedPtr RCIsReadyRequestPtr; - -class RCIsReadyRequestTest - : public CommandRequestTest { - public: - RCIsReadyRequestTest() : command_(CreateCommand()) {} - - void SetUpExpectations(bool is_rc_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, - am::HmiInterfaces::InterfaceState state) { - if (is_send_message_to_hmi) { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillRepeatedly(ReturnRef(mock_hmi_capabilities_)); - ExpectSendMessagesToHMI(); - } else { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - } - EXPECT_CALL(mock_hmi_capabilities_, - set_is_rc_cooperating(is_rc_cooperating_available)); - if (!is_rc_cooperating_available) { - EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(false)); - } - - 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_RC, state)); - } else { - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - } - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_RC)) - .WillOnce(Return(state)); - } - - void ExpectSendMessagesToHMI() { - smart_objects::SmartObjectSPtr capabilities( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::RC_GetCapabilities, _)) - .WillOnce(Return(capabilities)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(capabilities)); - } - - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_rc_cooperating_available = false) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { - (*msg)[am::strings::msg_params][am::strings::available] = - is_rc_cooperating_available; - } - event.set_smart_object(*msg); - } - - RCIsReadyRequestPtr command_; - am::MockHmiInterfaces mock_hmi_interfaces_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; -}; - -TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - const bool is_rc_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; - Event event(hmi_apis::FunctionID::RC_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_rc_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); - command_->on_event(event); -} - -TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_rc_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::RC_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_rc_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); - command_->on_event(event); -} - -TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { - const bool is_rc_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::RC_IsReady); - PrepareEvent(is_message_contain_param, event, is_rc_cooperating_available); - SetUpExpectations(is_rc_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); - command_->on_event(event); -} - -TEST_F(RCIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { - ExpectSendMessagesToHMI(); - command_->onTimeOut(); -} - -} // namespace rc_is_ready_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/rc_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/rc_is_ready_response_test.cc deleted file mode 100644 index 157dff6216..0000000000 --- a/src/components/application_manager/test/commands/hmi/rc_is_ready_response_test.cc +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2016, 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 "commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/commands/hmi/rc_is_ready_response.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace rc_is_ready_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::RCIsReadyResponse; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr RCIsReadyResponsePtr; - -class RCIsReadyResponseTest : public CommandsTest { -}; - -TEST_F(RCIsReadyResponseTest, RUN_SUCCESS) { - RCIsReadyResponsePtr command(CreateCommand()); - - 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 rc_is_ready_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/response_from_hmi_test.cc b/src/components/application_manager/test/commands/hmi/response_from_hmi_test.cc deleted file mode 100644 index 0bedfea6f6..0000000000 --- a/src/components/application_manager/test/commands/hmi/response_from_hmi_test.cc +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (c) 2016, 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 "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.h" -#include "application_manager/mock_event_dispatcher.h" -#include "hmi/response_from_hmi.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace response_from_hmi { - -using ::testing::_; -using ::testing::Return; -using ::testing::SaveArg; -using ::testing::DoAll; - -using ::utils::SharedPtr; -using ::test::components::event_engine_test::MockEventDispatcher; - -namespace am = ::application_manager; - -using am::commands::ResponseFromHMI; - -typedef SharedPtr ResponseFromHMIPtr; - -class ResponseFromHMITest : public CommandsTest {}; - -TEST_F(ResponseFromHMITest, BasicMethodsOverloads_SUCCESS) { - ResponseFromHMIPtr command(CreateCommand()); - - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_NO_THROW(command->Run()); - EXPECT_TRUE(command->CleanUp()); -} - -TEST_F(ResponseFromHMITest, SendResponseToMobile_SUCCESS) { - ResponseFromHMIPtr command(CreateCommand()); - - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(msg, _)); - - command->SendResponseToMobile(msg, app_mngr_); - - const application_manager::MessageType received_message_tipe = - static_cast( - (*msg)[am::strings::params][am::strings::message_type].asInt()); - - EXPECT_EQ(application_manager::MessageType::kResponse, received_message_tipe); -} - -TEST_F(ResponseFromHMITest, CreateHMIRequest_SUCCESS) { - ResponseFromHMIPtr command(CreateCommand()); - - MessageSharedPtr result_msg; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(true))); - - const hmi_apis::FunctionID::eType posted_function_id = - hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr dummy_msg_params = CreateMessage(); - command->CreateHMIRequest(posted_function_id, *dummy_msg_params); - - ASSERT_TRUE(result_msg); - - const application_manager::MessageType received_message_tipe = - static_cast( - (*result_msg)[am::strings::params][am::strings::message_type] - .asInt()); - - EXPECT_EQ(am::MessageType::kRequest, received_message_tipe); - - const hmi_apis::FunctionID::eType received_function_id = - static_cast( - (*result_msg)[am::strings::params][am::strings::function_id].asInt()); - - EXPECT_EQ(posted_function_id, received_function_id); -} - -TEST_F(ResponseFromHMITest, CreateHMIRequest_CantManageCommand_Covering) { - ResponseFromHMIPtr command(CreateCommand()); - - MessageSharedPtr result_msg; - ON_CALL(app_mngr_, GetNextHMICorrelationID()).WillByDefault(Return(1u)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(false))); - - const hmi_apis::FunctionID::eType posted_function_id = - hmi_apis::FunctionID::INVALID_ENUM; - MessageSharedPtr dummy_msg_params = CreateMessage(); - command->CreateHMIRequest(posted_function_id, *dummy_msg_params); -} - -} // namespace response_from_hmi -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc deleted file mode 100644 index 4f59199006..0000000000 --- a/src/components/application_manager/test/commands/hmi/sdl_activate_app_request_test.cc +++ /dev/null @@ -1,506 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/lock.h" -#include "utils/helpers.h" -#include "application_manager/commands/hmi/sdl_activate_app_request.h" -#include "application_manager/mock_application.h" -#include "application_manager/application_manager.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "commands/command_request_test.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/mock_state_controller.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace sdl_activate_app_request { - -namespace am = ::application_manager; -namespace strings = am::strings; -namespace hmi_response = am::hmi_response; -using am::commands::MessageSharedPtr; -using am::commands::SDLActivateAppRequest; -using am::ApplicationSet; -using testing::Mock; -using testing::Return; -using testing::ReturnRef; -using testing::Mock; -using ::testing::NiceMock; -using policy_test::MockPolicyHandlerInterface; -using am::event_engine::Event; - -namespace { -const uint32_t kCorrelationID = 1u; -const uint32_t kAppID = 2u; -const uint32_t kAppIDFirst = 1u; -const connection_handler::DeviceHandle kHandle = 2u; -} // namespace - -MATCHER_P2(CheckMsgParams, result, corr_id, "") { - const bool is_func_id_valid = - hmi_apis::FunctionID::SDL_ActivateApp == - static_cast( - (*arg)[am::strings::params][am::strings::function_id].asInt()); - - const bool is_result_code_valid = - hmi_apis::Common_Result::APPLICATION_NOT_REGISTERED == - static_cast( - (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); - - const bool is_result_valid = - result == (*arg)[am::strings::msg_params][am::strings::success].asBool(); - - const bool is_corr_id_valid = - corr_id == - ((*arg)[am::strings::params][am::strings::correlation_id].asUInt()); - - using namespace helpers; - return Compare(true, - is_func_id_valid, - is_result_code_valid, - is_result_valid, - is_corr_id_valid); -} - -class SDLActivateAppRequestTest - : public CommandRequestTest { - protected: - ~SDLActivateAppRequestTest() { - // Fix DataAccessor release and WinQt crash - Mock::VerifyAndClearExpectations(&app_mngr_); - } - - void InitCommand(const uint32_t& timeout) OVERRIDE { - MockAppPtr mock_app = CreateMockApp(); - CommandRequestTest::InitCommand(timeout); - ON_CALL((*mock_app), app_id()).WillByDefault(Return(kAppID)); - ON_CALL(app_mngr_, application_by_hmi_app(kAppID)) - .WillByDefault(Return(mock_app)); - } - void SetCorrelationAndAppID(MessageSharedPtr msg) { - (*msg)[am::strings::params][strings::correlation_id] = kCorrelationID; - (*msg)[am::strings::msg_params][strings::app_id] = kAppID; - } - - ApplicationSet app_list_; - ::sync_primitives::Lock lock_; - policy_test::MockPolicyHandlerInterface policy_handler_; - application_manager_test::MockStateController mock_state_controller_; - NiceMock mock_event_dispatcher_; -}; - -#ifdef EXTERNAL_PROPRIETARY_MODE - -TEST_F(SDLActivateAppRequestTest, Run_ActivateApp_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler_)); - EXPECT_CALL(policy_handler_, OnActivateApp(kAppID, kCorrelationID)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, DISABLED_Run_DactivateApp_REJECTED) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - (*msg)[am::strings::msg_params][strings::function_id] = - hmi_apis::FunctionID::SDL_ActivateApp; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(true)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::SDL_ActivateApp))) - .WillOnce(Return(true)); - - command->Run(); -} -#else - -TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kAppID)).WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - - EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); - ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); - - MockAppPtr mock_app_first(CreateMockApp()); - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); - - app_list_.insert(mock_app_first); - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); - ON_CALL(*mock_app_first, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - ON_CALL(*mock_app, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - - const std::string url = "url"; - ON_CALL(*mock_app_first, SchemaUrl()).WillByDefault(Return(url)); - const std::string package = "package"; - ON_CALL(*mock_app_first, PackageName()).WillByDefault(Return(package)); - - EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, AppIdNotFound_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kAppID)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(app_mngr_, WaitingApplicationByID(kAppID)) - .WillOnce(Return(ApplicationSharedPtr())); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, DevicesAppsEmpty_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(app_mngr_, GetRPCService()).WillOnce(ReturnRef(rpc_service_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - - EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); - ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); - - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - app_list_ = accessor.GetData(); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - - app_list_ = accessor.GetData(); - - MockAppPtr mock_app_first(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppIDFirst)) - .WillByDefault(Return(mock_app_first)); - - app_list_.insert(mock_app_first); - ON_CALL(*mock_app_first, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); - - EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler_)); - EXPECT_CALL(policy_handler_, OnActivateApp(kAppID, kCorrelationID)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - - const std::string schema("schema"); - mock_app->SetShemaUrl(schema); - const std::string package_name("package_name"); - mock_app->SetPackageName(package_name); - - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - MockAppPtr mock_app_first(CreateMockApp()); - ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); - - app_list_.insert(mock_app_first); - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - ON_CALL(*mock_app_first, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(true)); - - EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, schema, package_name, _)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - - MockAppPtr mock_app_first(CreateMockApp()); - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); - - app_list_.insert(mock_app_first); - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - ON_CALL(*mock_app_first, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); - - EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); - - command->Run(); -} - -TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, state_controller()) - .WillOnce(ReturnRef(mock_state_controller_)); - EXPECT_CALL(mock_state_controller_, - IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) - .WillOnce(Return(false)); - DataAccessor accessor(app_list_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); - - app_list_ = accessor.GetData(); - - MockAppPtr mock_app_first(CreateMockApp()); - ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); - ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); - - app_list_.insert(mock_app_first); - ON_CALL(*mock_app_first, protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); - - EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); - - command->Run(); -} -#endif - -TEST_F(SDLActivateAppRequestTest, OnTimeout_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - SetCorrelationAndAppID(msg); - - SharedPtr command( - CreateCommand(msg)); - ON_CALL(mock_event_dispatcher_, remove_observer(_, _)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - command->onTimeOut(); -} - -TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[am::strings::params][strings::correlation_id] = kCorrelationID; - - SharedPtr command( - CreateCommand()); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - event.set_smart_object(*event_msg); - EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).Times(0); - - command->on_event(event); -} - -TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidAppId_UNSUCCESS) { - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[strings::msg_params][strings::application][strings::app_id] = - kAppID; - - SharedPtr command( - CreateCommand()); - - Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); - event.set_smart_object(*event_msg); - - MockAppPtr invalid_mock_app; - EXPECT_CALL(app_mngr_, application_by_hmi_app(_)) - .WillOnce(Return(invalid_mock_app)); - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - - command->on_event(event); -} - -TEST_F(SDLActivateAppRequestTest, OnEvent_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - SharedPtr command( - CreateCommand(msg)); - - MessageSharedPtr event_msg = CreateMessage(); - (*event_msg)[strings::msg_params][strings::application][strings::app_id] = - kAppID; - - Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); - event.set_smart_object(*event_msg); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppID)); - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler_)); - EXPECT_CALL(policy_handler_, OnActivateApp(kAppID, kCorrelationID)); - - command->on_event(event); -} - -} // namespace sdl_activate_app_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/sdl_activate_app_response_test.cc b/src/components/application_manager/test/commands/hmi/sdl_activate_app_response_test.cc deleted file mode 100644 index 65bd2d830e..0000000000 --- a/src/components/application_manager/test/commands/hmi/sdl_activate_app_response_test.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/commands/hmi/sdl_activate_app_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace sdl_activate_app_response { - -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::SDLActivateAppResponse; -using am::commands::CommandImpl; - -typedef SharedPtr SDLActivateAppResponsePtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kStrNumber = "123"; -} // namespace - -class SDLActivateAppResponseTest - : public CommandsTest {}; - -TEST_F(SDLActivateAppResponseTest, RUN_SendRequest_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; - - SDLActivateAppResponsePtr command( - CreateCommand(command_msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -} // namespace sdl_activate_app_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc deleted file mode 100644 index 1bcdaebb35..0000000000 --- a/src/components/application_manager/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/sdl_get_list_of_permissions_request.h" -#include "application_manager/mock_application.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "commands/command_request_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace sdl_get_list_of_permissions_request { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::SDLGetListOfPermissionsRequest; -using test::components::policy_test::MockPolicyHandlerInterface; -using smart_objects::SmartObject; -using testing::Return; -using testing::ReturnRef; - -namespace { -const uint32_t kCorrelationID = 1u; -const uint32_t kAppID = 2u; -const uint32_t kConnectionKey = 0u; -} // namespace - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -class SDLGetListOfPermissionsRequestTest - : public CommandRequestTest { - protected: - void SetUp() OVERRIDE { - mock_app_ = CreateMockApp(); - } - - void InitCommand(const uint32_t& timeout) OVERRIDE { - CommandRequestTest::InitCommand(timeout); - ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); - } - MockAppPtr mock_app_; -}; - -TEST_F(SDLGetListOfPermissionsRequestTest, Run_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - (*msg)[strings::msg_params][strings::app_id] = kAppID; - - EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) - .WillOnce(Return(mock_app_)); - - SharedPtr command( - CreateCommand(msg)); - - MockPolicyHandlerInterface policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(policy_handler, OnGetListOfPermissions(kAppID, kCorrelationID)); - - command->Run(); -} - -TEST_F(SDLGetListOfPermissionsRequestTest, Run_KeyDoesntExist_SUCCESS) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Binary); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - - SharedPtr command( - CreateCommand(msg)); - - MockPolicyHandlerInterface policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(policy_handler, - OnGetListOfPermissions(kConnectionKey, kCorrelationID)); - - command->Run(); -} - -} // namespace sdl_get_list_of_permissions_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/sdl_get_status_update_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_get_status_update_request_test.cc deleted file mode 100644 index 988cdd18c7..0000000000 --- a/src/components/application_manager/test/commands/hmi/sdl_get_status_update_request_test.cc +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/sdl_get_status_update_request.h" -#include "application_manager/mock_application.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "commands/command_request_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace sdl_get_status_update_request { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::SDLGetStatusUpdateRequest; -using test::components::policy_test::MockPolicyHandlerInterface; -using testing::Return; -using testing::ReturnRef; - -namespace { -const uint32_t kCorrelationID = 1u; -} // namespace - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -class SDLGetStatusUpdateRequestTest - : public CommandRequestTest {}; - -TEST_F(SDLGetStatusUpdateRequestTest, Run_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - - SharedPtr command( - CreateCommand(msg)); - - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler)); - EXPECT_CALL(mock_policy_handler, OnGetStatusUpdate(kCorrelationID)); - - command->Run(); -} - -} // namespace sdl_get_status_update_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc deleted file mode 100644 index 66fedda3ca..0000000000 --- a/src/components/application_manager/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/sdl_get_user_friendly_message_request.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_state_controller.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "smart_objects/smart_object.h" -#include "commands/command_request_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace sdl_get_user_friendly_message_request { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::SDLGetUserFriendlyMessageRequest; -using application_manager::MockMessageHelper; -using test::components::policy_test::MockPolicyHandlerInterface; -using test::components::application_manager_test::MockHMICapabilities; -using testing::_; -using testing::Return; -using testing::ReturnRef; - -namespace { -const uint32_t kCorrelationID = 1u; -const uint32_t kAppID = 2u; -const std::string kLanguageDe = "de-de"; -const std::string kLanguageEn = "en-gb"; -const std::string kMessageCodes = "messageCodes"; -const hmi_apis::Common_Language::eType kLanguage = - hmi_apis::Common_Language::EN_GB; -} // namespace - -namespace strings = ::application_manager::strings; - -class SDLGetUserFriendlyMessageRequestTest - : public CommandRequestTest { - protected: - void SetUp() OVERRIDE { - mock_app_ = CreateMockApp(); - } - - void InitCommand(const uint32_t& timeout) OVERRIDE { - CommandRequestTest::InitCommand(timeout); - ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); - EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) - .WillOnce(Return(mock_app_)); - } - MockAppPtr mock_app_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - (*msg)[strings::msg_params][strings::app_id] = kAppID; - - (*msg)[strings::msg_params][kMessageCodes] = - SmartObject(smart_objects::SmartType_Array); - (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); - (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); - - (*msg)[strings::msg_params][strings::language] = kLanguage; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) - .WillOnce(Return(kLanguageEn)); - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); - std::vector msg_codes; - msg_codes.push_back(kLanguageDe); - msg_codes.push_back(kLanguageEn); - EXPECT_CALL(mock_policy_handler_, - OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); - - command->Run(); -} - -TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageNotSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - (*msg)[strings::msg_params][strings::app_id] = kAppID; - - (*msg)[strings::msg_params][kMessageCodes] = - SmartObject(smart_objects::SmartType_Array); - (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); - (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, active_ui_language()) - .WillOnce(Return(kLanguage)); - EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) - .WillOnce(Return(kLanguageEn)); - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); - std::vector msg_codes; - msg_codes.push_back(kLanguageDe); - msg_codes.push_back(kLanguageEn); - EXPECT_CALL(mock_policy_handler_, - OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); - - command->Run(); -} - -TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_NoMsgCodes_Canceled) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::correlation_id] = kCorrelationID; - (*msg)[strings::msg_params][strings::app_id] = kAppID; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); - - command->Run(); -} - -} // namespace sdl_get_user_friendly_message_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/simple_notifications_test.cc b/src/components/application_manager/test/commands/hmi/simple_notifications_test.cc deleted file mode 100644 index 9d7441fef7..0000000000 --- a/src/components/application_manager/test/commands/hmi/simple_notifications_test.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" - -#include "commands/commands_test.h" - -#include "hmi/notification_to_hmi.h" -#include "application_manager/commands/command_notification_impl.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace simple_notifications_test { - -using namespace application_manager; - -using ::testing::Types; - -template -class SimpleNotificationsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -typedef Types - CommandsList; - -TYPED_TEST_CASE(SimpleNotificationsTest, CommandsList); - -TYPED_TEST(SimpleNotificationsTest, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_NO_THROW(command->Run()); - EXPECT_TRUE(command->CleanUp()); -} - -} // namespace simple_notifications_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/simple_request_from_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_request_from_hmi_test.cc deleted file mode 100644 index c45a67bcd6..0000000000 --- a/src/components/application_manager/test/commands/hmi/simple_request_from_hmi_test.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2016, 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 "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.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_event_dispatcher.h" -#include "hmi/request_from_hmi.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace simple_requests_from_hmi_test { - -using ::testing::_; -using ::testing::Types; -using ::testing::NotNull; -using ::testing::NiceMock; - -using ::utils::SharedPtr; -namespace commands = ::application_manager::commands; -using commands::MessageSharedPtr; -using ::application_manager::event_engine::EventObserver; -using ::test::components::event_engine_test::MockEventDispatcher; - -class RequestFromHMITest : public CommandsTest { - protected: - void SetUp() OVERRIDE { - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher_)); - } - NiceMock mock_event_dispatcher_; -}; - -TEST_F(RequestFromHMITest, BasicMethodsOverloads_SUCCESS) { - SharedPtr command( - CreateCommand()); - application_manager::event_engine::Event event( - hmi_apis::FunctionID::BasicCommunication_ActivateApp); - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_TRUE(command->CleanUp()); - EXPECT_NO_THROW(command->Run()); - EXPECT_NO_THROW(command->on_event(event)); -} - -TEST_F(RequestFromHMITest, SendResponse_SUCCESS) { - SharedPtr command( - CreateCommand()); - - const bool success = false; - const uint32_t correlation_id = 1u; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(NotNull())); - - command->SendResponse(success, - correlation_id, - hmi_apis::FunctionID::BasicCommunication_ActivateApp, - hmi_apis::Common_Result::SUCCESS); -} - -} // namespace simple_requests_to_hmi_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc deleted file mode 100644 index ced6f29964..0000000000 --- a/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2016, Ford Motor Company - * All rights reserved. - * - * Copyright (c) 2017 Xevo Inc. - * 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 "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/commands/command.h" -#include "application_manager/commands/hmi/allow_app_request.h" -#include "application_manager/commands/hmi/allow_all_apps_request.h" -#include "application_manager/commands/hmi/basic_communication_system_request.h" -#include "application_manager/commands/hmi/button_get_capabilities_request.h" -#include "application_manager/commands/hmi/navi_alert_maneuver_request.h" -#include "application_manager/commands/hmi/navi_audio_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_get_way_points_request.h" -#include "application_manager/commands/hmi/navi_is_ready_request.h" -#include "application_manager/commands/hmi/navi_send_location_request.h" -#include "application_manager/commands/hmi/navi_show_constant_tbt_request.h" -#include "application_manager/commands/hmi/navi_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_subscribe_way_points_request.h" -#include "application_manager/commands/hmi/navi_unsubscribe_way_points_request.h" -#include "application_manager/commands/hmi/navi_update_turn_list_request.h" -#include "application_manager/commands/hmi/sdl_activate_app_response.h" -#include "application_manager/commands/hmi/sdl_get_list_of_permissions_response.h" -#include "application_manager/commands/hmi/sdl_get_status_update_response.h" -#include "application_manager/commands/hmi/ui_scrollable_message_request.h" -#include "application_manager/commands/hmi/ui_set_app_icon_request.h" -#include "application_manager/commands/hmi/ui_set_display_layout_request.h" -#include "application_manager/commands/hmi/ui_set_global_properties_request.h" -#include "application_manager/commands/hmi/request_to_hmi.h" -#include "application_manager/commands/hmi/vi_get_vehicle_type_request.h" -#include "application_manager/commands/hmi/vi_is_ready_request.h" -#include "application_manager/commands/hmi/vi_read_did_request.h" -#include "application_manager/commands/hmi/vi_subscribe_vehicle_data_request.h" -#include "application_manager/commands/hmi/dial_number_request.h" -#include "application_manager/commands/hmi/tts_is_ready_request.h" -#include "application_manager/commands/hmi/tts_set_global_properties_request.h" -#include "application_manager/commands/hmi/tts_speak_request.h" -#include "application_manager/commands/hmi/tts_stop_speaking_request.h" -#include "application_manager/commands/hmi/tts_get_supported_languages_request.h" -#include "application_manager/commands/hmi/tts_change_registration_request.h" -#include "application_manager/commands/hmi/tts_get_capabilities_request.h" -#include "application_manager/commands/hmi/tts_get_language_request.h" -#include "application_manager/commands/hmi/close_popup_request.h" -#include "application_manager/commands/hmi/ui_add_command_request.h" -#include "application_manager/commands/hmi/ui_add_submenu_request.h" -#include "application_manager/commands/hmi/ui_alert_request.h" -#include "application_manager/commands/hmi/ui_change_registration_request.h" -#include "application_manager/commands/hmi/ui_delete_command_request.h" -#include "application_manager/commands/hmi/ui_delete_submenu_request.h" -#include "application_manager/commands/hmi/ui_end_audio_pass_thru_request.h" -#include "application_manager/commands/hmi/ui_get_capabilities_request.h" -#include "application_manager/commands/hmi/ui_get_language_request.h" -#include "application_manager/commands/hmi/ui_get_supported_languages_request.h" -#include "application_manager/commands/hmi/ui_is_ready_request.h" -#include "application_manager/commands/hmi/ui_perform_audio_pass_thru_request.h" -#include "application_manager/commands/hmi/ui_perform_interaction_request.h" -#include "application_manager/commands/hmi/vi_diagnostic_message_request.h" -#include "application_manager/commands/hmi/vi_get_dtcs_request.h" -#include "application_manager/commands/hmi/vi_get_vehicle_data_request.h" -#include "application_manager/commands/hmi/ui_set_media_clock_timer_request.h" -#include "application_manager/commands/hmi/ui_show_request.h" -#include "application_manager/commands/hmi/ui_slider_request.h" -#include "application_manager/commands/hmi/vi_unsubscribe_vehicle_data_request.h" -#include "application_manager/commands/hmi/vr_add_command_request.h" -#include "application_manager/commands/hmi/vr_change_registration_request.h" -#include "application_manager/commands/hmi/vr_delete_command_request.h" -#include "application_manager/commands/hmi/vr_get_capabilities_request.h" -#include "application_manager/commands/hmi/vr_get_supported_languages_request.h" -#include "application_manager/commands/hmi/vr_get_language_request.h" -#include "application_manager/commands/hmi/vr_is_ready_request.h" -#include "application_manager/commands/hmi/vr_perform_interaction_request.h" -#include "application_manager/commands/hmi/allow_all_apps_request.h" -#include "application_manager/commands/hmi/basic_communication_system_request.h" -#include "application_manager/commands/hmi/button_get_capabilities_request.h" -#include "application_manager/commands/hmi/allow_app_request.h" -#include "application_manager/commands/hmi/navi_send_location_request.h" -#include "application_manager/commands/hmi/navi_unsubscribe_way_points_request.h" -#include "application_manager/commands/hmi/navi_update_turn_list_request.h" -#include "application_manager/commands/hmi/navi_show_constant_tbt_request.h" -#include "application_manager/commands/hmi/navi_stop_stream_request.h" -#include "application_manager/commands/hmi/navi_subscribe_way_points_request.h" -#include "application_manager/commands/hmi/sdl_policy_update.h" -#include "application_manager/commands/hmi/ui_set_icon_request.h" -#include "application_manager/commands/hmi/dial_number_request.h" -#include "application_manager/commands/hmi/ui_send_haptic_data_request.h" - -#include "application_manager/test/include/application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace simple_requests_to_hmi_test { - -using ::testing::_; -using ::testing::Types; -using ::testing::NotNull; - -using ::utils::SharedPtr; - -namespace am_commands = application_manager::commands; -using am_commands::MessageSharedPtr; -using event_engine_test::MockEventDispatcher; - -class RequestToHMITest : public CommandsTest {}; - -TEST_F(RequestToHMITest, BasicMethodsOverloads_SUCCESS) { - SharedPtr command( - CreateCommand()); - - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_NO_THROW(command->Run()); - EXPECT_TRUE(command->CleanUp()); -} - -TEST_F(RequestToHMITest, SendRequest_SUCCESS) { - SharedPtr command( - CreateCommand()); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(NotNull())); - - command->SendRequest(); -} - -template -class RequestToHMICommandsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -template -class RequestToHMICommandsTest2 : public RequestToHMICommandsTest {}; - -template -class RequestToHMICommandsTest3 - : public CommandRequestTest { - public: - typedef Command CommandType; -}; - -typedef Types RequestCommandsList; - -typedef Types RequestCommandsList2; - -typedef Types RequestCommandsList3; - -TYPED_TEST_CASE(RequestToHMICommandsTest, RequestCommandsList); -TYPED_TEST_CASE(RequestToHMICommandsTest2, RequestCommandsList2); -TYPED_TEST_CASE(RequestToHMICommandsTest3, RequestCommandsList3); - -TYPED_TEST(RequestToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, SendMessageToHMI(NotNull())); - - command->Run(); -} - -TYPED_TEST(RequestToHMICommandsTest2, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, SendMessageToHMI(NotNull())); - - command->Run(); -} - -TYPED_TEST(RequestToHMICommandsTest3, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, SendMessageToHMI(NotNull())); - - command->Run(); -} - -} // namespace simple_requests_to_hmi_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc deleted file mode 100644 index f9e0536f95..0000000000 --- a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc +++ /dev/null @@ -1,374 +0,0 @@ -/* - * Copyright (c) 2016, Ford Motor Company - * All rights reserved. - * - * Copyright (c) 2017 Xevo Inc. - * 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 - -#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.h" -#include "hmi/activate_app_response.h" -#include "hmi/basic_communication_system_response.h" -#include "hmi/navi_alert_maneuver_response.h" -#include "hmi/navi_audio_start_stream_response.h" -#include "hmi/navi_audio_stop_stream_response.h" -#include "hmi/navi_get_way_points_response.h" -#include "hmi/navi_send_location_response.h" -#include "hmi/navi_show_constant_tbt_response.h" -#include "hmi/navi_start_stream_response.h" -#include "hmi/navi_stop_stream_response.h" -#include "hmi/navi_subscribe_way_points_response.h" -#include "hmi/navi_unsubscribe_way_points_response.h" -#include "hmi/navi_update_turn_list_response.h" -#include "hmi/tts_change_registration_response.h" -#include "hmi/ui_set_app_icon_response.h" -#include "hmi/ui_set_display_layout_response.h" -#include "hmi/ui_set_global_properties_response.h" -#include "hmi/ui_scrollable_message_response.h" -#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" -#include "hmi/tts_speak_response.h" -#include "hmi/tts_stop_speaking_response.h" -#include "hmi/tts_change_registration_response.h" -#include "hmi/ui_add_command_response.h" -#include "hmi/ui_add_submenu_response.h" -#include "hmi/ui_alert_response.h" -#include "hmi/ui_change_registration_response.h" -#include "hmi/ui_delete_command_response.h" -#include "hmi/ui_delete_submenu_response.h" -#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" -#include "hmi/vr_perform_interaction_response.h" -#include "hmi/activate_app_response.h" -#include "hmi/basic_communication_system_response.h" -#include "hmi/navi_unsubscribe_way_points_response.h" -#include "hmi/navi_update_turn_list_response.h" -#include "hmi/navi_send_location_response.h" -#include "hmi/navi_show_constant_tbt_response.h" -#include "hmi/navi_start_stream_response.h" -#include "hmi/navi_subscribe_way_points_response.h" -#include "hmi/on_find_applications.h" -#include "hmi/on_update_device_list.h" -#include "hmi/sdl_policy_update_response.h" -#include "hmi/update_app_list_response.h" -#include "hmi/update_device_list_response.h" -#include "hmi/notification_from_hmi.h" -#include "hmi/ui_send_haptic_data_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace simple_response_from_hmi_test { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::Types; -using ::testing::Eq; - -using ::utils::SharedPtr; -using ::test::components::event_engine_test::MockEventDispatcher; - -namespace am = ::application_manager; -namespace commands = am::commands; -using commands::MessageSharedPtr; - -template -class ResponseFromHMICommandsTest - : public CommandsTest { - public: - typedef CommandD CommandData; - MockEventDispatcher event_dispatcher_; - - ResponseFromHMICommandsTest() { - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - } -}; - -template -class EmptyResponseFromHMICommandsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -template -struct CommandData { - typedef Command CommandType; - enum { kEventId = kExpectedEventId }; -}; - -typedef Types< - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData, - CommandData > ResponseCommandsList; - -typedef Types EmptyResponseCommandsList; - -TYPED_TEST_CASE(ResponseFromHMICommandsTest, ResponseCommandsList); - -TYPED_TEST_CASE(EmptyResponseFromHMICommandsTest, EmptyResponseCommandsList); - -MATCHER_P(EventIdIsEqualTo, function_id, "") { - return static_cast(function_id) == arg.id(); -} - -TYPED_TEST(ResponseFromHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandData CommandData; - typedef typename CommandData::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - - EXPECT_CALL(this->event_dispatcher_, - raise_event(EventIdIsEqualTo(CommandData::kEventId))); - - command->Run(); -} - -TYPED_TEST(EmptyResponseFromHMICommandsTest, Run_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - - command->Run(); -} - -class OtherResponseFromHMICommandsTest - : public CommandsTest {}; - -MATCHER_P(VehicleTypeIsEqualTo, vehicle_type, "") { - return (*vehicle_type) == arg.asString(); -} - -TEST_F(OtherResponseFromHMICommandsTest, VIGetVehicleTypeResponse_Run_SUCCESS) { - const std::string kVehicleType = "Test"; - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::hmi_response::vehicle_type] = - kVehicleType; - - SharedPtr command( - CreateCommand(command_msg)); - - application_manager_test::MockHMICapabilities hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(hmi_capabilities)); - - EXPECT_CALL(hmi_capabilities, - set_vehicle_type(VehicleTypeIsEqualTo(&kVehicleType))); - - command->Run(); -} - -TEST_F(OtherResponseFromHMICommandsTest, VIIsReadyResponse_Run_SUCCESS) { - SharedPtr command( - CreateCommand()); - - MockEventDispatcher mock_event_dispatcher; - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher)); - EXPECT_CALL(mock_event_dispatcher, raise_event(_)); - - command->Run(); -} - -MATCHER_P(CheckMsgType, msg_type, "") { - return msg_type == - static_cast( - (*arg)[am::strings::params][am::strings::message_type].asInt()); -} - -class NotificationFromHMITest - : public CommandsTest {}; - -TEST_F(NotificationFromHMITest, BasicMethodsOverloads_SUCCESS) { - SharedPtr command( - CreateCommand()); - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_TRUE(command->CleanUp()); - EXPECT_NO_THROW(command->Run()); -} - -TEST_F(NotificationFromHMITest, SendNotificationToMobile_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kNotification); - - SharedPtr command( - CreateCommand()); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(CheckMsgType(am::MessageType::kNotification), - am::commands::Command::CommandSource::SOURCE_SDL)); - - command->SendNotificationToMobile(command_msg); -} - -TEST_F(NotificationFromHMITest, CreateHMIRequest_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params] = 0; - SharedPtr command( - CreateCommand(command_msg)); - - const uint32_t correlation_id = 1u; - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(correlation_id)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(CheckMsgType(am::MessageType::kRequest))) - .WillOnce(Return(false)); - - command->CreateHMIRequest(hmi_apis::FunctionID::INVALID_ENUM, - (*command_msg)[am::strings::msg_params]); -} - -} // namespace simple_response_from_hmi_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/simple_response_to_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_response_to_hmi_test.cc deleted file mode 100644 index 1ca21fe725..0000000000 --- a/src/components/application_manager/test/commands/hmi/simple_response_to_hmi_test.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2016, 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 "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.h" -#include "application_manager/commands/hmi/sdl_activate_app_response.h" -#include "application_manager/commands/hmi/sdl_get_list_of_permissions_response.h" -#include "application_manager/commands/hmi/sdl_get_status_update_response.h" -#include "application_manager/commands/hmi/sdl_get_user_friendly_message_response.h" -#include "application_manager/commands/hmi/response_to_hmi.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace simple_response_to_hmi_test { - -using ::testing::_; -using ::testing::Types; -using ::testing::NotNull; -using ::utils::SharedPtr; - -namespace commands = ::application_manager::commands; -using commands::MessageSharedPtr; - -template -class ResponseToHMICommandsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -typedef Types ResponseCommandsList; - -TYPED_TEST_CASE(ResponseToHMICommandsTest, ResponseCommandsList); - -TYPED_TEST(ResponseToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { - typedef typename TestFixture::CommandType CommandType; - - SharedPtr command = this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, SendMessageToHMI(NotNull())); - - command->Run(); -} - -class ResponseToHMITest : public CommandsTest {}; - -TEST_F(ResponseToHMITest, BasicMethodsOverloads_SUCCESS) { - SharedPtr command( - CreateCommand()); - - // Current implementation always return `true` - EXPECT_TRUE(command->Init()); - EXPECT_TRUE(command->CleanUp()); -} - -TEST_F(ResponseToHMITest, Run_SUCCESS) { - SharedPtr command( - CreateCommand()); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(NotNull())); - - command->Run(); -} - -} // namespace simple_response_to_hmi_test -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc deleted file mode 100644 index c7b5c76b40..0000000000 --- a/src/components/application_manager/test/commands/hmi/tts_get_capabilities_response_test.cc +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/tts_get_capabilities_response.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "smart_objects/smart_object.h" -#include "commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace tts_get_capabilities_response { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::TTSGetCapabilitiesResponse; -using test::components::application_manager_test::MockHMICapabilities; -using utils::SharedPtr; -using testing::_; - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -namespace { -const std::string kText = "TEXT"; -} - -class TTSGetCapabilitiesResponseTest - : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; -}; - -TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; - (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = - kText; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, - set_speech_capabilities(SmartObject(kText))); - EXPECT_CALL(mock_hmi_capabilities_, - set_prerecorded_speech(SmartObject(kText))); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlySpeech_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, - set_speech_capabilities(SmartObject(kText))); - EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlyPrerecorded_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = - kText; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); - EXPECT_CALL(mock_hmi_capabilities_, - set_prerecorded_speech(SmartObject(kText))); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(TTSGetCapabilitiesResponseTest, Run_Nothing_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); - EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -} // namespace tts_get_capabilities_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/tts_get_language_response_test.cc b/src/components/application_manager/test/commands/hmi/tts_get_language_response_test.cc deleted file mode 100644 index e0b2fad5b9..0000000000 --- a/src/components/application_manager/test/commands/hmi/tts_get_language_response_test.cc +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/tts_get_language_response.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_event_dispatcher.h" -#include "commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace tts_get_language_response { - -using utils::SharedPtr; -using application_manager::commands::TTSGetLanguageResponse; -using test::components::application_manager_test::MockHMICapabilities; -using test::components::event_engine_test::MockEventDispatcher; -using testing::_; -using testing::ReturnRef; - -namespace strings = application_manager::strings; -namespace hmi_response = application_manager::hmi_response; -using namespace hmi_apis; - -namespace { -const Common_Language::eType kLanguage = Common_Language::EN_GB; -} // namespace - -class TTSGetLanguageResponseTest - : public CommandsTest {}; - -TEST_F(TTSGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::language] = kLanguage; - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, set_active_tts_language(kLanguage)); - - 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(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, - set_active_tts_language(Common_Language::INVALID_ENUM)); - - 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 tts_get_language_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/tts_get_supported_languages_response_test.cc b/src/components/application_manager/test/commands/hmi/tts_get_supported_languages_response_test.cc deleted file mode 100644 index 547fc02481..0000000000 --- a/src/components/application_manager/test/commands/hmi/tts_get_supported_languages_response_test.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/response_from_hmi.h" -#include "application_manager/commands/hmi/tts_get_supported_languages_response.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace tts_get_supported_languages_response { - -using ::testing::_; -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::ResponseFromHMI; -using am::commands::TTSGetSupportedLanguagesResponse; -using am::commands::CommandImpl; - -typedef SharedPtr ResponseFromHMIPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class TTSGetSupportedLanguageResponseTest - : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(TTSGetSupportedLanguageResponseTest, RUN_SUCCESS) { - smart_objects::SmartObject supported_languages("EN_US"); - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - (*command_msg)[strings::msg_params][hmi_response::languages] = - supported_languages; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_tts_supported_languages(( - *command_msg)[strings::msg_params][hmi_response::languages])); - - command->Run(); -} -TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { - smart_objects::SmartObject supported_languages("EN_US"); - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WRONG_LANGUAGE; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_tts_supported_languages(supported_languages)).Times(0); - - command->Run(); - - EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( - am::hmi_response::languages)); -} - -} // namespace tts_get_supported_languages_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/tts_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/tts_is_ready_response_test.cc deleted file mode 100644 index 52c66ff877..0000000000 --- a/src/components/application_manager/test/commands/hmi/tts_is_ready_response_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/response_from_hmi.h" -#include "application_manager/commands/hmi/tts_is_ready_response.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace tts_is_ready_response { - -using ::testing::_; -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::ResponseFromHMI; -using am::commands::TTSIsReadyResponse; -using am::commands::CommandImpl; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr ResponseFromHMIPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -const bool kIsAvailable = true; -const bool kIsNotAvailable = false; -} // namespace - -class TTSIsReadyResponseTest : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(TTSIsReadyResponseTest, RUN_SUCCESS) { - ResponseFromHMIPtr command(CreateCommand()); - 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 tts_is_ready_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/ui_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/ui_get_capabilities_response_test.cc deleted file mode 100644 index 7dd7a74f4c..0000000000 --- a/src/components/application_manager/test/commands/hmi/ui_get_capabilities_response_test.cc +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Copyright (c) 2016, Ford Motor Company - * All rights reserved. - * - * Copyright (c) 2017 Xevo Inc. - * 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 - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/mock_hmi_capabilities.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/commands/hmi/ui_get_capabilities_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace ui_get_capabilities_response { - -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = am::strings; -namespace hmi_response = am::hmi_response; -using am::commands::ResponseFromHMI; -using am::commands::UIGetCapabilitiesResponse; -using am::commands::CommandImpl; - -typedef SharedPtr ResponseFromHMIPtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class UIGetCapabilitiesResponseTest - : public CommandsTest { - public: - MessageSharedPtr CreateCommandMsg() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - return command_msg; - } - - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(UIGetCapabilitiesResponseTest, RUN_SetDisplay_SUCCESSS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][hmi_response::display_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - (*command_msg)[strings::msg_params][hmi_response::display_capabilities] - [hmi_response::display_type] = "GEN2_8_DMA"; - (*command_msg)[strings::msg_params][hmi_response::display_capabilities] - [hmi_response::display_name] = "GENERIC_DISPLAY"; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject display_capabilities_so = - (*command_msg)[strings::msg_params][hmi_response::display_capabilities]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_display_capabilities(display_capabilities_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetSoftButton_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] - [hmi_response::image_supported] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject soft_button_capabilities_so = (*command_msg) - [strings::msg_params][hmi_response::soft_button_capabilities]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_soft_button_capabilities(soft_button_capabilities_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities][0] = - "FRONT"; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject hmi_zone_capabilities_so = - (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_hmi_zone_capabilities(hmi_zone_capabilities_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::audio_pass_thru_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject audio_pass_thru_capabilities_so = (*command_msg) - [strings::msg_params][strings::audio_pass_thru_capabilities]; - EXPECT_CALL( - mock_hmi_capabilities_, - set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetNavigation_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] - [strings::navigation] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject hmi_capabilities_so = - (*command_msg)[strings::msg_params][strings::hmi_capabilities]; - EXPECT_CALL(mock_hmi_capabilities_, - set_navigation_supported( - hmi_capabilities_so[strings::navigation].asBool())); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetPhoneCall_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] - [strings::phone_call] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject hmi_capabilities_so = - (*command_msg)[strings::msg_params][strings::hmi_capabilities]; - EXPECT_CALL(mock_hmi_capabilities_, - set_phone_call_supported( - hmi_capabilities_so[strings::phone_call].asBool())); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreaming_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - (*command_msg)[strings::msg_params][strings::hmi_capabilities] - [strings::video_streaming] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject hmi_capabilities_so = - (*command_msg)[strings::msg_params][strings::hmi_capabilities]; - EXPECT_CALL(mock_hmi_capabilities_, - set_video_streaming_supported( - hmi_capabilities_so[strings::video_streaming].asBool())); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetNavigationCapability_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::system_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::navigation_capability]["sendLocationEnabled"] = true; - - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::navigation_capability]["getWayPointsEnabled"] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject navigation_capability_so = - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::navigation_capability]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_navigation_capability(navigation_capability_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetPhonenCapability_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::system_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::phone_capability]["dialNumberEnabled"] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject phone_capability_so = - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::phone_capability]; - - EXPECT_CALL(mock_hmi_capabilities_, - set_phone_capability(phone_capability_so)); - - command->Run(); -} - -TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::system_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::video_streaming_capability] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - smart_objects::SmartObject& video_streaming_capability = - (*command_msg)[strings::msg_params][strings::system_capabilities] - [strings::video_streaming_capability]; - - video_streaming_capability[strings::preferred_resolution] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - video_streaming_capability[strings::preferred_resolution] - [strings::resolution_width] = 800; - video_streaming_capability[strings::preferred_resolution] - [strings::resolution_height] = 350; - - video_streaming_capability[strings::max_bitrate] = 10000; - - video_streaming_capability[strings::supported_formats] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - video_streaming_capability[strings::supported_formats][0] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - - video_streaming_capability[strings::supported_formats][0][strings::protocol] = - hmi_apis::Common_VideoStreamingProtocol::RAW; - - video_streaming_capability[strings::supported_formats][0][strings::codec] = - hmi_apis::Common_VideoStreamingCodec::H264; - - video_streaming_capability[strings::haptic_spatial_data_supported] = true; - - ResponseFromHMIPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_video_streaming_capability(video_streaming_capability)); - - command->Run(); -} - -} // namespace ui_get_capabilities_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/ui_get_language_response_test.cc b/src/components/application_manager/test/commands/hmi/ui_get_language_response_test.cc deleted file mode 100644 index e45e4583e5..0000000000 --- a/src/components/application_manager/test/commands/hmi/ui_get_language_response_test.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/ui_get_language_response.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/mock_application_manager.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace ui_get_language_response { - -using utils::SharedPtr; -using application_manager::commands::UIGetLanguageResponse; -using test::components::event_engine_test::MockEventDispatcher; -using testing::_; -using testing::ReturnRef; -using ::testing::NiceMock; - -namespace strings = application_manager::strings; -namespace hmi_response = application_manager::hmi_response; -using namespace hmi_apis; - -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; -} // namespace - -class UIGetLanguageResponseTest - : public CommandsTest {}; - -TEST_F(UIGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::language] = kLanguage; - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, set_active_ui_language(kLanguage)); - - 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(UIGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, - set_active_ui_language(Common_Language::INVALID_ENUM)); - - 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 ui_get_language_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/ui_get_supported_languages_response_test.cc b/src/components/application_manager/test/commands/hmi/ui_get_supported_languages_response_test.cc deleted file mode 100644 index 690c863ccb..0000000000 --- a/src/components/application_manager/test/commands/hmi/ui_get_supported_languages_response_test.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/application.h" -#include "commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/ui_get_supported_languages_response.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace ui_get_supported_languages_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::UIGetSupportedLanguagesResponse; - -typedef SharedPtr - UIGetSupportedLanguagesResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kStringNum = "123"; -const std::string kLanguage = "EN_US"; -const smart_objects::SmartObject supported_languages(kLanguage); -} // namespace - -class UIGetSupportedLanguagesResponseTest - : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(UIGetSupportedLanguagesResponseTest, RUN_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStringNum; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - (*command_msg)[strings::msg_params][hmi_response::languages] = - supported_languages; - - UIGetSupportedLanguagesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_ui_supported_languages((supported_languages))); - - command->Run(); -} -TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStringNum; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WRONG_LANGUAGE; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - UIGetSupportedLanguagesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_ui_supported_languages(supported_languages)).Times(0); - - command->Run(); - - EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( - am::hmi_response::languages)); -} - -} // namespace ui_get_supported_languages_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc deleted file mode 100644 index 5b1f46de93..0000000000 --- a/src/components/application_manager/test/commands/hmi/ui_is_ready_request_test.cc +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/ui_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 ui_is_ready_request { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using am::commands::MessageSharedPtr; -using am::commands::UIIsReadyRequest; -using am::event_engine::Event; - -typedef SharedPtr UIIsReadyRequestPtr; - -class UIIsReadyRequestTest - : public CommandRequestTest { - public: - UIIsReadyRequestTest() : command_(CreateCommand()) {} - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(mock_hmi_capabilities_)); - } - void SetUpExpectations(bool is_ui_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, - am::HmiInterfaces::InterfaceState state) { - EXPECT_CALL(mock_hmi_capabilities_, - set_is_ui_cooperating(is_ui_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_UI, state)); - } else { - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - } - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillOnce(Return(state)); - - if (is_send_message_to_hmi) { - ExpectSendMessagesToHMI(); - } - } - - void ExpectSendMessagesToHMI() { - smart_objects::SmartObjectSPtr get_language(CreateMessage()); - (*get_language)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kRequest); - (*get_language)[am::strings::msg_params] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - EXPECT_CALL(mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, _)) - .WillOnce(Return(get_language)); - - smart_objects::SmartObjectSPtr get_all_language(CreateMessage()); - (*get_all_language)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kRequest); - (*get_all_language)[am::strings::msg_params] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - EXPECT_CALL( - mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetSupportedLanguages, _)) - .WillOnce(Return(get_all_language)); - - smart_objects::SmartObjectSPtr get_capabilities(CreateMessage()); - (*get_capabilities)[am::strings::params][am::strings::message_type] = - static_cast(am::MessageType::kRequest); - (*get_capabilities)[am::strings::msg_params] = - smart_objects::SmartObject(smart_objects::SmartType_Map); - EXPECT_CALL(mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetCapabilities, _)) - .WillOnce(Return(get_capabilities)); - - EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*get_language)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(get_language)); - EXPECT_CALL(rpc_service_, ManageHMICommand(get_all_language)); - EXPECT_CALL(rpc_service_, ManageHMICommand(get_capabilities)); - } - - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_ui_cooperating_available = false) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { - (*msg)[am::strings::msg_params][am::strings::available] = - is_ui_cooperating_available; - } - event.set_smart_object(*msg); - } - - UIIsReadyRequestPtr command_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; -}; - -TEST_F(UIIsReadyRequestTest, - OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - const bool is_ui_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; - Event event(hmi_apis::FunctionID::UI_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_ui_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); - - command_->on_event(event); -} - -TEST_F(UIIsReadyRequestTest, - OnEvent_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_ui_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::UI_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_ui_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); - command_->on_event(event); -} - -TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { - const bool is_ui_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::UI_IsReady); - PrepareEvent(is_message_contain_param, event, is_ui_cooperating_available); - SetUpExpectations(is_ui_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); - command_->on_event(event); -} - -TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS) { - ExpectSendMessagesToHMI(); - command_->onTimeOut(); -} - -} // namespace ui_is_ready_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/ui_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/ui_is_ready_response_test.cc deleted file mode 100644 index d69ec0528e..0000000000 --- a/src/components/application_manager/test/commands/hmi/ui_is_ready_response_test.cc +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2016, 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 "commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/commands/hmi/ui_is_ready_response.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace ui_is_ready_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::UIIsReadyResponse; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr UIIsReadyResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kStringNum = "123"; -const bool kIsAvailable = true; -const bool kIsNotAvailable = false; -} // namespace - -class UIIsReadyResponseTest : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(UIIsReadyResponseTest, RUN_SUCCESS) { - UIIsReadyResponsePtr command(CreateCommand()); - - 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 ui_is_ready_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/update_device_list_request_test.cc b/src/components/application_manager/test/commands/hmi/update_device_list_request_test.cc deleted file mode 100644 index 0f24624e09..0000000000 --- a/src/components/application_manager/test/commands/hmi/update_device_list_request_test.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "interfaces/HMI_API.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/application_manager.h" -#include "application_manager/application_manager_impl.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/mock_application.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/request_controller_settings.h" -#include "application_manager/mock_application_manager_settings.h" -#include "application_manager/commands/hmi/update_device_list_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace update_device_list_request { - -using ::utils::SharedPtr; -using testing::_; -using testing::ReturnRef; -using testing::Return; -using test::components::event_engine_test::MockEventDispatcher; -using ::test::components::application_manager_test:: - MockApplicationManagerSettings; -namespace am = ::application_manager; -namespace strings = am::strings; -namespace hmi_response = am::hmi_response; -using am::event_engine::Event; -using am::commands::UpdateDeviceListRequest; -using am::commands::CommandImpl; - -typedef SharedPtr UpdateDeviceListRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class UpdateDeviceListRequestTest - : public CommandsTest { - public: - MessageSharedPtr CreateCommandMsg() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - return command_msg; - } - - MockApplicationManagerSettings settings_; - MockEventDispatcher mock_event_dispatcher_; -}; - -TEST_F(UpdateDeviceListRequestTest, RUN_LaunchHMIReturnsFalse) { - MessageSharedPtr command_msg = CreateCommandMsg(); - - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher_)); - EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); - - UpdateDeviceListRequestPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); - - EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(false)); - - EXPECT_CALL(app_mngr_, IsHMICooperating()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -TEST_F(UpdateDeviceListRequestTest, RUN_HMICooperatingReturnsTrue_SUCCESSS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher_)); - EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); - - UpdateDeviceListRequestPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); - - EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, IsHMICooperating()).WillOnce(Return(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -TEST_F(UpdateDeviceListRequestTest, OnEvent_WrongEventId_UNSUCCESS) { - Event event(Event::EventID::INVALID_ENUM); - - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher_)); - EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); - - UpdateDeviceListRequestPtr command(CreateCommand()); - - command->on_event(event); -} - -TEST_F(UpdateDeviceListRequestTest, OnEvent_SUCCESS) { - Event event(Event::EventID::BasicCommunication_OnReady); - - EXPECT_CALL(app_mngr_, event_dispatcher()) - .WillOnce(ReturnRef(mock_event_dispatcher_)); - EXPECT_CALL(mock_event_dispatcher_, remove_observer(_, _)); - EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); - - UpdateDeviceListRequestPtr command(CreateCommand()); - - command->on_event(event); -} - -} // namespace update_device_list_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/update_sdl_request_test.cc b/src/components/application_manager/test/commands/hmi/update_sdl_request_test.cc deleted file mode 100644 index e9bf402aa7..0000000000 --- a/src/components/application_manager/test/commands/hmi/update_sdl_request_test.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/commands/hmi/update_sdl_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace update_sdl_request { - -using ::utils::SharedPtr; -using ::testing::ReturnRef; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::UpdateSDLRequest; - -typedef SharedPtr UpdateSDLRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 1u; -const std::string kStrNumber = "123"; -} // namespace - -class UpdateSDLRequestTest : public CommandsTest {}; - -TEST_F(UpdateSDLRequestTest, 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::correlation_id] = kCorrelationId; - - UpdateSDLRequestPtr command(CreateCommand(command_msg)); - policy_test::MockPolicyHandlerInterface policy_handler; - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(policy_handler, PTExchangeAtUserRequest(kCorrelationId)); - - command->Run(); - - EXPECT_EQ(kCorrelationId, - (*command_msg)[strings::params][strings::correlation_id].asUInt()); -} - -} // namespace update_sdl_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/update_sdl_response_test.cc b/src/components/application_manager/test/commands/hmi/update_sdl_response_test.cc deleted file mode 100644 index 116256a601..0000000000 --- a/src/components/application_manager/test/commands/hmi/update_sdl_response_test.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "commands/commands_test.h" -#include "application_manager/application.h" -#include "hmi/update_sdl_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace update_sdl_response { - -using ::utils::SharedPtr; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -using am::commands::UpdateSDLResponse; -using am::commands::CommandImpl; - -typedef SharedPtr UpdateSDLResponsePtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kStrNumber = "123"; -} // namespace - -class UpdateSDLResponseTest : public CommandsTest { -}; - -TEST_F(UpdateSDLResponseTest, RUN_SendRequest_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; - - UpdateSDLResponsePtr command(CreateCommand(command_msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToHMI(command_msg)); - - command->Run(); - - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), - CommandImpl::hmi_protocol_type_); - EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), - CommandImpl::protocol_version_); -} - -} // namespace update_sdl_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vi_get_vehicle_data_response_test.cc b/src/components/application_manager/test/commands/hmi/vi_get_vehicle_data_response_test.cc deleted file mode 100644 index e61f90a2fa..0000000000 --- a/src/components/application_manager/test/commands/hmi/vi_get_vehicle_data_response_test.cc +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2016, 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 "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 am::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); - - policy_test::MockPolicyHandlerInterface policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(policy_handler)); - EXPECT_CALL(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/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc deleted file mode 100644 index 2d7d1d72b3..0000000000 --- a/src/components/application_manager/test/commands/hmi/vi_is_ready_request_test.cc +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/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 am::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(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - 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(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_interface_)); - EXPECT_CALL(mock_policy_handler_interface_, 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; - policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; -}; - -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/test/commands/hmi/vr_get_capabilities_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_get_capabilities_response_test.cc deleted file mode 100644 index 907a013972..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_get_capabilities_response_test.cc +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/mock_hmi_capabilities.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/commands/hmi/vr_get_capabilities_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vr_get_capabilities_response { - -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = am::strings; -namespace hmi_response = am::hmi_response; -using am::commands::VRGetCapabilitiesResponse; -using am::commands::CommandImpl; - -typedef SharedPtr VRGetCapabilitiesResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class VRGetCapabilitiesResponseTest - : public CommandsTest { - public: - MessageSharedPtr CreateCommandMsg() { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = "123"; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - return command_msg; - } - - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(VRGetCapabilitiesResponseTest, RUN_SUCCESSS) { - MessageSharedPtr command_msg = CreateCommandMsg(); - (*command_msg)[strings::msg_params][strings::vr_capabilities] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - (*command_msg)[strings::msg_params][strings::vr_capabilities][0] = - "vrCapabilities"; - - VRGetCapabilitiesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - smart_objects::SmartObject vr_capabilities_so = - (*command_msg)[strings::msg_params][strings::vr_capabilities]; - - EXPECT_CALL(mock_hmi_capabilities_, set_vr_capabilities(vr_capabilities_so)); - - command->Run(); -} - -} // namespace vr_get_capabilities_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_get_language_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_get_language_response_test.cc deleted file mode 100644 index 7d42e39548..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_get_language_response_test.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/hmi/vr_get_language_response.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_event_dispatcher.h" -#include "application_manager/mock_application_manager.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vr_get_language_response { - -using utils::SharedPtr; -using application_manager::commands::VRGetLanguageResponse; -using test::components::event_engine_test::MockEventDispatcher; -using testing::_; -using testing::ReturnRef; -using ::testing::NiceMock; - -namespace strings = application_manager::strings; -namespace hmi_response = application_manager::hmi_response; -using namespace hmi_apis; - -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; -} // namespace - -class VRGetLanguageResponseTest - : public CommandsTest {}; - -TEST_F(VRGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::msg_params][hmi_response::language] = kLanguage; - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, set_active_vr_language(kLanguage)); - - 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(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(msg)); - - MockHMICapabilities mock_hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities)); - EXPECT_CALL(mock_hmi_capabilities, - set_active_vr_language(Common_Language::INVALID_ENUM)); - - 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 vr_get_language_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_get_supported_languages_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_get_supported_languages_response_test.cc deleted file mode 100644 index 27be9e0f0f..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_get_supported_languages_response_test.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/application.h" -#include "commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/commands/hmi/vr_get_supported_languages_response.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vr_get_supported_languages_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::VRGetSupportedLanguagesResponse; - -typedef SharedPtr - VRGetSupportedLanguagesResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kStringNum = "123"; -const std::string kLanguage = "EN_US"; -const smart_objects::SmartObject supported_languages(kLanguage); -} // namespace - -class VRGetSupportedLanguagesResponseTest - : public CommandsTest { - public: - MockHMICapabilities mock_hmi_capabilities_; - SmartObject capabilities_; -}; - -TEST_F(VRGetSupportedLanguagesResponseTest, RUN_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStringNum; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - (*command_msg)[strings::msg_params][hmi_response::languages] = - supported_languages; - - VRGetSupportedLanguagesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_vr_supported_languages((supported_languages))); - - command->Run(); -} -TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[strings::msg_params][strings::number] = kStringNum; - (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; - (*command_msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::WRONG_LANGUAGE; - (*command_msg)[strings::msg_params][hmi_response::capabilities] = - (capabilities_); - - VRGetSupportedLanguagesResponsePtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(mock_hmi_capabilities_, - set_vr_supported_languages(supported_languages)).Times(0); - - command->Run(); - - EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( - am::hmi_response::languages)); -} - -} // namespace vr_get_supported_languages_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc deleted file mode 100644 index a1ad208191..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_is_ready_request_test.cc +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/hmi/vr_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/mock_message_helper.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vr_is_ready_request { - -using ::testing::_; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::VRIsReadyRequest; -using am::event_engine::Event; - -typedef SharedPtr VRIsReadyRequestPtr; - -class VRIsReadyRequestTest - : public CommandRequestTest { - public: - VRIsReadyRequestTest() : command_(CreateCommand()) {} - - void SetUpExpectations(bool is_vr_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, - am::HmiInterfaces::InterfaceState state) { - const bool is_send_message_by_timeout = false; - if (is_send_message_to_hmi) { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillRepeatedly(ReturnRef(mock_hmi_capabilities_)); - ExpectSendMessagesToHMI(is_send_message_by_timeout); - } else { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - } - EXPECT_CALL(mock_hmi_capabilities_, - set_is_vr_cooperating(is_vr_cooperating_available)); - - if (is_message_contain_param) { - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL( - mock_hmi_interfaces_, - SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, state)); - } else { - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillOnce(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); - } - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillOnce(Return(state)); - } - - void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { - if (is_send_message_by_timeout) { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - } - - smart_objects::SmartObjectSPtr language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) - .WillOnce(Return(language)); - EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(language)); - - smart_objects::SmartObjectSPtr support_language( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL( - mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, _)) - .WillOnce(Return(support_language)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(support_language)); - - smart_objects::SmartObjectSPtr capabilities( - new smart_objects::SmartObject(smart_objects::SmartType_Map)); - EXPECT_CALL(mock_message_helper_, - CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) - .WillOnce(Return(capabilities)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(capabilities)); - } - - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_vr_cooperating_available = false) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { - (*msg)[am::strings::msg_params][am::strings::available] = - is_vr_cooperating_available; - } - event.set_smart_object(*msg); - } - - VRIsReadyRequestPtr command_; - application_manager_test::MockHMICapabilities mock_hmi_capabilities_; -}; - -TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { - const bool is_vr_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; - Event event(hmi_apis::FunctionID::VR_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_vr_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); - command_->on_event(event); -} - -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { - const bool is_vr_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::VR_IsReady); - PrepareEvent(is_message_contain_param, event); - SetUpExpectations(is_vr_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); - command_->on_event(event); -} - -TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { - const bool is_vr_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; - Event event(hmi_apis::FunctionID::VR_IsReady); - PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); - SetUpExpectations(is_vr_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); - command_->on_event(event); -} - -TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { - const bool is_send_message_by_timeout = true; - ExpectSendMessagesToHMI(is_send_message_by_timeout); - command_->onTimeOut(); -} - -} // namespace vr_is_ready_request -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc b/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc deleted file mode 100644 index 37e945bc11..0000000000 --- a/src/components/application_manager/test/commands/hmi/vr_is_ready_response_test.cc +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2016, 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 "commands/commands_test.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/commands/hmi/vr_is_ready_response.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace test { -namespace components { -namespace commands_test { -namespace hmi_commands_test { -namespace vr_is_ready_response { - -using ::testing::Return; -using ::utils::SharedPtr; -using ::testing::NiceMock; -namespace am = ::application_manager; -namespace strings = ::application_manager::strings; -namespace hmi_response = am::hmi_response; -using am::commands::VRIsReadyResponse; -using test::components::event_engine_test::MockEventDispatcher; - -typedef SharedPtr VRIsReadyResponsePtr; - -class VRIsReadyResponseTest : public CommandsTest { -}; - -TEST_F(VRIsReadyResponseTest, RUN_SUCCESS) { - VRIsReadyResponsePtr command(CreateCommand()); - - 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 vr_is_ready_response -} // namespace hmi_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/add_command_request_test.cc b/src/components/application_manager/test/commands/mobile/add_command_request_test.cc deleted file mode 100644 index b847512d75..0000000000 --- a/src/components/application_manager/test/commands/mobile/add_command_request_test.cc +++ /dev/null @@ -1,1125 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/add_command_request.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/helpers.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "utils/custom_string.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace add_command_request { - -namespace am = application_manager; -using am::commands::CommandImpl; -using am::ApplicationManager; -using am::commands::MessageSharedPtr; -using am::ApplicationSharedPtr; -using ::testing::_; -using ::utils::SharedPtr; -using ::testing::Return; -using ::testing::InSequence; -using am::commands::AddCommandRequest; -using NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr; -using ::test::components::application_manager_test::MockApplication; -using am::event_engine::EventObserver; -using namespace smart_objects; - -namespace custom_str = utils::custom_string; -namespace strings = ::application_manager::strings; -namespace mobile_result = mobile_apis::Result; -namespace hmi_response = ::application_manager::hmi_response; -namespace hmi_request = ::application_manager::hmi_request; -using namespace strings; - -namespace { -const hmi_apis::FunctionID::eType kInvalidFunctionId = - hmi_apis::FunctionID::INVALID_ENUM; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const std::string kMenuName = "LG"; -const uint32_t kFirstParentId = 10u; -const uint32_t kSecondParentId = 1u; -const std::string kErroredVRCommand = "l\namer"; -const std::string kFirstVrCommand = "lamer"; -const std::string kSecondVrCommand = "hacker"; -const uint32_t kFirstCommandId = 10u; -const uint32_t kSecondCommandId = 11u; -const int32_t kType = 34; -const int32_t kGrammarId = 12; -const int32_t kPosition = 10; -} // namespace - -class AddCommandRequestTest - : public CommandRequestTest { - public: - AddCommandRequestTest() - : msg_(CreateMessage()) - , default_app_name_("test_default_app_name_") - , mock_app_(CreateMockApp()) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app_)); - InitGetters(); - InitBasicMessage(); - } - - protected: - void InitBasicMessage() { - (*msg_)[params][connection_key] = kConnectionKey; - (*msg_)[msg_params][app_id] = kAppId; - (*msg_)[msg_params][app_name] = default_app_name_; - } - - void InitGetters() { - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); - ON_CALL(*mock_app_, FindCommand(kCmdId)) - .WillByDefault(Return(so_ptr_.get())); - } - - void CreateBasicParamsUIRequest() { - SmartObject menu_params = SmartObject(SmartType_Map); - menu_params[position] = kPosition; - menu_params[menu_name] = kMenuName; - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[cmd_id] = kCmdId; - msg_params[strings::menu_params] = menu_params; - msg_params[cmd_icon] = 1; - msg_params[cmd_icon][value] = "10"; - msg_params[info] = "UI info"; - } - - void CreateBasicParamsVRRequest() { - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[cmd_id] = kCmdId; - msg_params[vr_commands] = SmartObject(SmartType_Array); - msg_params[vr_commands][0] = kFirstVrCommand; - msg_params[type] = kPosition; - msg_params[grammar_id] = kGrammarId; - msg_params[info] = "VR info"; - } - - const am::CommandsMap CreateCommandsMap(SmartObject& first_command, - SmartObject& second_command) { - second_command[menu_params] = SmartObject(SmartType_Map); - second_command[menu_params][hmi_request::parent_id] = kFirstParentId; - second_command[menu_params][menu_name] = kMenuName; - second_command[vr_commands] = SmartObject(SmartType_Array); - second_command[vr_commands][0] = kSecondVrCommand; - am::CommandsMap commands_map; - commands_map.insert(std::make_pair(kFirstCommandId, &first_command)); - commands_map.insert(std::make_pair(kSecondCommandId, &second_command)); - return commands_map; - } - - void CheckOnTimeOutCommandDeletion( - const hmi_apis::FunctionID::eType incoming_cmd, - const hmi_apis::FunctionID::eType cmd_to_delete) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)) - .WillOnce(Return(so_ptr_.get())); - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return(DataAccessor( - commands_map, lock_))); - so_ptr_ = utils::MakeShared(SmartType_Map); - EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) - .WillOnce(Return(so_ptr_.get())); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()) - .WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - Event event(incoming_cmd); - event.set_smart_object(*msg_); - request_ptr->on_event(event); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(HMIResultCodeIs(cmd_to_delete))) - .WillOnce(Return(true)); - SmartObjectSPtr response = utils::MakeShared(SmartType_Map); - (*response)[strings::msg_params][strings::info] = "info"; - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) - .WillOnce(Return(response)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(response, - am::commands::Command::CommandSource::SOURCE_SDL)); - utils::SharedPtr base_class_request = - static_cast >(request_ptr); - base_class_request->onTimeOut(); - } - - MessageSharedPtr msg_; - SmartObjectSPtr so_ptr_; - const utils::custom_string::CustomString default_app_name_; - sync_primitives::Lock lock_; - MockAppPtr mock_app_; -}; - -TEST_F(AddCommandRequestTest, Run_AppNotExisted_EXPECT_AppNotRegistered) { - CreateBasicParamsUIRequest(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, Run_ImageVerificationFailed_EXPECT_INVALID_DATA) { - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, Run_MenuNameHasSyntaxError_EXPECT_INVALID_DATA) { - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; - const std::string errored_menu_name = "L\nG"; - msg_params[menu_params][menu_name] = errored_menu_name; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - SmartObject parent = SmartObject(SmartType_Map); - EXPECT_CALL(*mock_app_, FindSubMenu(kFirstParentId)) - .WillOnce(Return(&parent)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, - Run_VRCommandsHaveSyntaxError_EXPECT_INVALID_DATA) { - CreateBasicParamsVRRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[vr_commands][0] = kErroredVRCommand; - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, Run_CMDIconHasError_EXPECT_INVALID_DATA) { - MessageSharedPtr msg = CreateMessage(); - SmartObject& msg_params = (*msg)[strings::msg_params]; - (*msg)[params][connection_key] = kConnectionKey; - msg_params[cmd_id] = kCmdId; - msg_params[cmd_icon] = 1; - const std::string errored_cmd_icon_value = "1\n0"; - msg_params[cmd_icon][value] = errored_cmd_icon_value; - msg_params[vr_commands][0] = kFirstVrCommand; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, Run_CommandIDAlreadyExists_EXPECT_INVALID_ID) { - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - so_ptr_ = utils::MakeShared(SmartType_Map); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, - Run_CommandNameAlreadyExists_EXPECT_DUPLICATE_NAME) { - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, - Run_CmdAndMsgParentIDsAreDifferentSubmenuNotExisted_EXPECT_INVALID_ID) { - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) - .WillOnce(Return(so_ptr_.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, - Run_CmdAndMsgVrSynonymsAreTheSame_EXPECT_DUPLICATE_NAME) { - CreateBasicParamsVRRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; - msg_params[vr_commands][0] = kSecondVrCommand; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - so_ptr_ = utils::MakeShared(SmartType_Map); - EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) - .WillOnce(Return(so_ptr_.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, Run_MsgDataEmpty_EXPECT_INVALID_DATA) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[params][connection_key] = kConnectionKey; - SmartObject& msg_params = (*msg)[strings::msg_params]; - msg_params[app_id] = kAppId; - msg_params[cmd_id] = kCmdId; - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, - Run_CmdAndMsg_UI_and_Vr_AreCorrect_EXPECT_VR_AND_UI_SENT) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; - SmartObject& image = msg_params[cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - so_ptr_ = utils::MakeShared(SmartType_Map); - EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) - .WillOnce(Return(so_ptr_.get())); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, GetRunMethods_SUCCESS) { - CreateBasicParamsUIRequest(); - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); - - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); -} - -TEST_F(AddCommandRequestTest, OnEvent_UI_SUCCESS) { - CreateBasicParamsUIRequest(); - (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); - - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly( - Return(DataAccessor(commands_map, lock_))); - - Event event(hmi_apis::FunctionID::UI_AddCommand); - event.set_smart_object(*msg_); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, OnEvent_VR_SUCCESS) { - CreateBasicParamsVRRequest(); - MessageSharedPtr msg = CreateMessage(SmartType_Map); - (*msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - (*msg)[msg_params][cmd_id] = kCmdId; - - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*msg); - EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); - - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly( - Return(DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_VR_DeleteCommand) { - CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::VR_AddCommand, - hmi_apis::FunctionID::VR_DeleteCommand); -} - -TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_UI_DeleteCommand) { - CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::UI_AddCommand, - hmi_apis::FunctionID::UI_DeleteCommand); -} - -TEST_F(AddCommandRequestTest, OnEvent_BothSend_SUCCESS) { - MessageSharedPtr command_msg = CreateMessage(SmartType_Map); - (*command_msg)[params][connection_key] = kConnectionKey; - MessageSharedPtr event_msg = CreateMessage(SmartType_Map); - (*event_msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - (*event_msg)[msg_params][cmd_id] = kCmdId; - - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*event_msg); - - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*event_msg); - - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - utils::SharedPtr request_ptr = - CreateCommand(command_msg); - request_ptr->Run(); - request_ptr->on_event(event_ui); - request_ptr->on_event(event_vr); -} - -TEST_F(AddCommandRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - Event event(hmi_apis::FunctionID::INVALID_ENUM); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, OnEvent_AppNotExisted_UNSUCCESS) { - CreateBasicParamsUIRequest(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - Event event(hmi_apis::FunctionID::UI_AddCommand); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, - OnEvent_HmiResponseCodeIsRejected_ExpectUICommandRemoved) { - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::REJECTED; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::REJECTED), _)); - Event event(hmi_apis::FunctionID::UI_AddCommand); - event.set_smart_object(*msg_); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, - OnEvent_HmiResponseCodeIsWarnings_ExpectCommandUpdated) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::WARNINGS; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::WARNINGS), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_); - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*msg_); - request_ptr->on_event(event_ui); - request_ptr->on_event(event_vr); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_UI_HmiResponseCodeIsGenericError_VR_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_); - request_ptr->on_event(event_ui); - - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); - (*msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_vr)[msg_params][cmd_id] = kCmdId; - event_vr.set_smart_object(*msg_vr); - request_ptr->on_event(event_vr); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_VR_HmiResponseCodeIsGenericError_UI_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*msg_); - request_ptr->on_event(event_vr); - - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); - (*msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_ui)[msg_params][cmd_id] = kCmdId; - event_ui.set_smart_object(*msg_ui); - request_ptr->on_event(event_ui); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_UI_NotAvailableInterfaceState_ExpectCommandRemoved) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_); - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*msg_); - request_ptr->on_event(event_ui); - request_ptr->on_event(event_vr); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_VR_NotAvailableInterfaceState_ExpectCommandRemoved) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_); - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*msg_); - request_ptr->on_event(event_ui); - request_ptr->on_event(event_vr); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_UI_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); - Event event(hmi_apis::FunctionID::UI_AddCommand); - event.set_smart_object(*msg_); - request_ptr->on_event(event); -} - -TEST_F( - AddCommandRequestTest, - OnEvent_VR_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { - CreateBasicParamsVRRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*msg_); - request_ptr->on_event(event); -} - -TEST_F(AddCommandRequestTest, - OnEvent_UI_EventWithNotSuccesResponseCode_ExpectVRCommandDelete) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); - (*msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::ABORTED; - (*msg_ui)[msg_params][cmd_id] = kCmdId; - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_ui); - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - event_vr.set_smart_object(*msg_); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) - .WillOnce(Return(true)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); - request_ptr->on_event(event_ui); - request_ptr->on_event(event_vr); -} - -TEST_F(AddCommandRequestTest, - OnEvent_UI_VR_Events_VRErrorPresent_ExpectRemoveCommand) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& params = (*msg_)[strings::params]; - params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - SmartObject& image = (*msg_)[msg_params][cmd_icon]; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - am::CommandsMap commands_map; - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - - Event event_ui(hmi_apis::FunctionID::UI_AddCommand); - event_ui.set_smart_object(*msg_); - request_ptr->on_event(event_ui); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) - .WillOnce(Return(true)); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); - Event event_vr(hmi_apis::FunctionID::VR_AddCommand); - MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); - (*msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::ABORTED; - (*msg_vr)[msg_params][cmd_id] = kCmdId; - event_vr.set_smart_object(*msg_vr); - request_ptr->on_event(event_vr); -} - -TEST_F(AddCommandRequestTest, - OnTimeOut_AppNotExisted_NoAppRemoveCommandCalled) { - CreateBasicParamsUIRequest(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); - SmartObjectSPtr response = utils::MakeShared(SmartType_Map); - (*response)[strings::msg_params][strings::info] = "info"; - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) - .WillOnce(Return(response)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - response, am::commands::Command::CommandSource::SOURCE_SDL)); - utils::SharedPtr base_class_request = - static_cast >( - CreateCommand(msg_)); - base_class_request->onTimeOut(); -} - -TEST_F(AddCommandRequestTest, OnTimeOut_AppRemoveCommandCalled) { - CreateBasicParamsVRRequest(); - CreateBasicParamsUIRequest(); - SmartObject& msg_params = (*msg_)[strings::msg_params]; - SmartObject& image = msg_params[cmd_icon]; - msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; - EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); - SmartObject first_command = SmartObject(SmartType_Map); - SmartObject second_command = SmartObject(SmartType_Map); - const am::CommandsMap commands_map = - CreateCommandsMap(first_command, second_command); - EXPECT_CALL(*mock_app_, commands_map()) - .WillRepeatedly(Return( - DataAccessor(commands_map, lock_))); - so_ptr_ = utils::MakeShared(SmartType_Map); - EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) - .WillOnce(Return(so_ptr_.get())); - { - InSequence dummy; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) - .WillOnce(Return(true)); - } - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - utils::SharedPtr request_ptr = - CreateCommand(msg_); - request_ptr->Run(); - EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); - SmartObjectSPtr response = utils::MakeShared(SmartType_Map); - (*response)[strings::msg_params][strings::info] = "info"; - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) - .WillOnce(Return(response)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - response, am::commands::Command::CommandSource::SOURCE_SDL)); - utils::SharedPtr base_class_request = - static_cast >(request_ptr); - base_class_request->onTimeOut(); -} - -} // namespace add_command_test -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc b/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc deleted file mode 100644 index d28f8d7f2e..0000000000 --- a/src/components/application_manager/test/commands/mobile/add_sub_menu_request_test.cc +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/add_sub_menu_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace add_sub_menu_request { - -namespace am = ::application_manager; -using am::commands::AddSubMenuRequest; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using ::testing::_; -using ::testing::Return; - -typedef SharedPtr AddSubMenuPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class AddSubMenuRequestTest - : public CommandRequestTest {}; - -TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { - const uint32_t menu_id = 10u; - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::menu_id] = menu_id; - - utils::SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - EXPECT_CALL(*mock_app, AddSubMenu(menu_id, _)); - EXPECT_CALL(*mock_app, UpdateHash()); - - MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); - (*ev_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; - - Event event(hmi_apis::FunctionID::UI_AddSubMenu); - event.set_smart_object(*ev_msg); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - command->Init(); - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -} // namespace add_sub_menu_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc deleted file mode 100644 index 992fcee59a..0000000000 --- a/src/components/application_manager/test/commands/mobile/alert_maneuver_request_test.cc +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2016, 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/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/mock_message_helper.h" -#include "event_engine/event.h" -#include "application_manager/commands/mobile/alert_maneuver_request.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/policies/policy_handler_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace alert_maneuver_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::AlertManeuverRequest; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; - -typedef SharedPtr CommandPtr; - -class AlertManeuverRequestTest - : public CommandRequestTest { - public: - void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, - const mobile_apis::Result::eType mobile_response, - const am::HmiInterfaces::InterfaceState state, - const bool success) { - MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); - (*response)[am::strings::params][am::hmi_response::code] = hmi_response; - (*response)[am::strings::msg_params][am::strings::info] = "test"; - - am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*response); - - utils::SharedPtr command = - CreateCommand(response); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(state)); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - _, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - command->on_event(event); - - EXPECT_EQ( - (*response_to_mobile)[am::strings::msg_params][am::strings::success] - .asBool(), - success); - EXPECT_EQ( - (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(mobile_response)); - } - - protected: - NiceMock policy_interface_; -}; - -TEST_F(AlertManeuverRequestTest, Run_RequiredFieldsDoesNotExist_UNSUCCESS) { - CommandPtr command(CreateCommand()); - EXPECT_CALL(app_mngr_, application(_)).Times(0); - 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(AlertManeuverRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; - (*msg)[am::strings::msg_params][am::strings::tts_chunks] = 0; - - CommandPtr command(CreateCommand(msg)); - - ON_CALL(app_mngr_, application(_)) - .WillByDefault(Return(ApplicationSharedPtr())); - - 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(AlertManeuverRequestTest, Run_ProcessingResult_UNSUCCESS) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] - [am::strings::text] = "text"; - - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(policy_interface_)); - - const mobile_apis::Result::eType kProcessingResult = - mobile_apis::Result::ABORTED; - - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) - .WillOnce(Return(kProcessingResult)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(kProcessingResult, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(AlertManeuverRequestTest, Run_IsWhiteSpaceExist_UNSUCCESS) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; - (*msg)[am::strings::msg_params][am::strings::tts_chunks] = - SmartObject(smart_objects::SmartType_Array); - - SmartObject tts_chunk(smart_objects::SmartType_Map); - tts_chunk[am::strings::text] = "wrong chunk syntax\t\n"; - - (*msg)[am::strings::msg_params][am::strings::tts_chunks].asArray()->push_back( - tts_chunk); - - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - 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(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] - [am::strings::text] = "text"; - - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(policy_interface_)); - - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) - .WillRepeatedly( - Return(am::HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS)); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); - - MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); - EXPECT_EQ(hmi_apis::FunctionID::Navigation_AlertManeuver, - static_cast( - (*result_msg)[am::strings::params][am::strings::function_id] - .asInt())); -} - -TEST_F(AlertManeuverRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { - CommandPtr command(CreateCommand()); - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - MessageSharedPtr result_msg( - CatchMobileCommandResult(CallOnEvent(*command, event))); - EXPECT_EQ(mobile_apis::Result::INVALID_ENUM, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(AlertManeuverRequestTest, OnEvent_SUCCESS) { - CheckExpectations(hmi_apis::Common_Result::SUCCESS, - mobile_apis::Result::SUCCESS, - am::HmiInterfaces::STATE_AVAILABLE, - true); -} - -TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_AVAILABLE, - false); -} - -TEST_F(AlertManeuverRequestTest, OnEvent_WARNINGS) { - CheckExpectations(hmi_apis::Common_Result::WARNINGS, - mobile_apis::Result::WARNINGS, - am::HmiInterfaces::STATE_NOT_RESPONSE, - true); -} - -TEST_F(AlertManeuverRequestTest, OnEvent_GENERIC_ERROR) { - CheckExpectations(hmi_apis::Common_Result::GENERIC_ERROR, - mobile_apis::Result::GENERIC_ERROR, - am::HmiInterfaces::STATE_NOT_RESPONSE, - false); -} - -} // namespace alert_maneuver_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/alert_request_test.cc b/src/components/application_manager/test/commands/mobile/alert_request_test.cc deleted file mode 100644 index 8580a0a174..0000000000 --- a/src/components/application_manager/test/commands/mobile/alert_request_test.cc +++ /dev/null @@ -1,828 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/alert_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace alert_request { - -namespace am = application_manager; -using am::commands::AlertRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using ::utils::SharedPtr; -using am::event_engine::Event; -using policy_test::MockPolicyHandlerInterface; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -typedef SharedPtr CommandPtr; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kDefaultTimeout = 1000u; -const uint32_t kCorrelationId = 2u; -const mobile_apis::FunctionID::eType kFunctionId = - mobile_apis::FunctionID::AlertID; -} // namespace - -class AlertRequestTest : public CommandRequestTest { - public: - AlertRequestTest() : mock_app_(CreateMockApp()), msg_(CreateMessage()) {} - - protected: - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - void PreConditions() { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault( - Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault( - Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); - } - - void Expectations() { - (*msg_)[am::strings::params][am::strings::function_id] = kFunctionId; - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL( - *mock_app_, - AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) - .WillByDefault(Return(false)); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - ON_CALL(*mock_app_, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - ON_CALL(*mock_app_, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); - } - - void AddAlertTextsToMsg() { - (*msg_)[am::strings::msg_params][am::strings::alert_text1] = "alert_text1"; - (*msg_)[am::strings::msg_params][am::strings::alert_text2] = "alert_text2"; - (*msg_)[am::strings::msg_params][am::strings::alert_text3] = "alert_text3"; - } - void AddTTSChunkToMsg() { - (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "tts_chunk_text"; - } - - void ExpectCallHmiLevel(const mobile_apis::HMILevel::eType level) { - EXPECT_CALL(*mock_app_, hmi_level()).WillRepeatedly(Return(level)); - } - - void ExpectManageMobileCommandWithResultCode( - const mobile_apis::Result::eType code) { - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(code), - am::commands::Command::CommandSource::SOURCE_SDL)); - } - - void ExpectManageHmiCommandTTSAndUI() { - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Alert))) - .WillOnce(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) - .WillOnce(Return(true)); - } - sync_primitives::Lock lock_; - - MockAppPtr mock_app_; - MessageSharedPtr msg_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -TEST_F(AlertRequestTest, OnTimeout_GENERIC_ERROR) { - PreConditions(); - MessageSharedPtr command_msg = CreateMessage(smart_objects::SmartType_Map); - (*command_msg)[am::strings::msg_params][am::strings::result_code] = - am::mobile_api::Result::GENERIC_ERROR; - (*command_msg)[am::strings::msg_params][am::strings::success] = false; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - utils::SharedPtr command = CreateCommand(); - - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(command_msg)); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->onTimeOut(); - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - false); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(am::mobile_api::Result::GENERIC_ERROR)); -} - -TEST_F(AlertRequestTest, OnEvent_UI_HmiSendSuccess_UNSUPPORTED_RESOURCE) { - PreConditions(); - MessageSharedPtr command_msg = CreateFullParamsUISO(); - (*command_msg)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = 10u; - (*command_msg)[am::strings::msg_params][am::strings::menu_params] - [am::strings::menu_name] = "menu_name"; - - utils::SharedPtr command = - CreateCommand(command_msg); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - MessageSharedPtr msg_tts = CreateMessage(); - (*msg_tts)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - Event event_vr(hmi_apis::FunctionID::TTS_Speak); - event_vr.set_smart_object(*msg_tts); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - command->on_event(event_vr); - - Event event(hmi_apis::FunctionID::UI_Alert); - event.set_smart_object(*msg); - - MessageSharedPtr ui_command_result; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - ResultCommandExpectations(ui_command_result, "UI is not supported by system"); -} - -class CallOnTimeOut { - public: - CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} - - void operator()() { - command_.onTimeOut(); - } - - CommandRequestImpl& command_; -}; - -TEST_F(AlertRequestTest, Init_DurationExists_SUCCESS) { - Expectations(); - (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; - (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); -} - -TEST_F(AlertRequestTest, Init_DurationNotExists_SUCCESS) { - Expectations(); - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); -} - -TEST_F(AlertRequestTest, OnTimeOut_SUCCESS) { - Expectations(); - MessageSharedPtr result_msg(CreateMessage(smart_objects::SmartType_Null)); - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) - .WillOnce(Return(result_msg)); - - CommandPtr command(CreateCommand()); - MessageSharedPtr received_result_msg( - CatchMobileCommandResult(CallOnTimeOut(*command))); - EXPECT_EQ(result_msg, received_result_msg); -} - -TEST_F(AlertRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - Expectations(); - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(invalid_app)); - - CommandPtr command(CreateCommand(msg_)); - ExpectManageMobileCommandWithResultCode( - mobile_apis::Result::APPLICATION_NOT_REGISTERED); - command->Run(); -} - -TEST_F(AlertRequestTest, Run_AlertFrequencyIsTooHigh_UNSUCCESS) { - Expectations(); - EXPECT_CALL( - *mock_app_, - AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) - .WillOnce(Return(true)); - - CommandPtr command(CreateCommand(msg_)); - 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(AlertRequestTest, Run_FailToProcessSoftButtons_UNSUCCESS) { - Expectations(); - const mobile_apis::Result::eType result_code = - mobile_apis::Result::INVALID_ENUM; - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(result_code)); - - CommandPtr command(CreateCommand(msg_)); - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(result_code, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(AlertRequestTest, Run_MandatoryParametersAreMissed_UNSUCCESS) { - Expectations(); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(AlertRequestTest, Run_MandatoryParametersAreInvalid_UNSUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - (*msg_)[am::strings::msg_params][am::strings::alert_text2] = - "invalid\t\nParam"; - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(AlertRequestTest, Run_SUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - AddTTSChunkToMsg(); - - (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; - (*msg_)[am::strings::msg_params][am::strings::progress_indicator] = - "progress_indicator"; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - EXPECT_CALL(mock_message_helper_, - SubscribeApplicationToSoftButton( - (*msg_)[am::strings::msg_params], _, kFunctionId)); - - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - ExpectManageHmiCommandTTSAndUI(); - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(AlertRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - Expectations(); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - event.set_smart_object(*msg_); - - CommandPtr command(CreateCommand(msg_)); - command->on_event(event); -} - -TEST_F(AlertRequestTest, DISABLED_OnEvent_UI_OnResetTimeout_SUCCESS) { - PreConditions(); - Expectations(); - AddAlertTextsToMsg(); - - (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); - - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_ENUM); - - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, OnEvent_UIAlertHasHmiResponsesToWait_UNSUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - AddTTSChunkToMsg(); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::WARNINGS; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - CommandPtr command(CreateCommand(msg_)); - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - ExpectManageHmiCommandTTSAndUI(); - - command->Run(); - - Event event(hmi_apis::FunctionID::UI_Alert); - event.set_smart_object(*msg_); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))); - - command->on_event(event); -} - -TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarnings_SUCCESS) { - PreConditions(); - Expectations(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::WARNINGS; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) - .WillOnce(Return(true)); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSUnsupportedResource_SUCCESS) { - Expectations(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) - .WillOnce(Return(true)); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - PreConditions(); - - command->on_event(event); -} - -TEST_F(AlertRequestTest, - DISABLED_OnEvent_TTSUnsupportedResourceUiAlertSent_SUCCESS) { - PreConditions(); - - Expectations(); - AddAlertTextsToMsg(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(mock_message_helper_, - SubscribeApplicationToSoftButton( - (*msg_)[am::strings::msg_params], _, kFunctionId)); - - ExpectManageHmiCommandTTSAndUI(); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(true)); - - Event ui_event(hmi_apis::FunctionID::UI_Alert); - ui_event.set_smart_object(*msg_); - command->on_event(ui_event); - - Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); - tts_stop_event.set_smart_object(*msg_); - command->on_event(tts_stop_event); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, OnEvent_TTSUnsupportedResourceUiAlertSuccess_SUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(mock_message_helper_, - SubscribeApplicationToSoftButton( - (*msg_)[am::strings::msg_params], _, kFunctionId)); - ExpectManageHmiCommandTTSAndUI(); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(true)); - - Event ui_event(hmi_apis::FunctionID::UI_Alert); - ui_event.set_smart_object(*msg_); - command->on_event(ui_event); - - Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); - tts_stop_event.set_smart_object(*msg_); - command->on_event(tts_stop_event); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, OnEvent_TTSSuccesUiAlertInvalidEnum_SUCCESS) { - Expectations(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) - .WillOnce(Return(true)); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::INVALID_ENUM; - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(true)); - - Event ui_event(hmi_apis::FunctionID::UI_Alert); - ui_event.set_smart_object(*msg_); - command->on_event(ui_event); - - Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); - tts_stop_event.set_smart_object(*msg_); - command->on_event(tts_stop_event); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSAbortedUiAlertNotSent_SUCCESS) { - Expectations(); - AddTTSChunkToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) - .WillOnce(Return(true)); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::INVALID_ENUM; - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(true)); - - Event ui_event(hmi_apis::FunctionID::UI_Alert); - ui_event.set_smart_object(*msg_); - command->on_event(ui_event); - - Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); - tts_stop_event.set_smart_object(*msg_); - command->on_event(tts_stop_event); - - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::ABORTED; - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarningUiAlertWarning_SUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::WARNINGS; - (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; - - ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ExpectManageHmiCommandTTSAndUI(); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(true)); - - Event ui_event(hmi_apis::FunctionID::UI_Alert); - ui_event.set_smart_object(*msg_); - command->on_event(ui_event); - - Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); - tts_stop_event.set_smart_object(*msg_); - command->on_event(tts_stop_event); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); - - Event event(hmi_apis::FunctionID::TTS_Speak); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(AlertRequestTest, Run_InvalidAlert2_UNSUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - (*msg_)[am::strings::msg_params][am::strings::alert_text2] = - "invalid_text_with_empty_str\\n"; - - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(AlertRequestTest, Run_InvalidAlert3_UNSUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - (*msg_)[am::strings::msg_params][am::strings::alert_text3] = - "invalid_text_with_empty_str\\n"; - - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(AlertRequestTest, Run_InvalidTTSChunk_UNSUCCESS) { - Expectations(); - AddAlertTextsToMsg(); - (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "invalid_text_with_empty_str\\n"; - - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -} // namespace alert_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/test/commands/mobile/change_registration_test.cc deleted file mode 100644 index 3f039c3915..0000000000 --- a/src/components/application_manager/test/commands/mobile/change_registration_test.cc +++ /dev/null @@ -1,567 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/change_registration_request.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/helpers.h" -#include "utils/make_shared.h" -#include "utils/custom_string.h" -#include "smart_objects/smart_object.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/smart_object_keys.h" -#include "policy/usage_statistics/mock_statistics_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace change_registration_request { - -namespace am = application_manager; -using am::commands::CommandImpl; -using am::ApplicationManager; -using am::commands::MessageSharedPtr; -using am::ApplicationSharedPtr; -using am::MockMessageHelper; -using ::testing::_; -using ::utils::SharedPtr; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::SetArgPointee; -using am::commands::ChangeRegistrationRequest; -using policy_test::MockPolicyHandlerInterface; -using ::test::components::application_manager_test::MockApplication; - -namespace custom_str = utils::custom_string; -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -} // namespace - -class ChangeRegistrationRequestTest - : public CommandRequestTest { - public: - ChangeRegistrationRequestTest() - : mock_app_(CreateMockApp()) - , supported_languages_(CreateMessage(smart_objects::SmartType_Array)) {} - - MessageSharedPtr CreateMsgFromMobile() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::hmi_display_language] = mobile_apis::Language::EN_US; - msg_params[strings::language] = mobile_apis::Language::EN_US; - (*msg)[strings::msg_params] = msg_params; - return msg; - } - void PrepareExpectationBeforeRun() { - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities_)); - (*supported_languages_)[0] = - static_cast(mobile_apis::Language::EN_US); - EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) - .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) - .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) - .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - } - - void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, - const mobile_apis::Result::eType mobile_response, - const am::HmiInterfaces::InterfaceState state, - const bool success, - const hmi_apis::Common_Result::eType ui_hmi_response = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - const hmi_apis::Common_Result::eType vr_hmi_response = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); - - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); - am::ApplicationSet application_set; - const utils::custom_string::CustomString name("name"); - MockAppPtr app = CreateMockApp(); - app->set_name(name); - - DataAccessor accessor(application_set, app_set_lock_); - - application_set.insert(app); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - PrepareExpectationBeforeRun(); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(state)); - command->Run(); - - MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); - CreateResponseFromHMI(ui_response, ui_hmi_response, "ui_info"); - CreateResponseFromHMI(vr_response, vr_hmi_response, "unsupported_resource"); - - (*tts_response)[strings::params][hmi_response::code] = hmi_response; - (*tts_response)[strings::msg_params] = 0; - - am::event_engine::Event event_ui( - hmi_apis::FunctionID::UI_ChangeRegistration); - event_ui.set_smart_object(*ui_response); - am::event_engine::Event event_vr( - hmi_apis::FunctionID::VR_ChangeRegistration); - event_vr.set_smart_object(*vr_response); - am::event_engine::Event event_tts( - hmi_apis::FunctionID::TTS_ChangeRegistration); - event_tts.set_smart_object(*tts_response); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - _, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_ui); - command->on_event(event_vr); - command->on_event(event_tts); - - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::success].asBool(), - success); - EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] - .asInt(), - static_cast(mobile_response)); - } - - void CreateResponseFromHMI(MessageSharedPtr msg, - hmi_apis::Common_Result::eType result, - const std::string& info) { - (*msg)[strings::params][hmi_response::code] = static_cast(result); - (*msg)[strings::msg_params][strings::info] = info; - } - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - } - - void ExpectationsHmiCapabilities( - smart_objects::SmartObjectSPtr supported_languages) { - EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages.get())); - EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages.get())); - EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages.get())); - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - typedef TypeIf, - application_manager_test::MockHMICapabilities>::Result - MockHMICapabilities; - sync_primitives::Lock app_set_lock_; - MockHMICapabilities hmi_capabilities_; - MockAppPtr mock_app_; - MessageSharedPtr supported_languages_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -typedef ChangeRegistrationRequestTest::MockHMICapabilities MockHMICapabilities; - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - - am::ApplicationSet application_set; - const utils::custom_string::CustomString name("name"); - MockAppPtr app = CreateMockApp(); - app->set_name(name); - - DataAccessor accessor(application_set, app_set_lock_); - - application_set.insert(app); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - - smart_objects::SmartObjectSPtr supported_languages( - CreateMessage(smart_objects::SmartType_Array)); - (*supported_languages)[0] = - static_cast(mobile_apis::Language::EN_US); - - ExpectationsHmiCapabilities(supported_languages); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); - - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - command->Run(); - - MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); - CreateResponseFromHMI( - ui_response, hmi_apis::Common_Result::WARNINGS, "ui_info"); - CreateResponseFromHMI(vr_response, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - "VR is not supported by system"); - CreateResponseFromHMI( - tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); - (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*tts_response)[am::strings::msg_params][am::strings::app_id] = - kConnectionKey; - am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); - event_ui.set_smart_object(*ui_response); - am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); - event_vr.set_smart_object(*vr_response); - am::event_engine::Event event_tts( - hmi_apis::FunctionID::TTS_ChangeRegistration); - event_tts.set_smart_object(*tts_response); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_ui); - command->on_event(event_tts); - command->on_event(event_vr); - - ResultCommandExpectations(response_to_mobile, - "ui_info, VR is not supported by system, tts_info"); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { - MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); - am::ApplicationSet application_set; - const utils::custom_string::CustomString name("name"); - MockAppPtr app = CreateMockApp(); - app->set_name(name); - DataAccessor accessor(application_set, app_set_lock_); - application_set.insert(app); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities_)); - (*supported_languages_)[0] = - static_cast(mobile_apis::Language::EN_US); - EXPECT_CALL(hmi_capabilities_, ui_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - EXPECT_CALL(hmi_capabilities_, vr_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - EXPECT_CALL(hmi_capabilities_, tts_supported_languages()) - .WillOnce(Return(supported_languages_.get())); - - EXPECT_CALL(app_mngr_, hmi_interfaces()) - .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - command->Run(); - - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::success].asBool(), - false); - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), - static_cast(mobile_apis::Result::UNSUPPORTED_RESOURCE)); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_false) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_NOT_RESPONSE, - false); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_false) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_AVAILABLE, - false); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_UNSUPPORTED_RESOURCE_SUCCESS_STATE_AVAILABLE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_AVAILABLE, - true, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::SUCCESS); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_SUCCESS_STATE_AVAILABLE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::SUCCESS, - mobile_apis::Result::SUCCESS, - am::HmiInterfaces::STATE_AVAILABLE, - true, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::SUCCESS); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_WRONG_LANGUAGE_STATE_AVAILABLE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::WRONG_LANGUAGE, - mobile_apis::Result::WRONG_LANGUAGE, - am::HmiInterfaces::STATE_AVAILABLE, - true, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::SUCCESS); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_TTS_INVALID_DATA_STATE_AVAILABLE_Expect_false) { - CheckExpectations(hmi_apis::Common_Result::INVALID_DATA, - mobile_apis::Result::INVALID_DATA, - am::HmiInterfaces::STATE_AVAILABLE, - false, - hmi_apis::Common_Result::SUCCESS, - hmi_apis::Common_Result::SUCCESS); -} - -TEST_F(ChangeRegistrationRequestTest, - OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); - - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - - am::ApplicationSet application_set; - const utils::custom_string::CustomString name("name"); - MockAppPtr app = CreateMockApp(); - app->set_name(name); - - DataAccessor accessor(application_set, app_set_lock_); - - application_set.insert(app); - - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); - - smart_objects::SmartObjectSPtr supported_languages( - CreateMessage(smart_objects::SmartType_Array)); - (*supported_languages)[0] = - static_cast(mobile_apis::Language::EN_US); - - ExpectationsHmiCapabilities(supported_languages); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - command->Run(); - - MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); - MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); - CreateResponseFromHMI(ui_response, - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - "unsupported_resource"); - CreateResponseFromHMI( - vr_response, hmi_apis::Common_Result::WARNINGS, "vr_info"); - CreateResponseFromHMI( - tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); - (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*tts_response)[am::strings::msg_params][am::strings::app_id] = - kConnectionKey; - am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); - event_ui.set_smart_object(*ui_response); - am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); - event_vr.set_smart_object(*vr_response); - am::event_engine::Event event_tts( - hmi_apis::FunctionID::TTS_ChangeRegistration); - event_tts.set_smart_object(*tts_response); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_vr); - command->on_event(event_tts); - command->on_event(event_ui); - - ResultCommandExpectations(response_to_mobile, - "unsupported_resource, vr_info, tts_info"); -} - -} // namespace change_registration_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc deleted file mode 100644 index e5d2f4a522..0000000000 --- a/src/components/application_manager/test/commands/mobile/create_interaction_choice_set_test.cc +++ /dev/null @@ -1,843 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/create_interaction_choice_set_request.h" -#include "application_manager/commands/mobile/create_interaction_choice_set_response.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/helpers.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "utils/custom_string.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace create_interaction_choice_set_request { - -namespace am = application_manager; -using am::commands::CommandImpl; -using am::ApplicationManager; -using am::commands::MessageSharedPtr; -using am::ApplicationSharedPtr; -using am::MockMessageHelper; -using ::testing::_; -using ::utils::SharedPtr; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::AtLeast; -using am::commands::CreateInteractionChoiceSetRequest; -using am::commands::CreateInteractionChoiceSetResponse; -using ::test::components::application_manager_test::MockApplication; - -namespace custom_str = utils::custom_string; -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -typedef SharedPtr - CreateInteractionChoiceSetRequestPtr; -typedef SharedPtr - CreateInteractionChoiceSetResponsePtr; - -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -namespace { -const hmi_apis::FunctionID::eType kInvalidFunctionId = - hmi_apis::FunctionID::INVALID_ENUM; -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 10u; -const uint32_t kGrammarId = 10u; -const int32_t kMenuId = 5; -const uint32_t kChoiceSetId = 1u; -const uint32_t kChoiceId1 = 2u; -const uint32_t kChoiceId2 = 3u; -const std::string kImage = "image"; -const std::string kSecondImage = "second_image"; -const std::string kVrCommands1 = "vr_commands_1"; -const std::string kVrCommands2 = "vr_commands_2"; -const std::string kMenuName = "menu_name"; - -} // namespace - -class CreateInteractionChoiceSetRequestTest - : public CommandRequestTest { - public: - CreateInteractionChoiceSetRequestTest() - : message_(CreateMessage()) - , command_(CreateCommand(message_)) - , mock_app_(CreateMockApp()) {} - - MessageSharedPtr CreateFullParamsVRSO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[strings::cmd_id] = kCmdId; - msg_params[strings::vr_commands] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - msg_params[strings::vr_commands][0] = "lamer"; - msg_params[strings::type] = 34; - msg_params[strings::grammar_id] = 12; - msg_params[strings::app_id] = kAppId; - (*msg)[strings::msg_params] = msg_params; - - return msg; - } - - void FillMessageFieldsItem1(MessageSharedPtr message) { - (*message)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::menu_name] = kMenuName; - (*message)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image][am::strings::value] = kImage; - (*message)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::choice_id] = kChoiceId1; - (*message)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::vr_commands][0] = kVrCommands1; - (*message)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image][am::strings::value] = kSecondImage; - } - void FillMessageFieldsItem2(MessageSharedPtr message) { - (*message)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::choice_id] = kChoiceId2; - (*message)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::menu_name] = kMenuName; - (*message)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::vr_commands][0] = kVrCommands2; - (*message)[am::strings::msg_params] - [am::strings::interaction_choice_set_id] = kChoiceSetId; - } - - MessageSharedPtr message_; - CreateInteractionChoiceSetRequestPtr command_; - MockAppPtr mock_app_; - sync_primitives::Lock lock_; -}; - -class CreateInteractionChoiceSetResponseTest - : public CommandsTest {}; - -TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeout_GENERIC_ERROR) { - MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); - (*msg_vr)[strings::msg_params][strings::result_code] = - am::mobile_api::Result::GENERIC_ERROR; - (*msg_vr)[strings::msg_params][strings::success] = false; - - utils::SharedPtr req_vr = - CreateCommand(); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(*mock_app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(*mock_app, RemoveCommand(_)).WillByDefault(Return()); - - MessageSharedPtr vr_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - req_vr->onTimeOut(); - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), - false); - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast(am::mobile_api::Result::GENERIC_ERROR)); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateFullParamsVRSO(); - (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = - 10; - (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = - "menu_name"; - (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; - utils::SharedPtr req_vr = - CreateCommand(msg_vr); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - smart_objects::SmartObject* null_obj = NULL; - ON_CALL(*mock_app_, FindChoiceSet(_)).WillByDefault(Return(null_obj)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[strings::msg_params][strings::info] = "VR is not supported by system"; - (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; - - am::event_engine::Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*msg); - - smart_objects::SmartObject* ptr = NULL; - ON_CALL(*mock_app_, FindCommand(kCmdId)).WillByDefault(Return(ptr)); - EXPECT_EQ(NULL, ptr); - - am::CommandsMap commands_map; - ON_CALL(*mock_app_, commands_map()) - .WillByDefault( - Return(DataAccessor(commands_map, lock_))); - - ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) - .WillByDefault( - Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - req_vr->Run(); - - MessageSharedPtr vr_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - req_vr->on_event(event); - - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), - false); - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::info].asString(), - (*msg)[strings::msg_params][strings::info].asString()); - } -} - -TEST_F(CreateInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, Run_VerifyImageFail_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image] = kImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image] = kSecondImage; - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::INVALID_DATA)); - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image] = kImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image] = kSecondImage; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* invalid_choice_set_id = - &((*message_)[am::strings::msg_params] - [am::strings::interaction_choice_set_id]); - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(invalid_choice_set_id)); - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - Run_CheckChoiceSet_InvalidChoiceId_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::menu_name] = kMenuName; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image][am::strings::value] = kImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::choice_id] = kChoiceId1; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image][am::strings::value] = kSecondImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::vr_commands][0] = kVrCommands1; - - FillMessageFieldsItem2(message_); - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::vr_commands][0] = kVrCommands1; - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::vr_commands][1] = " kVrCommands2\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::vr_commands][0] = kVrCommands1; - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - Run_IsWhiteSpaceVRCommandsExist_InvalidMenuName_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::menu_name] = "menu_name\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_text] = "secondary_text\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::tertiary_text] = "tertiary_text\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image][am::strings::value] = "image\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::choice_id] = kChoiceId1; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image][am::strings::value] = - "second_image\t"; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::vr_commands][0] = "vr_commands_1\t"; - - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillRepeatedly(Return(choice_set_id)); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::menu_name)) { - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::secondary_text)) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::menu_name] = kMenuName; - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::tertiary_text)) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_text] = "secondary_text"; - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::vr_commands)) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::tertiary_text] = "tertiary_text"; - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::image)) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::vr_commands][0] = "vr_commands"; - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } - if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] - .keyExists(am::strings::secondary_image)) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image][am::strings::value] = kImage; - CreateInteractionChoiceSetRequestPtr command( - CreateCommand(message_)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); - command->Run(); - } -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - Run_ValidAmountVrCommands_SUCCESS) { - FillMessageFieldsItem1(message_); - FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .Times(AtLeast(2)) - .WillOnce(Return(kConnectionKey)) - .WillOnce(Return(kConnectionKey)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - Run_EmptyAmountVrCommands_SUCCESS) { - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::menu_name] = kMenuName; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::image][am::strings::value] = kImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::choice_id] = kChoiceId1; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::secondary_image][am::strings::value] = kSecondImage; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::vr_commands][0] = kVrCommands1; - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::choice_id] = kChoiceId2; - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::menu_name] = kMenuName; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - (*message_)[am::strings::msg_params][am::strings::choice_set][1] - [am::strings::vr_commands][0] = kVrCommands2; - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - command_->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnEvent_InvalidEventId_UNSUCCESS) { - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); - command_->on_event(event); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnEvent_InvalidVrCommand_UNSUCCESS) { - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::WARNINGS; - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*message_); - - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); - command_->on_event(event); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { - Event event(hmi_apis::FunctionID::VR_AddCommand); - - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::WARNINGS; - - FillMessageFieldsItem1(message_); - FillMessageFieldsItem2(message_); - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - command_->Run(); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); - event.set_smart_object(*message_); - - command_->on_event(event); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnEvent_InValidVrNoError_UNSUCCESS) { - Event event(hmi_apis::FunctionID::VR_AddCommand); - - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::INVALID_DATA; - - FillMessageFieldsItem1(message_); - FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - command_->Run(); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); - event.set_smart_object(*message_); - - command_->on_event(event); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnEvent_ValidVrNoErrorAndExpectedChoiceLessThanReceiveChoice_SUCCESS) { - Event event(hmi_apis::FunctionID::VR_AddCommand); - - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::WARNINGS; - - FillMessageFieldsItem1(message_); - - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(3) - .WillRepeatedly(ReturnRef(rpc_service_)); - command_->Run(); - - FillMessageFieldsItem2(message_); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - event.set_smart_object(*message_); - command_->on_event(event); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnTimeOut_InvalidErrorFromHMI_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), - am::commands::Command::SOURCE_SDL)); - - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - command_->onTimeOut(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnTimeOut_ValidErrorFromHMI_SUCCESS) { - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::INVALID_ENUM; - - FillMessageFieldsItem1(message_); - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(3) - .WillRepeatedly(ReturnRef(rpc_service_)); - command_->Run(); - - FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*message_); - command_->on_event(event); - - EXPECT_CALL(*mock_app_, RemoveChoiceSet(kChoiceSetId)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - command_->onTimeOut(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::INVALID_ENUM; - - FillMessageFieldsItem1(message_); - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(3) - .WillRepeatedly(ReturnRef(rpc_service_)); - command_->Run(); - - FillMessageFieldsItem2(message_); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(2); - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*message_); - command_->on_event(event); - - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(invalid_app)); - EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)).Times(0); - command_->onTimeOut(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, - OnTimeOut_SuccessfulResponseReceived_UNSUCCESS) { - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - - FillMessageFieldsItem1(message_); - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObject* choice_set_id = NULL; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); - - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(6) - .WillRepeatedly(ReturnRef(rpc_service_)); - command_->Run(); - - FillMessageFieldsItem2(message_); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - - Event event(hmi_apis::FunctionID::VR_AddCommand); - event.set_smart_object(*message_); - - command_->on_event(event); - - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)); - - command_->onTimeOut(); -} - -TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { - MessageSharedPtr message(CreateMessage()); - (*message)[am::strings::msg_params][am::strings::success] = false; - (*message)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::INVALID_ENUM; - CreateInteractionChoiceSetResponsePtr command( - CreateCommand(message)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(message, false)); - command->Run(); -} - -TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessTrue_SUCCESS) { - MessageSharedPtr message(CreateMessage()); - (*message)[am::strings::msg_params][am::strings::success] = true; - (*message)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::SUCCESS; - CreateInteractionChoiceSetResponsePtr command( - CreateCommand(message)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(message, false)); - command->Run(); -} - -TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { - Event event(hmi_apis::FunctionID::VR_AddCommand); - - (*message_)[am::strings::params][am::strings::correlation_id] = - kCorrelationId; - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::GENERIC_ERROR; - - FillMessageFieldsItem1(message_); - - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) - .WillRepeatedly(Return(choice_set_id)); - - EXPECT_CALL(app_mngr_, GenerateGrammarID()) - .WillRepeatedly(Return(kGrammarId)); - EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(2); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(3) - .WillRepeatedly(ReturnRef(rpc_service_)); - command_->Run(); - - FillMessageFieldsItem2(message_); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), - am::commands::Command::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); - event.set_smart_object(*message_); - command_->on_event(event); - command_->Run(); -} - -} // namespace create_interaction_choice_set_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc b/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc deleted file mode 100644 index f2ea90d10d..0000000000 --- a/src/components/application_manager/test/commands/mobile/delete_command_request_test.cc +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/delete_command_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/test/include/application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace delete_command_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::DeleteCommandRequest; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using am::MockMessageHelper; -using am::MockHmiInterfaces; - -typedef SharedPtr DeleteCommandPtr; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -} // namespace - -class DeleteCommandRequestTest - : public CommandRequestTest { - public: - DeleteCommandRequestTest() : mock_app_(CreateMockApp()) {} - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - MessageSharedPtr CreateFullParamsVRSO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::vr_commands] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - msg_params[am::strings::vr_commands][0] = "lamer"; - msg_params[am::strings::type] = 34; - msg_params[am::strings::grammar_id] = 12; - msg_params[am::strings::app_id] = kAppId; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(app_mngr_, hmi_interfaces()) - .WillByDefault(ReturnRef(hmi_interfaces_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - } - - NiceMock hmi_interfaces_; - MockAppPtr mock_app_; -}; - -TEST_F(DeleteCommandRequestTest, - OnEvent_VrHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr command_msg = CreateFullParamsVRSO(); - (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DeleteCommandPtr command(CreateCommand(command_msg)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - - MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); - (*test_msg)[am::strings::vr_commands] = 0; - (*test_msg)[am::strings::menu_params] = 0; - - ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - ON_CALL(hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(*mock_app_, FindCommand(kCommandId)) - .WillByDefault(Return(test_msg.get())); - ON_CALL(*mock_app_, get_grammar_id()).WillByDefault(Return(kConnectionKey)); - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); - event_ui.set_smart_object(*msg); - command->Init(); - command->Run(); - command->on_event(event_ui); - - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*event_msg)[am::strings::msg_params][am::strings::info] = - "VR is not supported by system"; - Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); - event_vr.set_smart_object(*event_msg); - - EXPECT_CALL(*mock_app_, RemoveCommand(kCommandId)); - - EXPECT_CALL(*mock_app_, UpdateHash()); - - MessageSharedPtr vr_command_result; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - command->on_event(event_vr); - - ResultCommandExpectations(vr_command_result, "VR is not supported by system"); -} - -TEST_F(DeleteCommandRequestTest, - OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr command_msg = CreateFullParamsUISO(); - (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DeleteCommandPtr command(CreateCommand(command_msg)); - - MockAppPtr app = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); - (*test_msg)[am::strings::vr_commands] = 0; - (*test_msg)[am::strings::menu_params] = 0; - - ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(*app, FindCommand(kCommandId)).WillByDefault(Return(test_msg.get())); - ON_CALL(*app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); - event_vr.set_smart_object(*msg); - - command->Init(); - command->Run(); - command->on_event(event_vr); - - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*event_msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); - event_ui.set_smart_object(*event_msg); - - EXPECT_CALL(*app, RemoveCommand(kCommandId)); - - EXPECT_CALL(*app, UpdateHash()); - - MessageSharedPtr result_msg( - CatchMobileCommandResult(CallOnEvent(*command, event_ui))); - - ASSERT_TRUE(result_msg); - - ResultCommandExpectations(result_msg, "UI is not supported by system"); -} - -} // namespace delete_command_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/delete_file_test.cc b/src/components/application_manager/test/commands/mobile/delete_file_test.cc deleted file mode 100644 index 850d62a461..0000000000 --- a/src/components/application_manager/test/commands/mobile/delete_file_test.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* - * Copyright (c) 2016, 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 - -#include "mobile/delete_file_request.h" -#include "mobile/delete_file_response.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/file_system.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/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_application_manager_settings.h" - -#include "interfaces/MOBILE_API.h" -#include "application_manager/policies/policy_handler_interface.h" -#include "application_manager/policies/policy_handler.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace delete_file { - -using ::testing::_; -using ::testing::Test; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::SetArgReferee; -using ::testing::AtLeast; -namespace am = ::application_manager; -using am::commands::DeleteFileRequest; -using am::commands::DeleteFileResponse; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using am::MockMessageHelper; - -typedef SharedPtr DeleteFileRequestPtr; -typedef SharedPtr DeleteFileResponsePtr; -typedef NiceMock< - ::test::components::application_manager_test::MockHMICapabilities> - MockHMICapabilities; - -ACTION_TEMPLATE(SetArgPointer, - HAS_1_TEMPLATE_PARAMS(int, k), - AND_1_VALUE_PARAMS(vec)) { - *std::tr1::get(args) = *vec; -} - -MATCHER_P(CheckMessageResultCode, result_code, "") { - return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == - result_code; -} - -namespace { -const uint32_t kConnectionKey = 1u; -const uint32_t kCorrelationId = 10u; -const int32_t kMenuId = 5; -} // namespace - -class DeleteFileRequestTest - : public CommandRequestTest { - protected: - void SetUp() OVERRIDE { - message_ = CreateMessage(); - command_ = CreateCommand(message_); - mock_app_ = CreateMockApp(); - } - DeleteFileRequestPtr command_; - MessageSharedPtr message_; - MockAppPtr mock_app_; -}; - -class DeleteFileResponseTest : public CommandsTest { -}; - -TEST_F(DeleteFileRequestTest, Run_InvalidApp_UNSUCCESS) { - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(app_mngr_, get_settings()).Times(0); - - command_->Run(); -} - -TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - const uint32_t num = 0; - EXPECT_CALL(app_mngr_settings_, delete_file_in_none()) - .WillOnce(ReturnRef(num)); - EXPECT_CALL(*mock_app_, delete_file_in_none_count()).WillOnce(Return(1)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::REJECTED), - am::commands::Command::CommandSource::SOURCE_SDL)); - - command_->Run(); -} - -TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) { - const std::string file_name = "test_file.txt"; - EXPECT_TRUE(file_system::CreateFile(file_name)); - (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); - EXPECT_CALL(app_mngr_settings_, app_storage_folder()) - .WillOnce(ReturnRef(kFullFilePath)); - - am::AppFile file; - file.file_name = file_name; - file.file_type = mobile_apis::FileType::BINARY; - - EXPECT_CALL(*mock_app_, GetFile(_)).WillOnce(Return(&file)); - EXPECT_CALL(*mock_app_, DeleteFile(_)); - EXPECT_CALL(*mock_app_, increment_delete_file_in_none_count()); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::SUCCESS), - am::commands::Command::CommandSource::SOURCE_SDL)); - - command_->Run(); -} - -TEST_F(DeleteFileRequestTest, Run_InvalidFile_UNSUCCESS) { - const std::string file_name = "test_file.txt"; - (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; - - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); - EXPECT_CALL(app_mngr_settings_, app_storage_folder()) - .WillOnce(ReturnRef(kFullFilePath)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::REJECTED), - am::commands::Command::CommandSource::SOURCE_SDL)); - command_->Run(); -} - -TEST_F(DeleteFileResponseTest, Run_InvalidApp_UNSUCCESS) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; - DeleteFileResponsePtr command = CreateCommand(message); - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(invalid_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - SendMessageToMobile(CheckMessageResultCode( - mobile_apis::Result::APPLICATION_NOT_REGISTERED), - false)); - - command->Run(); -} - -TEST_F(DeleteFileResponseTest, Run_ValidApp_SUCCESS) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*message)[am::strings::msg_params][am::strings::success] = true; - - DeleteFileResponsePtr command = CreateCommand(message); - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - const uint32_t kAvailableDiskSpace = 10u; - EXPECT_CALL(*app, GetAvailableDiskSpace()) - .WillOnce(Return(kAvailableDiskSpace)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - SendMessageToMobile( - CheckMessageResultCode(mobile_apis::Result::SUCCESS), _)); - - command->Run(); -} - -} // namespace delete_file -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc b/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc deleted file mode 100644 index 17785dc729..0000000000 --- a/src/components/application_manager/test/commands/mobile/delete_interaction_choice_set_test.cc +++ /dev/null @@ -1,296 +0,0 @@ -/* - * Copyright (c) 2016, 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 "mobile/delete_interaction_choice_set_request.h" -#include "mobile/delete_interaction_choice_set_response.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/commands_test.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace delete_interaction_choice_set { - -using ::testing::_; -using ::testing::Return; -using ::testing::InSequence; - -namespace am = ::application_manager; - -using am::commands::DeleteInteractionChoiceSetRequest; -using am::commands::DeleteInteractionChoiceSetResponse; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; - -typedef SharedPtr - DeleteInteractionChoiceSetRequestPtr; -typedef SharedPtr - DeleteInteractionChoiceSetResponsePtr; - -MATCHER_P(CheckMessageSuccess, success, "") { - return success == - (*arg)[am::strings::msg_params][am::strings::success].asBool(); -} - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kChoiceSetId = 11u; -const uint32_t kChoiceId = 110u; -const uint32_t kGrammarId = 101u; -} // namespace - -class DeleteInteractionChoiceSetRequestTest - : public CommandRequestTest { - public: - DeleteInteractionChoiceSetRequestTest() - : accessor_(choice_set_map_, performinteraction_choice_set_lock_) {} - - ~DeleteInteractionChoiceSetRequestTest() { - // Fix DataAccessor release and WinQt crash - Mock::VerifyAndClearExpectations(&app_mngr_); - } - - am::PerformChoiceSetMap choice_set_map_; - mutable sync_primitives::Lock performinteraction_choice_set_lock_; - DataAccessor accessor_; - - protected: - void SetUp() OVERRIDE { - message_ = CreateMessage(); - command_ = CreateCommand(message_); - app_ = CreateMockApp(); - } - - DeleteInteractionChoiceSetRequestPtr command_; - MessageSharedPtr message_; - MockAppPtr app_; -}; - -class DeleteInteractionChoiceSetResponseTest - : public CommandsTest { - protected: - void SetUp() OVERRIDE { - message_ = CreateMessage(); - command_ = CreateCommand(message_); - app_ = CreateMockApp(); - } - DeleteInteractionChoiceSetResponsePtr command_; - MessageSharedPtr message_; - MockAppPtr app_; -}; - -TEST_F(DeleteInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_, FindChoiceSet(_)).Times(0); - command_->Run(); -} - -TEST_F(DeleteInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); - - smart_objects::SmartObject* choice_set_id = NULL; - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); - - command_->Run(); -} - -TEST_F(DeleteInteractionChoiceSetRequestTest, Run_ChoiceSetInUse_SUCCESS) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); - - smart_objects::SmartObject* choice_set_id = - &((*message_)[am::strings::msg_params] - [am::strings::interaction_choice_set_id]); - - choice_set_map_[0].insert( - std::make_pair(kChoiceSetId, - &((*message_)[am::strings::msg_params] - [am::strings::interaction_choice_set_id]))); - - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(true)); - EXPECT_CALL(*app_, performinteraction_choice_set_map()) - .WillOnce(Return(accessor_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); - - command_->Run(); -} - -TEST_F(DeleteInteractionChoiceSetRequestTest, - Run_SendVrDeleteCommand_PerformInteractionFalse_UNSUCCESS) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - smart_objects::SmartObject* choice_set_id = - &((*message_)[am::strings::msg_params] - [am::strings::interaction_choice_set_id]); - smart_objects::SmartObject* invalid_choice_set_id = NULL; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(app_)); - - { - InSequence seq; - - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); - EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); - - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(invalid_choice_set_id)); - - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); - EXPECT_CALL(*app_, UpdateHash()); - } - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - - DeleteInteractionChoiceSetRequestPtr command = - CreateCommand(message_); - - command->Init(); - command->Run(); -} - -TEST_F(DeleteInteractionChoiceSetRequestTest, Run_SendVrDeleteCommand_SUCCESS) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = - kChoiceSetId; - (*message_)[am::strings::msg_params][am::strings::grammar_id] = kGrammarId; - (*message_)[am::strings::msg_params][am::strings::choice_set][0] - [am::strings::choice_id] = kChoiceId; - smart_objects::SmartObject* choice_set_id = - &((*message_)[am::strings::msg_params]); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(app_)); - - { - InSequence seq; - - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); - EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); - - EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) - .WillOnce(Return(choice_set_id)); - - EXPECT_CALL(*app_, app_id()) - .WillOnce(Return(kConnectionKey)) - .WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); - EXPECT_CALL(*app_, UpdateHash()); - } - EXPECT_CALL(app_mngr_, GetRPCService()) - .Times(2) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - DeleteInteractionChoiceSetRequestPtr command = - CreateCommand(message_); - - command->Init(); - command->Run(); -} - -TEST_F(DeleteInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::success] = false; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - SendMessageToMobile(CheckMessageSuccess(false), false)); - command_->Run(); -} - -TEST_F(DeleteInteractionChoiceSetResponseTest, Run_ValidResultCode_SUCCESS) { - (*message_)[am::strings::msg_params][am::strings::result_code] = - hmi_apis::Common_Result::SUCCESS; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - SendMessageToMobile(CheckMessageSuccess(true), false)); - command_->Run(); -} - -TEST_F(DeleteInteractionChoiceSetResponseTest, - Run_InvalidResultCode_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::result_code] = - hmi_apis::Common_Result::INVALID_ENUM; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - SendMessageToMobile(CheckMessageSuccess(false), false)); - command_->Run(); -} - -} // namespace delete_interaction_choice_set -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc b/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc deleted file mode 100644 index 508a4ba856..0000000000 --- a/src/components/application_manager/test/commands/mobile/delete_sub_menu_test.cc +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/delete_sub_menu_request.h" -#include "application_manager/commands/mobile/delete_sub_menu_response.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace delete_sub_menu_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::InSequence; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using am::MockHmiInterfaces; -using am::MockMessageHelper; - -using am::commands::DeleteSubMenuRequest; -using am::commands::DeleteSubMenuResponse; - -typedef SharedPtr DeleteSubMenuRequestPtr; -typedef SharedPtr DeleteSubMenuResponsePtr; - -MATCHER_P(CheckMessageResultCode, result_code, "") { - return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == - result_code; -} - -MATCHER_P(CheckMessageConnectionKey, connection_key, "") { - return (*arg)[am::strings::msg_params][am::strings::connection_key].asInt() == - connection_key; -} - -ACTION_P(DeleteCommand, commands_map) { - am::CommandsMap::iterator it = (*commands_map).begin(); - if ((*commands_map).end() != it) { - (*commands_map).erase(it); - } -} - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 10u; -const uint32_t kMenuId = 100u; -const uint32_t kGrammarId = 101u; -const int32_t kCmdId = 102; -} // namespace - -class DeleteSubMenuRequestTest - : public CommandRequestTest { - public: - DeleteSubMenuRequestTest() - : accessor_(commands_map_, commands_lock_) - , message_(CreateMessage()) - , command_(CreateCommand(message_)) - , app_(CreateMockApp()) {} - - am::CommandsMap commands_map_; - mutable sync_primitives::Lock commands_lock_; - DataAccessor accessor_; - - MessageSharedPtr message_; - DeleteSubMenuRequestPtr command_; - MockAppPtr app_; -}; - -class DeleteSubMenuResponseTest - : public CommandsTest {}; - -TEST_F(DeleteSubMenuRequestTest, DISABLED_OnEvent_UI_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::menu_id] = 10u; - - utils::SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - EXPECT_CALL(*mock_app, RemoveSubMenu(_)); - - MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); - (*ev_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; - - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - event.set_smart_object(*ev_msg); - - MockHmiInterfaces hmi_interfaces; - ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); - EXPECT_CALL(hmi_interfaces, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - am::CommandsMap commands_map; - smart_objects::SmartObject commands_msg(smart_objects::SmartType_Map); - commands_map.insert(std::pair(1u, &commands_msg)); - sync_primitives::Lock lock; - DataAccessor accessor(commands_map, lock); - EXPECT_CALL(*mock_app, commands_map()) - .WillOnce(Return(accessor)) - .WillOnce(Return(accessor)); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -TEST_F(DeleteSubMenuRequestTest, Run_InvalidApp_UNSUCCESS) { - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(CheckMessageResultCode( - mobile_apis::Result::APPLICATION_NOT_REGISTERED), - am::commands::Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_, FindSubMenu(_)).Times(0); - command_->Run(); -} - -TEST_F(DeleteSubMenuRequestTest, Run_FindSubMenuFalse_UNSUCCESS) { - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - smart_objects::SmartObject* invalid_sub_menu = NULL; - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); - EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(invalid_sub_menu)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - CheckMessageResultCode(mobile_apis::Result::INVALID_ID), - am::commands::Command::CommandSource::SOURCE_SDL)); - EXPECT_CALL(*app_, app_id()).Times(0); - command_->Run(); -} - -TEST_F(DeleteSubMenuRequestTest, Run_SendHMIRequest_SUCCESS) { - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - smart_objects::SmartObject* sub_menu = - &((*message_)[am::strings::msg_params][am::strings::menu_id]); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); - EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(sub_menu)); - - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteSubMenu))) - .WillOnce(Return(true)); - command_->Run(); -} - -TEST_F(DeleteSubMenuRequestTest, OnEvent_UnknownEventId_UNSUCCESS) { - Event event(hmi_apis::FunctionID::INVALID_ENUM); - EXPECT_CALL(app_mngr_, application(_)).Times(0); - command_->on_event(event); -} - -TEST_F(DeleteSubMenuRequestTest, OnEvent_InvalidApp_UNSUCCESS) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - event.set_smart_object(*message_); - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - EXPECT_CALL(*app_, RemoveSubMenu(_)).Times(0); - command_->on_event(event); -} - -TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenu_SUCCESS) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::msg_params][am::strings::vr_commands] = - "vr_commands"; - (*message_)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - (*message_)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = kMenuId; - const hmi_apis::Common_Result::eType result_code = - hmi_apis::Common_Result::SUCCESS; - (*message_)[am::strings::params][am::hmi_response::code] = result_code; - event.set_smart_object(*message_); - - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - - InSequence seq; - EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, get_grammar_id()).WillOnce(Return(kGrammarId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) - .WillOnce(Return(true)); - - EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); - EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(*app_, RemoveCommand(_)).WillOnce(DeleteCommand(&commands_map_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) - .WillOnce(Return(true)); - - EXPECT_CALL(*app_, RemoveSubMenu(_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - EXPECT_CALL(*app_, UpdateHash()); - DeleteSubMenuRequestPtr command = - CreateCommand(message_); - - command->Init(); - command->on_event(event); -} - -TEST_F(DeleteSubMenuResponseTest, Run_SUCCESS) { - MessageSharedPtr message(CreateMessage()); - (*message)[am::strings::msg_params][am::strings::connection_key] = - kConnectionKey; - DeleteSubMenuResponsePtr command( - CreateCommand(message)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - SendMessageToMobile(CheckMessageConnectionKey(kConnectionKey), _)); - command->Run(); -} - -TEST_F(DeleteSubMenuRequestTest, - DeleteSubmenu_CommandhaventVrCommadsAndMenuParams_DontSendHMIRequest) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - am::mobile_api::Result::SUCCESS; - event.set_smart_object(*message_); - - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); - EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - command_->on_event(event); -} - -TEST_F(DeleteSubMenuRequestTest, - DeleteSubmenu_NotAChildOfMenupartam_DontSendHMIRequest) { - Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); - (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; - (*message_)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = kMenuId + 1; - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*message_)[am::strings::params][am::hmi_response::code] = - am::mobile_api::Result::SUCCESS; - event.set_smart_object(*message_); - - commands_map_.insert( - std::make_pair(0, &((*message_)[am::strings::msg_params]))); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); - EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - command_->on_event(event); -} - -} // namespace delete_sub_menu_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc b/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc deleted file mode 100644 index 85aab0e311..0000000000 --- a/src/components/application_manager/test/commands/mobile/diagnostic_message_request_test.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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 "application_manager/mock_message_helper.h" -#include "application_manager/commands/mobile/diagnostic_message_request.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace diagnostic_message_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::DiagnosticMessageRequest; -using am::event_engine::Event; -namespace mobile_result = mobile_apis::Result; - -typedef SharedPtr DiagnosticMessageRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kDiagnosticMode = 5u; -} // namespace - -class DiagnosticMessageRequestTest - : public CommandRequestTest {}; - -TEST_F(DiagnosticMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DiagnosticMessageRequestPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(DiagnosticMessageRequestTest, Run_NotSupportedDiagnosticMode_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::message_data][0] = - kDiagnosticMode; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DiagnosticMessageRequestPtr command( - CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - - const std::vector empty_supported_diag_modes; - EXPECT_CALL(app_mngr_settings_, supported_diag_modes()) - .WillOnce(ReturnRef(empty_supported_diag_modes)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::REJECTED), _)); - - command->Run(); -} - -TEST_F(DiagnosticMessageRequestTest, Run_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::message_data][0] = - kDiagnosticMode; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DiagnosticMessageRequestPtr command( - CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - - std::vector supported_diag_modes; - supported_diag_modes.push_back(kDiagnosticMode); - - EXPECT_CALL(app_mngr_settings_, supported_diag_modes()) - .WillOnce(ReturnRef(supported_diag_modes)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage))); - - command->Run(); -} - -TEST_F(DiagnosticMessageRequestTest, OnEvent_UNSUCCESS) { - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - DiagnosticMessageRequestPtr command( - CreateCommand()); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->on_event(event); -} - -TEST_F(DiagnosticMessageRequestTest, OnEvent_SUCCESS) { - Event event(hmi_apis::FunctionID::VehicleInfo_DiagnosticMessage); - - MessageSharedPtr event_message(CreateMessage(smart_objects::SmartType_Map)); - (*event_message)[am::strings::msg_params] = 0; - (*event_message)[am::strings::params][am::hmi_response::code] = - mobile_result::SUCCESS; - event.set_smart_object(*event_message); - - DiagnosticMessageRequestPtr command( - CreateCommand()); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - command->on_event(event); -} - -} // namespace diagnostic_message_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/dial_number_request_test.cc b/src/components/application_manager/test/commands/mobile/dial_number_request_test.cc deleted file mode 100644 index ed0fadda78..0000000000 --- a/src/components/application_manager/test/commands/mobile/dial_number_request_test.cc +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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 "application_manager/commands/mobile/dial_number_request.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace dial_number_request { - -using ::testing::_; -using ::testing::Return; -namespace am = ::application_manager; -using am::commands::MessageSharedPtr; -using am::commands::DialNumberRequest; -using am::event_engine::Event; -namespace mobile_result = mobile_apis::Result; - -typedef SharedPtr DialNumberRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -} // namespace - -class DialNumberRequestTest - : public CommandRequestTest {}; - -TEST_F(DialNumberRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - DialNumberRequestPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(DialNumberRequestTest, Run_InvalidNumber_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::number] = "\t\n"; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DialNumberRequestPtr command(CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(DialNumberRequestTest, Run_EmptyNumber_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::number] = "NotANumber"; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DialNumberRequestPtr command(CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(DialNumberRequestTest, Run_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DialNumberRequestPtr command(CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::BasicCommunication_DialNumber))); - - command->Run(); -} - -TEST_F(DialNumberRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DialNumberRequestPtr command(CreateCommand(command_msg)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->on_event(event); -} - -TEST_F(DialNumberRequestTest, OnEvent_SUCCESS) { - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = - mobile_apis::Result::SUCCESS; - (*event_msg)[am::strings::params][am::strings::info] = "test_info"; - - Event event(hmi_apis::FunctionID::BasicCommunication_DialNumber); - event.set_smart_object(*event_msg); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - DialNumberRequestPtr command(CreateCommand(command_msg)); - command->on_event(event); -} - -} // namespace dial_number_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/dummy_mobile_commands_test.cc b/src/components/application_manager/test/commands/mobile/dummy_mobile_commands_test.cc deleted file mode 100644 index 27a8499c09..0000000000 --- a/src/components/application_manager/test/commands/mobile/dummy_mobile_commands_test.cc +++ /dev/null @@ -1,342 +0,0 @@ -/* - * Copyright (c) 2016, 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 "commands/command_request_test.h" - -#include -#include -#include -#include "gtest/gtest.h" - -#include "mobile/add_command_request.h" -#include "mobile/add_command_response.h" -#include "mobile/add_sub_menu_request.h" -#include "mobile/add_sub_menu_response.h" -#include "mobile/alert_maneuver_request.h" -#include "mobile/alert_maneuver_response.h" -#include "mobile/alert_request.h" -#include "mobile/alert_response.h" -#include "mobile/change_registration_request.h" -#include "mobile/change_registration_response.h" -#include "mobile/create_interaction_choice_set_request.h" -#include "mobile/create_interaction_choice_set_response.h" -#include "mobile/delete_command_request.h" -#include "mobile/delete_command_response.h" -#include "mobile/delete_file_request.h" -#include "mobile/delete_file_response.h" -#include "mobile/delete_interaction_choice_set_request.h" -#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" -#include "mobile/list_files_response.h" -#include "mobile/on_app_interface_unregistered_notification.h" -#include "mobile/on_audio_pass_thru_notification.h" -#include "mobile/on_button_event_notification.h" -#include "mobile/on_button_press_notification.h" -#include "mobile/on_command_notification.h" -#include "mobile/on_driver_distraction_notification.h" -#include "mobile/on_hash_change_notification.h" -#include "mobile/on_hmi_status_notification.h" -#include "mobile/on_hmi_status_notification_from_mobile.h" -#include "mobile/on_keyboard_input_notification.h" -#include "mobile/on_language_change_notification.h" -#include "mobile/on_permissions_change_notification.h" -#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" -#include "mobile/perform_interaction_request.h" -#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" -#include "mobile/reset_global_properties_response.h" -#include "mobile/scrollable_message_request.h" -#include "mobile/scrollable_message_response.h" -#include "mobile/send_location_request.h" -#include "mobile/send_location_response.h" -#include "mobile/set_app_icon_request.h" -#include "mobile/set_app_icon_response.h" -#include "mobile/set_display_layout_request.h" -#include "mobile/set_display_layout_response.h" -#include "mobile/set_global_properties_request.h" -#include "mobile/set_global_properties_response.h" -#include "mobile/set_media_clock_timer_request.h" -#include "mobile/set_media_clock_timer_response.h" -#include "mobile/show_constant_tbt_request.h" -#include "mobile/show_constant_tbt_response.h" -#include "mobile/show_request.h" -#include "mobile/show_response.h" -#include "mobile/slider_request.h" -#include "mobile/slider_response.h" -#include "mobile/speak_request.h" -#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" -#include "mobile/unregister_app_interface_request.h" -#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" -#include "mobile/update_turn_list_response.h" - -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "test/application_manager/mock_application_manager_settings.h" -#include "application_manager/mock_event_dispatcher.h" - -namespace am = application_manager; - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace dummy_mobile_commands_test { - -namespace commands = ::application_manager::commands; - -using ::testing::_; -using ::testing::NotNull; -using ::testing::Types; -using commands::MessageSharedPtr; -using ::test::components::event_engine_test::MockEventDispatcher; -using ::test::components::application_manager_test::MockApplicationManager; -using ::test::components::application_manager_test:: - MockApplicationManagerSettings; -using ::application_manager::ApplicationSharedPtr; -using ::test::components::application_manager_test::MockApplication; - -namespace { -const std::string kEmptyString_ = ""; -} // namespace - -template -class MobileCommandsTest : public components::commands_test::CommandRequestTest< - CommandsTestMocks::kIsNice> { - public: - typedef Command CommandType; - - void InitCommand(const uint32_t& timeout) OVERRIDE { - EXPECT_CALL(app_mngr_settings_, default_timeout()) - .WillOnce(ReturnRef(timeout)); - ON_CALL(app_mngr_, event_dispatcher()) - .WillByDefault(ReturnRef(event_dispatcher_)); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); - ON_CALL(app_mngr_settings_, app_icons_folder()) - .WillByDefault(ReturnRef(kEmptyString_)); - } -}; - -template -class MobileCommandsTestFirst : public MobileCommandsTest { - public: - using typename MobileCommandsTest::CommandType; -}; - -template -class MobileCommandsTestSecond : public MobileCommandsTest { - public: - using typename MobileCommandsTest::CommandType; -}; - -template -class MobileCommandsTestThird : public MobileCommandsTest { - public: - using typename MobileCommandsTest::CommandType; -}; - -/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few - * TYPED_TEST_CASE for HMI and mobile commands - */ - -typedef Types - MobileCommandsListFirst; - -typedef Types MobileCommandsListSecond; - -typedef Types MobileCommandsListThird; - -TYPED_TEST_CASE(MobileCommandsTestFirst, MobileCommandsListFirst); -TYPED_TEST_CASE(MobileCommandsTestSecond, MobileCommandsListSecond); -TYPED_TEST_CASE(MobileCommandsTestThird, MobileCommandsListThird); - -TYPED_TEST(MobileCommandsTestFirst, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -TYPED_TEST(MobileCommandsTestSecond, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} -TYPED_TEST(MobileCommandsTestThird, CtorAndDtorCall) { - utils::SharedPtr command = - this->template CreateCommand(); - UNUSED(command); -} - -} // namespace dummy_mobile_commands_test -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc b/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc deleted file mode 100644 index 2702fb1ffe..0000000000 --- a/src/components/application_manager/test/commands/mobile/end_audio_pass_thru_request_test.cc +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/end_audio_pass_thru_request.h" - -#include "gtest/gtest.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/include/application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace end_audio_pass_thru_request { - -namespace am = ::application_manager; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using am::commands::MessageSharedPtr; -using am::commands::EndAudioPassThruRequest; -using am::event_engine::Event; -using am::MockMessageHelper; - -typedef SharedPtr EndAudioPassThruRequestPtr; - -class EndAudioPassThruRequestTest - : public CommandRequestTest {}; - -TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { - const uint32_t kConnectionKey = 2u; - const uint32_t app_id = kConnectionKey; - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - EndAudioPassThruRequestPtr command( - CreateCommand(command_msg)); - - 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::UNSUPPORTED_RESOURCE; - - Event event(hmi_apis::FunctionID::UI_EndAudioPassThru); - event.set_smart_object(*event_msg); - - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -} // namespace end_audio_pass_thru_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc b/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc deleted file mode 100644 index 698171a9a5..0000000000 --- a/src/components/application_manager/test/commands/mobile/get_dtcs_request_test.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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 "application_manager/commands/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 am::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())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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/test/commands/mobile/get_vehicle_data_request_test.cc b/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc deleted file mode 100644 index 81cc001e29..0000000000 --- a/src/components/application_manager/test/commands/mobile/get_vehicle_data_request_test.cc +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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 "application_manager/commands/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 am::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) - : GetVehicleDataRequest(message, application_manager) {} - - 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())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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/test/commands/mobile/get_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc deleted file mode 100644 index 716431ee08..0000000000 --- a/src/components/application_manager/test/commands/mobile/get_way_points_request_test.cc +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "commands/commands_test.h" -#include "commands/command_request_test.h" -#include "application_manager/application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "mobile/get_way_points_request.h" -#include "application_manager/smart_object_keys.h" -#include "mock_message_helper.h" -#include "interfaces/HMI_API.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_message_helper.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace get_way_points_request { - -using namespace mobile_apis::Result; -using ::testing::Return; -using ::testing::_; -using application_manager::commands::GetWayPointsRequest; -using application_manager::MockMessageHelper; -using application_manager::MockHmiInterfaces; - -typedef SharedPtr CommandPtr; -typedef mobile_apis::Result::eType MobileResult; -typedef hmi_apis::Common_Result::eType HmiResult; - -namespace { -const uint32_t kCorrelationId = 2u; -const uint32_t kAppId = 3u; -const uint32_t kConnectionKey = kAppId; -const std::string kMethodName = "Navigation.GetWayPoints"; -} - -class GetWayPointsRequestTest - : public CommandRequestTest { - public: - GetWayPointsRequestTest() : mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - message_ = utils::MakeShared(::smart_objects::SmartType_Map); - (*message_)[am::strings::msg_params] = - ::smart_objects::SmartObject(::smart_objects::SmartType_Map); - - command_sptr_ = - CreateCommand( - message_); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - } - - MockAppPtr mock_app_; - MessageSharedPtr message_; - utils::SharedPtr - command_sptr_; -}; - -class GetWayPointsRequestOnEventTest - : public CommandRequestTest { - public: - GetWayPointsRequestOnEventTest() : app_(CreateMockApp()) {} - - void CheckOnEventResponse(const std::string& wayPointsParam, - const HmiResult ResultCode, - const bool success) { - Event event(Event::EventID::Navigation_GetWayPoints); - CommandPtr command(CreateCommand()); - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::params][am::hmi_response::code] = ResultCode; - if ("0" == wayPointsParam) { - (*event_msg)[am::strings::msg_params] = 0; - } else { - (*event_msg)[am::strings::msg_params][am::strings::way_points][0]["123"] = - wayPointsParam; - } - - event.set_smart_object(*event_msg); - - const MobileResult mobile_result = static_cast(ResultCode); - - MessageSharedPtr result_msg( - CatchMobileCommandResult(CallOnEvent(*command, event))); - EXPECT_EQ( - mobile_result, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); - EXPECT_EQ( - success, - (*result_msg)[am::strings::msg_params][am::strings::success].asBool()); - } - - protected: - MockAppPtr app_; - MockHmiInterfaces hmi_interfaces_; -}; - -TEST_F(GetWayPointsRequestTest, - Run_InvalidApp_ApplicationNotRegisteredResponce) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - utils::SharedPtr null_application_sptr; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(null_application_sptr)); - - CallRun caller(*command_sptr_); - - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const mobile_apis::Result::eType result = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - - EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, result); -} - -TEST_F(GetWayPointsRequestTest, Run_ApplicationRegistered_Success) { - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - MockAppPtr application_sptr = CreateMockApp(); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(application_sptr)); - EXPECT_CALL(*application_sptr, app_id()).WillOnce(Return(1)); - - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId)); - - CallRun caller(*command_sptr_); - - MessageSharedPtr result_message = CatchHMICommandResult(caller); - - const hmi_apis::FunctionID::eType result_function_id = - static_cast( - (*result_message)[am::strings::params][am::strings::function_id] - .asInt()); - - EXPECT_EQ(hmi_apis::FunctionID::Navigation_GetWayPoints, result_function_id); - EXPECT_EQ(kCorrelationId, - (*result_message)[am::strings::params][am::strings::correlation_id] - .asUInt()); -} - -TEST_F(GetWayPointsRequestTest, - OnEvent_NavigationGetWayPointsEvent_SendResponse) { - am::event_engine::Event event(hmi_apis::FunctionID::Navigation_GetWayPoints); - - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - event.set_smart_object(*message_); - - CallOnEvent caller(*command_sptr_, event); - - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const mobile_apis::Result::eType result = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - - EXPECT_EQ(mobile_apis::Result::SUCCESS, result); -} - -TEST_F(GetWayPointsRequestTest, OnEvent_DefaultCase) { - am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); - - event.set_smart_object(*message_); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - - CallOnEvent caller(*command_sptr_, event); - caller(); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_WrongEventId_UNSUCCESS) { - Event event(Event::EventID::INVALID_ENUM); - CommandPtr command(CreateCommand()); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->on_event(event); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case1) { - CheckOnEventResponse("0", HmiResult::SUCCESS, true); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case2) { - CheckOnEventResponse("", HmiResult::SUCCESS, true); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case3) { - CheckOnEventResponse("test", HmiResult::SUCCESS, true); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case1) { - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - CheckOnEventResponse(" ", HmiResult::GENERIC_ERROR, false); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case2) { - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - CheckOnEventResponse("test\t", HmiResult::GENERIC_ERROR, false); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case3) { - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - CheckOnEventResponse("test\n", HmiResult::GENERIC_ERROR, false); -} - -TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case4) { - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - CheckOnEventResponse("test\t\n", HmiResult::GENERIC_ERROR, false); -} - -} // namespace get_way_points_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/list_files_request_test.cc b/src/components/application_manager/test/commands/mobile/list_files_request_test.cc deleted file mode 100644 index ae0e523832..0000000000 --- a/src/components/application_manager/test/commands/mobile/list_files_request_test.cc +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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/commands/mobile/list_files_request.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/smart_object_keys.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace list_files_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::DoAll; -using ::testing::SaveArg; -namespace am = ::application_manager; -using am::commands::ListFilesRequest; -using am::commands::MessageSharedPtr; - -class ListFilesRequestTest - : public CommandRequestTest { - public: - ListFilesRequestTest() : kStoragePath_("storage"), kResponseSize_(1) {} - const std::string kStoragePath_; - const uint32_t kResponseSize_; -}; - -TEST_F(ListFilesRequestTest, 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(ListFilesRequestTest, Run_TooManyHmiNone_UNSUCCESS) { - MockAppPtr app(CreateMockApp()); - SharedPtr command(CreateCommand()); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_NONE)); - - const uint32_t kListFilesInNoneAllowed = 1u; - const uint32_t kListFilesInNoneCount = 2u; - - EXPECT_CALL(app_mngr_, get_settings()) - .WillOnce(ReturnRef(app_mngr_settings_)); - ON_CALL(app_mngr_settings_, list_files_in_none()) - .WillByDefault(ReturnRef(kListFilesInNoneAllowed)); - ON_CALL(*app, list_files_in_none_count()) - .WillByDefault(Return(kListFilesInNoneCount)); - - 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(ListFilesRequestTest, Run_SUCCESS) { - MockAppPtr app(CreateMockApp()); - SharedPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, get_settings()) - .WillRepeatedly(ReturnRef(app_mngr_settings_)); - - ON_CALL(app_mngr_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kStoragePath_)); - - ON_CALL(app_mngr_settings_, list_files_response_size()) - .WillByDefault(ReturnRef(kResponseSize_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - ON_CALL(*app, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - - ON_CALL(*app, increment_list_files_in_none_count()).WillByDefault(Return()); - - ON_CALL(*app, GetAvailableDiskSpace()).WillByDefault(Return(0)); - - am::AppFilesMap files_map; - ON_CALL(*app, getAppFiles()).WillByDefault(ReturnRef(files_map)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -} // namespace list_files_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_button_notification_commands_test.cc b/src/components/application_manager/test/commands/mobile/on_button_notification_commands_test.cc deleted file mode 100644 index a08a43c97e..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_button_notification_commands_test.cc +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" - -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" - -#include "application_manager/include/application_manager/commands/command_impl.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/include/application_manager/commands/command_request_test.h" -#include "application_manager/commands/mobile/on_button_event_notification.h" -#include "application_manager/commands/mobile/on_button_press_notification.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_button_notification { - -namespace am = ::application_manager; -namespace commands = am::commands; - -using ::testing::_; -using ::testing::Types; -using ::testing::Return; - -using ::utils::SharedPtr; -using am::commands::MessageSharedPtr; - -namespace { -const uint32_t kAppId = 5u; -const uint32_t kCustomButtonId = 3u; -const mobile_apis::ButtonName::eType kButtonName = mobile_apis::ButtonName::OK; -} // namespace - -template -struct NotificationData { - typedef NotificationT Notification; - enum { kFunctionId = kExpectedFunctionId }; -}; - -template -class OnButtonNotificationCommandsTest - : public CommandsTest, - public NotificationDataT {}; - -typedef Types, - NotificationData > - OnButtonNotificationCommandsList; - -MATCHER_P(CheckNotificationMessage, function_id, "") { - const bool kIsMobileProtocolTypeCorrect = - (*arg)[am::strings::params][am::strings::protocol_type].asInt() == - commands::CommandImpl::mobile_protocol_type_; - - const bool kIsProtocolVersionCorrect = - (*arg)[am::strings::params][am::strings::protocol_version].asInt() == - commands::CommandImpl::protocol_version_; - - const bool kIsNotificationCorrect = - (*arg)[am::strings::params][am::strings::message_type].asInt() == - am::MessageType::kNotification; - - const bool kIsFunctionIdCorrect = - (*arg)[am::strings::params][am::strings::function_id].asInt() == - function_id; - - bool is_custom_button_id_correct = true; - if ((*arg)[am::strings::msg_params].keyExists( - am::hmi_response::custom_button_id)) { - is_custom_button_id_correct = - (*arg)[am::strings::msg_params][am::strings::custom_button_id] == - kCustomButtonId; - } - - return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && - kIsNotificationCorrect && kIsFunctionIdCorrect && - is_custom_button_id_correct; -} - -TYPED_TEST_CASE(OnButtonNotificationCommandsTest, - OnButtonNotificationCommandsList); - -TYPED_TEST(OnButtonNotificationCommandsTest, - Run_CustomButton_NoAppId_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - mobile_apis::ButtonName::CUSTOM_BUTTON; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, - Run_CustomButton_NoCustomButtonId_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - mobile_apis::ButtonName::CUSTOM_BUTTON; - (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, - Run_CustomButton_AppNotRegistered_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - mobile_apis::ButtonName::CUSTOM_BUTTON; - (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*notification_msg)[am::strings::msg_params] - [am::hmi_response::custom_button_id] = kCustomButtonId; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - EXPECT_CALL(this->app_mngr_, application(kAppId)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, - Run_CustomButton_AppNotSubscribedToCustomButtonId_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - mobile_apis::ButtonName::CUSTOM_BUTTON; - (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*notification_msg)[am::strings::msg_params] - [am::hmi_response::custom_button_id] = kCustomButtonId; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) - .WillOnce(Return(false)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - mobile_apis::ButtonName::CUSTOM_BUTTON; - (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*notification_msg)[am::strings::msg_params] - [am::hmi_response::custom_button_id] = kCustomButtonId; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - ON_CALL(*mock_app, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) - .WillOnce(Return(true)); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, - SendMessageToMobile( - CheckNotificationMessage(TestFixture::kFunctionId), _)); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, Run_NoSubscribedApps_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - kButtonName; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - const std::vector empty_subscribed_apps_list; - EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) - .WillOnce(Return(empty_subscribed_apps_list)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, Run_InvalidHmiLevel_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - kButtonName; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - std::vector subscribed_apps_list; - subscribed_apps_list.push_back(mock_app); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); - - EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) - .WillOnce(Return(subscribed_apps_list)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, - Run_ButtonOkOnlyForHmiLevelFull_UNSUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - kButtonName; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - std::vector subscribed_apps_list; - subscribed_apps_list.push_back(mock_app); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED)); - - EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) - .WillOnce(Return(subscribed_apps_list)); - EXPECT_CALL(this->app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command->Run(); -} - -TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { - typedef typename TestFixture::Notification Notification; - - MessageSharedPtr notification_msg( - this->CreateMessage(smart_objects::SmartType_Map)); - - (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = - kButtonName; - - SharedPtr command( - this->template CreateCommand(notification_msg)); - - typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); - std::vector subscribed_apps_list; - subscribed_apps_list.push_back(mock_app); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); - - ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true)); - - EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) - .WillOnce(Return(subscribed_apps_list)); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, - SendMessageToMobile( - CheckNotificationMessage(TestFixture::kFunctionId), _)); - - command->Run(); -} - -} // namespace on_button_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_command_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_command_notification_test.cc deleted file mode 100644 index 7a69dd3bb6..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_command_notification_test.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/commands/commands_test.h" -#include "application_manager/commands/command_impl.h" -#include "application_manager/commands/mobile/on_command_notification.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_command_notification { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; - -using am::commands::MessageSharedPtr; -using am::commands::OnCommandNotification; - -typedef ::utils::SharedPtr CommandPtr; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCommandId = 5u; -} // namespace - -class OnCommandNotificationTest - : public CommandsTest {}; - -TEST_F(OnCommandNotificationTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->Run(); -} - -TEST_F(OnCommandNotificationTest, Run_NoAppsForTheCommand_UNSUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, FindCommand(kCommandId)) - .WillOnce(Return(static_cast(NULL))); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command->Run(); -} - -MATCHER(CheckNotificationMessage, "") { - 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; - - return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && - kIsNotificationCorrect; -} - -TEST_F(OnCommandNotificationTest, Run_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); - - MessageSharedPtr dummy_msg(CreateMessage()); - EXPECT_CALL(*mock_app, FindCommand(kCommandId)) - .WillOnce(Return(dummy_msg.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(CheckNotificationMessage(), _)); - - command->Run(); -} - -} // namespace on_command_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc deleted file mode 100644 index e6e2ea70f3..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_hash_change_notification_test.cc +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/mobile/on_hash_change_notification.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/commands/command_impl.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_hash_change_notification { - -namespace strings = application_manager::strings; - -using application_manager::commands::mobile::OnHashChangeNotification; -using application_manager::MockMessageHelper; -using application_manager::commands::CommandImpl; -using testing::Mock; -using testing::Return; -using testing::ReturnRef; -using testing::_; - -class OnHashChangeNotificationTest - : public CommandsTest {}; - -TEST_F(OnHashChangeNotificationTest, Run_ValidApp_SUCCESS) { - const uint32_t kConnectionKey = 1u; - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - - SharedPtr command = - CreateCommand(msg); - - std::string return_string = "1234"; - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, curHash()).WillOnce(ReturnRef(return_string)); - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); - ASSERT_EQ(CommandImpl::mobile_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - ASSERT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); - ASSERT_EQ(return_string, - (*msg)[strings::msg_params][strings::hash_id].asString()); -} - -TEST_F(OnHashChangeNotificationTest, Run_InvalidApp_NoNotification) { - const uint32_t kConnectionKey = 1u; - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - - SharedPtr command = - CreateCommand(msg); - - std::string return_string; - MockAppPtr mock_app = CreateMockApp(); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - EXPECT_CALL(*mock_app, curHash()).Times(0); - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)).Times(0); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -} // namespace on_hash_change_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc deleted file mode 100644 index 78875ad164..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc +++ /dev/null @@ -1,282 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/mobile/on_hmi_status_notification_from_mobile.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include -#include "application_manager/message.h" -#include "application_manager/application_manager.h" -#include "application_manager/mock_message_helper.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_hmi_status_notification_from_mobile { - -namespace { -const uint32_t kConnectionKey = 1u; -const connection_handler::DeviceHandle kHandle = 2u; -} // namespace - -namespace strings = application_manager::strings; - -using application_manager::commands::OnHMIStatusNotificationFromMobile; -using protocol_handler::MajorProtocolVersion; -using application_manager::ApplicationSet; -using testing::Mock; -using testing::Return; -using testing::_; - -class OnHMIStatusNotificationFromMobileTest - : public CommandsTest { - public: - MessageSharedPtr CreateMsgParams( - const mobile_apis::HMILevel::eType kHMIState) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; - return msg; - } - ApplicationSet app_set_; - sync_primitives::Lock lock_; -}; - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_CurrentStateForeground_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(true)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); - - DataAccessor accessor(app_set_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillRepeatedly( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, Run_InvalidApp_NoNotification) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - EXPECT_CALL(*mock_app, set_foreground(true)).Times(0); - - EXPECT_CALL(*mock_app, device()).Times(0); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).Times(0); - - EXPECT_CALL(app_mngr_, applications()).Times(0); - - EXPECT_CALL(*mock_app, protocol_version()).Times(0); - EXPECT_CALL(*mock_app, is_foreground()).Times(0); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_CurrentStateNotForeground_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(false)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); - - DataAccessor accessor(app_set_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillRepeatedly( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_ProtocolVersionKV3_NoNotification) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(false)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); - - DataAccessor accessor(app_set_, lock_); - EXPECT_CALL(app_mngr_, applications()).Times(0); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillOnce( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); - EXPECT_CALL(*mock_app, is_foreground()).Times(0); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_AppNotRequestedBeforeAndKV3_NoNotification) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(true)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); - - EXPECT_CALL(app_mngr_, applications()).Times(0); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillOnce( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); - EXPECT_CALL(*mock_app, is_foreground()).Times(0); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_AppNotRequestedBefore_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(true)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillOnce( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - - EXPECT_CALL(app_mngr_, applications()).Times(0); - - EXPECT_CALL(*mock_app, is_foreground()).WillOnce(Return(true)); - - EXPECT_CALL(mock_message_helper_, SendQueryApps(kConnectionKey, _)); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -TEST_F(OnHMIStatusNotificationFromMobileTest, - Run_AnotherForegroundSDLApp_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, set_foreground(true)); - - EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); - EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); - - DataAccessor accessor(app_set_, lock_); - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - EXPECT_CALL(*mock_app, protocol_version()) - .WillRepeatedly( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); - EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(false)); - - EXPECT_CALL(app_mngr_, MarkAppsGreyOut(kHandle, false)); - EXPECT_CALL(app_mngr_, SendUpdateAppList()); - - command->Run(); - - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); -} - -} // namespace on_hmi_status_notification_from_mobile -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc deleted file mode 100644 index 78f39b1e48..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_hmi_status_notification_test.cc +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/mobile/on_hmi_status_notification.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/commands/command_impl.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_hmi_status_notification { - -namespace { -const uint32_t kConnectionKey = 1u; -} // namespace - -namespace strings = application_manager::strings; - -using application_manager::commands::OnHMIStatusNotification; -using protocol_handler::MajorProtocolVersion; -using application_manager::MockMessageHelper; -using application_manager::commands::CommandImpl; -using testing::Mock; -using testing::Return; -using testing::_; - -class OnHMIStatusNotificationTest - : public CommandsTest { - public: - MessageSharedPtr CreateMsgParams( - const mobile_apis::HMILevel::eType kHMIState) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; - return msg; - } - - void SetSendNotificationExpectations(MessageSharedPtr& msg) { - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)); - } - - void VerifySendNotificationData(MessageSharedPtr& msg) { - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); - ASSERT_EQ(CommandImpl::mobile_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - ASSERT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); - } -}; - -TEST_F(OnHMIStatusNotificationTest, Run_InvalidApp_NoNotification) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - - EXPECT_CALL(*mock_app, tts_properties_in_full()).Times(0); - EXPECT_CALL(*mock_app, set_tts_properties_in_full(_)).Times(0); - EXPECT_CALL(*mock_app, app_id()).Times(0); - EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)) - .Times(0); - - command->Run(); -} - -TEST_F(OnHMIStatusNotificationTest, Run_InvalidEnum_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::INVALID_ENUM); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - VerifySendNotificationData(msg); -} - -TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndFalseProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - SetSendNotificationExpectations(msg); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(false)); - EXPECT_CALL(*mock_app, set_tts_properties_in_none(true)); - EXPECT_CALL(mock_message_helper_, SendTTSGlobalProperties(_, false, _)); - - command->Run(); - - VerifySendNotificationData(msg); -} - -TEST_F(OnHMIStatusNotificationTest, Run_BackgroundAndTrueProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_none()).WillOnce(Return(true)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - VerifySendNotificationData(msg); -} - -TEST_F(OnHMIStatusNotificationTest, Run_FullAndFalseProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(false)); - EXPECT_CALL(*mock_app, set_tts_properties_in_full(true)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); - EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - VerifySendNotificationData(msg); -} - -TEST_F(OnHMIStatusNotificationTest, Run_FullAndTrueProperties_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(true)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - VerifySendNotificationData(msg); -} - -} // namespace on_hmi_status_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc deleted file mode 100644 index 9106a369b5..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_keyboard_input_notification_test.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/mobile/on_keyboard_input_notification.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include -#include "application_manager/message.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/commands/command_impl.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_keyboard_input_notification { - -namespace strings = application_manager::strings; - -namespace { -const uint32_t kConnectionKey = 1u; -} // namespace - -using application_manager::commands::mobile::OnKeyBoardInputNotification; -using application_manager::MockMessageHelper; -using application_manager::commands::CommandImpl; -using application_manager::ApplicationSet; -using testing::Mock; -using testing::Return; -using testing::_; - -class OnKeyBoardInputNotificationTest - : public CommandsTest { - public: - void SetSendNotificationExpectations(MessageSharedPtr msg) { - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)); - } - - void SetSendNotificationVariables(MessageSharedPtr msg) { - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); - ASSERT_EQ(CommandImpl::mobile_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - ASSERT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); - } - - MockAppPtr InitAppSetDataAccessor(SharedPtr& app_set) { - app_set = (!app_set ? ::utils::MakeShared() : app_set); - MockAppPtr app(CreateMockApp()); - app_set->insert(app); - EXPECT_CALL(app_mngr_, applications()) - .WillOnce(Return(DataAccessor(*app_set, lock_))); - return app; - } - - SharedPtr app_set_; - sync_primitives::Lock lock_; -}; - -TEST_F(OnKeyBoardInputNotificationTest, Run_ActionActive_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); - EXPECT_CALL(*mock_app, is_perform_interaction_active()).WillOnce(Return(1)); - EXPECT_CALL(*mock_app, perform_interaction_layout()) - .WillOnce(Return(mobile_apis::LayoutMode::KEYBOARD)); - EXPECT_CALL(*mock_app, hmi_level()).Times(0); - - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - SetSendNotificationVariables(msg); - - ASSERT_EQ(kConnectionKey, - (*msg)[strings::params][strings::connection_key].asInt()); -} - -TEST_F(OnKeyBoardInputNotificationTest, Run_ActionNotActive_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); - EXPECT_CALL(*mock_app, is_perform_interaction_active()) - .WillRepeatedly(Return(0)); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_FULL)); - - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); - - SetSendNotificationExpectations(msg); - - command->Run(); - - SetSendNotificationVariables(msg); - - ASSERT_EQ(kConnectionKey, - (*msg)[strings::params][strings::connection_key].asInt()); -} - -TEST_F(OnKeyBoardInputNotificationTest, Run_InvalidApp_NoNotification) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); - EXPECT_CALL(*mock_app, is_perform_interaction_active()) - .WillRepeatedly(Return(0)); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_BACKGROUND)); - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)).Times(0); - - command->Run(); -} - -} // namespace on_keyboard_input_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc deleted file mode 100644 index 56aabe7b70..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_system_request_notification_test.cc +++ /dev/null @@ -1,297 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "application_manager/commands/mobile/on_system_request_notification.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include "application_manager/commands/command_impl.h" -#include "interfaces/MOBILE_API.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_system_request_notification { - -namespace strings = application_manager::strings; - -using application_manager::commands::mobile::OnSystemRequestNotification; -using application_manager::commands::CommandImpl; -using application_manager::MockMessageHelper; -using test::components::policy_test::MockPolicyHandlerInterface; -using namespace mobile_apis; -using testing::SaveArg; -using testing::Mock; -using testing::Return; -using testing::ReturnRef; -using testing::_; - -namespace { -const uint32_t kConnectionKey = 1u; -const std::string kPolicyAppId = "fake-app-id"; -} // namespace - -class OnSystemRequestNotificationTest - : public CommandsTest { - public: - OnSystemRequestNotificationTest() : mock_app_(CreateMockApp()) {} - - void PreConditions() { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); - } - - protected: - MockAppPtr mock_app_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { - const mobile_apis::RequestType::eType request_type = - mobile_apis::RequestType::PROPRIETARY; - - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::request_type] = request_type; - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillRepeatedly(ReturnRef(mock_policy_handler)); - std::string policy_app_id; - EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); - EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)) - .WillOnce(Return(true)); - -#ifdef PROPRIETARY_MODE - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .Times(2) - .WillRepeatedly(ReturnRef(mock_policy_handler)); - EXPECT_CALL(mock_policy_handler, TimeoutExchangeSec()).WillOnce(Return(5u)); -#endif // PROPRIETARY_MODE - - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)); - - command->Run(); - - ASSERT_EQ(FileType::JSON, - (*msg)[strings::msg_params][strings::file_type].asInt()); - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); - ASSERT_EQ(CommandImpl::mobile_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - ASSERT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); -} - -TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { - const mobile_apis::RequestType::eType request_type = - mobile_apis::RequestType::HTTP; - - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::request_type] = request_type; - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler)); - std::string policy_app_id; - EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); - EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)) - .WillOnce(Return(true)); - - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)); - - command->Run(); - - ASSERT_EQ(FileType::BINARY, - (*msg)[strings::msg_params][strings::file_type].asInt()); - ASSERT_EQ(application_manager::MessageType::kNotification, - (*msg)[strings::params][strings::message_type].asInt()); - ASSERT_EQ(CommandImpl::mobile_protocol_type_, - (*msg)[strings::params][strings::protocol_type].asInt()); - ASSERT_EQ(CommandImpl::protocol_version_, - (*msg)[strings::params][strings::protocol_version].asInt()); -} - -TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { - const mobile_apis::RequestType::eType request_type = - mobile_apis::RequestType::HTTP; - - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::request_type] = request_type; - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - EXPECT_CALL(*mock_app, policy_app_id()).Times(0); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)).Times(0); - - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)).Times(0); - - command->Run(); -} - -TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { - const mobile_apis::RequestType::eType request_type = - mobile_apis::RequestType::HTTP; - - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - (*msg)[strings::msg_params][strings::request_type] = request_type; - - SharedPtr command = - CreateCommand(msg); - - MockAppPtr mock_app = CreateMockApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler)); - std::string policy_app_id; - EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(policy_app_id)); - EXPECT_CALL(mock_policy_handler, IsRequestTypeAllowed(_, _)) - .WillOnce(Return(false)); - - EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(msg, _)).Times(0); - ; - - command->Run(); -} - -TEST_F( - OnSystemRequestNotificationTest, - Run_RequestTypeAllowedAndRequestSubTypeDisallowed_MessageNotSentToMobile) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - const auto request_type = mobile_apis::RequestType::HTTP; - (*msg)[strings::msg_params][strings::request_type] = request_type; - const std::string request_subtype = "fakeSubType"; - (*msg)[am::strings::msg_params][am::strings::request_subtype] = - request_subtype; - - PreConditions(); - - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) - .WillOnce(Return(true)); - EXPECT_CALL(mock_policy_handler_, - IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) - .WillOnce(Return(false)); - - EXPECT_CALL(app_mngr_, SendMessageToMobile(_, _)).Times(0); - - auto command = CreateCommand(msg); - - ASSERT_TRUE(command->Init()); - command->Run(); -} - -TEST_F(OnSystemRequestNotificationTest, - Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendMessageToMobile) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[strings::params][strings::connection_key] = kConnectionKey; - const auto request_type = mobile_apis::RequestType::OEM_SPECIFIC; - (*msg)[strings::msg_params][strings::request_type] = request_type; - const std::string request_subtype = "fakeSubType"; - (*msg)[am::strings::msg_params][am::strings::request_subtype] = - request_subtype; - - PreConditions(); - - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kPolicyAppId, request_type)) - .WillOnce(Return(true)); - EXPECT_CALL(mock_policy_handler_, - IsRequestSubTypeAllowed(kPolicyAppId, request_subtype)) - .WillOnce(Return(true)); - - smart_objects::SmartObjectSPtr result; - EXPECT_CALL(app_mngr_, SendMessageToMobile(_, _)) - .WillOnce((SaveArg<0>(&result))); - - auto command = CreateCommand(msg); - - ASSERT_TRUE(command->Init()); - command->Run(); - - EXPECT_EQ(application_manager::MessageType::kNotification, - (*result)[strings::params][strings::message_type].asInt()); - EXPECT_EQ(request_type, - (*result)[strings::msg_params][strings::request_type].asInt()); - EXPECT_EQ( - request_subtype, - (*result)[strings::msg_params][strings::request_subtype].asString()); -} - -} // namespace on_system_request_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_tbt_client_state_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_tbt_client_state_notification_test.cc deleted file mode 100644 index b2ddce0bfe..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_tbt_client_state_notification_test.cc +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/on_tbt_client_state_notification.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_impl.h" -#include "utils/helpers.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_tbt_client_state_notification { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; - -using am::commands::MessageSharedPtr; -using am::commands::OnTBTClientStateNotification; - -typedef ::utils::SharedPtr NotificationPtr; - -namespace { -const uint32_t kAppId = 1u; -} // namespace - -class OnTBTClientStateNotificationTest - : public CommandsTest { - public: - OnTBTClientStateNotificationTest() - : command_(CreateCommand()) {} - - NotificationPtr command_; -}; - -TEST_F(OnTBTClientStateNotificationTest, Run_HmiLevelNone_UNSUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - std::vector applications_with_navi; - applications_with_navi.push_back(mock_app); - - EXPECT_CALL(app_mngr_, applications_with_navi()) - .WillOnce(Return(applications_with_navi)); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); - - EXPECT_CALL(*mock_app, app_id()).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command_->Run(); -} - -MATCHER(CheckMessageData, "") { - 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; - - using namespace helpers; - return Compare(true, - kIsMobileProtocolTypeCorrect, - kIsProtocolVersionCorrect, - kIsNotificationCorrect, - kIsConnectionKeyCorrect); -} - -TEST_F(OnTBTClientStateNotificationTest, - Run_NotEmptyListOfAppsWithNavi_SUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - std::vector applications_with_navi; - applications_with_navi.push_back(mock_app); - - EXPECT_CALL(app_mngr_, applications_with_navi()) - .WillOnce(Return(applications_with_navi)); - - EXPECT_CALL(*mock_app, hmi_level()) - .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); - - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(CheckMessageData(), _)); - - command_->Run(); -} - -} // namespace on_tbt_client_state_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_touch_event_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_touch_event_notification_test.cc deleted file mode 100644 index 6656955431..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_touch_event_notification_test.cc +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/on_touch_event_notification.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_impl.h" -#include "utils/helpers.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_touch_event_notification { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; - -using am::commands::MessageSharedPtr; -using am::commands::mobile::OnTouchEventNotification; - -typedef ::utils::SharedPtr NotificationPtr; - -namespace { -const uint32_t kAppId = 1u; -} // namespace - -class OnTouchEventNotificationTest - : public CommandsTest { - public: - OnTouchEventNotificationTest() - : command_(CreateCommand()) {} - - NotificationPtr command_; -}; - -TEST_F(OnTouchEventNotificationTest, Run_AppIsNotFullscreen_UNSUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - std::vector applications_with_navi; - applications_with_navi.push_back(mock_app); - - std::vector applications_with_mobile_projection; - applications_with_mobile_projection.push_back(mock_app); - - EXPECT_CALL(app_mngr_, applications_with_navi()) - .WillOnce(Return(applications_with_navi)); - - EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) - .WillOnce(Return(applications_with_mobile_projection)); - - EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(false)); - - EXPECT_CALL(*mock_app, app_id()).Times(0); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, SendMessageToMobile(_, _)).Times(0); - - command_->Run(); -} - -MATCHER(CheckMessageData, "") { - 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; - - using namespace helpers; - return Compare(true, - kIsMobileProtocolTypeCorrect, - kIsProtocolVersionCorrect, - kIsNotificationCorrect, - kIsConnectionKeyCorrect); -} - -TEST_F(OnTouchEventNotificationTest, Run_NotEmptyListOfAppsWithNavi_SUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - std::vector applications_with_navi; - applications_with_navi.push_back(mock_app); - - std::vector applications_with_mobile_projection; - applications_with_mobile_projection.push_back(mock_app); - - EXPECT_CALL(app_mngr_, applications_with_navi()) - .WillOnce(Return(applications_with_navi)); - - EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) - .WillOnce(Return(applications_with_mobile_projection)); - - EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(true)); - - EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(CheckMessageData(), _)) - .Times(2); - - command_->Run(); -} - -} // namespace on_touch_event_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc deleted file mode 100644 index fb2aeb0c8d..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_vehicle_data_notification_test.cc +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/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 am::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)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/test/commands/mobile/on_way_point_change_notification_test.cc deleted file mode 100644 index b6f18bf2fb..0000000000 --- a/src/components/application_manager/test/commands/mobile/on_way_point_change_notification_test.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/on_way_point_change_notification.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_impl.h" -#include "utils/helpers.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace on_way_point_change_notification { - -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::Return; - -using am::commands::MessageSharedPtr; -using am::commands::OnWayPointChangeNotification; - -typedef ::utils::SharedPtr NotificationPtr; - -namespace { -const uint32_t kAppId = 1u; -} // namespace - -class OnWayPointChangeNotificationTest - : public CommandsTest { - public: - OnWayPointChangeNotificationTest() - : command_(CreateCommand()) {} - - NotificationPtr command_; -}; - -MATCHER(CheckMessageData, "") { - 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; - - using namespace helpers; - return Compare(true, - kIsMobileProtocolTypeCorrect, - kIsProtocolVersionCorrect, - kIsNotificationCorrect, - kIsConnectionKeyCorrect); -} - -TEST_F(OnWayPointChangeNotificationTest, - Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { - std::set apps_subscribed_for_way_points; - apps_subscribed_for_way_points.insert(kAppId); - - EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) - .WillOnce(Return(apps_subscribed_for_way_points)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(CheckMessageData(), _)); - - command_->Run(); -} - -} // namespace on_way_point_change_notification -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc b/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc deleted file mode 100644 index 58316b9cb2..0000000000 --- a/src/components/application_manager/test/commands/mobile/perform_audio_pass_thru_test.cc +++ /dev/null @@ -1,841 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/perform_audio_pass_thru_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace perform_audio_pass_thru_request { - -namespace am = application_manager; -using am::commands::PerformAudioPassThruRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::InSequence; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 2u; -const std::string kCorrectPrompt = "CorrectPrompt"; -const std::string kCorrectType = "CorrectType"; -const std::string kCorrectDisplayText1 = "CorrectDisplayText1"; -const std::string kCorrectDisplayText2 = "CorrectDisplayText2"; -const std::string kFunctionId = "FunctionId"; -const uint32_t kTimeoutForTTSSpeak = 1u; -} // namespace - -class PerformAudioPassThruRequestTest - : public CommandRequestTest { - public: - PerformAudioPassThruRequestTest() - : mock_app_(CreateMockApp()) - , message_(utils::MakeShared(::smart_objects::SmartType_Map)) - , msg_params_((*message_)[am::strings::msg_params]) {} - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void TestWrongSyntaxInField(const std::string& field) { - if (field == am::strings::initial_prompt) { - msg_params_[field][0][am::strings::text] = "prompt\\n"; - } else { - msg_params_[field] = "prompt\\n"; - } - - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - CallRun caller(*command_sptr_); - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const am::mobile_api::Result::eType result = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - - EXPECT_EQ(am::mobile_api::Result::INVALID_DATA, result); - } - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - (*message_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - command_sptr_ = - CreateCommand(message_); - - application_sptr_ = CreateMockApp(); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(application_sptr_)); - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - sync_primitives::Lock lock_; - MockAppPtr mock_app_; - MessageSharedPtr message_; - ::smart_objects::SmartObject& msg_params_; - utils::SharedPtr command_sptr_; - MockAppPtr application_sptr_; -}; - -TEST_F(PerformAudioPassThruRequestTest, OnTimeout_GENERIC_ERROR) { - MessageSharedPtr msg_ui = CreateMessage(smart_objects::SmartType_Map); - (*msg_ui)[am::strings::msg_params][am::strings::result_code] = - am::mobile_api::Result::GENERIC_ERROR; - (*msg_ui)[am::strings::msg_params][am::strings::success] = false; - - MessageSharedPtr message = - utils::MakeShared(::smart_objects::SmartType_Map); - (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - utils::SharedPtr command = - CreateCommand(message); - - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); - - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(msg_ui)); - - MessageSharedPtr vr_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - command->onTimeOut(); - EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - false); - EXPECT_EQ( - (*vr_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(am::mobile_api::Result::GENERIC_ERROR)); -} - -TEST_F(PerformAudioPassThruRequestTest, - OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr mobile_request = CreateFullParamsUISO(); - (*mobile_request)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - smart_objects::SmartObject initial_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Array); - initial_prompt[0] = smart_objects::SmartObject(smart_objects::SmartType_Map); - initial_prompt[0][am::strings::text] = "tts chunk text"; - initial_prompt[0][am::strings::type] = 0; - (*mobile_request)[am::strings::msg_params][am::strings::initial_prompt] = - initial_prompt; - - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - utils::SharedPtr command = - CreateCommand(mobile_request); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MessageSharedPtr response_msg_tts = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_tts)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*response_msg_tts)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; - am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); - event_tts.set_smart_object(*response_msg_tts); - - MessageSharedPtr response_ui = CreateMessage(smart_objects::SmartType_Map); - (*response_ui)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*response_ui)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*response_ui)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - am::event_engine::Event event_ui( - hmi_apis::FunctionID::UI_PerformAudioPassThru); - event_ui.set_smart_object(*response_ui); - - MessageSharedPtr response_to_mobile; - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillRepeatedly(Return(true)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - EXPECT_CALL(mock_message_helper_, - VerifyTtsFiles((*mobile_request)[am::strings::msg_params] - [am::strings::initial_prompt], - _, - _)).WillOnce(Return(mobile_apis::Result::SUCCESS)); - - command->Run(); - command->on_event(event_tts); - command->on_event(event_ui); - - EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] - .asBool(), - false); - EXPECT_EQ( - (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::info] - .asString(), - "UI is not supported by system"); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_InvalidApp_ApplicationNotRegisteredResponce) { - utils::SharedPtr null_application_sptr; - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(null_application_sptr)); - - CallRun caller(*command_sptr_); - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const am::mobile_api::Result::eType result = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - EXPECT_EQ(am::mobile_api::Result::APPLICATION_NOT_REGISTERED, result); -} - -TEST_F(PerformAudioPassThruRequestTest, Run_HmiLevelNone_Rejected) { - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); - - CallRun caller(*command_sptr_); - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const am::mobile_api::Result::eType result = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - EXPECT_EQ(am::mobile_api::Result::REJECTED, result); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_WhitespaceInInitialPrompt_InvalidData) { - TestWrongSyntaxInField(am::strings::initial_prompt); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_WhitespaceInAudioPassDisplayText1_InvalidData) { - TestWrongSyntaxInField(am::strings::audio_pass_display_text1); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_WhitespaceInAudioPassDisplayText2_InvalidData) { - TestWrongSyntaxInField(am::strings::audio_pass_display_text2); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_InitPromptCorrect_TTSSpeakIsAbsent) { - // First we need to call SendSpeakRequest() - // to enable the "is_active_tts_speak" key - - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - msg_params_[am::strings::initial_prompt][0][am::strings::text] = - kCorrectPrompt; - msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; - - EXPECT_CALL(mock_message_helper_, - VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - MessageSharedPtr speak_reqeust_result_msg; - MessageSharedPtr perform_result_msg; - { - InSequence dummy; - // Send speak request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); - - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); - } - CallRun run_caller(*command_sptr_); - run_caller(); - - const ::smart_objects::SmartObject& speak_msg_params = - (*speak_reqeust_result_msg)[am::strings::msg_params]; - - const std::string result_initial_prompt = - speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] - .asString(); - const std::string result_prompt_type = - speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] - .asString(); - - EXPECT_EQ(kCorrectPrompt, result_initial_prompt); - EXPECT_EQ(kCorrectType, result_prompt_type); - - // Now we recieve on_event() - - am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::GENERIC_ERROR; - event.set_smart_object(*message_); - - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); - - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_StopSpeaking)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - CallOnEvent on_event_caller(*command_sptr_, event); - MessageSharedPtr command_result = CatchHMICommandResult(on_event_caller); - - const hmi_apis::FunctionID::eType result_function_id = - static_cast( - (*command_result)[am::strings::params][am::strings::function_id] - .asInt()); - - EXPECT_EQ(hmi_apis::FunctionID::TTS_StopSpeaking, result_function_id); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteTrue) { - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - msg_params_[am::strings::initial_prompt][0][am::strings::text] = - kCorrectPrompt; - msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; - msg_params_[am::strings::audio_pass_display_text1] = kCorrectDisplayText1; - msg_params_[am::strings::audio_pass_display_text2] = kCorrectDisplayText2; - - EXPECT_CALL(mock_message_helper_, - VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - MessageSharedPtr speak_reqeust_result_msg; - MessageSharedPtr perform_result_msg; - { - InSequence dummy; - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); - - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); - } - CallRun caller(*command_sptr_); - caller(); - - const ::smart_objects::SmartObject& speak_msg_params = - (*speak_reqeust_result_msg)[am::strings::msg_params]; - const ::smart_objects::SmartObject& perform_msg_params = - (*perform_result_msg)[am::strings::msg_params]; - - const std::string result_initial_prompt = - speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] - .asString(); - const std::string result_prompt_type = - speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] - .asString(); - const std::string result_display_text_1 = - perform_msg_params[am::hmi_request::audio_pass_display_texts][0] - [am::hmi_request::field_text].asString(); - const std::string result_display_text_2 = - perform_msg_params[am::hmi_request::audio_pass_display_texts][1] - [am::hmi_request::field_text].asString(); - - EXPECT_EQ(kCorrectPrompt, result_initial_prompt); - EXPECT_EQ(kCorrectType, result_prompt_type); - EXPECT_EQ(kCorrectDisplayText1, result_display_text_1); - EXPECT_EQ(kCorrectDisplayText2, result_display_text_2); - - EXPECT_EQ(true, perform_msg_params[am::strings::mute_audio].asBool()); -} - -TEST_F(PerformAudioPassThruRequestTest, - Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteFalse) { - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - msg_params_[am::strings::initial_prompt][0][am::strings::text] = - kCorrectPrompt; - msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; - - EXPECT_CALL(mock_message_helper_, - VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - const bool muted = false; - - msg_params_[am::strings::mute_audio] = muted; - - MessageSharedPtr speak_reqeust_result_msg; - MessageSharedPtr perform_result_msg; - { - InSequence dummy; - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); - - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); - } - CallRun caller(*command_sptr_); - caller(); - - EXPECT_EQ( - muted, - (*perform_result_msg)[am::strings::msg_params][am::strings::mute_audio] - .asBool()); -} - -TEST_F( - PerformAudioPassThruRequestTest, - Run_InitPromptEmpty_PerformAndRecordStartNotificationsAndStartRecording) { - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - MessageSharedPtr start_record_result_msg; - MessageSharedPtr perform_result_msg; - { - InSequence dummy; - - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); - - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_OnRecordStart)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - // Start recording notification sending - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&start_record_result_msg), Return(true))); - } - - // Start microphone recording cals - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); - EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); - - CallRun caller(*command_sptr_); - caller(); - - const hmi_apis::FunctionID::eType start_record_result_function_id = - static_cast( - (*start_record_result_msg)[am::strings::params] - [am::strings::function_id].asInt()); - EXPECT_EQ(hmi_apis::FunctionID::UI_OnRecordStart, - start_record_result_function_id); -} - -TEST_F(PerformAudioPassThruRequestTest, OnEvent_UIPAPT_Rejected) { - am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); - - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::REJECTED; - event.set_smart_object(*message_); - - CallOnEvent caller(*command_sptr_, event); - - MessageSharedPtr result_message = CatchMobileCommandResult(caller); - - const am::mobile_api::Result::eType result_code = - static_cast( - (*result_message)[am::strings::msg_params][am::strings::result_code] - .asInt()); - - EXPECT_EQ(am::mobile_api::Result::REJECTED, result_code); -} - -TEST_F(PerformAudioPassThruRequestTest, - OnEvent_TTSSpeakSuccess_UpdateRequestTimeout) { - am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); - - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - event.set_smart_object(*message_); - - // Start recording notification sending - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - // Start microphone recording cals - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); - EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - CallOnEvent caller(*command_sptr_, event); - caller(); -} - -TEST_F(PerformAudioPassThruRequestTest, - DISABLED_OnEvent_PAPTunsupportedResource_CorrectInfo) { - const std::string return_info = "Unsupported phoneme type sent in a prompt"; - - am::event_engine::Event event_speak(hmi_apis::FunctionID::TTS_Speak); - am::event_engine::Event event_perform( - hmi_apis::FunctionID::UI_PerformAudioPassThru); - - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - event_speak.set_smart_object(*message_); - - (*message_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - event_perform.set_smart_object(*message_); - - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - // First call on_event for setting result_tts_speak_ to UNSUPPORTED_RESOURCE - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - CallOnEvent caller_speak(*command_sptr_, event_speak); - caller_speak(); - - // Second call for test correct behavior of UI_PerformAudioPassThru event - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); - EXPECT_CALL(app_mngr_, StopAudioPassThru(_)).Times(0); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - CallOnEvent caller_perform(*command_sptr_, event_perform); - - MessageSharedPtr perform_event_result = - CatchMobileCommandResult(caller_perform); - - EXPECT_EQ(return_info, - (*perform_event_result)[am::strings::msg_params][am::strings::info] - .asString()); -} - -TEST_F(PerformAudioPassThruRequestTest, - DISABLED_OnEvent_TTSSpeak_UpdateTimeout) { - am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); - - msg_params_[am::strings::connection_key] = kConnectionKey; - msg_params_[am::strings::function_id] = kFunctionId; - msg_params_[am::strings::correlation_id] = kCorrelationId; - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); - - EXPECT_CALL( - app_mngr_, - StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - CallOnEvent caller(*command_sptr_, event); - caller(); - - EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); - EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); -} - -TEST_F(PerformAudioPassThruRequestTest, - DISABLED_OnEvent_TTSOnResetTimeout_UpdateTimeout) { - am::event_engine::Event event(hmi_apis::FunctionID::TTS_OnResetTimeout); - - msg_params_[am::strings::connection_key] = kConnectionKey; - msg_params_[am::strings::function_id] = kFunctionId; - - uint32_t app_id = kConnectionKey; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); - - EXPECT_CALL( - app_mngr_, - StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - CallOnEvent caller(*command_sptr_, event); - caller(); - - EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); - EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); -} - -TEST_F(PerformAudioPassThruRequestTest, OnEvent_DefaultCase) { - am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); - - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).Times(0); - - CallOnEvent caller(*command_sptr_, event); - caller(); -} - -TEST_F(PerformAudioPassThruRequestTest, Init_CorrectTimeout) { - const uint32_t kDefaultTimeout = command_sptr_->default_timeout(); - const uint32_t kMaxDuration = 10000u; - - msg_params_[am::strings::max_duration] = kMaxDuration; - - command_sptr_->Init(); - - EXPECT_EQ(kDefaultTimeout + kMaxDuration, command_sptr_->default_timeout()); -} - -TEST_F(PerformAudioPassThruRequestTest, - onTimeOut_ttsSpeakNotActive_DontSendHMIReqeust) { - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); - - // For setting current_state_ -> kCompleted - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - - command_sptr_->onTimeOut(); -} - -TEST_F(PerformAudioPassThruRequestTest, - DISABLED_onTimeOut_ttsSpeakActive_SendHMIReqeust) { - uint32_t app_id = kConnectionKey; - EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); - - EXPECT_CALL(*application_sptr_, hmi_level()) - .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); - - msg_params_[am::strings::initial_prompt][0][am::strings::text] = - kCorrectPrompt; - msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; - - EXPECT_CALL(mock_message_helper_, - VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - MessageSharedPtr speak_reqeust_result_msg; - MessageSharedPtr perform_result_msg; - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); - - // Perform audio path thru request sending - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(msg)); - - // For setting is_active_tts_speak -> true - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .Times(2) - .WillRepeatedly(Return(false)); - CallRun caller(*command_sptr_); - caller(); - - // For setting current_state_ -> kCompleted - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)); - command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); - - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) - .WillOnce(Return(false)); - - command_sptr_->onTimeOut(); -} - -} // namespace perform_audio_pass_thru_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc deleted file mode 100644 index 02da6148ad..0000000000 --- a/src/components/application_manager/test/commands/mobile/perform_interaction_test.cc +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/perform_interaction_request.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/helpers.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "utils/custom_string.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace perform_interaction_request { - -namespace am = application_manager; -using am::commands::CommandImpl; -using am::ApplicationManager; -using am::commands::MessageSharedPtr; -using am::ApplicationSharedPtr; -using am::MockMessageHelper; -using ::testing::_; -using ::utils::SharedPtr; -using ::testing::Return; -using ::testing::ReturnRef; -using am::commands::PerformInteractionRequest; -using ::test::components::application_manager_test::MockApplication; - -namespace strings = ::application_manager::strings; -namespace hmi_response = ::application_manager::hmi_response; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -} // namespace - -class PerformInteractionRequestTest - : public CommandRequestTest { - public: - PerformInteractionRequestTest() : mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - sync_primitives::Lock lock_; - MockAppPtr mock_app_; -}; - -TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { - MessageSharedPtr response_msg_vr = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_vr)[strings::params][hmi_response::code] = - static_cast(hmi_apis::Common_Result::SUCCESS); - (*response_msg_vr)[strings::msg_params][strings::info] = "info"; - MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); - (*request_msg)[strings::msg_params][strings::interaction_mode] = - mobile_apis::InteractionMode::BOTH; - utils::SharedPtr command = - CreateCommand(request_msg); - MockAppPtr mock_app; - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - - Event event(hmi_apis::FunctionID::VR_PerformInteraction); - event.set_smart_object(*response_msg_vr); - - command->Init(); - command->on_event(event); - MessageSharedPtr response_to_mobile = - CreateMessage(smart_objects::SmartType_Map); - (*response_to_mobile)[strings::msg_params][strings::result_code] = - static_cast(am::mobile_api::Result::GENERIC_ERROR); - EXPECT_CALL( - mock_message_helper_, - CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) - .WillOnce(Return(response_to_mobile)); - - MessageSharedPtr vr_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - command->onTimeOut(); - - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::success].asBool(), - false); - EXPECT_EQ( - (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), - static_cast(am::mobile_api::Result::GENERIC_ERROR)); -} - -TEST_F(PerformInteractionRequestTest, - OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_from_mobile = - CreateMessage(smart_objects::SmartType_Map); - (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = - mobile_apis::InteractionMode::VR_ONLY; - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - command->Init(); - - MockAppPtr mock_app; - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); - - MessageSharedPtr response_msg_vr = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; - (*response_msg_vr)[am::strings::msg_params][am::strings::info] = - "VR is not supported by system"; - - am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); - event_vr.set_smart_object(*response_msg_vr); - - MessageSharedPtr response_msg_ui = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - - am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); - event_ui.set_smart_object(*response_msg_ui); - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_vr); - command->on_event(event_ui); - - ResultCommandExpectations(response_to_mobile, - "VR is not supported by system"); -} - -TEST_F(PerformInteractionRequestTest, - OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_from_mobile = - CreateMessage(smart_objects::SmartType_Map); - (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; - (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = - mobile_apis::InteractionMode::VR_ONLY; - utils::SharedPtr command = - CreateCommand(msg_from_mobile); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - MessageSharedPtr response_msg_vr = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_vr)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); - event_vr.set_smart_object(*response_msg_vr); - - MessageSharedPtr response_msg_ui = - CreateMessage(smart_objects::SmartType_Map); - (*response_msg_ui)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*response_msg_ui)[strings::msg_params][strings::cmd_id] = kCommandId; - (*response_msg_ui)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); - event_ui.set_smart_object(*response_msg_ui); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_vr); - - EXPECT_CALL(*mock_app_, is_perform_interaction_active()) - .WillOnce(Return(false)); - EXPECT_CALL(*mock_app_, DeletePerformInteractionChoiceSet(_)); - - command->on_event(event_ui); - - ResultCommandExpectations(response_to_mobile, - "UI is not supported by system"); -} - -} // namespace perform_interaction_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/put_file_test.cc b/src/components/application_manager/test/commands/mobile/put_file_test.cc deleted file mode 100644 index 4a89160772..0000000000 --- a/src/components/application_manager/test/commands/mobile/put_file_test.cc +++ /dev/null @@ -1,416 +0,0 @@ -/* - * Copyright (c) 2016, 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 "commands/commands_test.h" -#include "commands/command_request_test.h" - -#include "mobile/put_file_response.h" -#include "mobile/put_file_request.h" - -#include "utils/make_shared.h" -#include "utils/file_system.h" -#include "smart_objects/smart_object.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/application.h" -#include "application_manager/mock_application.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace put_file { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::AtLeast; - -namespace am = ::application_manager; - -using am::commands::PutFileRequest; -using am::commands::PutFileResponse; -using am::commands::MessageSharedPtr; -using policy_test::MockPolicyHandlerInterface; - -typedef SharedPtr PutFileRequestPtr; -typedef SharedPtr PutFileResponsePtr; - -namespace { -const uint32_t kConnectionKey = 1u; -const std::string kFileName = "sync_file_name.txt"; -const int64_t kOffset = 10u; -const int64_t kZeroOffset = 0u; -const std::string kStorageFolder = "./storage"; -const std::string kFolder = "folder"; -const std::string kAppFolder = "app_folder"; -} - -class PutFileRequestTest - : public CommandRequestTest { - public: - PutFileRequestTest() - : msg_(CreateMessage(::smart_objects::SmartType_Map)) - , mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - binary_data_.push_back(1u); - - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::msg_params][am::strings::sync_file_name] = kFileName; - (*msg_)[am::strings::msg_params][am::strings::persistent_file] = true; - (*msg_)[am::strings::msg_params][am::strings::file_type] = - mobile_apis::FileType::JSON; - (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; - - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - ON_CALL(*mock_app_, hmi_level()) - .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); - } - - void ExpectReceiveMessageFromSDK() { - EXPECT_CALL(mock_policy_handler_, - ReceiveMessageFromSDK(kFileName, binary_data_)) - .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); - } - void ExpectManageMobileCommandWithResultCode( - const mobile_apis::Result::eType code) { - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(code), - am::commands::Command::CommandSource::SOURCE_SDL)); - } - - MessageSharedPtr msg_; - MockAppPtr mock_app_; - MockPolicyHandlerInterface mock_policy_handler_; - std::vector binary_data_; -}; - -class PutFileResponceTest : public CommandsTest { - public: - PutFileResponceTest() : message_(CreateMessage()) {} - - void SetUp() OVERRIDE { - command_sptr_ = CreateCommand(message_); - } - - MessageSharedPtr message_; - SharedPtr command_sptr_; -}; - -TEST_F(PutFileResponceTest, Run_InvalidApp_ApplicationNotRegisteredResponce) { - ::smart_objects::SmartObject& message_ref = *message_; - - message_ref[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - utils::SharedPtr null_application_sptr; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(null_application_sptr)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - SendMessageToMobile( - MobileResultCodeIs(mobile_apis::Result::APPLICATION_NOT_REGISTERED), - _)); - command_sptr_->Run(); -} - -TEST_F(PutFileResponceTest, Run_ApplicationRegistered_Success) { - ::smart_objects::SmartObject& message_ref = *message_; - - message_ref[am::strings::params][am::strings::connection_key] = - kConnectionKey; - message_ref[am::strings::msg_params][am::strings::success] = true; - - utils::SharedPtr application_sptr = - utils::MakeShared(); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(application_sptr)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - command_sptr_->Run(); -} - -TEST_F(PutFileRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - ExpectManageMobileCommandWithResultCode( - mobile_apis::Result::APPLICATION_NOT_REGISTERED); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_HmiLevelNone_UNSUCCESS) { - EXPECT_CALL(*mock_app_, hmi_level()) - .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); - - const uint32_t settings_put_file_in_none = 1u; - const uint32_t app_put_file_in_none_count = 2u; - EXPECT_CALL(app_mngr_settings_, put_file_in_none()) - .WillOnce(ReturnRef(settings_put_file_in_none)); - EXPECT_CALL(*mock_app_, put_file_in_none_count()) - .WillOnce(Return(app_put_file_in_none_count)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_BinaryDataDoesNotExists_UNSUCCESS) { - (*msg_)[am::strings::params].erase(am::strings::binary_data); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_SyncFileNameDoesNotExists_UNSUCCESS) { - (*msg_)[am::strings::msg_params].erase(am::strings::sync_file_name); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_FileTypeDoesNotExists_UNSUCCESS) { - (*msg_)[am::strings::msg_params].erase(am::strings::file_type); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_BinaryDataGreaterThanAvaliableSpace_UNSUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = false; - - ExpectReceiveMessageFromSDK(); - EXPECT_CALL(app_mngr_settings_, app_storage_folder()) - .WillOnce(ReturnRef(kStorageFolder)); - EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); - - const uint32_t avaliable_space = 0u; - EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) - .WillOnce(Return(avaliable_space)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::OUT_OF_MEMORY); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_IvalidCreationDirectory_UNSUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = true; - - ExpectReceiveMessageFromSDK(); - - const std::string storage_folder = "/storage"; - EXPECT_CALL(app_mngr_settings_, system_files_path()) - .WillOnce(ReturnRef(storage_folder)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::GENERIC_ERROR); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_IvalidUpdateFile_UNSUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = false; - - ExpectReceiveMessageFromSDK(); - EXPECT_CALL(app_mngr_settings_, app_storage_folder()) - .WillOnce(ReturnRef(kStorageFolder)); - EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); - - const uint32_t avaliable_space = 2u; - EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) - .WillOnce(Return(avaliable_space)) - .WillOnce(Return(avaliable_space)); - - const std::string file_path = kStorageFolder + "/" + kAppFolder; - EXPECT_CALL(app_mngr_, - SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(false)); - EXPECT_CALL(*mock_app_, UpdateFile(_)).WillOnce(Return(false)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_AddFile_SUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = false; - - ExpectReceiveMessageFromSDK(); - EXPECT_CALL(app_mngr_settings_, app_storage_folder()) - .WillOnce(ReturnRef(kStorageFolder)); - EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); - - const uint32_t avaliable_space = 2u; - EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) - .WillOnce(Return(avaliable_space)) - .WillOnce(Return(avaliable_space)); - - const std::string file_path = kStorageFolder + "/" + kAppFolder; - EXPECT_CALL(app_mngr_, - SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(true)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_SendOnPutFileNotification_SUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = true; - - ExpectReceiveMessageFromSDK(); - EXPECT_CALL(app_mngr_settings_, system_files_path()) - .WillOnce(ReturnRef(kStorageFolder)); - EXPECT_CALL(app_mngr_, - SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::BasicCommunication_OnPutFile))) - .WillOnce(Return(true)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_InvalidPutFile_UNSUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; - (*msg_)[am::strings::msg_params][am::strings::system_file] = true; - - ExpectReceiveMessageFromSDK(); - EXPECT_CALL(app_mngr_settings_, system_files_path()) - .WillOnce(ReturnRef(kStorageFolder)); - EXPECT_CALL(app_mngr_, - SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) - .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - PutFileRequestPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(PutFileRequestTest, Run_CrcSumEqual_SendSuccessResponse) { - binary_data_ = {1u}; - (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; - const uint32_t correct_crc_sum = - 2768625435u; // calculated using the GetCrc32CheckSum method - (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = - correct_crc_sum; - - ExpectReceiveMessageFromSDK(); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); - ON_CALL(app_mngr_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kStorageFolder)); - ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); - const size_t available_space = binary_data_.size() + 1; - ON_CALL(*mock_app_, GetAvailableDiskSpace()) - .WillByDefault(Return(available_space)); - ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); - - const std::string file_path = kStorageFolder + "/" + kFolder; - EXPECT_CALL(app_mngr_, SaveBinary(binary_data_, file_path, kFileName, 0u)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, increment_put_file_in_none_count()); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); - PutFileRequestPtr command(CreateCommand(msg_)); - ASSERT_TRUE(command->Init()); - command->Run(); - // The folder was created in the "Run" method - EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); -} - -TEST_F(PutFileRequestTest, Run_CrcSumUnequal_SendCorruptedDataResponse) { - binary_data_ = {1u}; - (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; - const uint32_t incorrect_crc_sum = 0u; - (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = - incorrect_crc_sum; - - ExpectReceiveMessageFromSDK(); - ON_CALL(app_mngr_, get_settings()) - .WillByDefault(ReturnRef(app_mngr_settings_)); - ON_CALL(app_mngr_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kStorageFolder)); - ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); - const size_t available_space = binary_data_.size() + 1; - ON_CALL(*mock_app_, GetAvailableDiskSpace()) - .WillByDefault(Return(available_space)); - ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::CORRUPTED_DATA); - EXPECT_CALL(app_mngr_, SaveBinary(_, _, _, _)).Times(0); - PutFileRequestPtr command(CreateCommand(msg_)); - ASSERT_TRUE(command->Init()); - command->Run(); - // The folder was created in the "Run" method - EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); -} - -} // namespace put_file -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/read_did_request_test.cc b/src/components/application_manager/test/commands/mobile/read_did_request_test.cc deleted file mode 100644 index 5de1c8a894..0000000000 --- a/src/components/application_manager/test/commands/mobile/read_did_request_test.cc +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2016, 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/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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 "application_manager/commands/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 am::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(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(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/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc deleted file mode 100644 index e31f29202e..0000000000 --- a/src/components/application_manager/test/commands/mobile/register_app_interface_request_test.cc +++ /dev/null @@ -1,533 +0,0 @@ -/* - * Copyright (c) 2016, 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/register_app_interface_request.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_application_helper.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/policies/mock_policy_handler_interface.h" -#include "protocol_handler/mock_session_observer.h" -#include "connection_handler/mock_connection_handler.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_resume_ctrl.h" -#include "application_manager/mock_hmi_interface.h" -#include "utils/data_accessor.h" -#include "utils/custom_string.h" -#include "utils/lock.h" -#include "utils/macro.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace register_app_interface_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::DoAll; - -namespace am = ::application_manager; - -using ::utils::SharedPtr; -using am::commands::MessageSharedPtr; -using am::commands::RegisterAppInterfaceRequest; - -namespace { -const uint32_t kConnectionKey = 1u; -const hmi_apis::Common_Language::eType kHmiLanguage = - hmi_apis::Common_Language::EN_US; -const mobile_apis::Language::eType kMobileLanguage = - mobile_apis::Language::EN_US; -const std::string kMacAddress = "test_mac_address"; -const std::string kAppId = "test_app_id"; -const std::string kDummyString = "test_string"; -const std::vector kDummyDiagModes; -} // namespace - -class RegisterAppInterfaceRequestTest - : public CommandRequestTest { - public: - RegisterAppInterfaceRequestTest() - : msg_(CreateMessage()) - , command_(CreateCommand(msg_)) - , app_name_("test_app_name_") - , mock_application_helper_( - application_manager_test::MockApplicationHelper:: - application_helper_mock()) { - InitGetters(); - InitLanguage(); - } - - void SetUp() OVERRIDE { - testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); - } - - void TearDown() OVERRIDE { - testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); - } - - void InitBasicMessage() { - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; - (*msg_)[am::strings::msg_params][am::strings::app_name] = app_name_; - (*msg_)[am::strings::msg_params][am::strings::language_desired] = - kHmiLanguage; - (*msg_)[am::strings::msg_params] - [am::strings::hmi_display_language_desired] = kHmiLanguage; - } - - MockAppPtr CreateBasicMockedApp() { - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(app_name_)); - ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress)); - ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); - ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); - ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); - ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); - return mock_app; - } - - void InitLanguage( - hmi_apis::Common_Language::eType ui_language = kHmiLanguage, - hmi_apis::Common_Language::eType vr_language = kHmiLanguage, - hmi_apis::Common_Language::eType tts_language = kHmiLanguage) { - ON_CALL(mock_hmi_capabilities_, active_vr_language()) - .WillByDefault(Return(vr_language)); - ON_CALL(mock_hmi_capabilities_, active_ui_language()) - .WillByDefault(Return(ui_language)); - ON_CALL(mock_hmi_capabilities_, active_tts_language()) - .WillByDefault(Return(tts_language)); - } - - void InitGetters() { - ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(true)); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - ON_CALL(app_mngr_, resume_controller()) - .WillByDefault(ReturnRef(mock_resume_crt_)); - ON_CALL(app_mngr_, connection_handler()) - .WillByDefault(ReturnRef(mock_connection_handler_)); - ON_CALL(mock_connection_handler_, get_session_observer()) - .WillByDefault(ReturnRef(mock_session_observer_)); - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(mock_hmi_capabilities_)); - ON_CALL(app_mngr_settings_, sdl_version()) - .WillByDefault(ReturnRef(kDummyString)); - ON_CALL(mock_hmi_capabilities_, ccpu_version()) - .WillByDefault(ReturnRef(kDummyString)); - ON_CALL(app_mngr_settings_, supported_diag_modes()) - .WillByDefault(ReturnRef(kDummyDiagModes)); - ON_CALL(mock_policy_handler_, GetAppRequestTypes(_)) - .WillByDefault(Return(std::vector())); - ON_CALL(mock_policy_handler_, GetAppRequestTypeState(_)) - .WillByDefault(Return(policy::RequestType::State::EMPTY)); - ON_CALL(mock_policy_handler_, GetAppRequestSubTypes(_)) - .WillByDefault(Return(std::vector())); - ON_CALL(mock_policy_handler_, GetAppRequestSubTypeState(_)) - .WillByDefault(Return(policy::RequestSubType::State::EMPTY)); - ON_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) - .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); - ON_CALL(app_mngr_, GetDeviceTransportType(_)) - .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); - ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); - ON_CALL(app_mngr_, application_by_policy_id(_)) - .WillByDefault(Return(ApplicationSharedPtr())); - ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - } - - void SetCommonExpectionsOnSwitchedApplication( - MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { - EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); - - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(response_result_code), _)); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) - .Times(0); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Buttons_OnButtonSubscription))) - .Times(0); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_ChangeRegistration))).Times(0); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_ChangeRegistration))).Times(0); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::VR_ChangeRegistration))).Times(0); - - EXPECT_CALL( - app_mngr_, - OnApplicationSwitched( - MockAppPtr::static_pointer_cast( - mock_app))); - } - - MessageSharedPtr msg_; - SharedPtr command_; - - const utils::custom_string::CustomString app_name_; - sync_primitives::Lock lock_; - am::ApplicationSet app_set_; - - typedef IsNiceMock::Result MockPolicyHandlerInterface; - - typedef IsNiceMock::Result - MockResumeCtrl; - - typedef IsNiceMock::Result MockConnectionHandler; - - typedef IsNiceMock::Result MockSessionObserver; - - typedef IsNiceMock::Result MockHMICapabilities; - - MockPolicyHandlerInterface mock_policy_handler_; - MockResumeCtrl mock_resume_crt_; - MockConnectionHandler mock_connection_handler_; - MockSessionObserver mock_session_observer_; - MockHMICapabilities mock_hmi_capabilities_; - application_manager_test::MockApplicationHelper& mock_application_helper_; -}; - -TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { - EXPECT_TRUE(command_->Init()); -} - -TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { - InitBasicMessage(); - (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId; - EXPECT_CALL(app_mngr_, IsStopping()) - .WillOnce(Return(false)) - .WillOnce(Return(true)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); - - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); - - ON_CALL(app_mngr_, applications()) - .WillByDefault(Return(DataAccessor(app_set_, lock_))); - ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) - .WillByDefault(Return(true)); - policy::StatusNotifier notify_upd_manager = - utils::MakeShared(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) - .WillByDefault(Return(notify_upd_manager)); - - EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Buttons_OnButtonSubscription))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) - .Times(2); - command_->Run(); -} - -MATCHER_P(CheckHMIInterfacesRealtedData, expected_data, "") { - const bool is_result_id_correct = - mobile_apis::Result::SUCCESS == - static_cast( - (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); - - const bool are_ui_related_data_exist = - (*arg)[am::strings::msg_params].keyExists( - am::hmi_response::display_capabilities); - - const bool are_vi_related_data_exist = - (*arg)[am::strings::msg_params][am::hmi_response::vehicle_type] == - (*expected_data)[am::hmi_response::vehicle_type]; - - const bool are_vr_related_data_exist = - (*arg)[am::strings::msg_params][am::strings::vr_capabilities] == - (*expected_data)[am::strings::vr_capabilities]; - - return is_result_id_correct && are_ui_related_data_exist && - are_vi_related_data_exist && are_vr_related_data_exist; -} - -TEST_F(RegisterAppInterfaceRequestTest, - Run_HmiInterfacesStateAvailable_SUCCESS) { - InitBasicMessage(); - - EXPECT_CALL(app_mngr_, IsStopping()) - .WillOnce(Return(false)) - .WillOnce(Return(true)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); - EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); - EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); - - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())) - .WillRepeatedly(Return(mock_app)); - - MessageSharedPtr expected_message = - CreateMessage(smart_objects::SmartType_Map); - - (*expected_message)[am::hmi_response::vehicle_type] = "test_vehicle_type"; - (*expected_message)[am::strings::vr_capabilities] = "test_vr_capabilities"; - (*expected_message)[am::hmi_response::display_capabilities] = 0; - SmartObject& display_capabilities = - (*expected_message)[am::hmi_response::display_capabilities]; - display_capabilities[am::hmi_response::display_type] = "test_display_type"; - display_capabilities[am::hmi_response::display_name] = "GENERIC_DISPLAY"; - display_capabilities[am::hmi_response::text_fields] = "test_text_fields"; - display_capabilities[am::hmi_response::image_fields] = "test_image_fields"; - display_capabilities[am::hmi_response::media_clock_formats] = - "test_media_clock_formats"; - display_capabilities[am::hmi_response::num_custom_presets_available] = - "test_num_custom_presets_available"; - display_capabilities[am::hmi_response::graphic_supported] = - "test_graphic_supported"; - display_capabilities[am::hmi_response::templates_available] = - "test_templates_available"; - display_capabilities[am::hmi_response::screen_params] = "test_screen_params"; - - ON_CALL(mock_hmi_capabilities_, vehicle_type()) - .WillByDefault( - Return(&(*expected_message)[am::hmi_response::vehicle_type])); - ON_CALL(mock_hmi_capabilities_, vr_capabilities()) - .WillByDefault( - Return(&(*expected_message)[am::strings::vr_capabilities])); - ON_CALL(mock_hmi_capabilities_, display_capabilities()) - .WillByDefault( - Return(&(*expected_message)[am::hmi_response::display_capabilities])); - - ON_CALL(app_mngr_, applications()) - .WillByDefault(Return(DataAccessor(app_set_, lock_))); - ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); - ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) - .WillByDefault(Return(true)); - policy::StatusNotifier notify_upd_manager = - utils::MakeShared(); - ON_CALL(mock_policy_handler_, AddApplication(_, _)) - .WillByDefault(Return(notify_upd_manager)); - - EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Buttons_OnButtonSubscription))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::VR_ChangeRegistration))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_ChangeRegistration))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::UI_ChangeRegistration))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) - .Times(2); - - command_->Run(); -} - -TEST_F(RegisterAppInterfaceRequestTest, - SwitchApplication_CorrectHash_ExpectNoCleanupSuccess) { - InitBasicMessage(); - - const std::string request_hash_id = "abc123"; - (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; - - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); - - EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); - - EXPECT_CALL( - mock_resume_crt_, - CheckApplicationHash( - MockAppPtr::static_pointer_cast( - mock_app), - request_hash_id)).WillOnce(Return(true)); - - EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0); - - EXPECT_CALL(mock_application_helper_, RecallApplicationData(_, _)).Times(0); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - SetCommonExpectionsOnSwitchedApplication(mock_app, - mobile_apis::Result::SUCCESS); - - command_->Run(); -} - -TEST_F(RegisterAppInterfaceRequestTest, - SwitchApplication_WrongHash_ExpectCleanupResumeFailed) { - InitBasicMessage(); - - const std::string request_hash_id = "abc123"; - (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; - - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); - - EXPECT_CALL( - mock_resume_crt_, - CheckApplicationHash( - MockAppPtr::static_pointer_cast( - mock_app), - request_hash_id)).WillOnce(Return(false)); - - EXPECT_CALL( - mock_application_helper_, - RecallApplicationData( - MockAppPtr::static_pointer_cast( - mock_app), - _)); - - EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - SetCommonExpectionsOnSwitchedApplication(mock_app, - mobile_apis::Result::RESUME_FAILED); - - command_->Run(); -} - -TEST_F(RegisterAppInterfaceRequestTest, - SwitchApplication_NoHash_ExpectCleanupResumeFailed) { - InitBasicMessage(); - - MockAppPtr mock_app = CreateBasicMockedApp(); - EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); - - EXPECT_CALL( - mock_application_helper_, - RecallApplicationData( - MockAppPtr::static_pointer_cast( - mock_app), - _)); - - EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - SetCommonExpectionsOnSwitchedApplication(mock_app, - mobile_apis::Result::RESUME_FAILED); - - command_->Run(); -} - -} // namespace register_app_interface_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc deleted file mode 100644 index 4631f0394c..0000000000 --- a/src/components/application_manager/test/commands/mobile/reset_global_properties_test.cc +++ /dev/null @@ -1,578 +0,0 @@ -/* - * Copyright (c) 2016, 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 "mobile/reset_global_properties_request.h" -#include "mobile/reset_global_properties_response.h" - -#include "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "interfaces/HMI_API.h" -#include "interfaces/MOBILE_API.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/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace reset_global_properties { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -namespace am = ::application_manager; - -using am::commands::ResetGlobalPropertiesRequest; -using am::commands::ResetGlobalPropertiesResponse; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using am::MockMessageHelper; - -typedef SharedPtr ResetGlobalPropertiesRequestPtr; -typedef SharedPtr - ResetGlobalPropertiesResponsePtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 10u; -} // namespace - -class ResetGlobalPropertiesRequestTest - : public CommandRequestTest { - protected: - ResetGlobalPropertiesRequestTest() - : msg_(CreateMessage()), mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - - command_ = CreateCommand(msg_); - - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillByDefault(Return(kCorrelationId)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - } - - MessageSharedPtr msg_; - MockAppPtr mock_app_; - ResetGlobalPropertiesRequestPtr command_; -}; - -class ResetGlobalPropertiesResponseTest - : public CommandsTest {}; - -TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidApp_UNSUCCESS) { - MockAppPtr invalid_app; - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); - - MessageSharedPtr command_result; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); - - command_->Run(); - EXPECT_EQ( - (*command_result)[am::strings::msg_params][am::strings::success].asBool(), - false); - EXPECT_EQ( - (*command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(mobile_apis::Result::APPLICATION_NOT_REGISTERED)); -} - -TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::HELPPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][2] = - mobile_apis::GlobalProperty::VRHELPTITLE; - (*msg_)[am::strings::msg_params][am::strings::properties][3] = - mobile_apis::GlobalProperty::MENUNAME; - (*msg_)[am::strings::msg_params][am::strings::properties][4] = - mobile_apis::GlobalProperty::MENUICON; - (*msg_)[am::strings::msg_params][am::strings::properties][5] = - mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; - - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - smart_objects::SmartObject so_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Array); - EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - smart_objects::SmartObject timeout_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Map); - timeout_prompt[am::strings::text] = time_out_prompt[0]; - timeout_prompt[am::strings::type] = - hmi_apis::Common_SpeechCapabilities::SC_TEXT; - - smart_objects::SmartObject so_time_out_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - so_time_out_prompt[0] = timeout_prompt; - - EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); - - EXPECT_CALL(*mock_app_, reset_vr_help_title()); - EXPECT_CALL(*mock_app_, reset_vr_help()); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - smart_objects::SmartObjectSPtr vr_help; // = NULL; - EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) - .WillOnce(Return(vr_help)); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - - command_->Run(); -} - -TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::HELPPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][2] = - mobile_apis::GlobalProperty::VRHELPTITLE; - (*msg_)[am::strings::msg_params][am::strings::properties][3] = - mobile_apis::GlobalProperty::MENUNAME; - (*msg_)[am::strings::msg_params][am::strings::properties][4] = - mobile_apis::GlobalProperty::MENUICON; - (*msg_)[am::strings::msg_params][am::strings::properties][5] = - mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; - - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - smart_objects::SmartObject so_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Array); - EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - smart_objects::SmartObject timeout_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Map); - timeout_prompt[am::strings::text] = time_out_prompt[0]; - timeout_prompt[am::strings::type] = - hmi_apis::Common_SpeechCapabilities::SC_TEXT; - - smart_objects::SmartObject so_time_out_prompt = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - so_time_out_prompt[0] = timeout_prompt; - - EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); - - EXPECT_CALL(*mock_app_, reset_vr_help_title()); - EXPECT_CALL(*mock_app_, reset_vr_help()); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - smart_objects::SmartObjectSPtr vr_help = - ::utils::MakeShared( - smart_objects::SmartType_Map); - EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) - .WillOnce(Return(vr_help)); - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::hmi_request::menu_title] = ""; - - EXPECT_CALL(*mock_app_, - set_menu_title(msg_params[am::hmi_request::menu_title])); - - const smart_objects::SmartObjectSPtr so_help_prompt = - ::utils::MakeShared( - smart_objects::SmartType_Map); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(so_help_prompt.get())); - EXPECT_CALL(*mock_app_, timeout_prompt()) - .WillOnce(Return(so_help_prompt.get())); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - - command_->Run(); -} - -TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - Event event(hmi_apis::FunctionID::INVALID_ENUM); - // EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command_->on_event(event); -} - -TEST_F(ResetGlobalPropertiesRequestTest, - OnEvent_UI_SetGlobalProperties_SUCCESS) { - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - const hmi_apis::Common_Result::eType result_code = - hmi_apis::Common_Result::SUCCESS; - (*msg_)[am::strings::params][am::hmi_response::code] = result_code; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::VRHELPTITLE; - - EXPECT_CALL(*mock_app_, reset_vr_help_title()); - EXPECT_CALL(*mock_app_, reset_vr_help()); - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - smart_objects::SmartObjectSPtr vr_help = - ::utils::MakeShared( - smart_objects::SmartType_Map); - EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) - .WillOnce(Return(vr_help)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - - command_->Run(); - - event.set_smart_object(*msg_); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), - am::commands::Command::SOURCE_SDL)); - - command_->on_event(event); -} - -TEST_F(ResetGlobalPropertiesRequestTest, - OnEvent_TTS_SetGlobalProperties_SUCCESS) { - Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::MENUICON; - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); - - smart_objects::SmartObjectSPtr prompt = - utils::MakeShared(); - *prompt = "prompt"; - - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - MessageSharedPtr ui_msg = CreateMessage(); - (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - (*ui_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); - ui_event.set_smart_object(*ui_msg); - - command_->Run(); - command_->on_event(ui_event); - event.set_smart_object(*msg_); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::WARNINGS), - am::commands::Command::SOURCE_SDL)); - - command_->on_event(event); -} - -TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { - MessageSharedPtr message(CreateMessage()); - ResetGlobalPropertiesResponsePtr command( - CreateCommand(message)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(message, _)); - command->Run(); -} - -TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::VRHELPTITLE; - - EXPECT_CALL(*mock_app_, reset_vr_help_title()); - EXPECT_CALL(*mock_app_, reset_vr_help()); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - smart_objects::SmartObjectSPtr vr_help = - ::utils::MakeShared( - smart_objects::SmartType_Map); - EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) - .WillOnce(Return(vr_help)); - - EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); - - ResetGlobalPropertiesRequestPtr command = - CreateCommand(msg_); - command->Run(); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), - am::commands::Command::SOURCE_SDL)); - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(ResetGlobalPropertiesRequestTest, - Run_WaitTTS_Timeout_GENERIC_ERROR_TTSNotRespond) { - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::MENUICON; - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); - - smart_objects::SmartObjectSPtr prompt = - utils::MakeShared(); - *prompt = "prompt"; - - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - - ResetGlobalPropertiesRequestPtr command = - CreateCommand(msg_); - command->Run(); - - // Received response only from UI - MessageSharedPtr ui_msg = CreateMessage(); - (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - (*ui_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - (*ui_msg)[am::strings::msg_params] = - SmartObject(smart_objects::SmartType_Map); - Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); - ui_event.set_smart_object(*ui_msg); - command->on_event(ui_event); - - // TTS doesn't respond, so timeout should send generic error - smart_objects::SmartObjectSPtr response = - utils::MakeShared(); - (*response)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::GENERIC_ERROR; - EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) - .WillOnce(Return(response)); - const std::string info = "TTS component does not respond"; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), - am::commands::Command::SOURCE_SDL)); - command->onTimeOut(); -} - -TEST_F(ResetGlobalPropertiesRequestTest, - Run_WaitUI_Timeout_GENERIC_ERROR_UINotRespond) { - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::MENUICON; - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); - - smart_objects::SmartObjectSPtr prompt = - utils::MakeShared(); - *prompt = "prompt"; - - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - - command_->Run(); - - // Received response only from TTS - MessageSharedPtr tts_msg = CreateMessage(); - (*tts_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - (*tts_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - - Event tts_event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - tts_event.set_smart_object(*tts_msg); - command_->on_event(tts_event); - - // UI doesn't respond, so timeout should send generic error - smart_objects::SmartObjectSPtr response = - utils::MakeShared(); - (*response)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::GENERIC_ERROR; - EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) - .WillOnce(Return(response)); - - const std::string info = "UI component does not respond"; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), - am::commands::Command::SOURCE_SDL)); - command_->onTimeOut(); -} - -TEST_F(ResetGlobalPropertiesRequestTest, - Run_WaitUIAndTTS_Timeout_GENERIC_ERROR_TTSAndUINotRespond) { - Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; - - (*msg_)[am::strings::msg_params][am::strings::properties][0] = - mobile_apis::GlobalProperty::TIMEOUTPROMPT; - (*msg_)[am::strings::msg_params][am::strings::properties][1] = - mobile_apis::GlobalProperty::MENUICON; - - std::vector time_out_prompt; - time_out_prompt.push_back("time_out"); - EXPECT_CALL(app_mngr_settings_, time_out_promt()) - .WillOnce(ReturnRef(time_out_prompt)); - - EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); - - smart_objects::SmartObjectSPtr prompt = - utils::MakeShared(); - *prompt = "prompt"; - - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); - - EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); - - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - - command_->Run(); - // TTS and UI don't respond, so timeout should send generic error - std::string info = "TTS, UI component does not respond"; - smart_objects::SmartObjectSPtr response = - utils::MakeShared(); - (*response)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::GENERIC_ERROR; - EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) - .WillOnce(Return(response)); - - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), - am::commands::Command::SOURCE_SDL)); - command_->onTimeOut(); -} - -} // namespace reset_global_properties -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc b/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc deleted file mode 100644 index 0d57b5413a..0000000000 --- a/src/components/application_manager/test/commands/mobile/scrollable_message_test.cc +++ /dev/null @@ -1,292 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/scrollable_message_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace scrollable_message_request { - -namespace am = application_manager; -namespace hmi_response = am::hmi_response; -namespace mobile_result = mobile_apis::Result; -namespace am = ::application_manager; - -using am::commands::ScrollableMessageRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Eq; -using ::testing::Ref; -using ::testing::Return; -using ::testing::ReturnRef; - -using namespace am::strings; -using test::components::policy_test::MockPolicyHandlerInterface; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kTimeOut = 30000u; -const uint32_t kCorrelationId = 10u; -const uint32_t kFunctionID = 3u; -} // namespace - -class ScrollableMessageRequestTest - : public CommandRequestTest { - public: - typedef TypeIf, - application_manager_test::MockHMICapabilities>::Result - MockHMICapabilities; - sync_primitives::Lock lock_; - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void SetUp() OVERRIDE { - mock_app_ = CreateMockApp(); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - command_ = CreateCommand(msg_); - } - - MockPolicyHandlerInterface mock_policy_handler_; - MockAppPtr mock_app_; - MessageSharedPtr msg_; - SharedPtr command_; -}; - -typedef ScrollableMessageRequestTest::MockHMICapabilities MockHMICapabilities; - -TEST_F(ScrollableMessageRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_ui = CreateFullParamsUISO(); - (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - utils::SharedPtr command = - CreateCommand(msg_ui); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - ON_CALL(hmi_capabilities, is_ui_cooperating()).WillByDefault(Return(true)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::info] = "info1"; - - Event event(hmi_apis::FunctionID::UI_ScrollableMessage); - event.set_smart_object(*msg); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { - (*msg_)[msg_params][timeout] = kTimeOut; - (*msg_)[msg_params][interaction_mode] = - mobile_apis::InteractionMode::MANUAL_ONLY; - EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); - command_->Init(); - EXPECT_EQ(kTimeOut, command_->default_timeout()); -} - -TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { - (*msg_)[msg_params][interaction_mode] = - mobile_apis::InteractionMode::MANUAL_ONLY; - EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); - command_->Init(); - EXPECT_EQ(kTimeOut, command_->default_timeout()); -} - -TEST_F(ScrollableMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - command_->Run(); -} - -TEST_F(ScrollableMessageRequestTest, - Run_SoftButtonProcessingResultWrogParameters_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); - const mobile_apis::Result::eType processing_result = - mobile_apis::Result::ABORTED; - smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; - EXPECT_CALL( - mock_message_helper_, - ProcessSoftButtons( - msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) - .WillOnce(Return(processing_result)); - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command_))); - EXPECT_EQ(processing_result, - static_cast( - (*result_msg)[am::strings::msg_params][result_code].asInt())); -} - -TEST_F(ScrollableMessageRequestTest, Run_SoftButtonProcessingResult_SUCCESS) { - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; - (*msg_)[am::strings::params][am::strings::function_id] = kFunctionID; - (*msg_)[am::strings::msg_params][am::strings::soft_buttons][0] - [am::strings::soft_button_id] = 0; - EXPECT_CALL( - mock_message_helper_, - ProcessSoftButtons( - msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); - - MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); - EXPECT_EQ(hmi_apis::FunctionID::UI_ScrollableMessage, - static_cast( - (*result_msg)[params][function_id].asInt())); -} - -TEST_F(ScrollableMessageRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - Event event(hmi_apis::FunctionID::INVALID_ENUM); - command_->on_event(event); -} - -TEST_F(ScrollableMessageRequestTest, - OnEvent_ReceivedUIOnResetTimeoutEvent_SUCCESS) { - (*msg_)[params][connection_key] = kConnectionKey; - (*msg_)[params][correlation_id] = kCorrelationId; - EXPECT_CALL( - app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout_)); - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command_->on_event(event); -} - -TEST_F(ScrollableMessageRequestTest, - DISABLED_OnEvent_ReceivedUIScrollableMessage_SUCCESS) { - (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - Event event(hmi_apis::FunctionID::UI_ScrollableMessage); - event.set_smart_object(*msg_); - command_->on_event(event); -} - -TEST_F(ScrollableMessageRequestTest, - DISABLED_OnEvent_UnsupportedRCAndUICoop_SUCCESS) { - (*msg_)[params][hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); - Event event(hmi_apis::FunctionID::UI_ScrollableMessage); - event.set_smart_object(*msg_); - command_->on_event(event); -} - -} // namespace scrollable_message_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc b/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc deleted file mode 100644 index 933cfa18a8..0000000000 --- a/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2017 Xevo Inc. - * 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 Xevo Inc. 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 "gtest/gtest.h" - -#include "commands/commands_test.h" -#include "commands/command_request_test.h" - -#include "mobile/send_haptic_data_request.h" -#include "mobile/send_haptic_data_response.h" - -#include "interfaces/MOBILE_API.h" -#include "application_manager/application.h" -#include "application_manager/mock_application.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace send_haptic_data { - -using ::testing::_; -using ::testing::Return; - -namespace am = ::application_manager; - -using am::commands::SendHapticDataRequest; -using am::commands::SendHapticDataResponse; -using am::commands::MessageSharedPtr; - -typedef SharedPtr SendHapticDataRequestPtr; -typedef SharedPtr SendHapticDataResponsePtr; - -namespace { -const uint32_t kConnectionKey = 1u; -} - -class SendHapticDataRequestTest - : public CommandRequestTest { - public: - SendHapticDataRequestTest() - : msg_(CreateMessage(::smart_objects::SmartType_Map)) - , mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - } - - MessageSharedPtr msg_; - MockAppPtr mock_app_; -}; - -class SendHapticDataResponseTest - : public CommandsTest { - public: - SendHapticDataResponseTest() : message_(CreateMessage()) {} - - void SetUp() OVERRIDE { - command_sptr_ = CreateCommand(message_); - } - - MessageSharedPtr message_; - SharedPtr command_sptr_; -}; - -TEST_F(SendHapticDataRequestTest, Run_SUCCESS) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand( - HMIResultCodeIs(hmi_apis::FunctionID::UI_SendHapticData))) - .WillOnce(Return(true)); - - SendHapticDataRequestPtr command(CreateCommand(msg_)); - - command->Init(); - command->Run(); -} - -TEST_F(SendHapticDataRequestTest, Run_DISALLOWED) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(false)); - - EXPECT_CALL(*mock_app_, mobile_projection_enabled()).WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).WillOnce(Return(true)); - - SendHapticDataRequestPtr command(CreateCommand(msg_)); - - command->Init(); - command->Run(); -} - -TEST_F(SendHapticDataRequestTest, OnEvent_SUCCESS) { - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), - am::commands::Command::SOURCE_SDL)); - - (*msg_)[am::strings::msg_params] = 0; - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - Event event(hmi_apis::FunctionID::UI_SendHapticData); - event.set_smart_object(*msg_); - SendHapticDataRequestPtr command(CreateCommand(msg_)); - - command->Init(); - command->on_event(event); -} - -TEST_F(SendHapticDataResponseTest, Run_Success) { - ::smart_objects::SmartObject& message_ref = *message_; - message_ref[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::SUCCESS; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - command_sptr_->Init(); - command_sptr_->Run(); -} - -} // namespace send_haptic_data -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/send_location_request_test.cc b/src/components/application_manager/test/commands/mobile/send_location_request_test.cc deleted file mode 100644 index 0cff846f31..0000000000 --- a/src/components/application_manager/test/commands/mobile/send_location_request_test.cc +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/send_location_request.h" -#include "application_manager/mock_hmi_capabilities.h" -#include "application_manager/mock_message_helper.h" -#include "utils/shared_ptr.h" -#include "commands/command_request_test.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace send_location_request { - -using application_manager::commands::MessageSharedPtr; -using application_manager::commands::SendLocationRequest; -using application_manager::MockMessageHelper; -using test::components::application_manager_test::MockHMICapabilities; -using smart_objects::SmartObject; -using utils::SharedPtr; -using testing::_; -using testing::Return; -using testing::ReturnRef; - -namespace strings = application_manager::strings; -namespace hmi_response = application_manager::hmi_response; -namespace Common_TextFieldName = hmi_apis::Common_TextFieldName; - -namespace { -const uint32_t kConnectionKey = 1u; -const uint32_t kFunctionID = 2u; -const uint32_t kAppID = 3u; -const double kLongitudeDegrees = 13.4; -const std::string kLocationDescription = "Location_Description"; -const std::string kNewLine = "\\n"; -const std::string kAddressLine = "Address_Line"; -const std::string kPhoneNumber = "Phone_number"; -const std::string kCorrectAddress = "Correct address"; -const std::string kEmptyAddress = ""; -const std::string kAddressWithWrongSyntax = "Wrong Syntax\\n"; -} // namespace - -class SendLocationRequestTest - : public CommandRequestTest { - public: - class UnwrappedSendLocationRequest : public SendLocationRequest { - public: - UnwrappedSendLocationRequest( - const MessageSharedPtr& message, - application_manager::ApplicationManager& application_manager) - : SendLocationRequest(message, application_manager) {} - - ::application_manager::CommandParametersPermissions& - get_parameters_permissions() { - return parameters_permissions_; - } - }; - - typedef SharedPtr CommandSPrt; - - SendLocationRequestTest() { - mock_app_ = CreateMockApp(); - disp_cap_ = utils::MakeShared(smart_objects::SmartType_Map); - message_ = CreateMessage(); - command_ = CreateCommand(message_); - } - - void InitialSetup(MessageSharedPtr message_) { - (*message_)[strings::params][strings::connection_key] = kConnectionKey; - (*message_)[strings::params][strings::function_id] = kFunctionID; - (*message_)[strings::msg_params] = - SmartObject(smart_objects::SmartType_Map); - (*message_)[strings::msg_params][strings::address] = kCorrectAddress; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - AllowMandatoryFields(); - } - - void HMICapabilitiesSetupHelper() { - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) - .WillOnce(Return(true)); - } - - void HMICapabilitiesSetupWithArguments( - Common_TextFieldName::eType field_name) { - HMICapabilitiesSetupHelper(); - (*disp_cap_)[hmi_response::text_fields] = - SmartObject(smart_objects::SmartType_Array); - (*disp_cap_)[hmi_response::text_fields][0] = - SmartObject(smart_objects::SmartType_Map); - (*disp_cap_)[hmi_response::text_fields][0][strings::name] = field_name; - EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) - .Times(2) - .WillRepeatedly(Return(disp_cap_.get())); - } - - void FinishSetup() { - EXPECT_CALL(*mock_app_, hmi_app_id()).WillOnce(Return(kAppID)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Navigation_SendLocation))); - } - - void FinishSetupCancelled(mobile_apis::Result::eType result) { - EXPECT_CALL(*mock_app_, hmi_app_id()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(MobileResultCodeIs(result), _)); - } - - void AllowMandatoryFields() { - application_manager::CommandParametersPermissions& permissions = - command_->get_parameters_permissions(); - permissions.allowed_params.insert(strings::longitude_degrees); - permissions.allowed_params.insert(strings::latitude_degrees); - } - - MockAppPtr mock_app_; - MockHMICapabilities mock_hmi_capabilities_; - SharedPtr disp_cap_; - MessageSharedPtr message_; - CommandSPrt command_; -}; - -TEST_F(SendLocationRequestTest, Run_InvalidApp_Success) { - (*message_)[strings::params][strings::connection_key] = kConnectionKey; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - FinishSetupCancelled(mobile_apis::Result::APPLICATION_NOT_REGISTERED); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_DeliveryMode_Success) { - InitialSetup(message_); - SmartObject msg_params = (*message_)[strings::msg_params]; - msg_params[strings::delivery_mode] = SmartObject(); - (*message_)[strings::msg_params] = msg_params; - msg_params.erase(strings::delivery_mode); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationNameIsAllowed_Success) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationNameIsNotAllowed_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); - FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationNameWrongSyntax_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_name] = "Location_Name\\n"; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); - FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsAllowed_Success) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_description] = - kLocationDescription; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsNotAllowed_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_description] = - kLocationDescription; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); - FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationDescriptionWrongSyntax_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_description] = - kLocationDescription + kNewLine; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); - FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_AddressLinesAreAllowed_Success) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::address_lines] = - SmartObject(smart_objects::SmartType_Array); - (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_AddressLinesAreNotAllowed_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::address_lines] = - SmartObject(smart_objects::SmartType_Array); - (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); - FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_AddressLinesWrongSyntax_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::address_lines] = - SmartObject(smart_objects::SmartType_Array); - (*message_)[strings::msg_params][strings::address_lines][0] = - kAddressLine + kNewLine; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); - FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_PhoneNumberIsAllowed_Success) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_PhoneNumberIsNotAllowed_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); - FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_PhoneNumberWrongSyntax_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::phone_number] = - kPhoneNumber + kNewLine; - HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); - FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_AddressesContainWrongSyntax_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::address] = - SmartObject(smart_objects::SmartType_Array); - (*message_)[strings::msg_params][strings::address]["Address 1"] = - kCorrectAddress; - (*message_)[strings::msg_params][strings::address]["Address 2"] = - kAddressWithWrongSyntax; - FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationImageValid_Success) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_image] = - SmartObject(smart_objects::SmartType_Map); - (*message_)[strings::msg_params][strings::location_image][strings::value] = - "1"; - EXPECT_CALL( - mock_message_helper_, - VerifyImage( - (*message_)[strings::msg_params][strings::location_image], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - FinishSetup(); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_LocationImageInvalid_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::location_image] = - SmartObject(smart_objects::SmartType_Map); - (*message_)[strings::msg_params][strings::location_image][strings::value] = - "1"; - EXPECT_CALL( - mock_message_helper_, - VerifyImage( - (*message_)[strings::msg_params][strings::location_image], _, _)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); - FinishSetupCancelled(mobile_apis::Result::ABORTED); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, Run_HMIUINotCoop_Cancelled) { - InitialSetup(message_); - (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; - (*disp_cap_)[hmi_response::text_fields] = - SmartObject(smart_objects::SmartType_Array); - (*disp_cap_)[hmi_response::text_fields][0] = - SmartObject(smart_objects::SmartType_Map); - (*disp_cap_)[hmi_response::text_fields][0][strings::name] = - Common_TextFieldName::phoneNumber; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(mock_hmi_capabilities_)); - EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) - .WillOnce(Return(false)); - FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); - command_->Run(); -} - -TEST_F(SendLocationRequestTest, OnEvent_Success) { - mobile_apis::Result::eType response_code = mobile_apis::Result::SUCCESS; - (*message_)[strings::params][hmi_response::code] = response_code; - (*message_)[strings::params][strings::connection_key] = kConnectionKey; - - Event event(hmi_apis::FunctionID::Navigation_SendLocation); - event.set_smart_object(*message_); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) - .WillOnce(Return(false)); - command_->on_event(event); -} - -TEST_F(SendLocationRequestTest, OnEvent_Cancelled) { - (*message_)[strings::params][hmi_response::code] = - mobile_apis::Result::SUCCESS; - Event event(hmi_apis::FunctionID::Navigation_OnWayPointChange); - event.set_smart_object(*message_); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) - .Times(0); - command_->on_event(event); -} - -TEST_F(SendLocationRequestTest, Run_MandatoryParamsDisallowed_InvalidData) { - (*message_)[strings::params][strings::connection_key] = kConnectionKey; - (*message_)[strings::params][strings::function_id] = kFunctionID; - (*message_)[strings::msg_params] = SmartObject(smart_objects::SmartType_Map); - (*message_)[strings::msg_params][strings::address] = kCorrectAddress; - (*message_)[strings::msg_params][strings::longitude_degrees] = - kLongitudeDegrees; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - application_manager::CommandParametersPermissions& permissions = - command_->get_parameters_permissions(); - // 1st one allowed - permissions.allowed_params.insert(strings::longitude_degrees); - // 2nd one disallowed - permissions.disallowed_params.insert(strings::latitude_degrees); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); - command_->Run(); -} - -} // namespace send_location_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc b/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc deleted file mode 100644 index c5137c6e73..0000000000 --- a/src/components/application_manager/test/commands/mobile/set_app_icon_test.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/set_app_icon_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "protocol_handler/mock_protocol_handler.h" -#include "protocol_handler/mock_protocol_handler_settings.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace set_app_icon_request { - -namespace am = application_manager; -using am::commands::SetAppIconRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using am::MockHmiInterfaces; -using test::components::protocol_handler_test::MockProtocolHandler; -using test::components::protocol_handler_test::MockProtocolHandlerSettings; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -} // namespace - -class SetAppIconRequestTest - : public CommandRequestTest { - public: - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - NiceMock hmi_interfaces_; - protocol_handler_test::MockProtocolHandler mock_protocol_handler_; - protocol_handler_test::MockProtocolHandlerSettings - mock_protocol_handler_settings_; -}; - -TEST_F(SetAppIconRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { - const std::string file_path = "file_path"; - MessageSharedPtr msg_vr = CreateFullParamsUISO(); - (*msg_vr)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_vr)[am::strings::msg_params][am::strings::sync_file_name] - [am::strings::value] = file_path; - - const std::string dir_path = "./"; - ON_CALL(app_mngr_settings_, app_icons_folder()) - .WillByDefault(ReturnRef(dir_path)); - - utils::SharedPtr req_vr = - CreateCommand(msg_vr); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - ON_CALL(app_mngr_, hmi_interfaces()) - .WillByDefault(ReturnRef(hmi_interfaces_)); - ON_CALL(hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - - ON_CALL(app_mngr_, protocol_handler()) - .WillByDefault(ReturnRef(mock_protocol_handler_)); - ON_CALL(mock_protocol_handler_, get_settings()) - .WillByDefault(ReturnRef(mock_protocol_handler_settings_)); - - ON_CALL(mock_protocol_handler_settings_, max_supported_protocol_version()) - .WillByDefault( - Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); - - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(*mock_app, set_app_icon_path(_)).WillByDefault(Return(true)); - ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(file_path)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::info] = "info1"; - - Event event(hmi_apis::FunctionID::UI_SetAppIcon); - event.set_smart_object(*msg); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - req_vr->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -} // namespace set_app_icon_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc b/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc deleted file mode 100644 index 0ff3c06fa0..0000000000 --- a/src/components/application_manager/test/commands/mobile/set_display_layout_test.cc +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/set_display_layout_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_hmi_capabilities.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace set_display_layout_request { - -namespace am = application_manager; -namespace mobile_result = mobile_apis::Result; -using am::commands::SetDisplayLayoutRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -typedef ::utils::SharedPtr CommandPtr; - -namespace { -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationKey = 2u; -const std::string kLayout = "media"; -} // namespace - -MATCHER_P(CheckMshCorrId, corr_id, "") { - return (*arg)[am::strings::params][am::strings::correlation_id].asUInt() == - corr_id; -} - -class SetDisplayLayoutRequestTest - : public CommandRequestTest { - public: - SetDisplayLayoutRequestTest() : mock_app_(CreateMockApp()) { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - } - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - typedef TypeIf, - application_manager_test::MockHMICapabilities>::Result - MockHMICapabilities; - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - false); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - sync_primitives::Lock lock_; - MockAppPtr mock_app_; -}; - -typedef SetDisplayLayoutRequestTest::MockHMICapabilities MockHMICapabilities; - -TEST_F(SetDisplayLayoutRequestTest, - OnEvent_UIHmiUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_ui = CreateFullParamsUISO(); - (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - utils::SharedPtr command = - CreateCommand(msg_ui); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); - event.set_smart_object(*msg); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - ResultCommandExpectations(ui_command_result, "UI is not supported by system"); -} - -TEST_F(SetDisplayLayoutRequestTest, Run_InvalidApp_UNSUCCESS) { - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - CommandPtr command(CreateCommand(msg)); - - MockAppPtr invalid_mock_app; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(invalid_mock_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), - am::commands::Command::CommandSource::SOURCE_SDL)); - - command->Run(); -} - -TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { - MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - CommandPtr command(CreateCommand(msg)); - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, display_layout()).WillOnce(ReturnRef(kLayout)); - EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationKey)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetDisplayLayout)) - .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(CheckMshCorrId(kCorrelationKey))) - .WillOnce(Return(true)); - - command->Run(); -} - -TEST_F(SetDisplayLayoutRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - CommandPtr command(CreateCommand()); - am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); - SmartObject msg(smart_objects::SmartType_Map); - - event.set_smart_object(msg); - - EXPECT_CALL(app_mngr_, hmi_capabilities()).Times(0); - command->on_event(event); -} - -TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { - am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); - MessageSharedPtr msg = CreateMessage(); - - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*msg)[am::strings::msg_params][am::hmi_response::display_capabilities] = 0; - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - event.set_smart_object(*msg); - - MockHMICapabilities hmi_capabilities; - MessageSharedPtr dispaly_capabilities_msg = CreateMessage(); - (*dispaly_capabilities_msg)[am::hmi_response::templates_available] = - "templates_available"; - - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(hmi_capabilities)); - - EXPECT_CALL(hmi_capabilities, display_capabilities()) - .WillOnce(Return(dispaly_capabilities_msg.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), - am::commands::Command::CommandSource::SOURCE_SDL)); - - CommandPtr command(CreateCommand(msg)); - command->on_event(event); -} - -} // namespace set_display_layout_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc b/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc deleted file mode 100644 index e565afb03b..0000000000 --- a/src/components/application_manager/test/commands/mobile/set_global_properties_test.cc +++ /dev/null @@ -1,1250 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/set_global_properties_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace set_global_properties_request { - -namespace am = application_manager; -using am::commands::SetGlobalPropertiesRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using am::CommandsMap; -using utils::custom_string::CustomString; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 1u; -const std::string kText = "one"; -const uint32_t kPosition = 1u; -} // namespace - -class SetGlobalPropertiesRequestTest - : public CommandRequestTest { - public: - SetGlobalPropertiesRequestTest() : mock_app_(CreateMockApp()) {} - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - msg_params[am::strings::vr_help_title] = "vr_help_title"; - msg_params[am::strings::vr_help][0][am::strings::text] = "vr_help"; - msg_params[am::strings::vr_help][0][am::strings::position] = 1u; - msg_params[am::strings::help_prompt][0][am::strings::text] = "help_promt"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - MessageSharedPtr CreateMsgParams() { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - return msg; - } - - void VRArraySetupHelper(MessageSharedPtr msg, - SmartObject& vr_help_title, - SmartObject& vr_help_array) { - (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; - vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); - vr_help_array[0][am::strings::text] = kText; - vr_help_array[0][am::strings::position] = kPosition; - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - } - - void OnEventUISetupHelper(MessageSharedPtr msg, - SharedPtr command) { - SmartObject vr_help_title("yes"); - SmartObject vr_help_array(smart_objects::SmartType_Array); - VRArraySetupHelper(msg, vr_help_title, vr_help_array); - EXPECT_CALL(mock_message_helper_, - VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(app_mngr_, - RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); - EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - command->Run(); - } - - void OnEventTTSSetupHelper(MessageSharedPtr msg, - SharedPtr command) { - SmartObject help_prompt(smart_objects::SmartType_Array); - help_prompt[0][am::strings::text] = "Help_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; - SmartObject timeout_prompt(smart_objects::SmartType_Array); - timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = - timeout_prompt; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, - RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); - EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - command->Run(); - } - - void EmptyExpectationsSetupHelper() { - EXPECT_CALL(*mock_app_, set_vr_help_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_vr_help(_)).Times(0); - EXPECT_CALL(*mock_app_, vr_help_title()).Times(0); - EXPECT_CALL(*mock_app_, vr_help()).Times(0); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - } - - void ExpectInvalidData() { - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), - am::commands::Command::SOURCE_SDL)); - } - - void ExpectVerifyImageVrHelpSuccess(SmartObject& smart_obj) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(smart_obj, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - } - - void ExpectVerifyImageVrHelpUnsuccess() { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - } - - void ExpectVerifyImageSuccess(SmartObject& smart_obj) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(smart_obj, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - } - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - void ExpectationsHmiInterface_Run() { - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - } - sync_primitives::Lock lock_; - MockAppPtr mock_app_; -}; - -TEST_F(SetGlobalPropertiesRequestTest, - OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateFullParamsUISO(); - (*msg_vr)[am::strings::msg_params][am::strings::vr_commands][0] = - "vr_command"; - - utils::SharedPtr command = - CreateCommand(msg_vr); - - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - const smart_objects::SmartObject* vr_help_title = - &((*msg_vr)[am::strings::msg_params][am::strings::vr_help_title]); - const smart_objects::SmartObject* vr_help = - &((*msg_vr)[am::strings::msg_params][am::strings::vr_help]); - const smart_objects::SmartObject* vr_help_prompt = - &((*msg_vr)[am::strings::msg_params][am::strings::help_prompt]); - ON_CALL(*mock_app_, vr_help_title()).WillByDefault(Return(vr_help_title)); - ON_CALL(*mock_app_, vr_help()).WillByDefault(Return(vr_help)); - ON_CALL(*mock_app_, help_prompt()).WillByDefault(Return(vr_help_prompt)); - - ExpectationsHmiInterface_Run(); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - (*msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg); - - ON_CALL(mock_message_helper_, - VerifyImageVrHelpItems( - (*msg_vr)[am::strings::msg_params][am::strings::vr_help], _, _)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); - - ON_CALL(mock_message_helper_, VerifyImage(_, _, _)) - .WillByDefault(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*msg_vr)[am::strings::msg_params][am::strings::help_prompt], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::UI_SetGlobalProperties))) - .WillOnce(Return(true)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::TTS_SetGlobalProperties))) - .WillOnce(Return(true)); - (*msg_vr)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - Event event_vr(hmi_apis::FunctionID::TTS_SetGlobalProperties); - event_vr.set_smart_object(*msg_vr); - - command->Run(); - command->on_event(event_vr); - - MessageSharedPtr ui_command_result; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - ResultCommandExpectations(ui_command_result, "UI is not supported by system"); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_SUCCESS_Expect_MessageNotSend) { - MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); - (*response)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*response)[am::strings::msg_params][am::strings::info] = "test"; - - am::event_engine::Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - event.set_smart_object(*response); - - utils::SharedPtr command = - CreateCommand(response); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .Times(0); - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, - OnEvent_UNSUPPORTED_RESOURCE_Expect_false) { - MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); - (*response)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*response)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*response)[am::strings::msg_params][am::strings::info] = "qwe"; - - am::event_engine::Event event_tts( - hmi_apis::FunctionID::TTS_SetGlobalProperties); - event_tts.set_smart_object(*response); - am::event_engine::Event event_ui( - hmi_apis::FunctionID::UI_SetGlobalProperties); - event_tts.set_smart_object(*response); - utils::SharedPtr command = - CreateCommand(response); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - MessageSharedPtr response_to_mobile; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->Run(); - command->on_event(event_ui); - command->on_event(event_tts); - - EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] - .asBool(), - false); - EXPECT_EQ( - (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(mobile_apis::Result::INVALID_DATA)); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRNoMenuAndKeyboard_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command( - CreateCommand(msg)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - OnEventUISetupHelper(msg, command); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRWithMenuAndKeyboard_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_title("yes"); - SmartObject vr_help_array(smart_objects::SmartType_Array); - VRArraySetupHelper(msg, vr_help_title, vr_help_array); - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; - SmartObject menu_title("Menu_Title"); - (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; - SmartObject menu_icon(smart_objects::SmartType_Map); - menu_icon[am::strings::value] = "1"; - (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - - EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); - EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); - EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); - EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); - EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenMenuIcon_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_title("yes"); - (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; - SmartObject menu_icon(smart_objects::SmartType_Map); - menu_icon[am::strings::value] = "1"; - (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) - .WillOnce((Return(mobile_apis::Result::ABORTED))); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenVRHelp_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_title("yes"); - SmartObject menu_icon(smart_objects::SmartType_Map); - menu_icon[am::strings::value] = "1"; - (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; - SmartObject vr_help_array(smart_objects::SmartType_Array); - VRArraySetupHelper(msg, vr_help_title, vr_help_array); - - EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::ABORTED))); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRIncorrectSyntax_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; - SmartObject vr_help_title("wrong syntax string\\n"); - SmartObject menu_icon(smart_objects::SmartType_Map); - menu_icon[am::strings::value] = "1"; - (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; - SmartObject vr_help_array(smart_objects::SmartType_Array); - VRArraySetupHelper(msg, vr_help_title, vr_help_array); - - EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingTitle_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_array(smart_objects::SmartType_Array); - vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); - vr_help_array[0][am::strings::text] = kText; - vr_help_array[0][am::strings::position] = kPosition; - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingArray_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_title("yes"); - (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRWrongOrder_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help_title("yes"); - SmartObject vr_help_array(smart_objects::SmartType_Array); - VRArraySetupHelper(msg, vr_help_title, vr_help_array); - vr_help_array[1] = SmartObject(smart_objects::SmartType_Map); - vr_help_array[1][am::strings::text] = "two"; - vr_help_array[1][am::strings::position] = 3u; - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; - - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) - .WillOnce((Return(mobile_apis::Result::SUCCESS))); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_NoVR_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - SmartObject menu_title("Menu_Title"); - (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("Menu_Title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_VRCouldNotGenerate_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - SmartObject menu_title("Menu_Title"); - (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject* vr_help_title = NULL; - CommandsMap commands_map; - SmartObject empty_msg(smart_objects::SmartType_Map); - commands_map.insert(std::pair(1u, &empty_msg)); - DataAccessor accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(vr_help_title)); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - - SharedPtr command( - CreateCommand(msg)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), - am::commands::Command::SOURCE_SDL)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataNoDefault_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .WillOnce(Return(&vr_help_title)) - .WillOnce(Return(&vr_help_title)); - - CommandsMap commands_map; - DataAccessor accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(_)); - EXPECT_CALL(*mock_app_, app_id()); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataDefaultCreated_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .Times(2) - .WillRepeatedly(Return(&vr_help_title)); - - CommandsMap commands_map; - SmartObject command_text(smart_objects::SmartType_Map); - commands_map[0] = &command_text; - (*commands_map[0])[am::strings::vr_commands] = SmartObject("one"); - DataAccessor accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - EXPECT_CALL(*mock_app_, set_vr_help(_)); - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); - SmartObject vr_help_array(smart_objects::SmartType_Array); - EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataFromSynonyms_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject keyboard_properties(smart_objects::SmartType_Map); - (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = - keyboard_properties; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title(smart_objects::SmartType_Null); - EXPECT_CALL(*mock_app_, vr_help_title()) - .Times(2) - .WillRepeatedly(Return(&vr_help_title)); - - CommandsMap commands_map; - DataAccessor accessor(commands_map, lock_); - EXPECT_CALL(*mock_app_, commands_map()).WillOnce(Return(accessor)); - SmartObject vr_help_array(smart_objects::SmartType_Array); - vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); - vr_help_array[0][am::strings::text] = kText; - vr_help_array[0][am::strings::position] = kPosition; - SmartObject vr_synonyms(smart_objects::SmartType_Array); - vr_synonyms[0] = vr_help_array; - const CustomString name("name"); - EXPECT_CALL(*mock_app_, name()).WillOnce(ReturnRef(name)); - EXPECT_CALL(*mock_app_, set_vr_help_title(SmartObject(name))); - EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); - EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); - EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject help_prompt(smart_objects::SmartType_Array); - help_prompt[0][am::strings::text] = "Help_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; - SmartObject timeout_prompt(smart_objects::SmartType_Array); - timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); - EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyHelp_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject help_prompt(smart_objects::SmartType_Array); - help_prompt[0][am::strings::text] = "Help_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); - EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); - EXPECT_CALL(*mock_app_, set_timeout_prompt(_)).Times(0); - EXPECT_CALL(*mock_app_, timeout_prompt()).Times(0); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyTimeout_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject timeout_prompt(smart_objects::SmartType_Array); - timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; - (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); - SmartObject vr_help_title("title"); - EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); - EXPECT_CALL(*mock_app_, set_help_prompt(_)).Times(0); - EXPECT_CALL(*mock_app_, help_prompt()).Times(0); - EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); - EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - EXPECT_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_TTSIncorrectSyntax_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject timeout_prompt(smart_objects::SmartType_Array); - timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One\\n"; - (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidHelpPromptText_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject help_prompt(smart_objects::SmartType_Array); - help_prompt[0][am::strings::text] = - "invalid help prompt text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; - - ExpectVerifyImageVrHelpUnsuccess(); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidVrHelpText_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help(smart_objects::SmartType_Array); - vr_help[0][am::strings::text] = - "invalid vr_help text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; - - ExpectVerifyImageVrHelpSuccess(vr_help); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidImageValue_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject vr_help(smart_objects::SmartType_Array); - vr_help[0][am::strings::text] = "vr_help"; - vr_help[0][am::strings::image][am::strings::value] = - "invalid value text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; - - ExpectVerifyImageVrHelpSuccess(vr_help); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuIcon_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject menu_icon(smart_objects::SmartType_Array); - menu_icon[am::strings::value] = - "invalid menu icon text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::menu_icon] = menu_icon; - - ExpectVerifyImageSuccess(menu_icon); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuTitle_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject menu_title(smart_objects::SmartType_Array); - menu_title = "invalid menu title text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::menu_title] = menu_title; - - ExpectVerifyImageVrHelpUnsuccess(); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, - Run_InvalidLimitedCharacterList_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject limited_character_list(smart_objects::SmartType_Array); - limited_character_list[0] = - "invalid limited character list text with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::keyboard_properties] - [am::strings::limited_character_list] = limited_character_list; - - ExpectVerifyImageVrHelpUnsuccess(); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, - Run_InvalidAutoCompleteText_INVALID_DATA) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject auto_complete_text(smart_objects::SmartType_Array); - auto_complete_text = - "invalid auto completetext with empty line in the end\\n"; - (*msg)[am::strings::msg_params][am::strings::keyboard_properties] - [am::strings::auto_complete_text] = auto_complete_text; - - ExpectVerifyImageVrHelpUnsuccess(); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectInvalidData(); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_NoData_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - ExpectVerifyImageVrHelpUnsuccess(); - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidApp_Canceled) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - ExpectVerifyImageVrHelpUnsuccess(); - - EmptyExpectationsSetupHelper(); - - SharedPtr command( - CreateCommand(msg)); - - command->Run(); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_PendingRequest_UNSUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::SUCCESS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - - SharedPtr command( - CreateCommand(msg)); - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndSuccessResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::SUCCESS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - SharedPtr command( - CreateCommand(msg)); - OnEventUISetupHelper(msg, command); - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) - .WillOnce(Return(true)); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndWarningResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::WARNINGS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - - SharedPtr command( - CreateCommand(msg)); - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - OnEventUISetupHelper(msg, command); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) - .WillOnce(Return(true)); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidApp_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::WARNINGS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - OnEventUISetupHelper(msg, command); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(MockAppPtr())); - - EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); - - Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); - event.set_smart_object(*msg); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidEventID_Canceled) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)).Times(0); - EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); - - Event event(hmi_apis::FunctionID::TTS_Stopped); - event.set_smart_object(*msg); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, - OnEvent_TTSAndSuccessResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::SUCCESS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - OnEventTTSSetupHelper(msg, command); - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) - .WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - event.set_smart_object(*msg); - - command->on_event(event); -} - -TEST_F(SetGlobalPropertiesRequestTest, - OnEvent_TTSAndWarningsResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - const hmi_apis::Common_Result::eType response_code = - hmi_apis::Common_Result::WARNINGS; - (*msg)[am::strings::params][am::hmi_response::code] = response_code; - ON_CALL( - mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) - .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - SharedPtr command( - CreateCommand(msg)); - - OnEventTTSSetupHelper(msg, command); - - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); - - MessageSharedPtr ui_command_result; - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); - event.set_smart_object(*msg); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::WARNINGS)); -} - -} // namespace set_global_properties_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc b/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc deleted file mode 100644 index 5ef0de34b4..0000000000 --- a/src/components/application_manager/test/commands/mobile/set_media_clock_timer_test.cc +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/set_media_clock_timer_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace set_media_clock_timer_request { - -namespace am = ::application_manager; -using am::commands::SetMediaClockRequest; -using am::commands::MessageSharedPtr; -using am::event_engine::Event; -using am::MockMessageHelper; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -namespace UpdateMode = mobile_apis::UpdateMode; - -typedef SharedPtr SetMediaClockRequestPtr; - -namespace { -const uint32_t kConnectionKey = 2u; -const uint32_t kCorrelationId = 2u; -const uint32_t kAppID = 2u; -const uint32_t kHours = 2u; -const uint32_t kMinutes = 26u; -const uint32_t kSeconds = 1u; -} // namespace - -class SetMediaClockRequestTest - : public CommandRequestTest { - public: - SetMediaClockRequestTest() : mock_app_(CreateMockApp()) {} - - void SetUp() OVERRIDE { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - } - - void ResultCommandExpectations(MessageSharedPtr msg, - const std::string& info) { - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), - true); - EXPECT_EQ( - (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), - info); - } - - MessageSharedPtr CreateMsgParams() { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - return msg; - } - - void ExpectationsSetupHelper(bool is_media) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(is_media)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - } - - MockAppPtr mock_app_; -}; - -TEST_F(SetMediaClockRequestTest, - OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - utils::SharedPtr command = - CreateCommand(msg); - - MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); - (*ev_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*ev_msg)[am::strings::msg_params][am::strings::info] = - "UI is not supported by system"; - - Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); - event.set_smart_object(*ev_msg); - - EXPECT_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - ResultCommandExpectations(ui_command_result, "UI is not supported by system"); -} - -TEST_F(SetMediaClockRequestTest, Run_UpdateCountUp_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::msg_params][am::strings::update_mode] = - UpdateMode::COUNTUP; - (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::minutes] = kMinutes; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = - kMinutes; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = - kSeconds; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_UpdateCountDown_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::msg_params][am::strings::update_mode] = - UpdateMode::COUNTDOWN; - (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::minutes] = kMinutes; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::seconds] = kSeconds; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = - kMinutes; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); - EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) - .WillOnce(Return(kCorrelationId)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) - .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); - ON_CALL(mock_hmi_interfaces_, - GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) - .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_UpdateCountUpWrongTime_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::msg_params][am::strings::update_mode] = - UpdateMode::COUNTUP; - (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::minutes] = kMinutes; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::seconds] = kSeconds; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = - kMinutes; - - SharedPtr command( - CreateCommand(msg)); - - ExpectationsSetupHelper(true); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_UpdateCountDownWrongTime_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::msg_params][am::strings::update_mode] = - UpdateMode::COUNTDOWN; - (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::start_time] - [am::strings::minutes] = kMinutes; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = - kHours; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = - kMinutes; - (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = - kSeconds; - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_NoStartTime_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - (*msg)[am::strings::msg_params][am::strings::update_mode] = - UpdateMode::COUNTDOWN; - - SharedPtr command( - CreateCommand(msg)); - - ExpectationsSetupHelper(true); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_NoUpdateMode_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectationsSetupHelper(true); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_NotMediaApp_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command( - CreateCommand(msg)); - - ExpectationsSetupHelper(false); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, Run_InvalidApp_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command( - CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - EXPECT_CALL(*mock_app_, is_media_application()).Times(0); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - command->Run(); -} - -TEST_F(SetMediaClockRequestTest, OnEvent_Success) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Null); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - MockAppPtr app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); - - Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); - event.set_smart_object(*msg); - SharedPtr command( - CreateCommand(msg)); - command->on_event(event); -} - -TEST_F(SetMediaClockRequestTest, OnEvent_Canceled) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command( - CreateCommand(msg)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - Event event(hmi_apis::FunctionID::UI_Slider); - event.set_smart_object(*msg); - - command->on_event(event); -} - -} // namespace set_media_clock_timer_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/show_test.cc b/src/components/application_manager/test/commands/mobile/show_test.cc deleted file mode 100644 index 533d7585cf..0000000000 --- a/src/components/application_manager/test/commands/mobile/show_test.cc +++ /dev/null @@ -1,953 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/show_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace show_request { - -namespace am = application_manager; -using am::commands::ShowRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using test::components::policy_test::MockPolicyHandlerInterface; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kFunctionID = 3u; -} // namespace - -class ShowRequestTest : public CommandRequestTest { - public: - ShowRequestTest() { - mock_app_ = CreateMockApp(); - } - sync_primitives::Lock lock_; - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - MessageSharedPtr CreateMsgParams() { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; - return msg; - } - - void TestSetupHelper(MessageSharedPtr msg, - hmi_apis::Common_TextFieldName::eType field_name, - const char* field) { - SmartObject msg_params(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; - msg_params[field] = text_field_; - (*msg)[am::strings::msg_params] = msg_params; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - msg_params.erase(field); - msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_name] = - static_cast(field_name); - msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_text] = - text_field_; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - } - - void TestSetupHelperWrongSyntax( - MessageSharedPtr msg, - hmi_apis::Common_TextFieldName::eType field_name, - const char* field) { - SmartObject msg_params(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - msg_params[field] = text_field_; - (*msg)[am::strings::msg_params] = msg_params; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); - } - - void TestSetupHelperWithMetadata( - MessageSharedPtr msg, - hmi_apis::Common_TextFieldName::eType field_name, - const char* field, - size_t num_tags, - int32_t* field_tags, - bool set_field_text = true) { - SmartObject msg_params(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; - if (set_field_text) { - msg_params[field] = text_field_; - } - msg_params[am::strings::metadata_tags][field] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - for (size_t i = 0; i < num_tags; ++i) { - const int32_t current_tag = field_tags[i]; - msg_params[am::strings::metadata_tags][field][i] = current_tag; - } - (*msg)[am::strings::msg_params] = msg_params; - - EXPECT_EQ((*msg)[am::strings::msg_params], msg_params); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params.erase(field); - msg_params.erase(am::strings::metadata_tags); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - if (set_field_text) { - msg_params[am::hmi_request::show_strings][0] - [am::hmi_request::field_name] = - static_cast(field_name); - msg_params[am::hmi_request::show_strings][0] - [am::hmi_request::field_text] = text_field_; - msg_params[am::hmi_request::show_strings][0] - [am::hmi_request::field_types] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - for (size_t i = 0; i < num_tags; ++i) { - const int32_t current_tag = field_tags[i]; - msg_params[am::hmi_request::show_strings][0] - [am::hmi_request::field_types][i] = current_tag; - } - } - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - } - - MockAppPtr mock_app_; - std::string text_field_; -}; - -TEST_F(ShowRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_vr = CreateFullParamsUISO(); - (*msg_vr)[am::strings::msg_params][am::strings::menu_params] - [am::hmi_request::parent_id] = 10u; - (*msg_vr)[am::strings::msg_params][am::strings::menu_params] - [am::strings::menu_name] = "menu_name"; - - utils::SharedPtr command = CreateCommand(msg_vr); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; - - Event event(hmi_apis::FunctionID::UI_Show); - event.set_smart_object(*msg); - - MessageSharedPtr vr_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); - - command->on_event(event); - - EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*vr_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*vr_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*vr_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - msg_params[am::strings::soft_buttons] = "Soft_Buttons"; - (*msg)[am::strings::msg_params] = msg_params; - SmartObject creation_msg_params(msg_params); - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler)); - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - EXPECT_CALL( - mock_message_helper_, - SubscribeApplicationToSoftButton(creation_msg_params, _, kFunctionID)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_SoftButtonNotExists_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - msg_params[am::strings::soft_buttons] = ""; - (*msg)[am::strings::msg_params] = msg_params; - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()).Times(0); - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - EXPECT_CALL(*mock_app_, UnsubscribeFromSoftButtons(kFunctionID)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - msg_params[am::strings::soft_buttons] = "Soft_Buttons"; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - MockPolicyHandlerInterface mock_policy_handler; - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler)); - EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)) - .Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_Graphic_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = "1"; - msg_params[am::strings::graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_Graphic_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = "1"; - msg_params[am::strings::graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_Graphic_WrongSyntax) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = "\\n"; - msg_params[am::strings::graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_SecondaryGraphic_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = "1"; - msg_params[am::strings::secondary_graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_SecondaryGraphic_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = "1"; - msg_params[am::strings::secondary_graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) - .WillOnce(Return(mobile_apis::Result::ABORTED)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_SecondaryGraphic_WrongSyntax) { - MessageSharedPtr msg = CreateMsgParams(); - - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject graphic(smart_objects::SmartType_Map); - graphic[am::strings::value] = ""; - msg_params[am::strings::secondary_graphic] = graphic; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)).Times(0); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField1_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_1"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mainField1, - am::strings::main_field_1); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField1_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_1\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mainField1, - am::strings::main_field_1); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField2_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_2"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mainField2, - am::strings::main_field_2); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField2_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_2\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mainField2, - am::strings::main_field_2); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField3_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_3"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mainField3, - am::strings::main_field_3); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField3_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_3\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mainField3, - am::strings::main_field_3); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField4_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_4"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mainField4, - am::strings::main_field_4); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField4_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_4\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mainField4, - am::strings::main_field_4); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField1_MetadataTag) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_1"; - const size_t num_tags = 1; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField1, - am::strings::main_field_1, - num_tags, - tags); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField1_MultipleMetadataTags) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_1"; - const size_t num_tags = 5; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaTitle, - hmi_apis::Common_MetadataType::mediaArtist, - hmi_apis::Common_MetadataType::rating, - hmi_apis::Common_MetadataType::humidity, - hmi_apis::Common_MetadataType::currentTemperature}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField1, - am::strings::main_field_1, - num_tags, - tags); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField2_MetadataTag) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_2"; - const size_t num_tags = 1; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField2, - am::strings::main_field_2, - num_tags, - tags); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField3_MetadataTag) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_3"; - const size_t num_tags = 1; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField3, - am::strings::main_field_3, - num_tags, - tags); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField4_MetadataTag) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_4"; - const size_t num_tags = 1; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField4, - am::strings::main_field_4, - num_tags, - tags); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Main_Field_1"; - const size_t num_tags = 1; - int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; - TestSetupHelperWithMetadata(msg, - hmi_apis::Common_TextFieldName::mainField1, - am::strings::main_field_1, - num_tags, - tags, - false); - command->Run(); - - MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); - (*ev_msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; - (*ev_msg)[am::strings::msg_params][am::strings::info] = ""; - - Event event(hmi_apis::FunctionID::UI_Show); - event.set_smart_object(*ev_msg); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(mobile_apis::Result::WARNINGS)); -} - -TEST_F(ShowRequestTest, Run_MediaClock_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Media_Clock"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mediaClock, - am::strings::media_clock); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MediaClock_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Media_Clock\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mediaClock, - am::strings::media_clock); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MediaTrack_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Media_Track"; - TestSetupHelper(msg, - hmi_apis::Common_TextFieldName::mediaTrack, - am::strings::media_track); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_MediaTrack_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Media_Track\\n"; - TestSetupHelperWrongSyntax(msg, - hmi_apis::Common_TextFieldName::mediaTrack, - am::strings::media_track); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_StatusBar_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Status_Bar"; - TestSetupHelper( - msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_StatusBar_WrongSyntax) { - MessageSharedPtr msg = CreateMessage(); - - SharedPtr command(CreateCommand(msg)); - - text_field_ = "Status_Bar\\n"; - TestSetupHelperWrongSyntax( - msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); - command->Run(); -} - -TEST_F(ShowRequestTest, Run_Alignment_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject msg_params(smart_objects::SmartType_Map); - msg_params[am::strings::alignment] = "Alignment"; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_CustomPresets_SUCCESS) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject custom_presets(smart_objects::SmartType_Array); - custom_presets[0] = "Custom_Presets"; - msg_params[am::strings::custom_presets] = custom_presets; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); - - msg_params[am::strings::app_id] = kAppId; - msg_params[am::hmi_request::show_strings] = - smart_objects::SmartObject(smart_objects::SmartType_Array); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)); - EXPECT_CALL(*mock_app_, set_show_command(msg_params)); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_CustomPresets_WrongSyntax) { - MessageSharedPtr msg = CreateMsgParams(); - SmartObject msg_params(smart_objects::SmartType_Map); - SmartObject custom_presets(smart_objects::SmartType_Array); - custom_presets[0] = "Custom_Presets\\t"; - msg_params[am::strings::custom_presets] = custom_presets; - (*msg)[am::strings::msg_params] = msg_params; - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_InvalidApp_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(MockAppPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, Run_EmptyParams_Canceled) { - MessageSharedPtr msg = CreateMsgParams(); - - SharedPtr command(CreateCommand(msg)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*mock_app_, app_id()).Times(0); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).Times(0); - EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); - - command->Run(); -} - -TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::eType::SUCCESS; - (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); - - SharedPtr command(CreateCommand(msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), _)); - - Event event(hmi_apis::FunctionID::UI_Show); - event.set_smart_object(*msg); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - - command->on_event(event); -} - -TEST_F(ShowRequestTest, OnEvent_WarningsResultCode_SUCCESS) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::hmi_response::code] = - mobile_apis::Result::WARNINGS; - (*msg)[am::strings::params][am::hmi_response::message] = "Response Info"; - (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); - - SharedPtr command(CreateCommand(msg)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - - Event event(hmi_apis::FunctionID::UI_Show); - event.set_smart_object(*msg); - - EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); - - command->on_event(event); -} - -TEST_F(ShowRequestTest, OnEvent_WrongFunctionID_Canceled) { - MessageSharedPtr msg = CreateMessage(); - (*msg)[am::strings::params][am::hmi_response::code] = - mobile_apis::Result::SUCCESS; - - SharedPtr command(CreateCommand(msg)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - Event event(hmi_apis::FunctionID::UI_Alert); - event.set_smart_object(*msg); - - command->on_event(event); -} - -} // namespace show_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc b/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc deleted file mode 100644 index 0eb124ed37..0000000000 --- a/src/components/application_manager/test/commands/mobile/simple_notification_commands_test.cc +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2016, 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/smart_object_keys.h" -#include "application_manager/mock_message_helper.h" -#include "command_impl.h" -#include "commands/commands_test.h" -#include "mobile/on_app_interface_unregistered_notification.h" -#include "mobile/on_audio_pass_thru_notification.h" -#include "mobile/on_driver_distraction_notification.h" -#include "mobile/on_language_change_notification.h" -#include "mobile/on_permissions_change_notification.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace simple_notification_commands_test { - -namespace am = ::application_manager; -namespace commands = am::commands; - -using ::testing::_; -using ::testing::Types; -using ::testing::Return; - -template -class MobileNotificationCommandsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -typedef Types - NotificationCommandsList; - -MATCHER(CheckNotificationMessage, "") { - return (*arg)[am::strings::params][am::strings::protocol_type].asInt() == - commands::CommandImpl::mobile_protocol_type_ && - (*arg)[am::strings::params][am::strings::protocol_version].asInt() == - commands::CommandImpl::protocol_version_ && - (*arg)[am::strings::params][am::strings::message_type].asInt() == - application_manager::MessageType::kNotification; -} - -TYPED_TEST_CASE(MobileNotificationCommandsTest, NotificationCommandsList); - -TYPED_TEST(MobileNotificationCommandsTest, Run_SendMessageToMobile_SUCCESS) { - ::utils::SharedPtr command = - this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, - SendMessageToMobile(CheckNotificationMessage(), _)); - command->Run(); -} - -} // namespace simple_notification_commands_test -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/simple_response_commands_test.cc b/src/components/application_manager/test/commands/mobile/simple_response_commands_test.cc deleted file mode 100644 index c2e776ca1e..0000000000 --- a/src/components/application_manager/test/commands/mobile/simple_response_commands_test.cc +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2016, 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/helpers.h" -#include "utils/shared_ptr.h" -#include "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" -#include "mobile/perform_interaction_response.h" -#include "mobile/perform_audio_pass_thru_response.h" -#include "mobile/set_global_properties_response.h" -#include "mobile/set_media_clock_timer_response.h" -#include "mobile/show_constant_tbt_response.h" -#include "mobile/show_response.h" -#include "mobile/add_command_response.h" -#include "mobile/send_location_response.h" -#include "mobile/set_app_icon_response.h" -#include "mobile/set_display_layout_response.h" -#include "mobile/generic_response.h" -#include "mobile/set_app_icon_response.h" -#include "mobile/scrollable_message_response.h" -#include "mobile/change_registration_response.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace simple_response_commands_test { - -namespace commands = ::application_manager::commands; -namespace am = ::application_manager; - -using ::testing::_; -using ::testing::NotNull; -using ::testing::Types; - -using commands::MessageSharedPtr; - -template -class MobileResponseCommandsTest - : public CommandsTest { - public: - typedef Command CommandType; -}; - -typedef Types ResponseCommandsList; - -TYPED_TEST_CASE(MobileResponseCommandsTest, ResponseCommandsList); - -TYPED_TEST(MobileResponseCommandsTest, Run_SendResponseToMobile_SUCCESS) { - ::utils::SharedPtr command = - this->template CreateCommand(); - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, SendMessageToMobile(NotNull(), _)); - command->Run(); -} - -class GenericResponseFromHMICommandsTest - : public CommandsTest {}; - -MATCHER_P2(CheckMessageParams, success, result, "") { - const bool is_msg_type_correct = - (am::MessageType::kResponse) == - static_cast( - (*arg)[am::strings::params][am::strings::message_type].asInt()); - const bool is_success_correct = - success == (*arg)[am::strings::msg_params][am::strings::success].asBool(); - const bool is_result_code_correct = - result == - static_cast( - (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); - - using namespace helpers; - return Compare( - true, is_msg_type_correct, is_success_correct, is_result_code_correct); -} - -TEST_F(GenericResponseFromHMICommandsTest, Run_SUCCESS) { - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - - SharedPtr command( - CreateCommand(command_msg)); - - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL( - this->rpc_service_, - SendMessageToMobile( - CheckMessageParams(false, mobile_apis::Result::INVALID_DATA), false)); - - command->Run(); -} - -class ScrollableMessageResponseTest - : public CommandsTest {}; - -TEST_F(ScrollableMessageResponseTest, Run_SUCCESS) { - MessageSharedPtr message = CreateMessage(); - (*message)[am::strings::msg_params][am::strings::result_code] = - mobile_apis::Result::SUCCESS; - - MockAppPtr app(CreateMockApp()); - - SharedPtr command( - CreateCommand(message)); - EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(*app, UnsubscribeFromSoftButtons(_)); - command->Run(); -} - -} // namespace simple_response_commands_test -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/slider_test.cc b/src/components/application_manager/test/commands/mobile/slider_test.cc deleted file mode 100644 index feff8c51c0..0000000000 --- a/src/components/application_manager/test/commands/mobile/slider_test.cc +++ /dev/null @@ -1,344 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/slider_request.h" - -#include "gtest/gtest.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace slider_request { - -namespace am = application_manager; -using am::commands::SliderRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockMessageHelper; -using policy_test::MockPolicyHandlerInterface; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; - -typedef SharedPtr CommandPtr; - -namespace { -const int32_t kCommandId = 1; -const uint32_t kAppId = 1u; -const uint32_t kCmdId = 1u; -const uint32_t kConnectionKey = 2u; -const uint32_t kDefaultTimeout = 1000u; -const uint32_t kCorrelationId = 2u; -const uint32_t kFunctionId = 3u; -const uint32_t kNumTicks = 2u; -const uint32_t kPositionGreaterTicks = 3u; -const uint32_t kPositionLessTicks = 1u; -} // namespace - -class SliderRequestTest - : public CommandRequestTest { - public: - SliderRequestTest() - : mock_app_(CreateMockApp()) - , msg_(CreateMessage(smart_objects::SmartType_Map)) {} - - MessageSharedPtr CreateFullParamsUISO() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - smart_objects::SmartObject menu_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - menu_params[am::strings::position] = 10; - menu_params[am::strings::menu_name] = "LG"; - - smart_objects::SmartObject msg_params = - smart_objects::SmartObject(smart_objects::SmartType_Map); - msg_params[am::strings::cmd_id] = kCmdId; - msg_params[am::strings::menu_params] = menu_params; - msg_params[am::strings::app_id] = kAppId; - msg_params[am::strings::cmd_icon] = 1; - msg_params[am::strings::cmd_icon][am::strings::value] = "10"; - (*msg)[am::strings::msg_params] = msg_params; - - return msg; - } - - void PreConditions() { - (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg_)[am::strings::msg_params][am::strings::num_ticks] = kNumTicks; - (*msg_)[am::strings::msg_params][am::strings::position] = - kPositionLessTicks; - (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = - "slider_footer1"; - (*msg_)[am::strings::msg_params][am::strings::slider_footer][1] = - "slider_footer2"; - (*msg_)[am::strings::msg_params][am::strings::slider_header] = - "slider_header"; - - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - } - - void ExpectManageMobileCommandWithResultCode( - const mobile_apis::Result::eType code) { - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(code), - am::commands::Command::CommandSource::SOURCE_SDL)); - } - - sync_primitives::Lock lock_; - - MockAppPtr mock_app_; - MessageSharedPtr msg_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -TEST_F(SliderRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { - MessageSharedPtr msg_ui = CreateFullParamsUISO(); - (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; - - utils::SharedPtr command = - CreateCommand(msg_ui); - - MockAppPtr mock_app = CreateMockApp(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app)); - - ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); - - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - (*msg)[am::strings::msg_params][am::strings::info] = "info"; - - Event event(hmi_apis::FunctionID::UI_Slider); - event.set_smart_object(*msg); - - MessageSharedPtr ui_command_result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); - - command->on_event(event); - - EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] - .asBool(), - true); - EXPECT_EQ( - (*ui_command_result)[am::strings::msg_params][am::strings::result_code] - .asInt(), - static_cast(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); - if ((*ui_command_result)[am::strings::msg_params].keyExists( - am::strings::info)) { - EXPECT_FALSE( - (*ui_command_result)[am::strings::msg_params][am::strings::info] - .asString() - .empty()); - } -} - -class CallOnTimeOut { - public: - CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} - - void operator()() { - command_.onTimeOut(); - } - - CommandRequestImpl& command_; -}; - -TEST_F(SliderRequestTest, Init_SUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); -} - -TEST_F(SliderRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - PreConditions(); - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(ApplicationSharedPtr())); - ExpectManageMobileCommandWithResultCode( - mobile_apis::Result::APPLICATION_NOT_REGISTERED); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(SliderRequestTest, Run_PositionGreaterTicks_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::position] = - kPositionGreaterTicks; - - CommandPtr command(CreateCommand(msg_)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - command->Run(); -} - -TEST_F(SliderRequestTest, Run_SliderFooterNotEqToNumticks_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::slider_footer][2] = - "slider_footer3"; - CommandPtr command(CreateCommand(msg_)); - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - command->Run(); -} - -TEST_F(SliderRequestTest, Run_InvalidSliderHeader_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::slider_header] = - "invalid_test_with_empty_str\\n"; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(SliderRequestTest, Run_InvalidSliderFooter_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = - "invalid_test_with_empty_str\\n"; - - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app_)); - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(SliderRequestTest, Run_SUCCESS) { - PreConditions(); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Slider))); - - CommandPtr command(CreateCommand(msg_)); - command->Run(); -} - -TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; - (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; - - CommandPtr command(CreateCommand(msg_)); - EXPECT_TRUE(command->Init()); - - EXPECT_CALL(app_mngr_, - updateRequestTimeout(kConnectionKey, kCorrelationId, _)); - - Event event(hmi_apis::FunctionID::UI_OnResetTimeout); - event.set_smart_object(*msg_); - command->on_event(event); -} - -TEST_F(SliderRequestTest, OnEvent_UI_UnknownEventId_UNSUCCESS) { - PreConditions(); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - event.set_smart_object(*msg_); - - CommandPtr command(CreateCommand(msg_)); - command->on_event(event); -} - -TEST_F(SliderRequestTest, OnEvent_UISliderPositionExists_SUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::TIMED_OUT; - (*msg_)[am::strings::params][am::strings::data] - [am::strings::slider_position] = "position"; - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::TIMED_OUT); - - Event event(hmi_apis::FunctionID::UI_Slider); - event.set_smart_object(*msg_); - - CommandPtr command(CreateCommand(msg_)); - command->on_event(event); -} - -TEST_F(SliderRequestTest, OnEvent_UISliderAborted_SUCCESS) { - PreConditions(); - (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; - (*msg_)[am::strings::params][am::hmi_response::code] = - hmi_apis::Common_Result::ABORTED; - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); - - Event event(hmi_apis::FunctionID::UI_Slider); - event.set_smart_object(*msg_); - - CommandPtr command(CreateCommand(msg_)); - command->on_event(event); -} - -} // namespace slider_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace tests diff --git a/src/components/application_manager/test/commands/mobile/speak_request_test.cc b/src/components/application_manager/test/commands/mobile/speak_request_test.cc deleted file mode 100644 index 5fecf1c4c1..0000000000 --- a/src/components/application_manager/test/commands/mobile/speak_request_test.cc +++ /dev/null @@ -1,414 +0,0 @@ -/* - - Copyright (c) 2016, 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 "gtest/gtest.h" -#include "mobile/speak_request.h" -#include "utils/shared_ptr.h" -#include "commands/commands_test.h" -#include "commands/command_request_test.h" -#include "interfaces/HMI_API.h" -#include "interfaces/MOBILE_API.h" -#include "utils/shared_ptr.h" -#include "utils/helpers.h" -#include "utils/make_shared.h" -#include "smart_objects/smart_object.h" -#include "utils/custom_string.h" -#include "application_manager/application.h" -#include "application_manager/smart_object_keys.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace speak_request { - -namespace am = application_manager; -namespace mobile_result = mobile_apis::Result; -namespace hmi_response = ::application_manager::hmi_response; -namespace strings = ::application_manager::strings; -using am::commands::CommandImpl; -using am::ApplicationManager; -using am::commands::MessageSharedPtr; -using am::ApplicationSharedPtr; -using am::MockMessageHelper; -using ::testing::_; -using ::utils::SharedPtr; -using ::testing::Return; -using ::testing::ReturnRef; -using am::commands::SpeakRequest; -using ::test::components::application_manager_test::MockApplication; - -typedef SharedPtr CommandPtr; - -namespace { -const uint32_t kAppId = 10u; -const uint32_t kConnectionKey = 5u; -} - -class SpeakRequestTest : public CommandRequestTest { - public: - SpeakRequestTest() - : request_(CreateMessage(smart_objects::SmartType_Map)) - , response_(CreateMessage(smart_objects::SmartType_Map)) - , app_(CreateMockApp()) {} - - void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, - const mobile_apis::Result::eType mobile_response, - const am::HmiInterfaces::InterfaceState state, - const bool success) { - utils::SharedPtr command = - CreateCommand(request_); - - (*response_)[strings::params][hmi_response::code] = hmi_response; - (*response_)[strings::msg_params] = 0; - - am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); - event_tts.set_smart_object(*response_); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - - MessageSharedPtr response_to_mobile; - EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) - .WillRepeatedly(Return(state)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - _, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_tts); - - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::success].asBool(), - success); - EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] - .asInt(), - static_cast(mobile_response)); - } - - MessageSharedPtr request_; - MessageSharedPtr response_; - MockAppPtr app_; -}; - -TEST_F(SpeakRequestTest, OnEvent_SUCCESS_Expect_true) { - utils::SharedPtr command = - CreateCommand(request_); - - (*response_)[strings::params][hmi_response::code] = - hmi_apis::Common_Result::SUCCESS; - (*response_)[strings::msg_params] = 0; - - am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); - event_tts.set_smart_object(*response_); - - MockAppPtr mock_app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); - - MessageSharedPtr response_to_mobile; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) - .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); - - command->on_event(event_tts); - - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::success].asBool(), - true); - EXPECT_EQ( - (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), - static_cast(mobile_apis::Result::SUCCESS)); -} - -TEST_F(SpeakRequestTest, - OnEvent_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_AVAILABLE, - true); -} - -TEST_F(SpeakRequestTest, - OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_NOT_AVAILABLE, - false); -} - -TEST_F(SpeakRequestTest, - OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_true) { - CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, - mobile_apis::Result::UNSUPPORTED_RESOURCE, - am::HmiInterfaces::STATE_NOT_RESPONSE, - true); -} - -TEST_F(SpeakRequestTest, Run_ApplicationIsNotRegistered) { - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)) - .WillByDefault(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithWhiteSpace_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = " "; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar1_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "sd\\t"; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar2_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "sd\\n"; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar3_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "sd\tdf"; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar4_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "sd\n rer"; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithIncorrectCharInfirstPlace_InvalidData) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "\n"; - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgWithEmptyString_Success) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = ""; - CommandPtr command(CreateCommand(request_)); - - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); - - command->Run(); -} - -TEST_F(SpeakRequestTest, Run_MsgCorrect_Success) { - (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "asda"; - CommandPtr command(CreateCommand(request_)); - - EXPECT_CALL( - mock_message_helper_, - VerifyTtsFiles( - (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); - - command->Run(); -} - -TEST_F(SpeakRequestTest, OnEvent_WrongEventId_UNSUCCESS) { - Event event(Event::EventID::INVALID_ENUM); - CommandPtr command(CreateCommand()); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - command->on_event(event); -} - -TEST_F(SpeakRequestTest, OnEvent_TTS_Speak_SUCCESS) { - Event event(Event::EventID::TTS_Speak); - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; - (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "1234"; - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; - (*event_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - event.set_smart_object(*event_msg); - CommandPtr command(CreateCommand(request_)); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - command->on_event(event); -} - -TEST_F(SpeakRequestTest, OnEvent_TTS_SpeakWithWarning_WarningWithSuccess) { - Event event(Event::EventID::TTS_Speak); - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::WARNINGS; - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; - (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "asda"; - event.set_smart_object(*event_msg); - CommandPtr command(CreateCommand()); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::WARNINGS), _)); - command->on_event(event); -} - -TEST_F(SpeakRequestTest, OnEvent_TTS_OnResetTimeout_UpdateTimeout) { - Event event(Event::EventID::TTS_OnResetTimeout); - (*request_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*request_)[am::strings::params][am::strings::correlation_id] = kAppId; - CommandPtr command(CreateCommand(request_)); - - EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey, kAppId, _)); - - command->on_event(event); -} - -TEST_F(SpeakRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) { - const hmi_apis::Common_Result::eType hmi_result = - hmi_apis::Common_Result::SUCCESS; - - Event event(Event::EventID::TTS_Speak); - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] - [am::strings::text] = "text"; - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; - (*event_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - event.set_smart_object(*event_msg); - CommandPtr command(CreateCommand(request_)); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - - command->on_event(event); -} - -} // namespace speak_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace component -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc deleted file mode 100644 index 453bcc06a5..0000000000 --- a/src/components/application_manager/test/commands/mobile/subscribe_button_request_test.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2016, 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_hmi_capabilities.h" -#include "application_manager/include/application_manager/commands/mobile/subscribe_button_request.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/smart_object_keys.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace subscribe_button_request { - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::DoAll; -using ::testing::SaveArg; -namespace am = ::application_manager; -using am::commands::SubscribeButtonRequest; -using am::commands::MessageSharedPtr; - -typedef SharedPtr CommandPtr; - -class SubscribeButtonRequestTest - : public CommandRequestTest { - public: - typedef TypeIf, - application_manager_test::MockHMICapabilities>::Result - MockHMICapabilities; -}; - -typedef SubscribeButtonRequestTest::MockHMICapabilities MockHMICapabilities; - -TEST_F(SubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr 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(SubscribeButtonRequestTest, Run_SubscriptionNotAllowed_UNSUCCESS) { - MessageSharedPtr msg(CreateMessage()); - (*msg)[am::strings::msg_params][am::strings::button_name] = - mobile_apis::ButtonName::SEEKLEFT; - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, is_media_application()).WillByDefault(Return(false)); - - 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(SubscribeButtonRequestTest, Run_UiIsNotSupported_UNSUCCESS) { - CommandPtr command(CreateCommand()); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - ON_CALL(hmi_capabilities, is_ui_cooperating()).WillByDefault(Return(false)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) { - const mobile_apis::ButtonName::eType kButtonName = - mobile_apis::ButtonName::SEEKLEFT; - - MessageSharedPtr msg(CreateMessage()); - (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - ON_CALL(hmi_capabilities, is_ui_cooperating()).WillByDefault(Return(true)); - - MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; - - ON_CALL(hmi_capabilities, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); - - ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(true)); - - MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); - EXPECT_EQ(mobile_apis::Result::IGNORED, - static_cast( - (*result_msg)[am::strings::msg_params][am::strings::result_code] - .asInt())); -} - -TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) { - const mobile_apis::ButtonName::eType kButtonName = - mobile_apis::ButtonName::SEEKLEFT; - - MessageSharedPtr msg(CreateMessage()); - (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; - CommandPtr command(CreateCommand(msg)); - - MockAppPtr app(CreateMockApp()); - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); - - MockHMICapabilities hmi_capabilities; - ON_CALL(app_mngr_, hmi_capabilities()) - .WillByDefault(ReturnRef(hmi_capabilities)); - ON_CALL(hmi_capabilities, is_ui_cooperating()).WillByDefault(Return(true)); - - MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; - - ON_CALL(hmi_capabilities, button_capabilities()) - .WillByDefault(Return(button_caps_ptr.get())); - - ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); - - MessageSharedPtr hmi_result_msg; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); - - MessageSharedPtr mobile_result_msg; - EXPECT_CALL(this->rpc_service_, ManageMobileCommand(_, _)) - .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); - ASSERT_TRUE(command->Init()); - command->Run(); - - EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, - static_cast( - (*hmi_result_msg)[am::strings::params][am::strings::function_id] - .asInt())); - - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*mobile_result_msg)[am::strings::msg_params] - [am::strings::result_code].asInt())); -} - -} // namespace subscribe_button_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc deleted file mode 100644 index fad6de5d0b..0000000000 --- a/src/components/application_manager/test/commands/mobile/subscribe_way_points_request_test.cc +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2016, 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 "gtest/gtest.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "application_manager/test/include/application_manager/commands/commands_test.h" -#include "application_manager/test/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_hmi_capabilities.h" -#include "application_manager/mock_message_helper.h" -#include "application_manager/include/application_manager/commands/mobile/subscribe_way_points_request.h" -#include "interfaces/MOBILE_API.h" -#include "application_manager/smart_object_keys.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace subscribe_way_points_request { - -using ::testing::_; -using ::testing::A; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::DoAll; -using ::testing::SaveArg; -using ::testing::InSequence; -namespace am = ::application_manager; -using am::commands::SubscribeWayPointsRequest; -using am::commands::MessageSharedPtr; - -typedef SharedPtr CommandPtr; - -class SubscribeWayPointsRequestTest - : public CommandRequestTest {}; - -TEST_F(SubscribeWayPointsRequestTest, Run_SUCCESS) { - CommandPtr command(CreateCommand()); - MockAppPtr app(CreateMockApp()); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(A())) - .WillByDefault(Return(false)); - ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) - .WillByDefault(Return(true)); - - { - InSequence dummy; - EXPECT_CALL(app_mngr_, - SubscribeAppForWayPoints(A())); - EXPECT_CALL(*app, UpdateHash()); - } - - command->Init(); - MessageSharedPtr mobile_result_msg( - CatchMobileCommandResult(CallRun(*command))); - - EXPECT_EQ(mobile_apis::Result::SUCCESS, - static_cast( - (*mobile_result_msg)[am::strings::msg_params] - [am::strings::result_code].asInt())); -} - -TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { - CommandPtr command(CreateCommand()); - MockAppPtr app(CreateMockApp()); - Event event(hmi_apis::FunctionID::Navigation_SubscribeWayPoints); - - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - const hmi_apis::Common_Result::eType result_code = - hmi_apis::Common_Result::SUCCESS; - (*event_msg)[am::strings::params][am::hmi_response::code] = result_code; - (*event_msg)[am::strings::msg_params] = 0; - - event.set_smart_object(*event_msg); - - ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); - - { - InSequence dummy; - EXPECT_CALL(app_mngr_, - SubscribeAppForWayPoints(A())); - EXPECT_CALL(mock_message_helper_, HMIToMobileResult(result_code)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)); - EXPECT_CALL(*app, UpdateHash()); - } - - command->Init(); - command->on_event(event); -} - -} // namespace subscribe_way_points_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/system_request_test.cc b/src/components/application_manager/test/commands/mobile/system_request_test.cc deleted file mode 100644 index 53e90e9d06..0000000000 --- a/src/components/application_manager/test/commands/mobile/system_request_test.cc +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2017, 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 "application_manager/commands/mobile/system_request.h" -#include "application_manager/commands/command_request_test.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_application_manager.h" -#include "application_manager/event_engine/event.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/policies/mock_policy_handler_interface.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace system_request { - -namespace am = application_manager; -using am::commands::SystemRequest; -using am::commands::CommandImpl; -using am::commands::MessageSharedPtr; -using am::MockHmiInterfaces; -using am::event_engine::Event; -using am::MessageType; -using policy_test::MockPolicyHandlerInterface; -using ::utils::SharedPtr; -using ::testing::_; -using ::testing::DoAll; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::SaveArg; - -namespace { -const uint32_t kConnectionKey = 2u; -const std::string kAppPolicyId = "fake-app-id"; -const uint32_t kDefaultTimeout = 1000u; -const std::string kAppFolderName = "fake-app-name"; -const std::string kAppStorageFolder = "fake-storage"; -const std::string kSystemFilesPath = "/fake/system/files"; -const std::string kFileName = "Filename"; -const uint32_t kHmiAppId = 3u; -} // namespace - -class SystemRequestTest - : public CommandRequestTest { - public: - SystemRequestTest() : mock_app_(CreateMockApp()) {} - - protected: - MessageSharedPtr CreateIVSUMessage() { - MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; - (*msg)[am::strings::msg_params][am::strings::request_type] = - mobile_apis::RequestType::HTTP; - (*msg)[am::strings::msg_params][am::strings::file_name] = kFileName; - return msg; - } - - void PreConditions() { - ON_CALL(app_mngr_, application(kConnectionKey)) - .WillByDefault(Return(mock_app_)); - ON_CALL(app_mngr_, GetPolicyHandler()) - .WillByDefault(ReturnRef(mock_policy_handler_)); - - ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); - ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kAppPolicyId)); - ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kAppFolderName)); - ON_CALL(*mock_app_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); - - ON_CALL(app_mngr_settings_, system_files_path()) - .WillByDefault(ReturnRef(kSystemFilesPath)); - ON_CALL(app_mngr_settings_, app_storage_folder()) - .WillByDefault(ReturnRef(kAppStorageFolder)); - - ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) - .WillByDefault(Return(true)); - } - - void ExpectManageMobileCommandWithResultCode( - const mobile_apis::Result::eType code) { - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(code), - am::commands::Command::CommandSource::SOURCE_SDL)); - } - - MockAppPtr mock_app_; - MockPolicyHandlerInterface mock_policy_handler_; -}; - -TEST_F(SystemRequestTest, Run_HTTP_FileName_no_binary_data_REJECTED) { - PreConditions(); - MessageSharedPtr msg = CreateIVSUMessage(); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); - - SharedPtr command(CreateCommand(msg)); - command->Run(); -} - -TEST_F(SystemRequestTest, - Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendHMIRequest) { - MessageSharedPtr msg = CreateIVSUMessage(); - - (*msg)[am::strings::msg_params][am::strings::request_type] = - mobile_apis::RequestType::OEM_SPECIFIC; - - const std::string request_subtype = "fakeSubType"; - (*msg)[am::strings::msg_params][am::strings::request_subtype] = - request_subtype; - - const std::vector binary_data = {1u, 2u}; - (*msg)[am::strings::params][am::strings::binary_data] = binary_data; - - PreConditions(); - - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) - .WillOnce(Return(true)); - - EXPECT_CALL(mock_policy_handler_, - IsRequestSubTypeAllowed(kAppPolicyId, request_subtype)) - .WillOnce(Return(true)); - - EXPECT_CALL(app_mngr_, - SaveBinary(binary_data, kSystemFilesPath, kFileName, 0u)) - .WillOnce(Return(mobile_apis::Result::SUCCESS)); - - smart_objects::SmartObjectSPtr result; - EXPECT_CALL(app_mngr_, ManageHMICommand(_)) - .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); - - SharedPtr command(CreateCommand(msg)); - ASSERT_TRUE(command->Init()); - command->Run(); - - EXPECT_EQ(MessageType::kRequest, - (*result)[am::strings::params][am::strings::message_type].asInt()); - EXPECT_EQ( - mobile_apis::RequestType::OEM_SPECIFIC, - (*result)[am::strings::msg_params][am::strings::request_type].asInt()); - EXPECT_EQ( - request_subtype, - (*msg)[am::strings::msg_params][am::strings::request_subtype].asString()); -} - -TEST_F( - SystemRequestTest, - Run_RequestTypeAllowedAndRequestSubTypeDisallowed_SendDisallowedResponse) { - MessageSharedPtr msg = CreateIVSUMessage(); - - (*msg)[am::strings::msg_params][am::strings::request_type] = - mobile_apis::RequestType::OEM_SPECIFIC; - - const std::string request_subtype = "fakeSubType2"; - (*msg)[am::strings::msg_params][am::strings::request_subtype] = - request_subtype; - - PreConditions(); - - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) - .WillOnce(Return(true)); - - EXPECT_CALL(mock_policy_handler_, - IsRequestSubTypeAllowed(kAppPolicyId, request_subtype)) - .WillOnce(Return(false)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); - EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); - - SharedPtr command(CreateCommand(msg)); - ASSERT_TRUE(command->Init()); - command->Run(); -} - -TEST_F(SystemRequestTest, Run_RequestTypeDisallowed_SendDisallowedResponse) { - MessageSharedPtr msg = CreateIVSUMessage(); - - (*msg)[am::strings::msg_params][am::strings::request_type] = - mobile_apis::RequestType::OEM_SPECIFIC; - - PreConditions(); - - EXPECT_CALL(mock_policy_handler_, - IsRequestTypeAllowed(kAppPolicyId, - mobile_apis::RequestType::OEM_SPECIFIC)) - .WillOnce(Return(false)); - - ExpectManageMobileCommandWithResultCode(mobile_apis::Result::DISALLOWED); - EXPECT_CALL(app_mngr_, ManageHMICommand(_)).Times(0); - - SharedPtr command(CreateCommand(msg)); - ASSERT_TRUE(command->Init()); - command->Run(); -} - -} // namespace system_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc b/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc deleted file mode 100644 index 6dcfd67978..0000000000 --- a/src/components/application_manager/test/commands/mobile/unregister_app_interface_request_test.cc +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/unregister_app_interface_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace unregister_app_interface_request { - -namespace am = ::application_manager; -namespace mobile_result = mobile_apis::Result; - -using ::testing::_; - -using am::commands::UnregisterAppInterfaceRequest; -using am::commands::MessageSharedPtr; - -typedef ::utils::SharedPtr CommandPtr; - -class UnregisterAppInterfaceRequestTest - : public CommandRequestTest {}; - -TEST_F(UnregisterAppInterfaceRequestTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(UnregisterAppInterfaceRequestTest, Run_SUCCESS) { - const uint32_t kConnectionKey = 1u; - - MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); - (*command_msg)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - const mobile_apis::AppInterfaceUnregisteredReason::eType kUnregisterReason = - mobile_apis::AppInterfaceUnregisteredReason::INVALID_ENUM; - - MessageSharedPtr dummy_msg(CreateMessage()); - EXPECT_CALL(mock_message_helper_, - GetOnAppInterfaceUnregisteredNotificationToMobile( - kConnectionKey, kUnregisterReason)) - .WillOnce(Return(dummy_msg)); - { - ::testing::InSequence sequence; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(dummy_msg, _)); - - EXPECT_CALL(app_mngr_, - UnregisterApplication( - kConnectionKey, mobile_apis::Result::SUCCESS, _, _)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); - } - - command->Run(); -} - -} // namespace unregister_app_interface_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_button_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_button_request_test.cc deleted file mode 100644 index 5e9e4d2f1b..0000000000 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_button_request_test.cc +++ /dev/null @@ -1,158 +0,0 @@ -#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 "application_manager/mock_hmi_capabilities.h" -#include "application_manager/commands/mobile/unsubscribe_button_request.h" - -namespace test { -namespace components { -namespace commands_test { -namespace mobile_commands_test { -namespace unsubscribe_button_request { - -namespace am = ::application_manager; -namespace mobile_result = mobile_apis::Result; - -using ::testing::_; - -using am::commands::UnsubscribeButtonRequest; -using am::commands::MessageSharedPtr; - -typedef ::utils::SharedPtr CommandPtr; - -namespace { -const uint32_t kConnectionKey = 1u; -const mobile_apis::ButtonName::eType kButtonId = mobile_apis::ButtonName::OK; -} // namespace - -class UnsubscribeButtonRequestTest - : public CommandRequestTest { - public: - typedef TypeIf, - application_manager_test::MockHMICapabilities>::Result - MockHMICapabilities; -}; - -TEST_F(UnsubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) { - CommandPtr command(CreateCommand()); - - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command->Run(); -} - -TEST_F(UnsubscribeButtonRequestTest, - Run_UnsubscribeNotSubscribedButton_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] = kButtonId; - - CommandPtr command(CreateCommand(command_msg)); - - UnsubscribeButtonRequestTest::MockHMICapabilities hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(hmi_capabilities)); - EXPECT_CALL(hmi_capabilities, is_ui_cooperating()).WillOnce(Return(true)); - - MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; - EXPECT_CALL(hmi_capabilities, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - - command->Run(); -} - -TEST_F(UnsubscribeButtonRequestTest, - Run_UnsubscribeNotAllowedByHmiCapabilities_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] = kButtonId; - CommandPtr command(CreateCommand(command_msg)); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - UnsubscribeButtonRequestTest::MockHMICapabilities hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(hmi_capabilities)); - EXPECT_CALL(hmi_capabilities, is_ui_cooperating()).WillOnce(Return(true)); - - MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - EXPECT_CALL(hmi_capabilities, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::UNSUPPORTED_RESOURCE), _)); - - command->Run(); -} - -TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) { - 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] = kButtonId; - - CommandPtr command(CreateCommand(command_msg)); - - UnsubscribeButtonRequestTest::MockHMICapabilities hmi_capabilities; - EXPECT_CALL(app_mngr_, hmi_capabilities()) - .WillOnce(ReturnRef(hmi_capabilities)); - EXPECT_CALL(hmi_capabilities, is_ui_cooperating()).WillOnce(Return(true)); - - MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); - (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; - EXPECT_CALL(hmi_capabilities, button_capabilities()) - .WillOnce(Return(button_caps_ptr.get())); - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) - .WillOnce(Return(true)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Buttons_OnButtonSubscription))); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - EXPECT_CALL(*mock_app, UpdateHash()); - command->Init(); - command->Run(); -} - -} // namespace unsubscribe_button_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc deleted file mode 100644 index 25281a147b..0000000000 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_request_test.cc +++ /dev/null @@ -1,288 +0,0 @@ -/* - Copyright (c) 2016, 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 "application_manager/commands/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 am::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())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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/test/commands/mobile/unsubscribe_vehicle_response_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_response_test.cc deleted file mode 100644 index 278d964e16..0000000000 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_vehicle_response_test.cc +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/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 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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - 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); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, SendMessageToMobile(ResultCodeIs(result_type), _)); - 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/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc deleted file mode 100644 index 53f122dff2..0000000000 --- a/src/components/application_manager/test/commands/mobile/unsubscribe_way_points_request_test.cc +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright (c) 2016, 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 "mobile/unsubscribe_way_points_request.h" -#include "interfaces/MOBILE_API.h" -#include "utils/shared_ptr.h" -#include "smart_objects/smart_object.h" -#include "commands/commands_test.h" -#include "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 "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 unsubscribe_way_points_request { - -namespace am = ::application_manager; -namespace mobile_result = mobile_apis::Result; - -using ::testing::_; -using ::testing::Return; - -using am::commands::UnSubscribeWayPointsRequest; -using am::commands::MessageSharedPtr; - -namespace { -const uint32_t kConnectionKey = 3u; -const uint32_t kAppId = 5u; -} // namespace - -class UnSubscribeWayPointsRequestTest - : public CommandRequestTest { - public: - UnSubscribeWayPointsRequestTest() - : command_msg_(CreateMessage(smart_objects::SmartType_Map)) - , command_(CreateCommand(command_msg_)) { - (*command_msg_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - } - - MessageSharedPtr command_msg_; - ::utils::SharedPtr command_; -}; - -TEST_F(UnSubscribeWayPointsRequestTest, - Run_ApplicationIsNotRegistered_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(_)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command_->Run(); -} - -TEST_F(UnSubscribeWayPointsRequestTest, - Run_AppIsNotSubscribedForWayPoints_UNSUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, - IsAppSubscribedForWayPoints( - ::testing::Matcher(mock_app))) - .WillOnce(Return(false)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); - - command_->Run(); -} - -TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, - IsAppSubscribedForWayPoints( - ::testing::Matcher(mock_app))) - .WillOnce(Return(true)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints))); - - command_->Run(); -} - -TEST_F(UnSubscribeWayPointsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - Event event(hmi_apis::FunctionID::INVALID_ENUM); - - command_->on_event(event); -} - -TEST_F(UnSubscribeWayPointsRequestTest, - OnEvent_ReceivedNavigationUnSubscribeWayPointsEvent_SUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillRepeatedly(Return(mock_app)); - - 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_result::SUCCESS; - Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); - event.set_smart_object(*event_msg); - - EXPECT_CALL(app_mngr_, - UnsubscribeAppFromWayPoints( - ::testing::Matcher(mock_app))); - - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); - - command_->on_event(event); -} - -} // namespace unsubscribe_way_points_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc b/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc deleted file mode 100644 index d539e9ac14..0000000000 --- a/src/components/application_manager/test/commands/mobile/update_turn_list_request_test.cc +++ /dev/null @@ -1,305 +0,0 @@ -/* - * Copyright (c) 2016, 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 "application_manager/commands/mobile/update_turn_list_request.h" -#include "interfaces/MOBILE_API.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 "application_manager/mock_hmi_capabilities.h" -#include "application_manager/policies/mock_policy_handler_interface.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 update_turn_list_request { - -namespace am = ::application_manager; -namespace mobile_result = mobile_apis::Result; - -using ::testing::_; -using ::testing::Return; -using ::testing::ReturnRef; -using ::testing::Ref; -using ::testing::Eq; - -using am::commands::UpdateTurnListRequest; -using am::commands::MessageSharedPtr; -using application_manager_test::MockHMICapabilities; - -namespace { -const uint32_t kConnectionKey = 3u; -const hmi_apis::FunctionID::eType kFunctionId = - hmi_apis::FunctionID::Buttons_OnButtonEvent; -const uint32_t kAppId = 5u; -} // namespace - -class UpdateTurnListRequestTest - : public CommandRequestTest { - public: - UpdateTurnListRequestTest() - : command_msg_(CreateMessage(smart_objects::SmartType_Map)) - , command_(CreateCommand(command_msg_)) { - (*command_msg_)[am::strings::params][am::strings::connection_key] = - kConnectionKey; - (*command_msg_)[am::strings::params][am::strings::function_id] = - kFunctionId; - } - - MessageSharedPtr command_msg_; - ::utils::SharedPtr command_; - TypeIf, - policy_test::MockPolicyHandlerInterface>::Result mock_policy_handler_; -}; - -TEST_F(UpdateTurnListRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(ApplicationSharedPtr())); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); - - command_->Run(); -} - -TEST_F(UpdateTurnListRequestTest, Run_InvalidNavigationText_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::navigation_text] = "invalid_navigation_text\t\n"; - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command_->Run(); -} - -TEST_F(UpdateTurnListRequestTest, Run_InvalidTurnIcon_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::navigation_text] = "valid_navigation_text"; - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::turn_icon][am::strings::value] = - "invalid_turn_icon\t\n"; - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command_->Run(); -} - -TEST_F(UpdateTurnListRequestTest, - Run_ProcessSoftButtonsNotSucceeded_UNSUCCESS) { - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::navigation_text] = "valid_navigation_text"; - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::turn_icon][am::strings::value] = - "valid_turn_icon"; - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); - - const mobile_result::eType kExpectedResult = mobile_result::INVALID_ENUM; - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*command_msg_)[am::strings::msg_params], - Eq(mock_app), - Ref(mock_policy_handler_), - Ref(app_mngr_))) - .WillOnce(Return(kExpectedResult)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(MobileResultCodeIs(kExpectedResult), _)); - - command_->Run(); -} - -TEST_F(UpdateTurnListRequestTest, Run_NoTurnList_UNSUCCESS) { - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*command_msg_)[am::strings::msg_params], - Eq(mock_app), - Ref(mock_policy_handler_), - Ref(app_mngr_))) - .WillOnce(Return(mobile_result::SUCCESS)); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL( - rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); - - command_->Run(); -} - -TEST_F(UpdateTurnListRequestTest, Run_ValidTurnList_SUCCESS) { - const std::string kNavigationText = "valid_navigation_text"; - - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::navigation_text] = kNavigationText; - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::turn_icon][am::strings::value] = - "valid_turn_icon"; - (*command_msg_)[am::strings::msg_params][am::strings::soft_buttons] = 0; - - MockAppPtr mock_app(CreateMockApp()); - EXPECT_CALL(app_mngr_, application(kConnectionKey)) - .WillOnce(Return(mock_app)); - - EXPECT_CALL(app_mngr_, GetPolicyHandler()) - .WillOnce(ReturnRef(mock_policy_handler_)); - - EXPECT_CALL(mock_message_helper_, - ProcessSoftButtons((*command_msg_)[am::strings::msg_params], - Eq(mock_app), - Ref(mock_policy_handler_), - Ref(app_mngr_))) - .WillOnce(Return(mobile_result::SUCCESS)); - - EXPECT_CALL( - mock_message_helper_, - VerifyImage( - (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] - [am::strings::turn_icon], - Eq(mock_app), - Ref(app_mngr_))).WillOnce(Return(mobile_result::SUCCESS)); - - EXPECT_CALL(mock_message_helper_, - SubscribeApplicationToSoftButton(_, _, kFunctionId)); - - MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); - ASSERT_TRUE(result_msg); - EXPECT_EQ( - hmi_apis::FunctionID::Navigation_UpdateTurnList, - (*result_msg)[am::strings::params][am::strings::function_id].asInt()); - - ASSERT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] - .keyExists(am::hmi_request::navi_text)); - - EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] - [am::hmi_request::navi_text].keyExists( - am::hmi_request::field_name)); - EXPECT_EQ( - hmi_apis::Common_TextFieldName::turnText, - (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] - [am::hmi_request::navi_text][am::hmi_request::field_name] - .asInt()); - - EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] - [am::hmi_request::navi_text].keyExists( - am::hmi_request::field_text)); - EXPECT_EQ( - kNavigationText, - (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] - [am::hmi_request::navi_text][am::hmi_request::field_text] - .asString()); -} - -TEST_F(UpdateTurnListRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { - Event event(hmi_apis::FunctionID::INVALID_ENUM); - EXPECT_CALL(app_mngr_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); - - command_->on_event(event); -} - -TEST_F(UpdateTurnListRequestTest, OnEvent_UnsupportedResource_SUCCESS) { - MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); - const hmi_apis::Common_Result::eType hmi_response_code = - hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; - const mobile_result::eType mobile_response_code = - mobile_result::UNSUPPORTED_RESOURCE; - (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; - (*event_msg)[am::strings::msg_params] = 0; - - Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); - event.set_smart_object(*event_msg); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); - - command_->on_event(event); -} - -TEST_F(UpdateTurnListRequestTest, - OnEvent_ReceivedNavigationUpdateTurnListEvent_SUCCESS) { - const hmi_apis::Common_Result::eType hmi_response_code = - hmi_apis::Common_Result::SUCCESS; - const mobile_result::eType mobile_response_code = mobile_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 event(hmi_apis::FunctionID::Navigation_UpdateTurnList); - event.set_smart_object(*event_msg); - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, - ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); - - command_->on_event(event); -} - -} // namespace update_turn_list_request -} // namespace mobile_commands_test -} // namespace commands_test -} // namespace components -} // namespace test diff --git a/src/components/application_manager/test/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 7ea467206b..e1d2eeb402 100644 --- a/src/components/application_manager/test/hmi_capabilities_test.cc +++ b/src/components/application_manager/test/hmi_capabilities_test.cc @@ -102,7 +102,7 @@ class HMICapabilitiesTest : public ::testing::Test { MockApplicationManagerSettings mock_application_manager_settings_; utils::SharedPtr hmi_capabilities_test; const std::string file_name_; - application_manager_test::MockRPCService rpc_service_; + application_manager_test::MockRPCService mock_rpc_service_; }; const char* const cstring_values_[] = { @@ -583,9 +583,8 @@ void HMICapabilitiesTest::SetCooperating() { smart_objects::SmartObjectSPtr test_so; EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), CreateModuleInfoSO(_, _)).WillRepeatedly(Return(test_so)); - EXPECT_CALL(app_mngr_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)).WillRepeatedly(Return(true)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillRepeatedly(Return(true)); } TEST_F(HMICapabilitiesTest, SetVRCooperating) { diff --git a/src/components/application_manager/test/hmi_language_handler_test.cc b/src/components/application_manager/test/hmi_language_handler_test.cc index a51d89ef76..97ca88a4dd 100644 --- a/src/components/application_manager/test/hmi_language_handler_test.cc +++ b/src/components/application_manager/test/hmi_language_handler_test.cc @@ -137,7 +137,7 @@ class HmiLanguageHandlerTest : public ::testing::Test { SharedPtr hmi_language_handler_; ::sync_primitives::Lock app_set_lock_; resumption_test::MockLastState last_state_; - MockRPCService rpc_service_; + MockRPCService mock_rpc_service_; }; TEST_F(HmiLanguageHandlerTest, OnEvent_AllLanguageIsReceivedAndSame_SUCCESS) { @@ -168,7 +168,7 @@ TEST_F(HmiLanguageHandlerTest, OnEvent_AllLanguageIsReceivedAndSame_SUCCESS) { // will never be called. EXPECT_CALL(app_manager_, applications()).Times(0); EXPECT_CALL(app_manager_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); EXPECT_CALL(app_manager_, UnregisterApplication(_, _, _, _)).Times(0); Event tts_event(hmi_apis::FunctionID::TTS_GetLanguage); hmi_language_handler_->on_event(tts_event); @@ -206,7 +206,7 @@ TEST_F(HmiLanguageHandlerTest, OnEvent_AllReceivedLanguagesMismatch_SUCCESS) { // app data will checked by `CheckApplication` method ON_CALL(app_manager_, applications()).WillByDefault(Return(data_accessor)); EXPECT_CALL(app_manager_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); EXPECT_CALL(app_manager_, UnregisterApplication(_, _, _, _)).Times(0); Event tts_event(hmi_apis::FunctionID::TTS_GetLanguage); @@ -322,8 +322,8 @@ TEST_F(HmiLanguageHandlerTest, // First time in `SendOnLanguageChangeToMobile` // method, second time in `HandleWrongLanguageApp`. EXPECT_CALL(app_manager_, GetRPCService()) - .WillRepeatedly(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(2); + .WillRepeatedly(ReturnRef(mock_rpc_service_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(2); EXPECT_CALL(app_manager_, UnregisterApplication(_, _, _, _)).Times(1); hmi_language_handler_->on_event(event); } @@ -352,7 +352,7 @@ TEST_F(HmiLanguageHandlerTest, OnUnregisterApp_SUCCESS) { hmi_apis::Common_Language::eType::RU_RU, hmi_apis::Common_Language::eType::RU_RU); EXPECT_CALL(app_manager_, GetRPCService()).Times(0); - EXPECT_CALL(rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); EXPECT_CALL(app_manager_, UnregisterApplication(_, _, _, _)).Times(0); hmi_language_handler_->on_event(event); } diff --git a/src/components/application_manager/test/include/application_manager/commands/command_request_test.h b/src/components/application_manager/test/include/application_manager/commands/command_request_test.h index 54552ef0d5..05cb80c989 100644 --- a/src/components/application_manager/test/include/application_manager/commands/command_request_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/command_request_test.h @@ -39,9 +39,10 @@ #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/test/include/application_manager/commands/commands_test.h" #include "application_manager/commands/command_request_impl.h" -#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/test/include/application_manager/mock_event_dispatcher.h" + #include "application_manager/event_engine/event.h" namespace test { @@ -94,9 +95,7 @@ class CommandRequestTest : public CommandsTest { MessageSharedPtr CatchMobileCommandResult(CallableT delegate, bool call_return = true) { MessageSharedPtr result_msg; - EXPECT_CALL(this->app_mngr_, GetRPCService()) - .WillOnce(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, ManageMobileCommand(_, _)) + EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(call_return))); delegate(); return result_msg; @@ -106,9 +105,7 @@ class CommandRequestTest : public CommandsTest { MessageSharedPtr CatchHMICommandResult(CallableT delegate, bool call_return = true) { MessageSharedPtr result_msg; - ON_CALL(this->app_mngr_, GetRPCService()) - .WillByDefault(ReturnRef(this->rpc_service_)); - EXPECT_CALL(this->rpc_service_, ManageHMICommand(_)) + EXPECT_CALL(this->mock_rpc_service_, ManageHMICommand(_)) .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(call_return))); delegate(); return result_msg; diff --git a/src/components/application_manager/test/include/application_manager/commands/commands_test.h b/src/components/application_manager/test/include/application_manager/commands/commands_test.h index 744a22e9c4..ab392c5ba0 100644 --- a/src/components/application_manager/test/include/application_manager/commands/commands_test.h +++ b/src/components/application_manager/test/include/application_manager/commands/commands_test.h @@ -42,10 +42,12 @@ #include "utils/make_shared.h" #include "application_manager/mock_application_manager.h" #include "test/application_manager/mock_application_manager_settings.h" -#include "application_manager/mock_hmi_interface.h" -#include "application_manager/mock_application.h" -#include "application_manager/mock_message_helper.h" +#include "application_manager/test/include/application_manager/mock_hmi_interface.h" +#include "application_manager/test/include/application_manager/mock_application.h" +#include "application_manager/test/include/application_manager/mock_message_helper.h" #include "application_manager/mock_rpc_service.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" namespace test { namespace components { namespace commands_test { @@ -122,7 +124,10 @@ class CommandsTest : public ::testing::Test { MessageSharedPtr& msg) { InitCommand(timeout); return ::utils::MakeShared((msg ? msg : msg = CreateMessage()), - app_mngr_); + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); } template @@ -134,16 +139,22 @@ class CommandsTest : public ::testing::Test { SharedPtr CreateCommand(const uint32_t timeout = kDefaultTimeout_) { InitCommand(timeout); MessageSharedPtr msg = CreateMessage(); - return ::utils::MakeShared(msg, app_mngr_); + return ::utils::MakeShared(msg, + app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_); } enum { kDefaultTimeout_ = 100 }; MockAppManager app_mngr_; + MockRPCService mock_rpc_service_; + application_manager_test::MockHMICapabilities mock_hmi_capabilities_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_; MockAppManagerSettings app_mngr_settings_; MOCK(am::MockHmiInterfaces) mock_hmi_interfaces_; am::MockMessageHelper& mock_message_helper_; - MockRPCService rpc_service_; protected: virtual void InitCommand(const uint32_t& timeout) { diff --git a/src/components/application_manager/test/include/application_manager/mock_command_factory.h b/src/components/application_manager/test/include/application_manager/mock_command_factory.h new file mode 100644 index 0000000000..ca4616cbd2 --- /dev/null +++ b/src/components/application_manager/test/include/application_manager/mock_command_factory.h @@ -0,0 +1,61 @@ +/* + Copyright (c) 2017, 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. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ + +#include +#include "application_manager/command_factory.h" +#include "application_manager/commands/command.h" +#include "smart_objects/smart_object.h" +#include "utils/shared_ptr.h" + +namespace test { +namespace components { +namespace application_manager_test { + +class MockCommandFactory : public application_manager::CommandFactory { + public: + MOCK_METHOD2(CreateCommand, + application_manager::CommandSharedPtr( + const application_manager::commands::MessageSharedPtr&, + application_manager::commands::Command::CommandSource)); + + // const commands::MessageSharedPtr& message, + // application_manager::commands::Command::CommandSource)); +}; + +} // namespace application_manager_test +} // namespace components +} // namespace test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ diff --git a/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h b/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h deleted file mode 100644 index cf40d7b98b..0000000000 --- a/src/components/application_manager/test/include/application_manager/mock_hmi_command_factory.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2017, 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. - */ - -#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ -#define SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ - -#include -#include "application_manager/application_manager.h" -#include "application_manager/commands/command.h" -#include "smart_objects/smart_object.h" -#include "utils/shared_ptr.h" - -namespace test { -namespace components { -namespace application_manager_test { - -class MockHMICommandFactory { - public: - MOCK_METHOD2(CreateCommand, - utils::SharedPtr( - const utils::SharedPtr&, - application_manager::ApplicationManager&)); - - static MockHMICommandFactory* mock_hmi_command_factory(); -}; - -} // namespace application_manager_test -} // namespace components -} // namespace test - -#endif // SRC_COMPONENTS_APPLICATION_MANAGER_TEST_INCLUDE_APPLICATION_MANAGER_MOCK_HMI_COMMAND_FACTORY_H_ diff --git a/src/components/application_manager/test/message_helper/message_helper_test.cc b/src/components/application_manager/test/message_helper/message_helper_test.cc index 9471926afe..581f8e690d 100644 --- a/src/components/application_manager/test/message_helper/message_helper_test.cc +++ b/src/components/application_manager/test/message_helper/message_helper_test.cc @@ -572,7 +572,7 @@ class MessageHelperTest : public ::testing::Test { protected: application_manager_test::MockApplicationManager mock_application_manager; - application_manager_test::MockRPCService rpc_service_; + application_manager_test::MockRPCService mock_rpc_service_; const StringArray language_strings; const StringArray hmi_result_strings; const StringArray mobile_result_strings; @@ -952,8 +952,8 @@ TEST_F(MessageHelperTest, SendGetListOfPermissionsResponse_SUCCESS) { permissions.push_back(permission); smart_objects::SmartObjectSPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const uint32_t correlation_id = 0u; @@ -990,8 +990,8 @@ TEST_F(MessageHelperTest, entity_type_2, entity_id_2, entity_status_2)); smart_objects::SmartObjectSPtr result; - ON_CALL(app_mngr_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); const uint32_t correlation_id = 0u; @@ -1036,8 +1036,8 @@ TEST_F(MessageHelperTest, TEST_F(MessageHelperTest, SendNaviSetVideoConfigRequest) { smart_objects::SmartObjectSPtr result; ON_CALL(mock_application_manager, GetRPCService()) - .WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, ManageHMICommand(_)) + .WillByDefault(ReturnRef(mock_rpc_service_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); int32_t app_id = 123; diff --git a/src/components/application_manager/test/mock_hmi_command_factory.cc b/src/components/application_manager/test/mock_hmi_command_factory.cc index c2b4644f86..375da26067 100644 --- a/src/components/application_manager/test/mock_hmi_command_factory.cc +++ b/src/components/application_manager/test/mock_hmi_command_factory.cc @@ -31,7 +31,7 @@ */ #include -#include "application_manager/hmi_command_factory.h" +#include "application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/hmi_command_factory.h" #include "application_manager/mock_hmi_command_factory.h" namespace test { @@ -47,10 +47,11 @@ MockHMICommandFactory* MockHMICommandFactory::mock_hmi_command_factory() { } // components } // test -namespace application_manager { -CommandSharedPtr HMICommandFactory::CreateCommand( - const commands::MessageSharedPtr& message, - ApplicationManager& application_manager) { +namespace sdl_rpc_plugin { +namespace app_mngr = application_manager; +app_mngr::CommandSharedPtr HMICommandFactory::CreateCommand( + const app_mngr::commands::MessageSharedPtr& message, + app_mngr::ApplicationManager& application_manager) { return test::components::application_manager_test::MockHMICommandFactory:: mock_hmi_command_factory()->CreateCommand(message, application_manager); } diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 3c49892ab2..89da0e382c 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -167,7 +167,7 @@ class PolicyHandlerTest : public ::testing::Test { const uint32_t kCallsCount_; const uint32_t kTimeout_; application_manager::MockMessageHelper& mock_message_helper_; - MockRPCService rpc_service_; + MockRPCService mock_rpc_service_; virtual void SetUp() OVERRIDE { Mock::VerifyAndClearExpectations(&mock_message_helper_); @@ -1010,8 +1010,8 @@ TEST_F(PolicyHandlerTest, kAppId1_, mobile_api::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED)) .WillOnce(Return(message)); - ON_CALL(app_manager_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, + ON_CALL(app_manager_, GetRPCService()).WillByDefault(ReturnRef(mock_rpc_service_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, commands::Command::SOURCE_SDL)); EXPECT_CALL(*mock_policy_manager_, @@ -1063,8 +1063,8 @@ TEST_F(PolicyHandlerTest, kAppId1_, mobile_api::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED)) .WillOnce(Return(message)); - ON_CALL(app_manager_, GetRPCService()).WillByDefault(ReturnRef(rpc_service_)); - EXPECT_CALL(rpc_service_, + ON_CALL(app_manager_, GetRPCService()).WillByDefault(ReturnRef(mock_rpc_service_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, commands::Command::SOURCE_SDL)); EXPECT_CALL(*mock_policy_manager_, diff --git a/src/components/application_manager/test/state_controller/state_controller_test.cc b/src/components/application_manager/test/state_controller/state_controller_test.cc index 721c795967..4000326849 100644 --- a/src/components/application_manager/test/state_controller/state_controller_test.cc +++ b/src/components/application_manager/test/state_controller/state_controller_test.cc @@ -151,7 +151,7 @@ class StateControllerImplTest : public ::testing::Test { } NiceMock app_manager_mock_; - NiceMock rpc_service_; + NiceMock mock_rpc_service_; NiceMock policy_interface_; NiceMock mock_connection_handler_; @@ -990,8 +990,8 @@ class StateControllerImplTest : public ::testing::Test { GetBCActivateAppRequestToHMI(_, _, _, hmi_lvl, _, _)) .WillByDefault(Return(bc_activate_app_request)); ON_CALL(app_manager_mock_, GetRPCService()) - .WillByDefault(ReturnRef(rpc_service_)); - ON_CALL(rpc_service_, ManageHMICommand(bc_activate_app_request)) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(bc_activate_app_request)) .WillByDefault(Return(true)); } @@ -1939,8 +1939,8 @@ TEST_F(StateControllerImplTest, DISABLED_ActivateAppSuccessReceivedFromHMI) { SetBCActivateAppRequestToHMI(hmi_level, corr_id); ON_CALL(app_manager_mock_, GetRPCService()) - .WillByDefault(ReturnRef(rpc_service_)); - ON_CALL(rpc_service_, ManageHMICommand(bc_activate_app_request)) + .WillByDefault(ReturnRef(mock_rpc_service_)); + ON_CALL(mock_rpc_service_, ManageHMICommand(bc_activate_app_request)) .WillByDefault(Return(true)); EXPECT_CALL(app_manager_mock_, application_id(corr_id)) diff --git a/src/components/include/test/application_manager/mock_application_manager.h b/src/components/include/test/application_manager/mock_application_manager.h index e74d2569ab..da227c7b60 100644 --- a/src/components/include/test/application_manager/mock_application_manager.h +++ b/src/components/include/test/application_manager/mock_application_manager.h @@ -51,6 +51,8 @@ #include "application_manager/event_engine/event_dispatcher.h" #include "application_manager/state_controller.h" #include "smart_objects/smart_object.h" +#include "application_manager/plugin_manager/rpc_plugin_manager.h" +#include "application_manager/command_factory.h" namespace test { namespace components { @@ -82,7 +84,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { const std::string& policy_app_id)); MOCK_METHOD2(ChangeAppsHMILevel, void(uint32_t app_id, mobile_apis::HMILevel::eType level)); - MOCK_METHOD0(GetPluginManager, plugin_manager::RPCPluginManager&()); + MOCK_METHOD0(GetPluginManager, + application_manager::plugin_manager::RPCPluginManager&()); MOCK_CONST_METHOD1( devices, std::vector(const std::string& policy_app_id)); #endif // SDL_REMOTE_CONTROL @@ -311,6 +314,8 @@ class MockApplicationManager : public application_manager::ApplicationManager { const uint32_t connection_key)); MOCK_CONST_METHOD1(IsAppInReconnectMode, bool(const std::string& policy_app_id)); + MOCK_CONST_METHOD0(GetCommandFactory, application_manager::CommandFactory&()); + MOCK_CONST_METHOD0(is_audio_pass_thru_active, bool()); }; } // namespace application_manager_test diff --git a/src/components/include/test/application_manager/mock_rpc_service.h b/src/components/include/test/application_manager/mock_rpc_service.h index 983e969b0a..360faae3ec 100644 --- a/src/components/include/test/application_manager/mock_rpc_service.h +++ b/src/components/include/test/application_manager/mock_rpc_service.h @@ -27,6 +27,10 @@ class MockRPCService : public application_manager::rpc_service::RPCService { void(const application_manager::MessagePtr& message)); MOCK_METHOD1(SendPostMessageToHMI, void(const application_manager::MessagePtr& message)); + MOCK_METHOD1(set_protocol_handler, + void(protocol_handler::ProtocolHandler* handler)); + MOCK_METHOD1(set_hmi_message_handler, + void(hmi_message_handler::HMIMessageHandler* handler)); #endif // SDL_REMOTE_CONTROL }; } diff --git a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h index 96e484acae..b48ebb59de 100644 --- a/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h +++ b/src/components/include/test/policy/policy_external/policy/mock_policy_manager.h @@ -67,7 +67,7 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD2(GetUpdateUrls, void(const std::string& service_type, EndpointUrls& out_end_points)); - MOCK_METHOD0(RequestPTUpdate, void()); + MOCK_METHOD0(RequestPTUpdate, bool()); MOCK_METHOD5(CheckPermissions, void(const PTString& app_id, const PTString& hmi_level, @@ -81,7 +81,7 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD0(ForcePTExchange, std::string()); MOCK_METHOD0(ForcePTExchangeAtUserRequest, std::string()); MOCK_METHOD0(ResetRetrySequence, void()); - MOCK_METHOD0(NextRetryTimeout, int()); + MOCK_METHOD0(NextRetryTimeout, uint32_t()); MOCK_METHOD0(TimeoutExchangeMSec, uint32_t()); MOCK_METHOD0(RetrySequenceDelaysSeconds, const std::vector()); MOCK_METHOD0(OnExceededTimeout, void()); @@ -110,9 +110,8 @@ class MockPolicyManager : public PolicyManager { MOCK_METHOD2(SetDeviceInfo, void(const std::string& device_id, const policy::DeviceInfo& device_info)); - MOCK_METHOD2(SetUserConsentForApp, - void(const policy::PermissionConsent& permissions, - const NotificationMode mode)); + MOCK_METHOD1(SetUserConsentForApp, + void(const policy::PermissionConsent& permissions)); MOCK_CONST_METHOD2(GetDefaultHmi, bool(const std::string& policy_app_id, std::string* default_hmi)); diff --git a/src/components/protocol_handler/CMakeLists.txt b/src/components/protocol_handler/CMakeLists.txt index ed3aaaf24c..d57211040a 100644 --- a/src/components/protocol_handler/CMakeLists.txt +++ b/src/components/protocol_handler/CMakeLists.txt @@ -65,7 +65,7 @@ endforeach() add_library(ProtocolHandler ${SOURCES}) -add_dependencies(ProtocolHandler libbson) +#add_dependencies(ProtocolHandler libbson) target_link_libraries(ProtocolHandler ${LIBRARIES}) if(BUILD_TESTS) -- cgit v1.2.1