diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc')
-rw-r--r-- | src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc | 203 |
1 files changed, 195 insertions, 8 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc index ae2a544cc9..1316952a92 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_bc_system_capability_updated_notification_from_hmi_test.cc @@ -33,6 +33,8 @@ #include "hmi/on_bc_system_capability_updated_notification_from_hmi.h" #include "application_manager/commands/commands_test.h" +#include "sdl_rpc_plugin/extensions/system_capability_app_extension.h" + #include "gtest/gtest.h" namespace test { @@ -47,8 +49,10 @@ using ::testing::Return; typedef std::shared_ptr<OnBCSystemCapabilityUpdatedNotificationFromHMI> OnBCSystemCapabilityUpdatedNotificationFromHMIPtr; +typedef mobile_apis::SystemCapabilityType::eType SystemCapabilityType; namespace strings = application_manager::strings; + namespace { const uint32_t kAppId = 1u; } // namespace @@ -61,11 +65,30 @@ MATCHER(CheckMessageToMobile, "") { (*arg)[strings::params][strings::function_id].asInt()); const bool app_id_exist = (*arg)[strings::msg_params].keyExists(strings::app_id); - bool is_connection_key_correct = true; - if ((*arg)[strings::msg_params].keyExists(strings::connection_key)) { - is_connection_key_correct = - (*arg)[strings::params][strings::connection_key] == kAppId; - } + const bool is_connection_key_correct = [](arg_type arg) { + if ((*arg)[strings::msg_params].keyExists(strings::connection_key)) { + return (*arg)[strings::params][strings::connection_key] == kAppId; + } + return false; + }; + + return is_function_id_matched && app_id_exist && is_connection_key_correct; +} + +MATCHER(CheckMessageToMobileWithoutAppId, "") { + const auto function_id = mobile_apis::FunctionID::OnSystemCapabilityUpdatedID; + + const bool is_function_id_matched = + function_id == static_cast<am::mobile_api::FunctionID::eType>( + (*arg)[strings::params][strings::function_id].asInt()); + const bool app_id_exist = + (*arg)[strings::msg_params].keyExists(strings::app_id); + const bool is_connection_key_correct = [](arg_type arg) { + if ((*arg)[strings::msg_params].keyExists(strings::connection_key)) { + return (*arg)[strings::params][strings::connection_key] == kAppId; + } + return false; + }; return is_function_id_matched && !app_id_exist && is_connection_key_correct; } @@ -73,6 +96,27 @@ MATCHER_P(CheckDisplayCapabilitiesNotChanged, display_capability, "") { return display_capability == arg; } +MATCHER_P2(CheckVideoStreamingCapability, + system_capability_type, + video_streaming_capability, + "") { + const mobile_apis::SystemCapabilityType::eType received_sys_cap_type = + static_cast<mobile_apis::SystemCapabilityType::eType>( + (*arg)[strings::msg_params][strings::system_capability] + [strings::system_capability_type] + .asInt()); + + const bool system_capability_type_matched = + received_sys_cap_type == system_capability_type; + + const bool video_capability_matched = + video_streaming_capability == + (*arg)[strings::msg_params][strings::system_capability] + [strings::video_streaming_capability]; + + return system_capability_type_matched && video_capability_matched; +} + class OnBCSystemCapabilityUpdatedNotificationFromHMITest : public CommandsTest<CommandsTestMocks::kIsNice> { protected: @@ -105,7 +149,7 @@ TEST_F( EXPECT_CALL( mock_rpc_service_, ManageMobileCommand( - CheckMessageToMobile(), + CheckMessageToMobileWithoutAppId(), ::application_manager::commands::Command::CommandSource::SOURCE_SDL)) .WillOnce(Return(true)); @@ -130,7 +174,7 @@ TEST_F(OnBCSystemCapabilityUpdatedNotificationFromHMITest, TEST_F( OnBCSystemCapabilityUpdatedNotificationFromHMITest, - Run_AppRegisteredWithPresentedAppIdInMessage_SetDisplayCapabilitiesToApp_SendMessageToMobile) { + Run_AppRegisteredWithPresentedAppIdInMessage_SetDisplayCapabilitiesToAppAndAppIdIsErasedFromMessage_SendMessageToMobile) { (*message_)[am::strings::msg_params][strings::system_capability] [am::strings::system_capability_type] = mobile_apis::SystemCapabilityType::DISPLAYS; @@ -147,7 +191,7 @@ TEST_F( EXPECT_CALL( mock_rpc_service_, ManageMobileCommand( - CheckMessageToMobile(), + CheckMessageToMobileWithoutAppId(), ::application_manager::commands::Command::CommandSource::SOURCE_SDL)) .WillOnce(Return(true)); @@ -155,6 +199,149 @@ TEST_F( command_->Run(); } +TEST_F( + OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_SysCapTypeVideoStreaming_CapabilityIsAbsent_DoesntSetInHMICapabilities) { + smart_objects::SmartObject system_capability = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + system_capability[strings::system_capability_type] = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + + ASSERT_TRUE(command_->Init()); + EXPECT_CALL(mock_hmi_capabilities_, set_video_streaming_capability(_)) + .Times(0); + command_->Run(); +} + +TEST_F(OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_VideoStreamingCapability_AppIdIsAbsent_NotificationIgnored) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_VideoStreamingCapability_AppNotRegistered_NotificationIgnored) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + (*message_)[am::strings::msg_params][strings::app_id] = kAppId; + + ApplicationSharedPtr app; // Empty application shared pointer + + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(app)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F(OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_VideoStreamingCapability_AppNotSubsribed_NotificationIgnored) { + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + (*message_)[am::strings::msg_params][strings::app_id] = kAppId; + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + + // By default system capability extension is not subsribed to the + // VIDEO_STREAMING + auto system_capability_app_extension = + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_); + + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_VideoStreamingCapability_AppIsSubsribed_VideoCapabilityIsAbsent_NotificationIgnored) { + const mobile_apis::SystemCapabilityType::eType system_capability_type = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = system_capability_type; + (*message_)[am::strings::msg_params][strings::app_id] = kAppId; + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + std::shared_ptr<sdl_rpc_plugin::SystemCapabilityAppExtension> + system_capability_app_extension( + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_)); + system_capability_app_extension->SubscribeTo(system_capability_type); + + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + +TEST_F( + OnBCSystemCapabilityUpdatedNotificationFromHMITest, + Run_VideoStreamingCapability_AppIsSubsribed_VideoCapabilityExists_NotificationForwarded) { + const mobile_apis::SystemCapabilityType::eType system_capability_type = + mobile_apis::SystemCapabilityType::VIDEO_STREAMING; + + (*message_)[am::strings::msg_params][strings::system_capability] + [am::strings::system_capability_type] = system_capability_type; + (*message_)[am::strings::msg_params][strings::app_id] = kAppId; + + (*message_)[am::strings::msg_params][strings::system_capability] + [strings::video_streaming_capability] = + new smart_objects::SmartObject( + smart_objects::SmartType::SmartType_Map); + + auto& video_streaming_capability = + (*message_)[am::strings::msg_params][strings::system_capability] + [strings::video_streaming_capability]; + + FillVideoStreamingCapability(video_streaming_capability); + + sdl_rpc_plugin::SDLRPCPlugin sdl_rpc_plugin; + std::shared_ptr<sdl_rpc_plugin::SystemCapabilityAppExtension> + system_capability_app_extension( + std::make_shared<sdl_rpc_plugin::SystemCapabilityAppExtension>( + sdl_rpc_plugin, *mock_app_)); + system_capability_app_extension->SubscribeTo(system_capability_type); + + ON_CALL(*mock_app_, + QueryInterface(sdl_rpc_plugin::SystemCapabilityAppExtension:: + SystemCapabilityAppExtensionUID)) + .WillByDefault(Return(system_capability_app_extension)); + ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckVideoStreamingCapability(system_capability_type, + video_streaming_capability), + _)); + + ASSERT_TRUE(command_->Init()); + command_->Run(); +} + } // namespace on_bc_system_capability_updated_notification_from_hmi } // namespace hmi_commands_test } // namespace commands_test |