diff options
author | Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com> | 2019-08-20 17:39:23 +0300 |
---|---|---|
committer | Andriy Byzhynar (GitHub) <AByzhynar@luxoft.com> | 2019-08-21 13:18:16 +0300 |
commit | f8085a5316b7b0deef654c69489a63b33d444a7f (patch) | |
tree | 23c734b8286d14a4fe9d5e5d63ad291f5bdefa71 | |
parent | c2192fa76603a4fa91be589d84b75b1742b5619f (diff) | |
download | sdl_core-f8085a5316b7b0deef654c69489a63b33d444a7f.tar.gz |
Add app version check to SetDisplayLayout RPC
Added app version check and appropriate result code generation
Updated old/added new unit tests
3 files changed, 78 insertions, 14 deletions
diff --git a/src/components/application_manager/include/application_manager/application.h b/src/components/application_manager/include/application_manager/application.h index 15c01072ed..53d98456c2 100644 --- a/src/components/application_manager/include/application_manager/application.h +++ b/src/components/application_manager/include/application_manager/application.h @@ -70,7 +70,9 @@ enum APIVersion { kAPIV1 = 1, kAPIV2 = 2, kAPIV3 = 3, - kAPIV4 = 4 + kAPIV4 = 4, + kAPIV5 = 5, + kAPIV6 = 6 }; enum TLimitSource { POLICY_TABLE = 0, CONFIG_FILE }; diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc index f28b136038..5ba1076084 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/src/commands/mobile/set_display_layout_request.cc @@ -125,6 +125,14 @@ void SetDisplayLayoutRequest::Run() { void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { LOG4CXX_AUTO_TRACE(logger_); + ApplicationSharedPtr app = application_manager_.application(connection_key()); + + if (!app) { + LOG4CXX_ERROR(logger_, "Application is not registered"); + SendResponse(false, mobile_apis::Result::APPLICATION_NOT_REGISTERED); + return; + } + const smart_objects::SmartObject& message = event.smart_object(); switch (event.id()) { case hmi_apis::FunctionID::UI_SetDisplayLayout: { @@ -152,18 +160,21 @@ void SetDisplayLayoutRequest::on_event(const event_engine::Event& event) { hmi_response::templates_available); } } - - // In case of successful response warn user that this RPC is deprecated - result_code = hmi_apis::Common_Result::WARNINGS; - info = - "The RPC is deprecated and will be removed in a future version. " - "The requested display layout is set to the main window. Please " - "use `Show.templateConfiguration` instead."; + const Version& app_version = app->version(); + if (app_version.max_supported_api_version >= APIVersion::kAPIV6) { + // In case of successful response warn user that this RPC is + // deprecated from 6.0 and higher API versions + result_code = hmi_apis::Common_Result::WARNINGS; + info = + "The RPC is deprecated and will be removed in a future version. " + "The requested display layout is set to the main window. Please " + "use `Show.templateConfiguration` instead."; + } } SendResponse(response_success, MessageHelper::HMIToMobileResult(result_code), - info.empty() ? NULL : info.c_str(), + info.empty() ? nullptr : info.c_str(), &msg_params); break; } 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 index 7b9b2e9f1a..cde15a2318 100644 --- 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 @@ -160,6 +160,7 @@ TEST_F(SetDisplayLayoutRequestTest, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + command->Init(); command->on_event(event); ResultCommandExpectations(ui_command_result, "UI is not supported by system"); @@ -178,6 +179,7 @@ TEST_F(SetDisplayLayoutRequestTest, Run_InvalidApp_UNSUCCESS) { MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), am::commands::Command::CommandSource::SOURCE_SDL)); + command->Init(); command->Run(); } @@ -204,20 +206,26 @@ TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { ManageHMICommand(CheckMshCorrId(kCorrelationKey), _)) .WillOnce(Return(true)); + command->Init(); command->Run(); } TEST_F(SetDisplayLayoutRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { - CommandPtr command(CreateCommand<SetDisplayLayoutRequest>()); - am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); - SmartObject msg(smart_objects::SmartType_Map); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); - event.set_smart_object(msg); + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*msg); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + command->Init(); command->on_event(event); } -TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { +TEST_F(SetDisplayLayoutRequestTest, OnEvent_AppVersion_v6_WARNING) { am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); MessageSharedPtr msg = CreateMessage(); @@ -239,6 +247,49 @@ TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { am::commands::Command::CommandSource::SOURCE_SDL)); CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ::application_manager::Version app_version; + app_version.max_supported_api_version = + ::application_manager::APIVersion::kAPIV6; + EXPECT_CALL(*mock_app, version()).WillOnce(ReturnRef(app_version)); + + command->Init(); + command->on_event(event); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_AppVersion_v5_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<SetDisplayLayoutRequest>(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + ::application_manager::Version app_version; + app_version.max_supported_api_version = + ::application_manager::APIVersion::kAPIV5; + EXPECT_CALL(*mock_app, version()).WillOnce(ReturnRef(app_version)); + + command->Init(); command->on_event(event); } |