diff options
author | BSolonenko <BSolonenko@luxoft.com> | 2018-04-20 12:38:26 +0300 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2018-05-24 13:15:46 +0300 |
commit | 5553510f8fb8fd3c7f8a6df90490ab5f39bd29d5 (patch) | |
tree | 7d5e7e88a63bd7b21cb6bfc9ccba2fd9737fde18 | |
parent | 8838c28ed711008ae24be8a313e97c5dec677825 (diff) | |
download | sdl_core-5553510f8fb8fd3c7f8a6df90490ab5f39bd29d5.tar.gz |
Added UT after implementation of Expandable Design
added next test cases:
Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendHMIRequest
Run_RequestTypeAllowedAndRequestSubTypeDisallowed_SendDisallowedResponse
Run_RequestTypeDisallowed_SendDisallowedResponse
Run_RequestTypeAllowedAndRequestSubTypeDisallowed_MessageNotSentToMobile
Run_RequestTypeAllowedAndRequestSubTypeAllowed_SendMessageToMobile
IsRequestSubTypeAllowed
3 files changed, 204 insertions, 1 deletions
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 index 7840e35cec..231727397d 100644 --- 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 @@ -54,6 +54,7 @@ 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; @@ -61,10 +62,27 @@ using testing::_; namespace { const uint32_t kConnectionKey = 1u; +const std::string kPolicyAppId = "fake-app-id"; } // namespace class OnSystemRequestNotificationTest - : public CommandsTest<CommandsTestMocks::kIsNice> {}; + : public CommandsTest<CommandsTestMocks::kIsNice> { + 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 RequestType::eType kRequestType = RequestType::PROPRIETARY; @@ -199,6 +217,71 @@ TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { 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<OnSystemRequestNotification>(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<OnSystemRequestNotification>(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 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 index 0e07889b4b..219ac54a8e 100644 --- a/src/components/application_manager/test/commands/mobile/system_request_test.cc +++ b/src/components/application_manager/test/commands/mobile/system_request_test.cc @@ -56,11 +56,14 @@ 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; @@ -70,6 +73,7 @@ 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 @@ -96,6 +100,7 @@ class SystemRequestTest 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)); @@ -128,6 +133,105 @@ TEST_F(SystemRequestTest, Run_HTTP_FileName_no_binary_data_REJECTED) { 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<uint8_t> 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<SystemRequest> command(CreateCommand<SystemRequest>(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<SystemRequest> command(CreateCommand<SystemRequest>(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<SystemRequest> command(CreateCommand<SystemRequest>(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + } // namespace system_request } // namespace mobile_commands_test } // namespace commands_test diff --git a/src/components/application_manager/test/policy_handler_test.cc b/src/components/application_manager/test/policy_handler_test.cc index 215f17a0e0..94ed43a465 100644 --- a/src/components/application_manager/test/policy_handler_test.cc +++ b/src/components/application_manager/test/policy_handler_test.cc @@ -1387,6 +1387,22 @@ TEST_F(PolicyHandlerTest, IsRequestTypeAllowed) { policy_handler_.IsRequestTypeAllowed(kPolicyAppId_, type); } +TEST_F(PolicyHandlerTest, IsRequestSubTypeAllowed) { + // Arrange + EnablePolicyAndPolicyManagerMock(); + + // Check expectations + EXPECT_CALL(*mock_policy_manager_, GetAppRequestSubTypesState(kPolicyAppId_)) + .WillOnce(Return(policy::RequestSubType::State::AVAILABLE)); + EXPECT_CALL(*mock_policy_manager_, GetAppRequestSubTypes(kPolicyAppId_)) + .WillOnce( + Return(std::vector<std::string>({"fakeSubType", "fakeSubType2"}))); + + // Act + const std::string subtype = "fakeSubType"; + EXPECT_TRUE(policy_handler_.IsRequestSubTypeAllowed(kPolicyAppId_, subtype)); +} + TEST_F(PolicyHandlerTest, GetVehicleInfo) { // Arrange EnablePolicyAndPolicyManagerMock(); |