From 5ad1ec608c31d34c2248cd62e46384da6910f34b Mon Sep 17 00:00:00 2001 From: oivin Date: Mon, 21 Jan 2019 10:14:49 +0200 Subject: Unit tests. --- .../mobile/set_interior_vehicle_data_request.cc | 2 +- .../get_interior_vehicle_data_request_test.cc | 137 +++++++++++++++++++++ .../set_interior_vehicle_data_request_test.cc | 99 ++++++++++++++- src/components/interfaces/HMI_API.xml | 2 +- src/components/interfaces/MOBILE_API.xml | 8 +- 5 files changed, 241 insertions(+), 7 deletions(-) diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc index 5f7fbfae48..54716fe9f6 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/src/commands/mobile/set_interior_vehicle_data_request.cc @@ -92,7 +92,7 @@ const std::map GetModuleDataToCapabilitiesMapping() { mapping["heatedWindshieldEnable"] = "heatedWindshieldAvailable"; mapping["heatedMirrorsEnable"] = "heatedMirrorsAvailable"; mapping["heatedRearWindowEnable"] = "heatedRearWindowAvailable"; - mapping["climateEnable"] = "climateEnable"; + mapping["climateEnable"] = "climateEnableAvailable"; mapping["climateEnableAvailable"] = "climateEnableAvailable"; // radio diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc index 9549830cec..25083d5f64 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/get_interior_vehicle_data_request_test.cc @@ -44,6 +44,7 @@ #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" +#include #include #include @@ -205,6 +206,8 @@ TEST_F(GetInteriorVehicleDataRequestTest, HMIResultCodeIs(hmi_apis::FunctionID::RC_GetInteriorVehicleData), _)) .WillOnce(Return(true)); // Act + + command->Init(); command->Run(); } @@ -232,6 +235,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, HMIResultCodeIs(hmi_apis::FunctionID::RC_GetInteriorVehicleData), _)) .WillOnce(Return(true)); // Act + command->Init(); command->Run(); } @@ -263,6 +267,7 @@ TEST_F( .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); // Act + command->Init(); command->Run(); // Assert @@ -314,6 +319,7 @@ TEST_F( command = CreateRCCommand< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + command->Init(); command->Run(); application_manager::event_engine::Event event( hmi_apis::FunctionID::RC_GetInteriorVehicleData); @@ -358,6 +364,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); // Act + command->Init(); command->Run(); // Assert @@ -393,6 +400,7 @@ TEST_F( MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)) .WillOnce((Return(true))); // Act + command->Init(); command->Run(); } @@ -418,6 +426,7 @@ TEST_F( .WillOnce((Return(true))); // Act + command->Init(); command->Run(); } @@ -458,6 +467,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, application_manager::event_engine::Event event( hmi_apis::FunctionID::RC_GetInteriorVehicleData); event.set_smart_object(*hmi_response_message); + command->Init(); command->Run(); command->on_event(event); } @@ -498,6 +508,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, hmi_apis::FunctionID::RC_GetInteriorVehicleData); event.set_smart_object(*hmi_message); auto command = CreateRCCommand(mobile_message); + command->Init(); command->Run(); command->on_event(event); } @@ -542,6 +553,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, command = CreateRCCommand< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + command->Init(); command->Run(); application_manager::event_engine::Event event( hmi_apis::FunctionID::RC_GetInteriorVehicleData); @@ -583,6 +595,7 @@ TEST_F(GetInteriorVehicleDataRequestTest, _)) .WillRepeatedly(Return(true)); // Act + command->Init(); command->Run(); } @@ -597,6 +610,130 @@ TEST_F(GetInteriorVehicleDataRequestTest, EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).Times(0); // Act + command->Init(); command->Run(); } + +TEST_F(GetInteriorVehicleDataRequestTest, + OnEvent_ValidHmiResponse_AvailableHDChanelsIsArrayWithHDChanels) { + using rc_rpc_plugin::commands::GetInteriorVehicleDataRequest; + namespace hmi_response = application_manager::hmi_response; + namespace strings = application_manager::strings; + + const uint32_t chanel1_index = 1u; + const uint32_t chanel2_index = 2u; + const uint32_t chanel3_index = 3u; + + const uint32_t expected_array_length = 3u; + + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + + MessageSharedPtr hmi_response_message = CreateBasicMessage(); + auto& hmi_response_params = (*hmi_response_message)[strings::msg_params]; + hmi_response_params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + hmi_response_params[strings::connection_key] = kAppId; + + auto& msg_params = (*hmi_response_message)[strings::msg_params]; + msg_params[message_params::kModuleType] = module_type; + + auto available_hd_chanels = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + available_hd_chanels[0] = chanel1_index; + available_hd_chanels[1] = chanel2_index; + available_hd_chanels[2] = chanel3_index; + + msg_params[message_params::kModuleData][message_params::kRadioControlData] + [message_params::kAvailableHdChannels] = available_hd_chanels; + + ON_CALL(mock_interior_data_cache_, Contains(_)).WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + MessageSharedPtr message_to_mob = CreateBasicMessage(); + + // Expectations + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mob), Return(true))); + + // Act + auto command = CreateRCCommand(mobile_message); + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleData); + + command->Init(); + command->Run(); + + event.set_smart_object(*hmi_response_message); + command->on_event(event); + + auto& hd_chanels = + (*message_to_mob)[strings::msg_params][message_params::kModuleData] + [message_params::kRadioControlData] + [message_params::kAvailableHdChannels]; + const size_t array_length = hd_chanels.length(); + + EXPECT_EQ(expected_array_length, array_length); + + EXPECT_EQ(chanel1_index, hd_chanels[0].asUInt()); + EXPECT_EQ(chanel2_index, hd_chanels[1].asUInt()); + EXPECT_EQ(chanel3_index, hd_chanels[2].asUInt()); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + OnEvent_ValidHmiResponse_ClimateEnableAvailable) { + using rc_rpc_plugin::commands::GetInteriorVehicleDataRequest; + namespace hmi_response = application_manager::hmi_response; + namespace strings = application_manager::strings; + + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + + MessageSharedPtr hmi_response_message = CreateBasicMessage(); + auto& hmi_response_params = (*hmi_response_message)[strings::msg_params]; + hmi_response_params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + hmi_response_params[strings::connection_key] = kAppId; + + auto& msg_params = (*hmi_response_message)[strings::msg_params]; + + auto climate_control_data = + smart_objects::SmartObject(smart_objects::SmartType_Boolean); + climate_control_data = true; + + msg_params[message_params::kModuleData][message_params::kClimateControlData] + [message_params::kClimateEnableAvailable] = climate_control_data; + + ON_CALL(mock_interior_data_cache_, Contains(_)).WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + auto message_to_mob = CreateBasicMessage(); + + // Expectations + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&message_to_mob), Return(true))); + + // Act + auto command = CreateRCCommand(mobile_message); + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleData); + + command->Init(); + command->Run(); + + event.set_smart_object(*hmi_response_message); + command->on_event(event); + + const bool climate_enable_available = + (*message_to_mob)[strings::msg_params][message_params::kModuleData] + [message_params::kClimateControlData] + [message_params::kClimateEnableAvailable] + .asBool(); + + EXPECT_TRUE(climate_enable_available); +} + } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc index 66280eb183..fc50288214 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/set_interior_vehicle_data_request_test.cc @@ -34,7 +34,6 @@ #include "application_manager/application.h" #include "application_manager/commands/command_request_test.h" #include "application_manager/mock_application.h" -#include "gtest/gtest.h" #include "interfaces/MOBILE_API.h" #include "rc_rpc_plugin/mock/mock_interior_data_cache.h" #include "rc_rpc_plugin/mock/mock_interior_data_manager.h" @@ -42,6 +41,9 @@ #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/rc_rpc_plugin.h" +#include +#include "gtest/gtest.h" + using application_manager::ApplicationSet; using application_manager::commands::MessageSharedPtr; using test::components::application_manager_test::MockApplication; @@ -51,6 +53,7 @@ using test::components::commands_test::CommandsTestMocks; using ::testing::_; using ::testing::NiceMock; using ::testing::Return; +using ::testing::SaveArg; namespace { const uint32_t kAppId = 0u; @@ -159,6 +162,7 @@ TEST_F(SetInteriorVehicleDataRequestTest, command = CreateRCCommand< rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( mobile_message); + command->Init(); command->Run(); } @@ -198,6 +202,7 @@ TEST_F( command = CreateRCCommand< rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( mobile_message); + command->Init(); command->Run(); } @@ -229,7 +234,99 @@ TEST_F( command = CreateRCCommand< rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( mobile_message); + command->Init(); command->Run(); } +TEST_F(SetInteriorVehicleDataRequestTest, + Execute_ValidWithSettableParams_SUCCESSSendToHMI) { + MessageSharedPtr mobile_message = CreateBasicMessage(); + auto& msg_params = + (*mobile_message)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleData][message_params::kModuleType] = + mobile_apis::ModuleType::CLIMATE; + + msg_params[message_params::kModuleData][message_params::kClimateControlData] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + msg_params[message_params::kModuleData][message_params::kClimateControlData] + [message_params::kClimateEnable] = true; + + // Expectations + EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) + .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); + + EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) + .WillOnce(Return(nullptr)); + + MessageSharedPtr message_from_mobile = CreateBasicMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&message_from_mobile), Return(true))); + + std::shared_ptr + command = CreateRCCommand< + rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( + mobile_message); + + command->Init(); + command->Run(); + + auto& msg_params_from_mobile = + (*message_from_mobile)[application_manager::strings::msg_params]; + + const bool climate_enable = + msg_params_from_mobile[message_params::kModuleData] + [message_params::kClimateControlData] + [message_params::kClimateEnable] + .asBool(); + EXPECT_TRUE(climate_enable); +} + +TEST_F(SetInteriorVehicleDataRequestTest, + Execute_ValidWithSettableParams_SUCCESSSendToHMI_HDChannel) { + MessageSharedPtr mobile_message = CreateBasicMessage(); + auto& msg_params = + (*mobile_message)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleData][message_params::kModuleType] = + mobile_apis::ModuleType::RADIO; + + msg_params[message_params::kModuleData][message_params::kRadioControlData] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + const std::uint32_t hd_channel = 2u; + msg_params[message_params::kModuleData][message_params::kRadioControlData] + [message_params::kHdChannel] = hd_channel; + + // Expectations + EXPECT_CALL(mock_policy_handler_, CheckModule(kPolicyAppId, _)) + .WillOnce(Return(rc_rpc_plugin::TypeAccess::kAllowed)); + + EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) + .WillOnce(Return(nullptr)); + + auto message_from_mobile = CreateBasicMessage(); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&message_from_mobile), Return(true))); + + std::shared_ptr + command = CreateRCCommand< + rc_rpc_plugin::commands::SetInteriorVehicleDataRequest>( + mobile_message); + + command->Init(); + command->Run(); + + auto& msg_params_from_mobile = + (*message_from_mobile)[application_manager::strings::msg_params]; + + const uint64_t hd_channel_from_hmi = + msg_params_from_mobile[message_params::kModuleData] + [message_params::kRadioControlData] + [message_params::kHdChannel] + .asUInt(); + + EXPECT_EQ(hd_channel, hd_channel_from_hmi); +} } // namespace rc_rpc_plugin_test diff --git a/src/components/interfaces/HMI_API.xml b/src/components/interfaces/HMI_API.xml index cd9e717b1d..0c7720e740 100644 --- a/src/components/interfaces/HMI_API.xml +++ b/src/components/interfaces/HMI_API.xml @@ -1882,7 +1882,7 @@ The list of available hd sub-channel indexes. Empty list means no Hd channel is available. Read-only. - + Current HD sub-channel if available diff --git a/src/components/interfaces/MOBILE_API.xml b/src/components/interfaces/MOBILE_API.xml index 6952eced29..0a3d7bb28d 100644 --- a/src/components/interfaces/MOBILE_API.xml +++ b/src/components/interfaces/MOBILE_API.xml @@ -3107,10 +3107,10 @@ - + The list of available HD sub-channel indexes. Empty list means no Hd channel is available. Read-only. - + Current HD sub-channel if available @@ -3208,7 +3208,7 @@ True: Available, False: Not Available, Not present: Not Available. - + Availability of the getting the number of available HD channels. True: Available, False: Not Available, Not present: Not Available. @@ -3217,7 +3217,7 @@ - + Availability of the list of available HD sub-channel indexes. True: Available, False: Not Available, Not present: Not Available. -- cgit v1.2.1