/* * 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 #include #include "mobile/delete_interaction_choice_set_request.h" #include "mobile/delete_interaction_choice_set_response.h" #include "gtest/gtest.h" #include "application_manager/commands/command_request_test.h" #include "application_manager/commands/commands_test.h" #include "application_manager/event_engine/event.h" #include "application_manager/mock_application.h" #include "application_manager/mock_application_manager.h" #include "application_manager/smart_object_keys.h" #include "smart_objects/smart_object.h" namespace test { namespace components { namespace commands_test { namespace mobile_commands_test { namespace delete_interaction_choice_set { using ::testing::_; using ::testing::InSequence; using ::testing::Return; namespace am = ::application_manager; using am::commands::MessageSharedPtr; using am::event_engine::Event; using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetRequest; using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetResponse; typedef std::shared_ptr DeleteInteractionChoiceSetRequestPtr; typedef std::shared_ptr DeleteInteractionChoiceSetResponsePtr; MATCHER_P(CheckMessageSuccess, success, "") { return success == (*arg)[am::strings::msg_params][am::strings::success].asBool(); } namespace { const uint32_t kConnectionKey = 2u; const uint32_t kChoiceSetId = 11u; const uint32_t kChoiceId = 110u; const uint32_t kGrammarId = 101u; } // namespace class DeleteInteractionChoiceSetRequestTest : public CommandRequestTest { public: DeleteInteractionChoiceSetRequestTest() : performinteraction_choice_set_lock_( std::make_shared()) , accessor_(choice_set_map_, performinteraction_choice_set_lock_) {} ~DeleteInteractionChoiceSetRequestTest() { // Fix DataAccessor release and WinQt crash Mock::VerifyAndClearExpectations(&app_mngr_); } am::PerformChoiceSetMap choice_set_map_; mutable std::shared_ptr performinteraction_choice_set_lock_; DataAccessor accessor_; protected: void SetUp() OVERRIDE { message_ = CreateMessage(); command_ = CreateCommand(message_); app_ = CreateMockApp(); } DeleteInteractionChoiceSetRequestPtr command_; MessageSharedPtr message_; MockAppPtr app_; }; class DeleteInteractionChoiceSetResponseTest : public CommandsTest { protected: void SetUp() OVERRIDE { message_ = CreateMessage(); command_ = CreateCommand(message_); app_ = CreateMockApp(); } DeleteInteractionChoiceSetResponsePtr command_; MessageSharedPtr message_; MockAppPtr app_; }; TEST_F(DeleteInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { MockAppPtr invalid_app; EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); EXPECT_CALL(*app_, FindChoiceSet(_)).Times(0); command_->Run(); } TEST_F(DeleteInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { (*message_)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = kChoiceSetId; EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); smart_objects::SmartObject choice_set_id(smart_objects::SmartType_Null); EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); command_->Run(); } TEST_F(DeleteInteractionChoiceSetRequestTest, Run_ChoiceSetInUse_SUCCESS) { (*message_)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = kChoiceSetId; EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); smart_objects::SmartObject choice_set_id = (*message_)[am::strings::msg_params] [am::strings::interaction_choice_set_id]; choice_set_map_[0].insert( std::make_pair(kChoiceSetId, &((*message_)[am::strings::msg_params] [am::strings::interaction_choice_set_id]))); EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(true)); EXPECT_CALL(*app_, performinteraction_choice_set_map()) .WillOnce(Return(accessor_)); EXPECT_CALL( mock_rpc_service_, ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)); command_->Run(); } TEST_F(DeleteInteractionChoiceSetRequestTest, Run_SendVrDeleteCommand_PerformInteractionFalse_UNSUCCESS) { (*message_)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = kChoiceSetId; smart_objects::SmartObject choice_set_id = (*message_)[am::strings::msg_params] [am::strings::interaction_choice_set_id]; smart_objects::SmartObject invalid_choice_set_id( smart_objects::SmartType_Null); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(app_)); { InSequence seq; EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(invalid_choice_set_id)); EXPECT_CALL(*app_, app_id()).Times(0); } DeleteInteractionChoiceSetRequestPtr command = CreateCommand(message_); command->Init(); command->Run(); } TEST_F(DeleteInteractionChoiceSetRequestTest, Run_SendVrDeleteCommand_SUCCESS) { using namespace application_manager; using namespace event_engine; (*message_)[am::strings::params][am::strings::connection_key] = kConnectionKey; (*message_)[strings::params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = kChoiceSetId; (*message_)[am::strings::msg_params][am::strings::grammar_id] = kGrammarId; (*message_)[am::strings::msg_params][am::strings::choice_set][0] [am::strings::choice_id] = kChoiceId; smart_objects::SmartObject choice_set_id = (*message_)[am::strings::msg_params]; application_manager::event_engine::Event event( hmi_apis::FunctionID::VR_DeleteCommand); event.set_smart_object(*message_); EXPECT_CALL(app_mngr_, application(kConnectionKey)) .WillRepeatedly(Return(app_)); { InSequence seq; EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); EXPECT_CALL(*app_, is_perform_interaction_active()).WillOnce(Return(false)); EXPECT_CALL(*app_, performinteraction_choice_set_map()).Times(0); EXPECT_CALL(*app_, FindChoiceSet(kChoiceSetId)) .WillOnce(Return(choice_set_id)); EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); } EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_, _)).WillOnce(Return(true)); { InSequence seq; EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); EXPECT_CALL(*app_, UpdateHash()); } EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) .WillOnce(Return(true)); DeleteInteractionChoiceSetRequestPtr command = CreateCommand(message_); command->Init(); command->Run(); command->on_event(event); } TEST_F(DeleteInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { (*message_)[am::strings::msg_params][am::strings::success] = false; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageSuccess(false), false)); command_->Run(); } TEST_F(DeleteInteractionChoiceSetResponseTest, Run_ValidResultCode_SUCCESS) { (*message_)[am::strings::msg_params][am::strings::result_code] = hmi_apis::Common_Result::SUCCESS; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageSuccess(true), false)); command_->Run(); } TEST_F(DeleteInteractionChoiceSetResponseTest, Run_InvalidResultCode_UNSUCCESS) { (*message_)[am::strings::msg_params][am::strings::result_code] = hmi_apis::Common_Result::INVALID_ENUM; EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageSuccess(false), false)); command_->Run(); } } // namespace delete_interaction_choice_set } // namespace mobile_commands_test } // namespace commands_test } // namespace components } // namespace test