/* * 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 "gtest/gtest.h" #include "smart_objects/smart_object.h" #include "application_manager/smart_object_keys.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_application.h" #include "application_manager/commands/command_impl.h" #include "application_manager/commands/commands_test.h" #include "application_manager/commands/command_request_test.h" #include "mobile/on_button_event_notification.h" #include "mobile/on_button_press_notification.h" namespace test { namespace components { namespace commands_test { namespace mobile_commands_test { namespace on_button_notification { namespace am = ::application_manager; namespace commands = am::commands; using sdl_rpc_plugin::commands::mobile::OnButtonEventNotification; using sdl_rpc_plugin::commands::mobile::OnButtonPressNotification; using ::testing::_; using ::testing::Types; using ::testing::Return; using am::commands::MessageSharedPtr; namespace { const uint32_t kAppId = 5u; const uint32_t kCustomButtonId = 3u; const mobile_apis::ButtonName::eType kButtonName = mobile_apis::ButtonName::OK; } // namespace template struct NotificationData { typedef NotificationT Notification; enum { kFunctionId = kExpectedFunctionId }; }; template class OnButtonNotificationCommandsTest : public CommandsTest, public NotificationDataT {}; typedef Types, NotificationData > OnButtonNotificationCommandsList; MATCHER_P(CheckNotificationMessage, function_id, "") { const bool kIsMobileProtocolTypeCorrect = (*arg)[am::strings::params][am::strings::protocol_type].asInt() == commands::CommandImpl::mobile_protocol_type_; const bool kIsProtocolVersionCorrect = (*arg)[am::strings::params][am::strings::protocol_version].asInt() == commands::CommandImpl::protocol_version_; const bool kIsNotificationCorrect = (*arg)[am::strings::params][am::strings::message_type].asInt() == am::MessageType::kNotification; const bool kIsFunctionIdCorrect = (*arg)[am::strings::params][am::strings::function_id].asInt() == function_id; bool is_custom_button_id_correct = true; if ((*arg)[am::strings::msg_params].keyExists( am::hmi_response::custom_button_id)) { is_custom_button_id_correct = (*arg)[am::strings::msg_params][am::strings::custom_button_id] == kCustomButtonId; } return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && kIsNotificationCorrect && kIsFunctionIdCorrect && is_custom_button_id_correct; } TYPED_TEST_CASE(OnButtonNotificationCommandsTest, OnButtonNotificationCommandsList); TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_NoAppId_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = mobile_apis::ButtonName::CUSTOM_BUTTON; std::shared_ptr command( this->template CreateCommand(notification_msg)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_NoCustomButtonId_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = mobile_apis::ButtonName::CUSTOM_BUTTON; (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_AppNotRegistered_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = mobile_apis::ButtonName::CUSTOM_BUTTON; (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; (*notification_msg)[am::strings::msg_params] [am::hmi_response::custom_button_id] = kCustomButtonId; std::shared_ptr command( this->template CreateCommand(notification_msg)); EXPECT_CALL(this->app_mngr_, application(kAppId)) .WillOnce(Return(ApplicationSharedPtr())); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_AppNotSubscribedToCustomButtonId_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = mobile_apis::ButtonName::CUSTOM_BUTTON; (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; (*notification_msg)[am::strings::msg_params] [am::hmi_response::custom_button_id] = kCustomButtonId; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) .WillOnce(Return(false)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_CustomButton_SUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = mobile_apis::ButtonName::CUSTOM_BUTTON; (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; (*notification_msg)[am::strings::msg_params] [am::hmi_response::custom_button_id] = kCustomButtonId; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); ON_CALL(*mock_app, hmi_level()) .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); EXPECT_CALL(this->app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); EXPECT_CALL(*mock_app, IsSubscribedToSoftButton(kCustomButtonId)) .WillOnce(Return(true)); EXPECT_CALL(this->mock_rpc_service_, SendMessageToMobile( CheckNotificationMessage(TestFixture::kFunctionId), _)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_NoSubscribedApps_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = kButtonName; std::shared_ptr command( this->template CreateCommand(notification_msg)); const std::vector empty_subscribed_apps_list; EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) .WillOnce(Return(empty_subscribed_apps_list)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_InvalidHmiLevel_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = kButtonName; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); std::vector subscribed_apps_list; subscribed_apps_list.push_back(mock_app); EXPECT_CALL(*mock_app, hmi_level()) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_NONE)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) .WillOnce(Return(subscribed_apps_list)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_ButtonOkOnlyForHmiLevelFull_UNSUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = kButtonName; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); std::vector subscribed_apps_list; subscribed_apps_list.push_back(mock_app); EXPECT_CALL(*mock_app, hmi_level()) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_LIMITED)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) .WillOnce(Return(subscribed_apps_list)); command->Run(); } TYPED_TEST(OnButtonNotificationCommandsTest, Run_SUCCESS) { typedef typename TestFixture::Notification Notification; MessageSharedPtr notification_msg( this->CreateMessage(smart_objects::SmartType_Map)); (*notification_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; (*notification_msg)[am::strings::msg_params][am::hmi_response::button_name] = kButtonName; std::shared_ptr command( this->template CreateCommand(notification_msg)); typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); std::vector subscribed_apps_list; subscribed_apps_list.push_back(mock_app); EXPECT_CALL(*mock_app, hmi_level()) .WillRepeatedly(Return(mobile_apis::HMILevel::HMI_FULL)); ON_CALL(*mock_app, IsFullscreen()).WillByDefault(Return(true)); EXPECT_CALL(this->app_mngr_, applications_by_button(kButtonName)) .WillOnce(Return(subscribed_apps_list)); EXPECT_CALL(this->mock_rpc_service_, SendMessageToMobile( CheckNotificationMessage(TestFixture::kFunctionId), _)); command->Run(); } } // namespace on_button_notification } // namespace mobile_commands_test } // namespace commands_test } // namespace components } // namespace test