diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/rc_rpc_plugin/test')
12 files changed, 798 insertions, 155 deletions
diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt index a1f0f5a6ff..c1c59d7e78 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/CMakeLists.txt @@ -41,6 +41,7 @@ include_directories ( set (RC_TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/resource_allocation_manager_impl_test.cc +${CMAKE_CURRENT_SOURCE_DIR}/interior_data_cache_test.cc ) set(RC_COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) @@ -72,5 +73,5 @@ if(ENABLE_LOG) endif() create_test("rc_commands_test" "${SOURCES}" "${LIBRARIES}" ) -create_test("resource_allocation_manager_test" "${RC_TEST_SOURCES}" "${LIBRARIES}") +create_test("rc_plugin_test" "${RC_TEST_SOURCES}" "${LIBRARIES}") diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc index 8ddcaa469d..022a3e51c9 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/button_press_request_test.cc @@ -37,6 +37,8 @@ #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/commands/command_request_test.h" @@ -115,7 +117,7 @@ class ButtonPressRequestTest } rc_capabilities_[strings::kbuttonCapabilities] = button_caps; ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); - ON_CALL(mock_allocation_manager_, GetApplicationExtention(_)) + ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); @@ -147,12 +149,14 @@ class ButtonPressRequestTest template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - mock_rpc_service_, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } protected: @@ -163,6 +167,10 @@ class ButtonPressRequestTest mock_policy_handler_; testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; }; TEST_F(ButtonPressRequestTest, 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 a6f0ee12ca..0b30bbf654 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 @@ -35,11 +35,17 @@ #include "application_manager/mock_application.h" #include "rc_rpc_plugin/rc_app_extension.h" #include "rc_rpc_plugin/rc_module_constants.h" +#include "rc_rpc_plugin/rc_rpc_plugin.h" #include "application_manager/message_helper.h" #include "rc_rpc_plugin/rc_command_factory.h" #include "application_manager/event_engine/event_dispatcher.h" #include "application_manager/commands/command_request_test.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" + +#include <thread> +#include <chrono> using ::testing::_; using ::testing::Mock; @@ -50,6 +56,7 @@ using ::testing::ReturnRef; using ::testing::SaveArg; using ::application_manager::Message; using ::application_manager::MessageType; +using application_manager::ApplicationSet; using application_manager::commands::MessageSharedPtr; using ::application_manager::ApplicationSharedPtr; using ::protocol_handler::MessagePriority; @@ -64,7 +71,11 @@ using test::components::commands_test::MobileResultCodeIs; namespace { const int32_t kConnectionKey = 5u; const uint32_t kAppId = 0u; +const uint32_t kAppId2 = 1u; const int kModuleId = 153u; +const auto module_type = mobile_apis::ModuleType::RADIO; +const int32_t time_frame_of_allowed_requests = 1; +const uint32_t max_request_in_time_frame = 5u; } namespace rc_rpc_plugin_test { @@ -75,163 +86,508 @@ class GetInteriorVehicleDataRequestTest public: GetInteriorVehicleDataRequestTest() : mock_app_(std::make_shared<NiceMock<MockApplication> >()) - , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) { + , mock_app2_(std::make_shared<NiceMock<MockApplication> >()) + , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) + , rc_app_extention2_(std::make_shared<RCAppExtension>(kModuleId)) + , apps_lock_(std::make_shared<sync_primitives::Lock>()) + , apps_da_(apps_, apps_lock_) { ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app2_, app_id()).WillByDefault(Return(kAppId2)); + ON_CALL(*mock_app_, is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL(*mock_app2_, is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, QueryInterface(_)) + .WillByDefault(Return(rc_app_extention_)); + ON_CALL(*mock_app2_, QueryInterface(_)) + .WillByDefault(Return(rc_app_extention2_)); + } + + /** + * @brief CreateBasicMessage creates message for + * GetInteriorVehicleData request for app1 + * @return message shared ptr + */ + MessageSharedPtr CreateBasicMessage() { + MessageSharedPtr message = CreateMessage(); + (*message)[application_manager::strings::params] + [application_manager::strings::function_id] = + mobile_apis::FunctionID::GetInteriorVehicleDataID; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kConnectionKey; + (*message)[application_manager::strings::params] + [application_manager::strings::connection_key] = kAppId; + return message; + } + + void SetUp() OVERRIDE { + std::pair<uint32_t, int32_t> frequency; + frequency.first = max_request_in_time_frame; + frequency.second = time_frame_of_allowed_requests; + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, get_interior_vehicle_data_frequency()) + .WillByDefault(ReturnRef(frequency)); + ON_CALL(app_mngr_, hmi_interfaces()) .WillByDefault(ReturnRef(mock_hmi_interfaces_)); - ON_CALL( mock_hmi_interfaces_, GetInterfaceState(application_manager::HmiInterfaces::HMI_INTERFACE_RC)) .WillByDefault(Return(application_manager::HmiInterfaces:: InterfaceState::STATE_AVAILABLE)); ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); - ON_CALL(mock_allocation_manager_, GetApplicationExtention(_)) - .WillByDefault(Return(rc_app_extention_)); + ON_CALL(app_mngr_, application(kAppId2)).WillByDefault(Return(mock_app2_)); ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); ON_CALL(app_mngr_, hmi_capabilities()) .WillByDefault(ReturnRef(mock_hmi_capabilities_)); ON_CALL(mock_hmi_capabilities_, rc_capability()) - .WillByDefault(Return(&rc_capabilities_)); + .WillByDefault(Return(nullptr)); ON_CALL(mock_policy_handler_, CheckHMIType( _, mobile_apis::AppHMIType::eType::REMOTE_CONTROL, nullptr)) .WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, CheckModule(_, _)) + .WillByDefault(Return(true)); ON_CALL(mock_allocation_manager_, is_rc_enabled()) .WillByDefault(Return(true)); } - MessageSharedPtr CreateBasicMessage() { - MessageSharedPtr message = CreateMessage(); - (*message)[application_manager::strings::params] - [application_manager::strings::function_id] = - mobile_apis::FunctionID::GetInteriorVehicleDataID; - (*message)[application_manager::strings::params] - [application_manager::strings::connection_key] = kConnectionKey; - (*message)[application_manager::strings::params] - [application_manager::strings::connection_key] = kAppId; - return message; - } template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - mock_rpc_service_, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } protected: - smart_objects::SmartObject rc_capabilities_; std::shared_ptr<MockApplication> mock_app_; + std::shared_ptr<MockApplication> mock_app2_; std::shared_ptr<RCAppExtension> rc_app_extention_; + std::shared_ptr<RCAppExtension> rc_app_extention2_; testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; + application_manager::ApplicationSet apps_; + const std::shared_ptr<sync_primitives::Lock> apps_lock_; + DataAccessor<application_manager::ApplicationSet> apps_da_; }; + TEST_F(GetInteriorVehicleDataRequestTest, - Execute_MessageValidationOk_ExpectCorrectMessageSentToHMI) { + Execute_ExpectCorrectMessageSentToHMI_NoSubscriptionNoCache) { // Arrange - ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(true)); - EXPECT_CALL(mock_hmi_capabilities_, rc_capability()) - .WillOnce(Return(nullptr)); + MessageSharedPtr mobile_message = CreateBasicMessage(); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + ON_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + .WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + mobile_message); + + // Expectations EXPECT_CALL(mock_rpc_service_, ManageHMICommand(HMIResultCodeIs( hmi_apis::FunctionID::RC_GetInteriorVehicleData))) .WillOnce(Return(true)); + // Act + command->Run(); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + Execute_ExpectCorrectMessageSentToHMI_SupscribeAppNoCache) { + // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kSubscribe] = true; + ON_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + .WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); std::shared_ptr< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + + // Expectations + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillOnce(Return(true)); + // Act command->Run(); } TEST_F( GetInteriorVehicleDataRequestTest, - Execute_MessageValidationFailed_ExpectMessageNotSentToHMI_AndFalseSentToMobile) { + Execute_ExpectMessageNotSentToHMI_SuccessSentToMobile_AppSubscribed_DataFromCache) { // Arrange + rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); MessageSharedPtr mobile_message = CreateBasicMessage(); - NsSmartDeviceLink::NsSmartObjects::SmartObject& msg_params = - (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; - ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(true)); - MessageSharedPtr command_result; - EXPECT_CALL(mock_rpc_service_, - ManageHMICommand(HMIResultCodeIs( - hmi_apis::FunctionID::RC_GetInteriorVehicleData))).Times(0); - EXPECT_CALL( - mock_rpc_service_, - ManageMobileCommand( - MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)) - .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + smart_objects::SmartObject radio_data; + radio_data[message_params::kBand] = enums_value::kAM; std::shared_ptr< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + + // Expectations + EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_interior_data_cache_, Retrieve(enums_value::kRadio)) + .WillOnce(Return(radio_data)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + MessageSharedPtr command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); + + // Act command->Run(); + + // Assert + EXPECT_EQ((*command_result)[application_manager::strings::msg_params] + [message_params::kModuleData] + [message_params::kRadioControlData], + radio_data); } -TEST_F(GetInteriorVehicleDataRequestTest, - OnEvent_ValidHmiResponse_ExpectSuccessfullResponseSentToMobile) { +TEST_F( + GetInteriorVehicleDataRequestTest, + Execute_ExpectCorrectMessageSentToHMI_LastAppSubscribedUnsubscibe_ClearCache) { // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); - NsSmartDeviceLink::NsSmartObjects::SmartObject& msg_params = - (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = mobile_apis::ModuleType::CLIMATE; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kSubscribe] = false; - MessageSharedPtr hmi_message = CreateBasicMessage(); + MessageSharedPtr hmi_response = CreateBasicMessage(); NsSmartDeviceLink::NsSmartObjects::SmartObject& hmi_msg_params = - (*hmi_message)[application_manager::strings::msg_params]; + (*hmi_response)[application_manager::strings::msg_params]; hmi_apis::Common_Result::eType response_code = hmi_apis::Common_Result::SUCCESS; hmi_msg_params[application_manager::hmi_response::code] = response_code; hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; + apps_.insert(mock_app_); + rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + // Expectations + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillOnce(Return(true)); EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) .WillOnce(Return(true)); + EXPECT_CALL(mock_interior_data_cache_, Remove(enums_value::kRadio)); + + // Act + std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + mobile_message); + command->Run(); application_manager::event_engine::Event event( hmi_apis::FunctionID::RC_GetInteriorVehicleData); - event.set_smart_object(*hmi_message); + event.set_smart_object(*hmi_response); + command->on_event(event); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + Execute_ExpectMessageNotSentToHMI_TwoApps_OneUnsubscribed) { + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kSubscribe] = false; + + apps_.insert(mock_app_); + apps_.insert(mock_app2_); + rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + rc_app_extention2_->SubscribeToInteriorVehicleData(enums_value::kRadio); + + smart_objects::SmartObject radio_data; + radio_data[message_params::kBand] = enums_value::kAM; + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + std::shared_ptr< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); + + // Expectations + EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_interior_data_cache_, Retrieve(enums_value::kRadio)) + .WillOnce(Return(radio_data)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + MessageSharedPtr command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); + + // Act + command->Run(); + + // Assert + EXPECT_FALSE( + rc_app_extention_->IsSubscibedToInteriorVehicleData(enums_value::kRadio)); + EXPECT_EQ((*command_result)[application_manager::strings::msg_params] + [message_params::kModuleData] + [message_params::kRadioControlData], + radio_data); +} + +TEST_F( + GetInteriorVehicleDataRequestTest, + Execute_CapabilitiesValidationFailed_ExpectMessageNotSentToHMI_AndFalseSentToMobile) { + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + NsSmartDeviceLink::NsSmartObjects::SmartObject& msg_params = + (*mobile_message)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; + std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + mobile_message); + smart_objects::SmartObject rc_capabilities; + ON_CALL(mock_hmi_capabilities_, rc_capability()) + .WillByDefault(Return(&rc_capabilities)); + + // Expectations + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), + _)).WillOnce((Return(true))); + // Act + command->Run(); +} + +TEST_F( + GetInteriorVehicleDataRequestTest, + Execute_PolicyValidationFailed_ExpectMessageNotSentToHMI_AndFalseSentToMobile) { + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + NsSmartDeviceLink::NsSmartObjects::SmartObject& msg_params = + (*mobile_message)[application_manager::strings::msg_params]; + msg_params[message_params::kModuleType] = mobile_apis::ModuleType::RADIO; + std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + mobile_message); + ON_CALL(mock_policy_handler_, CheckModule(_, _)).WillByDefault(Return(false)); + + // Expectations + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DISALLOWED), _)) + .WillOnce((Return(true))); + + // Act + command->Run(); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + OnEvent_ValidHmiResponse_ExpectSuccessfulResponseSentToMobile_NoCache) { + using rc_rpc_plugin::commands::GetInteriorVehicleDataRequest; + namespace hmi_response = application_manager::hmi_response; + namespace strings = application_manager::strings; + + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + auto& msg_params = (*mobile_message)[strings::msg_params]; + msg_params[message_params::kModuleType] = module_type; + + 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] = kConnectionKey; + + ON_CALL(mock_interior_data_cache_, Contains(_)).WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + // Expectations + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillOnce(Return(true)); + + // Act + auto command = CreateRCCommand<GetInteriorVehicleDataRequest>(mobile_message); + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleData); + event.set_smart_object(*hmi_response_message); + command->Run(); command->on_event(event); } TEST_F(GetInteriorVehicleDataRequestTest, OnEvent_InvalidHmiResponse_ExpectGenericErrorResponseSentToMobile) { + using rc_rpc_plugin::commands::GetInteriorVehicleDataRequest; + namespace hmi_response = application_manager::hmi_response; + namespace strings = application_manager::strings; + // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); - NsSmartDeviceLink::NsSmartObjects::SmartObject& msg_params = + auto& msg_params = (*mobile_message)[application_manager::strings::msg_params]; - msg_params[message_params::kModuleType] = mobile_apis::ModuleType::CLIMATE; + msg_params[message_params::kModuleType] = module_type; MessageSharedPtr hmi_message = CreateBasicMessage(); + auto& hmi_msg_params = (*hmi_message)[strings::params]; + hmi_msg_params[hmi_response::code] = hmi_apis::Common_Result::READ_ONLY; + hmi_msg_params[strings::connection_key] = kConnectionKey; + ON_CALL(mock_interior_data_cache_, Contains(_)).WillByDefault(Return(false)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + // Expectations + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)) + .WillOnce(Return(true)); + + // Act + application_manager::event_engine::Event event( + hmi_apis::FunctionID::RC_GetInteriorVehicleData); + event.set_smart_object(*hmi_message); + auto command = CreateRCCommand<GetInteriorVehicleDataRequest>(mobile_message); + command->Run(); + command->on_event(event); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + OnEvent_InvalidHmiResponse_DontUnsubscibeLastApp_NoClearCache) { + // Arrange + MessageSharedPtr mobile_message = CreateBasicMessage(); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kSubscribe] = false; + + MessageSharedPtr hmi_response = CreateBasicMessage(); NsSmartDeviceLink::NsSmartObjects::SmartObject& hmi_msg_params = - (*hmi_message)[application_manager::strings::params]; - hmi_apis::Common_Result::eType response_code = + (*hmi_response)[application_manager::strings::params]; + hmi_msg_params[application_manager::hmi_response::code] = hmi_apis::Common_Result::READ_ONLY; - hmi_msg_params[application_manager::hmi_response::code] = response_code; hmi_msg_params[application_manager::strings::connection_key] = kConnectionKey; + + apps_.insert(mock_app_); + rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kRadio); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + ON_CALL(mock_interior_data_manager_, CheckRequestsToHMIFrequency(_)) + .WillByDefault(Return(true)); + + // Expectations + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillOnce(Return(true)); EXPECT_CALL(mock_rpc_service_, ManageMobileCommand( MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)) - .WillOnce(Return(false)); + .WillOnce(Return(true)); + EXPECT_CALL(mock_interior_data_cache_, Clear()).Times(0); + + // Act + std::shared_ptr< + rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = + CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( + mobile_message); + command->Run(); application_manager::event_engine::Event event( hmi_apis::FunctionID::RC_GetInteriorVehicleData); - event.set_smart_object(*hmi_message); + event.set_smart_object(*hmi_response); + command->on_event(event); + + // Assert + EXPECT_TRUE( + rc_app_extention_->IsSubscibedToInteriorVehicleData(enums_value::kRadio)); +} + +TEST_F(GetInteriorVehicleDataRequestTest, + Execute_ExpectRejectDuToRequestLimitation_NoCahce) { + // Arrange + rc_app_extention_->UnsubscribeFromInteriorVehicleData(enums_value::kRadio); + MessageSharedPtr mobile_message = CreateBasicMessage(); + (*mobile_message)[application_manager::strings::msg_params] + [message_params::kModuleType] = module_type; + smart_objects::SmartObject radio_data; + radio_data[message_params::kBand] = enums_value::kAM; std::shared_ptr< rc_rpc_plugin::commands::GetInteriorVehicleDataRequest> command = CreateRCCommand<rc_rpc_plugin::commands::GetInteriorVehicleDataRequest>( mobile_message); - command->on_event(event); + size_t i = 0; + for (; i <= max_request_in_time_frame; ++i) { + // Expectations + EXPECT_CALL(mock_interior_data_manager_, + CheckRequestsToHMIFrequency(enums_value::kRadio)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_interior_data_manager_, + StoreRequestToHMITime(enums_value::kRadio)); + EXPECT_CALL(mock_interior_data_cache_, Contains(enums_value::kRadio)) + .WillRepeatedly(Return(false)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::RC_GetInteriorVehicleData))) + .WillRepeatedly(Return(true)); + // Act + command->Run(); + } + + // Expectations + EXPECT_CALL(mock_interior_data_manager_, + CheckRequestsToHMIFrequency(enums_value::kRadio)) + .WillOnce(Return(false)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::REJECTED), _)) + .WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + // Act + command->Run(); } } // namespace rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc index df11bf8c88..b344471254 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_interior_vehicle_data_notification_test.cc @@ -37,6 +37,8 @@ #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" #include "gtest/gtest.h" #include "interfaces/MOBILE_API.h" @@ -56,6 +58,7 @@ namespace { const uint32_t kAppId = 0u; const uint32_t kConnectionKey = 1u; const std::string kPolicyAppId = "Test"; +const int kModuleId = 153u; } namespace rc_rpc_plugin_test { @@ -66,62 +69,72 @@ class OnInteriorVehicleDataNotificationTest : public CommandsTest<CommandsTestMocks::kIsNice> { public: OnInteriorVehicleDataNotificationTest() - : mock_app_(std::make_shared<NiceMock<MockApplication> >()) {} + : mock_app_(std::make_shared<NiceMock<MockApplication> >()) + , rc_app_extention_(std::make_shared<RCAppExtension>(kModuleId)) + , apps_lock_(std::make_shared<sync_primitives::Lock>()) + , apps_da_(apps_, apps_lock_) { + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, is_remote_control_supported()) + .WillByDefault(Return(true)); + ON_CALL(*mock_app_, QueryInterface(_)) + .WillByDefault(Return(rc_app_extention_)); + } MessageSharedPtr CreateBasicMessage() { MessageSharedPtr message = CreateMessage(); (*message)[application_manager::strings::params] [application_manager::strings::function_id] = - mobile_apis::FunctionID::SetInteriorVehicleDataID; + mobile_apis::FunctionID::OnInteriorVehicleDataID; (*message)[application_manager::strings::params] [application_manager::strings::connection_key] = kConnectionKey; (*message)[application_manager::strings::params] - [application_manager::strings::connection_key] = kAppId; + [application_manager::strings::app_id] = kAppId; smart_objects::SmartObject& msg_param = (*message)[application_manager::strings::msg_params]; - msg_param[message_params::kModuleType] = mobile_apis::ModuleType::CLIMATE; - + msg_param[message_params::kModuleData][message_params::kModuleType] = + mobile_apis::ModuleType::CLIMATE; return message; } template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - mock_rpc_service_, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return ::std::make_shared<Command>(msg ? msg : msg = CreateMessage(), + params); } protected: std::shared_ptr<MockApplication> mock_app_; + std::shared_ptr<RCAppExtension> rc_app_extention_; testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; + application_manager::ApplicationSet apps_; + const std::shared_ptr<sync_primitives::Lock> apps_lock_; + DataAccessor<application_manager::ApplicationSet> apps_da_; }; TEST_F(OnInteriorVehicleDataNotificationTest, Run_SendMessageToMobile_Notification) { // Arrange MessageSharedPtr mobile_message = CreateBasicMessage(); - ApplicationSet app_set = {mock_app_}; - MessageSharedPtr message; - std::shared_ptr<sync_primitives::Lock> apps_lock = - std::make_shared<sync_primitives::Lock>(); - DataAccessor<ApplicationSet> accessor(app_set, apps_lock); - // Expectations - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - RCAppExtensionPtr rc_extention_ptr = - std::make_shared<RCAppExtension>(application_manager::AppExtensionUID( - rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); - rc_extention_ptr->SubscribeToInteriorVehicleData(enums_value::kClimate); - ON_CALL(*mock_app_, QueryInterface(_)) - .WillByDefault(Return(rc_extention_ptr)); - ON_CALL(*mock_app_, is_remote_control_supported()) - .WillByDefault(Return(true)); + apps_.insert(mock_app_); + rc_app_extention_->SubscribeToInteriorVehicleData(enums_value::kClimate); + ON_CALL(app_mngr_, applications()).WillByDefault(Return(apps_da_)); + // Expectations + EXPECT_CALL(mock_interior_data_cache_, Add(enums_value::kClimate, _)); + MessageSharedPtr message; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, false)) .WillOnce(SaveArg<0>(&message)); // Act @@ -130,8 +143,9 @@ TEST_F(OnInteriorVehicleDataNotificationTest, rc_rpc_plugin::commands::OnInteriorVehicleDataNotification>( mobile_message); command->Run(); + // Assertions - ASSERT_TRUE((bool)message); + ASSERT_TRUE(message.get()); Mock::VerifyAndClearExpectations(&app_mngr_); } diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc index 9054ce4830..b95725e0b4 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/on_remote_control_settings_test.cc @@ -38,6 +38,8 @@ #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" #include "gtest/gtest.h" #include "interfaces/MOBILE_API.h" @@ -87,18 +89,24 @@ class RCOnRemoteControlSettingsNotificationTest template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - mock_rpc_service_, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } protected: std::shared_ptr<MockApplication> mock_app_; testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; }; TEST_F(RCOnRemoteControlSettingsNotificationTest, @@ -131,22 +139,8 @@ TEST_F(RCOnRemoteControlSettingsNotificationTest, (*mobile_message)[application_manager::strings::msg_params] [message_params::kAllowed] = false; - ApplicationSet app_set = {mock_app_}; - - std::shared_ptr<sync_primitives::Lock> apps_lock = - std::make_shared<sync_primitives::Lock>(); - DataAccessor<ApplicationSet> accessor(app_set, apps_lock); - // Expectations - EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); - - RCAppExtensionPtr rc_extention_ptr = - std::make_shared<RCAppExtension>(application_manager::AppExtensionUID( - rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); - rc_extention_ptr->SubscribeToInteriorVehicleData(enums_value::kClimate); - ON_CALL(*mock_app_, QueryInterface(_)) - .WillByDefault(Return(rc_extention_ptr)); - EXPECT_CALL(mock_allocation_manager_, ResetAllAllocations()); + EXPECT_CALL(mock_interior_data_manager_, OnDisablingRC()); // Act std::shared_ptr< diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc index 7f36d251cc..567d4b1e20 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/commands/rc_get_interior_vehicle_data_consent_test.cc @@ -46,6 +46,8 @@ #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" #include "rc_rpc_plugin/commands/mobile/button_press_request.h" #include "rc_rpc_plugin/commands/hmi/rc_get_interior_vehicle_data_consent_response.h" #include "rc_rpc_plugin/commands/hmi/rc_get_interior_vehicle_data_consent_request.h" @@ -100,11 +102,11 @@ class RCGetInteriorVehicleDataConsentTest : mock_app_(std::make_shared<NiceMock<MockApplication> >()) , command_holder(app_mngr_) , request_controller(mock_request_controler) - , rpc_service(app_mngr_, - request_controller, - &mock_protocol_handler, - &mock_hmi_handler, - command_holder) + , rpc_service_(app_mngr_, + request_controller, + &mock_protocol_handler, + &mock_hmi_handler, + command_holder) , rc_app_extention_(std::make_shared<RCAppExtension>(kPluginID)) , mock_rpc_plugin_manager( std::make_shared<NiceMock<MockRPCPluginManager> >()) @@ -119,8 +121,10 @@ class RCGetInteriorVehicleDataConsentTest .WillByDefault(Return(application_manager::HmiInterfaces:: InterfaceState::STATE_AVAILABLE)); ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); - ON_CALL(mock_allocation_manager_, GetApplicationExtention(_)) + ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; ON_CALL(app_mngr_, GetPolicyHandler()) .WillByDefault(ReturnRef(mock_policy_handler_)); ON_CALL(app_mngr_, hmi_capabilities()) @@ -146,12 +150,14 @@ class RCGetInteriorVehicleDataConsentTest template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - rpc_service, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } MessageSharedPtr CreateBasicMessage() { @@ -174,11 +180,15 @@ class RCGetInteriorVehicleDataConsentTest am::CommandHolderImpl command_holder; testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; smart_objects::SmartObject rc_capabilities_; MockRPCPlugin mock_rpc_plugin; MockCommandFactory mock_command_factory; am::request_controller::RequestController request_controller; - am::rpc_service::RPCServiceImpl rpc_service; + am::rpc_service::RPCServiceImpl rpc_service_; std::shared_ptr<RCAppExtension> rc_app_extention_; std::shared_ptr<am::plugin_manager::MockRPCPluginManager> mock_rpc_plugin_manager; 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 8072783a71..4144beea2a 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 @@ -37,6 +37,8 @@ #include "rc_rpc_plugin/rc_rpc_plugin.h" #include "rc_rpc_plugin/rc_module_constants.h" #include "rc_rpc_plugin/mock/mock_resource_allocation_manager.h" +#include "rc_rpc_plugin/mock/mock_interior_data_cache.h" +#include "rc_rpc_plugin/mock/mock_interior_data_manager.h" #include "gtest/gtest.h" #include "interfaces/MOBILE_API.h" @@ -76,7 +78,7 @@ class SetInteriorVehicleDataRequestTest .WillByDefault(Return(application_manager::HmiInterfaces:: InterfaceState::STATE_AVAILABLE)); ON_CALL(app_mngr_, application(kAppId)).WillByDefault(Return(mock_app_)); - ON_CALL(mock_allocation_manager_, GetApplicationExtention(_)) + ON_CALL(*mock_app_, QueryInterface(RCRPCPlugin::kRCPluginID)) .WillByDefault(Return(rc_app_extention_)); ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); @@ -108,17 +110,23 @@ class SetInteriorVehicleDataRequestTest template <class Command> std::shared_ptr<Command> CreateRCCommand(MessageSharedPtr& msg) { InitCommand(kDefaultTimeout_); - return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), - app_mngr_, - mock_rpc_service_, - mock_hmi_capabilities_, - mock_policy_handler_, - mock_allocation_manager_); + RCCommandParams params{app_mngr_, + mock_rpc_service_, + mock_hmi_capabilities_, + mock_policy_handler_, + mock_allocation_manager_, + mock_interior_data_cache_, + mock_interior_data_manager_}; + return std::make_shared<Command>(msg ? msg : msg = CreateMessage(), params); } protected: testing::NiceMock<rc_rpc_plugin_test::MockResourceAllocationManager> mock_allocation_manager_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataCache> + mock_interior_data_cache_; + testing::NiceMock<rc_rpc_plugin_test::MockInteriorDataManager> + mock_interior_data_manager_; std::shared_ptr<MockApplication> mock_app_; std::shared_ptr<RCAppExtension> rc_app_extention_; }; diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h new file mode 100644 index 0000000000..45465f96b0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_cache.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_CACHE_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_CACHE_H_ + +#include <string> +#include "gmock/gmock.h" +#include "rc_rpc_plugin/interior_data_cache.h" + +namespace rc_rpc_plugin_test { + +class MockInteriorDataCache : public rc_rpc_plugin::InteriorDataCache { + public: + MOCK_METHOD2(Add, + void(const std::string&, const smart_objects::SmartObject&)); + MOCK_CONST_METHOD1(Retrieve, smart_objects::SmartObject(const std::string&)); + MOCK_CONST_METHOD1(Contains, bool(const std::string&)); + MOCK_METHOD1(Remove, void(const std::string&)); + MOCK_METHOD0(Clear, void()); +}; + +} // namespace rc_rpc_plugin_test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_CACHE_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h new file mode 100644 index 0000000000..fc19c6a889 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_interior_data_manager.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_MANAGER_H_ + +#include <string> +#include "gmock/gmock.h" +#include "rc_rpc_plugin/interior_data_manager.h" +namespace rc_rpc_plugin_test { + +class MockInteriorDataManager : public rc_rpc_plugin::InteriorDataManager { + public: + MOCK_METHOD1(OnPolicyEvent, + void(application_manager::plugin_manager::PolicyEvent)); + MOCK_METHOD2(OnApplicationEvent, + void(application_manager::plugin_manager::ApplicationEvent, + application_manager::ApplicationSharedPtr)); + MOCK_METHOD0(OnDisablingRC, void()); + MOCK_METHOD1(StoreRequestToHMITime, void(const std::string&)); + MOCK_METHOD1(CheckRequestsToHMIFrequency, bool(const std::string&)); +}; + +} // namespace rc_rpc_plugin_test + +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_INTERIOR_DATA_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h index d74e8fcb65..72ace1432a 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/include/rc_rpc_plugin/mock/mock_resource_allocation_manager.h @@ -30,8 +30,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SRC_COMPONENTS_REMOTE_CONTROL_TEST_INCLUDE_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ -#define SRC_COMPONENTS_REMOTE_CONTROL_TEST_INCLUDE_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ +#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ +#define SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ #include "gmock/gmock.h" #include "application_manager/rpc_plugins/rc_rpc_plugin/include/rc_rpc_plugin/resource_allocation_manager.h" @@ -61,9 +61,6 @@ class MockResourceAllocationManager const uint32_t app_id, const rc_rpc_plugin::ResourceState::eType state)); MOCK_CONST_METHOD1(IsResourceFree, bool(const std::string& module_type)); - MOCK_METHOD1(GetApplicationExtention, - rc_rpc_plugin::RCAppExtensionPtr( - application_manager::ApplicationSharedPtr application)); MOCK_METHOD0(ResetAllAllocations, void()); MOCK_METHOD2(SendOnRCStatusNotifications, void(rc_rpc_plugin::NotificationTrigger::eType, @@ -74,4 +71,4 @@ class MockResourceAllocationManager } // namespace rc_rpc_plugin_test -#endif // SRC_COMPONENTS_REMOTE_CONTROL_TEST_INCLUDE_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ +#endif // SRC_COMPONENTS_APPLICATION_MANAGER_RPC_PLUGINS_RC_RPC_PLUGIN_TEST_INCLUDE_RC_RPC_PLUGIN_MOCK_MOCK_RESOURCE_ALLOCATION_MANAGER_H_ diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc new file mode 100644 index 0000000000..e6922a4c83 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/interior_data_cache_test.cc @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2018, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ + +#include "gtest/gtest.h" +#include "rc_rpc_plugin/interior_data_cache_impl.h" + +namespace rc_rpc_plugin_test { + +class InteriorDataCacheTest : public ::testing::Test {}; + +namespace { +const uint32_t time_frame_alowed_requests = 1; +} // namespace + +TEST_F(InteriorDataCacheTest, + InteriorDataCacheDoesNotContainRandomDataInitialy) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + std::string module_type_key = "random_module_type"; + EXPECT_FALSE(cache.Contains(module_type_key)); + auto retrieved_data = cache.Retrieve(module_type_key); + EXPECT_EQ(smart_objects::SmartType_Null, retrieved_data.getType()); +} + +TEST_F(InteriorDataCacheTest, CheckThatCacheContansDataAfterAdding) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + const std::string module_type_key = "random_module_type"; + smart_objects::SmartObject data; + data["key"] = "value"; + + cache.Add(module_type_key, data); + EXPECT_TRUE(cache.Contains(module_type_key)); + auto retrieved_data = cache.Retrieve(module_type_key); + EXPECT_EQ(data, retrieved_data); +} + +TEST_F(InteriorDataCacheTest, DataDoesNotExistAfterClear) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + const std::string module_type_key = "random_module_type"; + smart_objects::SmartObject data; + data["key"] = "value"; + + cache.Add(module_type_key, data); + EXPECT_TRUE(cache.Contains(module_type_key)); + auto Retrieved_data = cache.Retrieve(module_type_key); + EXPECT_EQ(Retrieved_data, data); + cache.Clear(); + auto Retrieved_data_after_clear = cache.Retrieve(module_type_key); + EXPECT_EQ(smart_objects::SmartType_Null, + Retrieved_data_after_clear.getType()); +} + +TEST_F(InteriorDataCacheTest, MultipleDataCached) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + + const std::string module_type_key1 = "random_module_type"; + smart_objects::SmartObject data1; + data1["key"] = "value1"; + cache.Add(module_type_key1, data1); + EXPECT_TRUE(cache.Contains(module_type_key1)); + auto retrieved_data1 = cache.Retrieve(module_type_key1); + EXPECT_EQ(data1, retrieved_data1); + + std::string module_type_key2 = "random_module_type2"; + smart_objects::SmartObject data2; + data2["key"] = "value2"; + cache.Add(module_type_key2, data2); + EXPECT_TRUE(cache.Contains(module_type_key2)); + auto retrieved_data2 = cache.Retrieve(module_type_key2); + EXPECT_EQ(retrieved_data2, data2); + + ASSERT_TRUE(data1 != data2); + EXPECT_TRUE(data2 != retrieved_data1); + EXPECT_TRUE(data1 != retrieved_data2); +} + +TEST_F(InteriorDataCacheTest, RemoveFromChacheSuccessful) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + + const std::string module_type = "random_module_type"; + smart_objects::SmartObject data; + data["key"] = "value1"; + cache.Add(module_type, data); + EXPECT_TRUE(cache.Contains(module_type)); + auto retrieved_data1 = cache.Retrieve(module_type); + EXPECT_EQ(data, retrieved_data1); + + cache.Remove(module_type); + EXPECT_FALSE(cache.Contains(module_type)); + auto retreived = cache.Retrieve(module_type); + EXPECT_EQ(smart_objects::SmartType_Null, retreived.getType()); +} + +TEST_F(InteriorDataCacheTest, RemoveNotExistingNoSideEffects) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + const std::string module_type_key = "random_module_type"; + smart_objects::SmartObject data; + data["key"] = "value"; + + cache.Add(module_type_key, data); + cache.Remove("some other module_type"); + + EXPECT_TRUE(cache.Contains(module_type_key)); + auto retrieved_data = cache.Retrieve(module_type_key); + EXPECT_EQ(data, retrieved_data); +} + +TEST_F(InteriorDataCacheTest, Exist2ModuleTypesRemoveOneAnotherOneLeft) { + rc_rpc_plugin::InteriorDataCacheImpl cache; + + const std::string module_type_key1 = "random_module_type"; + smart_objects::SmartObject data1; + data1["key"] = "value1"; + cache.Add(module_type_key1, data1); + + std::string module_type_key2 = "random_module_type2"; + smart_objects::SmartObject data2; + data2["key"] = "value2"; + cache.Add(module_type_key2, data2); + + ASSERT_TRUE(data1 != data2); + + cache.Remove(module_type_key1); + EXPECT_FALSE(cache.Contains(module_type_key1)); + EXPECT_TRUE(cache.Contains(module_type_key2)); + + auto retrieved_data1 = cache.Retrieve(module_type_key1); + EXPECT_EQ(smart_objects::SmartType_Null, retrieved_data1.getType()); + auto retrieved_data2 = cache.Retrieve(module_type_key2); + EXPECT_EQ(data2, retrieved_data2); +} + +} // rc_rpc_plugin_test diff --git a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc index 4e2e4d7895..86c58b9d46 100644 --- a/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc +++ b/src/components/application_manager/rpc_plugins/rc_rpc_plugin/test/resource_allocation_manager_impl_test.cc @@ -71,7 +71,7 @@ const uint32_t kAppId1 = 11u; const uint32_t kHMIAppId1 = 1u; const uint32_t kAppId2 = 22u; const std::string policy_app_id_1_ = "policy_id_1"; -const uint32_t kSizeOfModules = 3u; +const uint32_t kSizeOfModules = 6u; } namespace rc_rpc_plugin_test { @@ -298,13 +298,6 @@ TEST_F(RAManagerTest, AnotherAppExit_NoReleaseResource) { EXPECT_CALL(mock_app_mngr_, application(kAppId2)) .WillRepeatedly(Return(mock_app_2_)); - RCAppExtensionPtr rc_extention_ptr = - std::make_shared<RCAppExtension>(application_manager::AppExtensionUID( - rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); - - EXPECT_CALL(*mock_app_2_, QueryInterface(_)) - .WillOnce(Return(rc_extention_ptr)); - // Act application_manager::ApplicationSharedPtr app_ptr(mock_app_2_); EXPECT_CALL(*mock_app_2_, app_id()).WillRepeatedly(Return(kAppId2)); @@ -358,13 +351,6 @@ TEST_F(RAManagerTest, AnotherAppUnregistered_NoReleaseResource) { EXPECT_CALL(mock_app_mngr_, application(kAppId1)) .WillRepeatedly(Return(mock_app_2_)); - RCAppExtensionPtr rc_extention_ptr = - std::make_shared<RCAppExtension>(application_manager::AppExtensionUID( - rc_rpc_plugin::RCRPCPlugin::kRCPluginID)); - - EXPECT_CALL(*mock_app_2_, QueryInterface(_)) - .WillOnce(Return(rc_extention_ptr)); - // Act application_manager::ApplicationSharedPtr app_ptr(mock_app_2_); EXPECT_CALL(*mock_app_2_, app_id()).WillRepeatedly(Return(kAppId2)); |