diff options
author | Masato Ogawa <mogawa@xevo.com> | 2017-08-22 12:56:21 +0900 |
---|---|---|
committer | Masato Ogawa <mogawa@xevo.com> | 2017-08-22 13:05:15 +0900 |
commit | 50bae5d173c9d71d2e3eea6e2a71c33049dd4786 (patch) | |
tree | 09c56183a59bd016b34705382021b4e1df363e4a | |
parent | ee854f20c4cd656e4448a658e86aecb8268127d5 (diff) | |
download | sdl_core-50bae5d173c9d71d2e3eea6e2a71c33049dd4786.tar.gz |
Add unit tests for Send Haptic Data RPC
3 files changed, 181 insertions, 2 deletions
diff --git a/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc index f444e45a6c..25681263ab 100644 --- a/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc +++ b/src/components/application_manager/test/commands/hmi/simple_requests_to_hmi_test.cc @@ -114,6 +114,7 @@ #include "application_manager/commands/hmi/sdl_policy_update.h" #include "application_manager/commands/hmi/ui_set_icon_request.h" #include "application_manager/commands/hmi/dial_number_request.h" +#include "application_manager/commands/hmi/ui_send_haptic_data_request.h" #include "application_manager/test/include/application_manager/mock_event_dispatcher.h" @@ -217,7 +218,8 @@ typedef Types<am_commands::VIGetVehicleTypeRequest, am_commands::NaviAlertManeuverRequest, am_commands::AudioStopStreamRequest, am_commands::NaviGetWayPointsRequest, - am_commands::UISetGlobalPropertiesRequest> RequestCommandsList; + am_commands::UISetGlobalPropertiesRequest, + am_commands::UISendHapticDataRequest> RequestCommandsList; typedef Types<am_commands::UIScrollableMessageRequest, am_commands::VRGetCapabilitiesRequest, diff --git a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc b/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc index 7e55b8b834..9f4cf23b0c 100644 --- a/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc +++ b/src/components/application_manager/test/commands/hmi/simple_response_from_hmi_test.cc @@ -102,6 +102,7 @@ #include "hmi/update_app_list_response.h" #include "hmi/update_device_list_response.h" #include "hmi/notification_from_hmi.h" +#include "hmi/ui_send_haptic_data_response.h" namespace test { namespace components { @@ -232,7 +233,9 @@ typedef Types< CommandData<commands::VRPerformInteractionResponse, hmi_apis::FunctionID::VR_PerformInteraction>, CommandData<commands::UIScrollableMessageResponse, - hmi_apis::FunctionID::UI_ScrollableMessage> > + hmi_apis::FunctionID::UI_ScrollableMessage>, + CommandData<commands::UISendHapticDataResponse, + hmi_apis::FunctionID::UI_SendHapticData> > ResponseCommandsList; typedef Types<commands::AudioStopStreamResponse, diff --git a/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc b/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc new file mode 100644 index 0000000000..47cd75fcb8 --- /dev/null +++ b/src/components/application_manager/test/commands/mobile/send_haptic_data_test.cc @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2017 Xevo Inc. + * 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 Xevo Inc. 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 "commands/commands_test.h" +#include "commands/command_request_test.h" + +#include "mobile/send_haptic_data_request.h" +#include "mobile/send_haptic_data_response.h" + +#include "interfaces/MOBILE_API.h" +#include "application_manager/application.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace send_haptic_data { + +using ::testing::_; +using ::testing::Return; + +namespace am = ::application_manager; + +using am::commands::SendHapticDataRequest; +using am::commands::SendHapticDataResponse; +using am::commands::MessageSharedPtr; + +typedef SharedPtr<SendHapticDataRequest> SendHapticDataRequestPtr; +typedef SharedPtr<SendHapticDataResponse> SendHapticDataResponsePtr; + +namespace { +const uint32_t kConnectionKey = 1u; +} + +class SendHapticDataRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SendHapticDataRequestTest() + : msg_(CreateMessage(::smart_objects::SmartType_Map)) + , mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; +}; + +class SendHapticDataResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + SendHapticDataResponseTest() : message_(CreateMessage()) {} + + void SetUp() OVERRIDE { + command_sptr_ = CreateCommand<SendHapticDataResponse>(message_); + } + + MessageSharedPtr message_; + SharedPtr<SendHapticDataResponse> command_sptr_; +}; + +TEST_F(SendHapticDataRequestTest, Run_SUCCESS) { + EXPECT_CALL( + app_mngr_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SendHapticData))) + .WillOnce(Return(true)); + + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::APPLICATION_NOT_REGISTERED), + am::commands::Command::ORIGIN_SDL)); + + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, OnEvent_SUCCESS) { + EXPECT_CALL(app_mngr_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::ORIGIN_SDL)); + + (*msg_)[am::strings::msg_params] = 0; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + Event event(hmi_apis::FunctionID::UI_SendHapticData); + event.set_smart_object(*msg_); + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->on_event(event); +} + +TEST_F(SendHapticDataRequestTest, + OnEvent_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::ORIGIN_SDL)).Times(0); + + (*msg_)[am::strings::msg_params] = 0; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + Event event(hmi_apis::FunctionID::UI_SendHapticData); + event.set_smart_object(*msg_); + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->on_event(event); +} + +TEST_F(SendHapticDataResponseTest, Run_Success) { + ::smart_objects::SmartObject& message_ref = *message_; + message_ref[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + EXPECT_CALL( + app_mngr_, + SendMessageToMobile( + MobileResultCodeIs(mobile_apis::Result::SUCCESS), + _)); + command_sptr_->Run(); +} + +} // namespace send_haptic_data +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test |