diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test')
106 files changed, 26649 insertions, 0 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt new file mode 100644 index 0000000000..1a206c2cce --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt @@ -0,0 +1,37 @@ +include(${CMAKE_SOURCE_DIR}/tools/cmake/helpers/sources.cmake) + +include_directories( + ${GMOCK_INCLUDE_DIRECTORY} + ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include + ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/ + ${COMPONENTS_DIR}/application_manager/test/include/ + ${POLICY_MOCK_INCLUDE_PATH}/ + ${CMAKE_SOURCE_DIR}/src +) + + +set(COMMANDS_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/commands) + +file(GLOB SOURCES + ${COMPONENTS_DIR}/application_manager/test/mock_message_helper.cc + ${COMPONENTS_DIR}/application_manager/test/mock_application_helper.cc + ${COMPONENTS_DIR}/application_manager/src/smart_object_keys.cc + ${COMMANDS_TEST_DIR}/hmi/* + ${COMMANDS_TEST_DIR}/mobile/* + ${COMPONENTS_DIR}/application_manager/src/message.cc + ${COMPONENTS_DIR}/application_manager/src/event_engine/* +) + +set(LIBRARIES + gmock + Utils + SmartObjects + HMI_API + MOBILE_API + connectionHandler + sdl_rpc_plugin + jsoncpp + Policy +) + +create_cotired_test("sdl_commands_test" "${SOURCES}" "${LIBRARIES}" ) diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc new file mode 100644 index 0000000000..50b7aae42a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/activate_app_request_test.cc @@ -0,0 +1,123 @@ +/* + * 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 "hmi/activate_app_request.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace activate_app_request { + +using ::testing::_; + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::ActivateAppRequest; +using am::commands::CommandImpl; + +using ::test::components::application_manager_test::MockApplication; + +typedef std::shared_ptr<MockApplication> MockAppPtr; +typedef std::shared_ptr<ActivateAppRequest> ActivateAppRequestPtr; + +MATCHER_P(CheckMessage, level, "") { + return level == + static_cast<mobile_apis::HMILevel::eType>( + (*arg)[strings::msg_params][strings::activate_app_hmi_level] + .asInt()); +} + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCorrelationId = 2u; +} // namespace + +class ActivateAppRequestTest : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::app_id] = kAppId; + msg_params[strings::correlation_id] = kCorrelationId; + (*msg)[strings::msg_params] = msg_params; + (*msg)[strings::params][strings::app_id] = kAppId; + (*msg)[strings::params][strings::correlation_id] = kCorrelationId; + (*msg)[strings::app_id] = kAppId; + return msg; + } +}; + +TEST_F(ActivateAppRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + MockAppPtr app = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + ON_CALL(*app, hmi_app_id()).WillByDefault(Return(kAppId)); + +// TODO(OKozlov) Investigate and fix issue with using log +#ifdef ENABLE_LOG + (*msg)[strings::msg_params][strings::activate_app_hmi_level] = + mobile_apis::HMILevel::HMI_FULL; +#endif + ActivateAppRequestPtr command(CreateCommand<ActivateAppRequest>(msg)); + + EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); +#ifdef ENABLE_LOG + EXPECT_CALL(mock_rpc_service_, + SendMessageToHMI(CheckMessage(mobile_apis::HMILevel::HMI_FULL))); +#else + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg)); +#endif + command->Run(); + +#ifndef ENABLE_LOG + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +#endif +} + +} // namespace activate_app_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc new file mode 100644 index 0000000000..a5707488dd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/add_statistics_info_notification_test.cc @@ -0,0 +1,85 @@ +/* + * 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 "hmi/add_statistics_info_notification.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/policies/policy_handler.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace add_statistics_info_notification { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_notification = ::application_manager::hmi_notification; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AddStatisticsInfoNotification; +using am::commands::CommandImpl; +using policy::PolicyHandler; +using policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef std::shared_ptr<AddStatisticsInfoNotification> NotificationPtr; + +namespace { +const uint32_t kStatisticType = 1u; +} // namespace + +class AddStatisticsInfoNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(AddStatisticsInfoNotificationTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::msg_params][am::hmi_notification::statistic_type] = + kStatisticType; + NotificationPtr command(CreateCommand<AddStatisticsInfoNotification>(msg)); + + EXPECT_CALL(mock_policy_handler_, AddStatisticsInfo(kStatisticType)); + + command->Run(); +} + +} // namespace add_statistics_info_notification +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc new file mode 100644 index 0000000000..a2fcf8f605 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_all_apps_response_test.cc @@ -0,0 +1,76 @@ +/* + * 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 "hmi/allow_all_apps_response.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace allow_all_apps_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AllowAllAppsResponse; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef std::shared_ptr<AllowAllAppsResponse> ResponsePtr; + +namespace { +const bool kResponseIsAllowed = true; +} // + +class AllowAllAppsResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(AllowAllAppsResponseTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::allowed] = kResponseIsAllowed; + + ResponsePtr command(CreateCommand<AllowAllAppsResponse>(msg)); + + EXPECT_CALL(app_mngr_, SetAllAppsAllowed(kResponseIsAllowed)); + + command->Run(); +} + +} // namespace allow_all_apps_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc new file mode 100644 index 0000000000..2ce400542a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/allow_app_response_test.cc @@ -0,0 +1,95 @@ +/* + * 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 "hmi/allow_app_response.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace allow_app_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AllowAppResponse; +using ::testing::_; +using ::testing::Return; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const uint32_t kConnectionKey = 1u; +const bool kIsResponseAllowed = true; +} + +typedef std::shared_ptr<AllowAppResponse> ResponsePtr; + +class AllowAppResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(AllowAppResponseTest, Run_AppCreated_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; + + ResponsePtr command(CreateCommand<AllowAppResponse>(msg)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_app_allowed(kIsResponseAllowed)); + + command->Run(); +} + +TEST_F(AllowAppResponseTest, Run_AppNotCreated_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][hmi_response::allowed] = kIsResponseAllowed; + + ResponsePtr command(CreateCommand<AllowAppResponse>(msg)); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + + command->Run(); +} + +} // namespace allow_app_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc new file mode 100644 index 0000000000..a3f0ab6933 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_request_test.cc @@ -0,0 +1,72 @@ +/* + * 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 names of the copyright holders 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 "hmi/basic_communication_get_system_time_request.h" + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "protocol_handler/mock_protocol_handler.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace basic_communication_get_system_time_request { + +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::BasicCommunicationGetSystemTimeRequest; +using namespace ::protocol_handler; + +class BasicCommunicationGetSystemTimeRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BasicCommunicationGetSystemTimeRequestTest, OnTimeout) { + MessageSharedPtr msg = CreateMessage(); + protocol_handler_test::MockProtocolHandler mock_protocol_handler; + + auto command = CreateCommand<BasicCommunicationGetSystemTimeRequest>(msg); + + ON_CALL(app_mngr_, protocol_handler()) + .WillByDefault(ReturnRef(mock_protocol_handler)); + EXPECT_CALL(mock_protocol_handler, NotifyOnFailedHandshake()); + + command->onTimeOut(); +} + +} // namespace basic_communication_get_system_time_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_response_test.cc new file mode 100644 index 0000000000..8f56c6462c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/basic_communication_get_system_time_response_test.cc @@ -0,0 +1,79 @@ +/* + * 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 names of the copyright holders 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 "application_manager/commands/commands_test.h" +#include "hmi/basic_communication_get_system_time_response.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/smart_object_keys.h" +#include "interfaces/HMI_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace basic_communication_get_system_time_response { + +using sdl_rpc_plugin::commands::BasicCommunicationGetSystemTimeResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::ReturnRef; + +ACTION_P(GetEventId, event_id) { + *event_id = arg0.id(); +} + +class BasicCommunicationGetSystemTimeResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(BasicCommunicationGetSystemTimeResponseTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + MockEventDispatcher mock_event_dispatcher; + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + + auto command(CreateCommand<BasicCommunicationGetSystemTimeResponse>(msg)); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + + command->Run(); + + EXPECT_EQ(hmi_apis::FunctionID::BasicCommunication_GetSystemTime, event_id); +} + +} // namespace basic_communication_get_system_time_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc new file mode 100644 index 0000000000..6ed15bebeb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_response_test.cc @@ -0,0 +1,112 @@ +/* + * 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 "hmi/button_get_capabilities_response.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace button_get_capabilities_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::ButtonGetCapabilitiesResponse; +using ::testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef std::shared_ptr<ButtonGetCapabilitiesResponse> ResponsePtr; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +class ButtonGetCapabilitiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateMsgParams() { + capabilities_[strings::name] = hmi_apis::Common_ButtonName::OK; + preset_bank_capabilities_ = true; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::capabilities] = (capabilities_); + (*msg)[strings::msg_params][hmi_response::preset_bank_capabilities] = + (preset_bank_capabilities_); + + return msg; + } + + SmartObject capabilities_; + SmartObject preset_bank_capabilities_; +}; + +TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeSuccess_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + ResponsePtr command(CreateCommand<ButtonGetCapabilitiesResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)); + EXPECT_CALL(mock_hmi_capabilities_, + set_preset_bank_capabilities(preset_bank_capabilities_)); + + command->Run(); +} + +TEST_F(ButtonGetCapabilitiesResponseTest, Run_CodeAborted_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ResponsePtr command(CreateCommand<ButtonGetCapabilitiesResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_button_capabilities(capabilities_)) + .Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + set_preset_bank_capabilities(preset_bank_capabilities_)).Times(0); + + command->Run(); +} + +} // namespace button_get_capabilities_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc new file mode 100644 index 0000000000..6914a4ca7e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/close_popup_response_test.cc @@ -0,0 +1,73 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/close_popup_response.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace close_popup_response { + +namespace am = ::application_manager; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::ClosePopupResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; + +class ClosePopupResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +}; + +TEST_F(ClosePopupResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + ResponseFromHMIPtr command(CreateCommand<ClosePopupResponse>(command_msg)); + + command->Run(); +} + +} // namespace close_popup_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc new file mode 100644 index 0000000000..2303948355 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/dummy_hmi_commands_test.cc @@ -0,0 +1,540 @@ +/* + * 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 "application_manager/commands/command_request_test.h" + +#include <stdint.h> +#include <string> +#include <vector> +#include "gtest/gtest.h" + +#include "hmi/allow_all_apps_request.h" +#include "hmi/allow_all_apps_response.h" +#include "hmi/allow_app_request.h" +#include "hmi/allow_app_response.h" +#include "hmi/navi_audio_start_stream_request.h" +#include "hmi/navi_audio_start_stream_response.h" +#include "hmi/navi_audio_stop_stream_request.h" +#include "hmi/navi_audio_stop_stream_response.h" +#include "hmi/update_device_list_request.h" +#include "hmi/update_device_list_response.h" +#include "hmi/on_update_device_list.h" +#include "hmi/on_start_device_discovery.h" +#include "hmi/update_app_list_request.h" +#include "hmi/update_app_list_response.h" +#include "hmi/on_find_applications.h" +#include "hmi/sdl_get_list_of_permissions_request.h" +#include "hmi/sdl_get_list_of_permissions_response.h" +#include "hmi/sdl_get_user_friendly_message_request.h" +#include "hmi/sdl_get_user_friendly_message_response.h" +#include "hmi/sdl_get_status_update_request.h" +#include "hmi/sdl_get_status_update_response.h" +#include "hmi/on_status_update_notification.h" +#include "hmi/update_sdl_request.h" +#include "hmi/update_sdl_response.h" +#include "hmi/activate_app_request.h" +#include "hmi/activate_app_response.h" +#include "hmi/mixing_audio_supported_request.h" +#include "hmi/mixing_audio_supported_response.h" +#include "hmi/on_allow_sdl_functionality_notification.h" +#include "hmi/on_app_permission_changed_notification.h" +#include "hmi/on_app_permission_consent_notification.h" +#include "hmi/on_app_activated_notification.h" +#include "hmi/on_audio_data_streaming_notification.h" +#include "hmi/on_video_data_streaming_notification.h" +#include "hmi/on_sdl_consent_needed_notification.h" +#include "hmi/on_exit_all_applications_notification.h" +#include "hmi/on_exit_application_notification.h" +#include "hmi/on_put_file_notification.h" +#include "hmi/on_resume_audio_source_notification.h" +#include "hmi/on_ignition_cycle_over_notification.h" +#include "hmi/on_system_info_changed_notification.h" +#include "hmi/get_system_info_request.h" +#include "hmi/get_system_info_response.h" +#include "hmi/close_popup_request.h" +#include "hmi/close_popup_response.h" +#include "hmi/button_get_capabilities_request.h" +#include "hmi/button_get_capabilities_response.h" +#include "hmi/ui_add_command_request.h" +#include "hmi/ui_add_command_response.h" +#include "hmi/ui_delete_command_request.h" +#include "hmi/ui_delete_command_response.h" +#include "hmi/ui_add_submenu_request.h" +#include "hmi/ui_add_submenu_response.h" +#include "hmi/ui_delete_submenu_request.h" +#include "hmi/ui_delete_submenu_response.h" +#include "hmi/ui_get_supported_languages_request.h" +#include "hmi/ui_get_supported_languages_response.h" +#include "hmi/ui_get_language_request.h" +#include "hmi/ui_get_language_response.h" +#include "hmi/ui_get_capabilities_request.h" +#include "hmi/ui_get_capabilities_response.h" +#include "hmi/ui_change_registration_request.h" +#include "hmi/ui_change_registration_response.h" +#include "hmi/ui_show_request.h" +#include "hmi/ui_show_response.h" +#include "hmi/ui_alert_request.h" +#include "hmi/ui_alert_response.h" +#include "hmi/ui_is_ready_request.h" +#include "hmi/ui_is_ready_response.h" +#include "hmi/ui_slider_request.h" +#include "hmi/ui_slider_response.h" +#include "hmi/ui_set_media_clock_timer_request.h" +#include "hmi/ui_set_media_clock_timer_response.h" +#include "hmi/ui_set_global_properties_request.h" +#include "hmi/ui_set_global_properties_response.h" +#include "hmi/ui_scrollable_message_request.h" +#include "hmi/ui_scrollable_message_response.h" +#include "hmi/ui_set_app_icon_request.h" +#include "hmi/ui_set_app_icon_response.h" +#include "hmi/ui_perform_audio_pass_thru_response.h" +#include "hmi/ui_perform_audio_pass_thru_request.h" +#include "hmi/ui_end_audio_pass_thru_request.h" +#include "hmi/ui_end_audio_pass_thru_response.h" +#include "hmi/ui_perform_interaction_request.h" +#include "hmi/ui_perform_interaction_response.h" +#include "hmi/vr_is_ready_request.h" +#include "hmi/vr_is_ready_response.h" +#include "hmi/vr_add_command_request.h" +#include "hmi/vr_add_command_response.h" +#include "hmi/vr_delete_command_request.h" +#include "hmi/vr_delete_command_response.h" +#include "hmi/vr_change_registration_request.h" +#include "hmi/vr_change_registration_response.h" +#include "hmi/vr_get_supported_languages_request.h" +#include "hmi/vr_get_supported_languages_response.h" +#include "hmi/vr_get_language_request.h" +#include "hmi/vr_get_language_response.h" +#include "hmi/vr_get_capabilities_request.h" +#include "hmi/vr_get_capabilities_response.h" +#include "hmi/tts_is_ready_request.h" +#include "hmi/tts_is_ready_response.h" +#include "hmi/tts_change_registration_request.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/tts_get_supported_languages_request.h" +#include "hmi/tts_get_supported_languages_response.h" +#include "hmi/tts_get_language_request.h" +#include "hmi/tts_get_language_response.h" +#include "hmi/tts_stop_speaking_request.h" +#include "hmi/tts_stop_speaking_response.h" +#include "hmi/tts_speak_request.h" +#include "hmi/tts_speak_response.h" +#include "hmi/tts_set_global_properties_request.h" +#include "hmi/tts_set_global_properties_response.h" +#include "hmi/tts_get_capabilities_request.h" +#include "hmi/tts_get_capabilities_response.h" +#include "hmi/vr_perform_interaction_request.h" +#include "hmi/vr_perform_interaction_response.h" +#include "hmi/sdl_activate_app_request.h" +#include "hmi/sdl_activate_app_response.h" +#include "hmi/on_app_permission_changed_notification.h" +#include "hmi/on_event_changed_notification.h" +#include "hmi/navi_is_ready_request.h" +#include "hmi/navi_show_constant_tbt_request.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_is_ready_response.h" +#include "hmi/navi_alert_maneuver_request.h" +#include "hmi/navi_alert_maneuver_response.h" +#include "hmi/navi_update_turn_list_request.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/navi_subscribe_way_points_request.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/navi_unsubscribe_way_points_request.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_get_way_points_request.h" +#include "hmi/navi_get_way_points_response.h" +#include "hmi/on_ready_notification.h" +#include "hmi/on_device_chosen_notification.h" +#include "hmi/on_file_removed_notification.h" +#include "hmi/on_system_context_notification.h" +#include "hmi/on_app_registered_notification.h" +#include "hmi/on_app_unregistered_notification.h" +#include "hmi/on_driver_distraction_notification.h" +#include "hmi/on_tts_started_notification.h" +#include "hmi/on_tts_stopped_notification.h" +#include "hmi/on_vr_started_notification.h" +#include "hmi/on_vr_stopped_notification.h" +#include "hmi/on_vr_command_notification.h" +#include "hmi/on_ui_command_notification.h" +#include "hmi/on_app_deactivated_notification.h" +#include "hmi/on_ui_language_change_notification.h" +#include "hmi/on_vr_language_change_notification.h" +#include "hmi/on_tts_language_change_notification.h" +#include "hmi/on_navi_tbt_client_state_notification.h" +#include "hmi/on_navi_way_point_change_notification.h" +#include "hmi/on_button_event_notification.h" +#include "hmi/on_button_press_notification.h" +#include "hmi/on_button_subscription_notification.h" +#include "hmi/on_ui_keyboard_input_notification.h" +#include "hmi/on_ui_touch_event_notification.h" +#include "hmi/on_ui_reset_timeout_notification.h" +#include "hmi/navi_start_stream_request.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_stop_stream_request.h" +#include "hmi/navi_stop_stream_response.h" +#include "hmi/on_system_request_notification.h" +#include "hmi/ui_set_display_layout_request.h" +#include "hmi/ui_set_display_layout_response.h" +#include "hmi/on_sdl_close_notification.h" +#include "hmi/on_sdl_persistence_complete_notification.h" +#include "hmi/on_record_start_notification.h" +#include "hmi/add_statistics_info_notification.h" +#include "hmi/on_system_error_notification.h" +#include "hmi/basic_communication_system_request.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/sdl_policy_update.h" +#include "hmi/sdl_policy_update_response.h" +#include "hmi/on_received_policy_update.h" +#include "hmi/on_policy_update.h" +#include "hmi/get_urls.h" +#include "hmi/get_urls_response.h" +#include "hmi/on_device_state_changed_notification.h" +#include "hmi/navi_send_location_request.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/on_tts_reset_timeout_notification.h" +#include "hmi/dial_number_request.h" +#include "hmi/dial_number_response.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace dummy_hmi_commands_test { + +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; +using application_manager::commands::MessageSharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; + +template <class Command> +class HMICommandsTest : public components::commands_test::CommandRequestTest< + CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; + + void InitCommand(const uint32_t& timeout) OVERRIDE { + stream_retry_.first = 0; + stream_retry_.second = 0; + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(stream_retry_)); + } + + protected: + std::pair<uint32_t, int32_t> stream_retry_; +}; + +template <class Command> +class HMICommandsTestFirst : public HMICommandsTest<Command> { + public: + using typename HMICommandsTest<Command>::CommandType; +}; + +template <class Command> +class HMICommandsTestSecond : public HMICommandsTest<Command> { + public: + using typename HMICommandsTest<Command>::CommandType; +}; + +template <class Command> +class HMICommandsTestThird : public HMICommandsTest<Command> { + public: + using typename HMICommandsTest<Command>::CommandType; +}; + +template <class Command> +class HMICommandsTestFourth : public HMICommandsTest<Command> { + public: + using typename HMICommandsTest<Command>::CommandType; +}; + +template <class Command> +class HMICommandsTestFifth : public HMICommandsTest<Command> { + public: + using typename HMICommandsTest<Command>::CommandType; +}; + +/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few + * TYPED_TEST_CASE for HMI and mobile commands + */ + +typedef Types<commands::OnStartDeviceDiscovery, + commands::UpdateDeviceListResponse, + commands::UpdateDeviceListRequest, + commands::ActivateAppResponse, + commands::ActivateAppRequest, + commands::GetSystemInfoResponse, + commands::GetSystemInfoRequest, + commands::SDLActivateAppResponse, + commands::SDLActivateAppRequest, + commands::SDLPolicyUpdateResponse, + commands::SDLPolicyUpdate, + commands::GetUrlsResponse, + commands::GetUrls, + commands::OnAppPermissionChangedNotification, + commands::SDLGetListOfPermissionsResponse, + commands::SDLGetListOfPermissionsRequest, + commands::SDLGetUserFriendlyMessageResponse, + commands::SDLGetUserFriendlyMessageRequest, + commands::SDLGetStatusUpdateResponse, + commands::SDLGetStatusUpdateRequest, + commands::OnStatusUpdateNotification, + commands::OnAppPermissionConsentNotification, + commands::MixingAudioSupportedResponse, + commands::MixingAudioSupportedRequest, + commands::OnExitAllApplicationsNotification, + commands::UIAddCommandResponse, + commands::UIAddCommandRequest, + commands::UIDeleteCommandResponse, + commands::UIDeleteCommandRequest, + commands::UIAddSubmenuResponse, + commands::UIAddSubmenuRequest, + commands::UIDeleteSubmenuResponse, + commands::UIDeleteSubmenuRequest, + commands::UISetMediaClockTimerResponse, + commands::UISetMediaClockTimerRequest, + commands::UIPerformInteractionResponse, + commands::UIPerformInteractionRequest, + commands::UISetGlobalPropertiesResponse, + commands::UISetGlobalPropertiesRequest, + commands::UIScrollableMessageResponse, + commands::UIScrollableMessageRequest, + commands::UISetAppIconResponse, + commands::UISetAppIconRequest, + commands::UIGetSupportedLanguagesResponse, + commands::UIGetSupportedLanguagesRequest, + commands::UIGetLanguageResponse, + commands::UIGetLanguageRequest, + commands::UIGetCapabilitiesResponse, + commands::UIGetCapabilitiesRequest, + commands::UIChangeRegistratioResponse> HMICommandsListFirst; + +typedef Types<commands::UIChangeRegistrationRequest, + commands::UIPerformAudioPassThruResponse, + commands::UIPerformAudioPassThruRequest, + commands::UIEndAudioPassThruResponse, + commands::UIEndAudioPassThruRequest, + commands::UIAlertResponse, + commands::UIAlertRequest, + commands::VRIsReadyResponse, + commands::VRIsReadyRequest, + commands::VRAddCommandResponse, + commands::VRAddCommandRequest, + commands::VRDeleteCommandResponse, + commands::VRDeleteCommandRequest, + commands::VRChangeRegistrationResponse, + commands::VRChangeRegistrationRequest, + commands::VRGetSupportedLanguagesResponse, + commands::VRGetSupportedLanguagesRequest, + commands::VRGetLanguageResponse, + commands::VRGetLanguageRequest, + commands::VRGetCapabilitiesResponse, + commands::VRGetCapabilitiesRequest, + commands::TTSIsReadyResponse, + commands::TTSIsReadyRequest, + commands::TTSChangeRegistratioResponse, + commands::TTSChangeRegistrationRequest, + commands::TTSGetSupportedLanguagesResponse, + commands::TTSGetSupportedLanguagesRequest, + commands::TTSStopSpeakingResponse, + commands::TTSStopSpeakingRequest, + commands::TTSGetLanguageResponse, + commands::TTSGetLanguageRequest, + commands::TTSSpeakResponse, + commands::TTSSpeakRequest, + commands::TTSSetGlobalPropertiesResponse, + commands::TTSSetGlobalPropertiesRequest, + commands::TTSGetCapabilitiesResponse, + commands::TTSGetCapabilitiesRequest, + commands::OnTTSStartedNotification, + commands::OnTTSStoppedNotification, + commands::OnAppActivatedNotification, + commands::OnExitApplicationNotification, + commands::UIShowResponse, + commands::UIShowRequest, + commands::UISliderResponse, + commands::UISliderRequest, + commands::ClosePopupResponse, + commands::ClosePopupRequest, + commands::UIIsReadyResponse, + commands::UIIsReadyRequest> HMICommandsListSecond; + +typedef Types<commands::NaviIsReadyResponse, + commands::NaviIsReadyRequest, + commands::NaviAlertManeuverResponse, + commands::NaviAlertManeuverRequest, + commands::NaviGetWayPointsResponse, + commands::NaviGetWayPointsRequest, + commands::NaviUpdateTurnListResponse, + commands::NaviUpdateTurnListRequest, + commands::NaviShowConstantTBTResponse, + commands::NaviShowConstantTBTRequest, + commands::NaviSubscribeWayPointsResponse, + commands::NaviSubscribeWayPointsRequest, + commands::NaviUnsubscribeWayPointsResponse, + commands::NaviUnSubscribeWayPointsRequest, + commands::ButtonGetCapabilitiesResponse, + commands::ButtonGetCapabilitiesRequest, + commands::OnAllowSDLFunctionalityNotification, + commands::OnSDLConsentNeededNotification, + commands::UpdateSDLResponse, + commands::UpdateSDLRequest, + commands::OnIgnitionCycleOverNotification, + commands::OnSystemInfoChangedNotification, + commands::OnReadyNotification, + commands::OnDeviceChosenNotification, + commands::OnSystemContextNotification, + sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification, + commands::OnUpdateDeviceList, + commands::OnAppRegisteredNotification, + commands::OnAppUnregisteredNotification, + commands::OnFindApplications, + commands::UpdateAppListResponse, + commands::UpdateAppListRequest, + commands::OnVRStartedNotification, + commands::OnVRStoppedNotification, + commands::OnVRCommandNotification, + commands::OnUICommandNotification, + commands::OnAppDeactivatedNotification> HMICommandsListThird; + +typedef Types<commands::hmi::OnButtonEventNotification, + commands::hmi::OnButtonPressNotification, + commands::hmi::OnButtonSubscriptionNotification, + commands::OnNaviTBTClientStateNotification, + commands::hmi::OnUIKeyBoardInputNotification, + commands::hmi::OnUITouchEventNotification, + commands::hmi::OnUIResetTimeoutNotification, + commands::NaviStartStreamResponse, + commands::NaviStartStreamRequest, + commands::NaviStopStreamResponse, + commands::NaviStopStreamRequest, + commands::AudioStartStreamResponse, + commands::AudioStartStreamRequest, + commands::AudioStopStreamResponse, + commands::AudioStopStreamRequest, + commands::OnAudioDataStreamingNotification, + commands::OnVideoDataStreamingNotification, + commands::VRPerformInteractionResponse, + commands::VRPerformInteractionRequest, + commands::OnSystemRequestNotification, + commands::OnPutFileNotification, + commands::OnResumeAudioSourceNotification, + commands::UiSetDisplayLayoutResponse, + commands::UiSetDisplayLayoutRequest, + commands::OnSDLCloseNotification, + commands::OnSDLPersistenceCompleteNotification, + commands::OnFileRemovedNotification, + commands::OnRecordStartdNotification, + commands::BasicCommunicationSystemResponse, + commands::BasicCommunicationSystemRequest, + commands::NaviSendLocationResponse, + commands::NaviSendLocationRequest, + commands::AddStatisticsInfoNotification, + commands::OnSystemErrorNotification, + commands::OnReceivedPolicyUpdate, + commands::OnPolicyUpdate, + commands::OnDeviceStateChangedNotification, + commands::hmi::OnTTSResetTimeoutNotification, + commands::hmi::DialNumberResponse, + commands::hmi::DialNumberRequest, + commands::OnEventChangedNotification, + commands::OnNaviWayPointChangeNotification, + commands::OnUILanguageChangeNotification, + commands::OnVRLanguageChangeNotification, + commands::OnTTSLanguageChangeNotification> HMICommandsListFourth; + +typedef Types<commands::AllowAllAppsRequest, + commands::AllowAllAppsResponse, + commands::AllowAppRequest, + commands::AllowAppResponse> HMICommandsListFifth; + +TYPED_TEST_CASE(HMICommandsTestFirst, HMICommandsListFirst); +TYPED_TEST_CASE(HMICommandsTestSecond, HMICommandsListSecond); +TYPED_TEST_CASE(HMICommandsTestThird, HMICommandsListThird); +TYPED_TEST_CASE(HMICommandsTestFourth, HMICommandsListFourth); +TYPED_TEST_CASE(HMICommandsTestFifth, HMICommandsListFifth); + +TYPED_TEST(HMICommandsTestFirst, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestSecond, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} +TYPED_TEST(HMICommandsTestThird, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestFourth, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +TYPED_TEST(HMICommandsTestFifth, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +} // namespace dummy_hmi_commands_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc new file mode 100644 index 0000000000..4cbe7305ea --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_request_test.cc @@ -0,0 +1,98 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/request_to_hmi.h" +#include "hmi/get_system_info_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_system_info_request { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::GetSystemInfoRequest; +using am::commands::CommandImpl; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 1u; +} // namespace + +class GetSystemInfoRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(GetSystemInfoRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + + RequestToHMIPtr command(CreateCommand<GetSystemInfoRequest>(command_msg)); + + const uint32_t kAppId = command->application_id(); + + EXPECT_CALL(app_mngr_, set_application_id(kCorrelationId, kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::msg_params][strings::app_id].asUInt(), + kAppId); + EXPECT_EQ((*command_msg)[strings::params][strings::correlation_id].asUInt(), + kCorrelationId); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace get_system_info_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc new file mode 100644 index 0000000000..6908e21053 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_system_info_response_test.cc @@ -0,0 +1,138 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/get_system_info_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/commands_test.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_system_info_response { + +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::GetSystemInfoResponse; +using sdl_rpc_plugin::commands::SystemInfo; +using am::commands::CommandImpl; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string ccpu_version("4.1.3.B_EB355B"); +const std::string wers_country_code("WAEGB"); +const uint32_t lang_code = 0u; +const std::string kLanguage = ""; +} // namespace + +class GetSystemInfoResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::msg_params]["ccpu_version"] = ccpu_version; + (*command_msg)[strings::msg_params]["wersCountryCode"] = wers_country_code; + (*command_msg)[strings::msg_params]["language"] = lang_code; + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand<GetSystemInfoResponse>(command_msg)); + + std::string language; + EXPECT_CALL(mock_message_helper_, + CommonLanguageToString( + static_cast<hmi_apis::Common_Language::eType>(lang_code))) + .WillOnce(Return(language)); + EXPECT_EQ(kLanguage, language); + + EXPECT_CALL(mock_policy_handler_, + OnGetSystemInfo(ccpu_version, wers_country_code, kLanguage)); + + command->Run(); +} + +TEST_F(GetSystemInfoResponseTest, GetSystemInfo_UNSUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command(CreateCommand<GetSystemInfoResponse>(command_msg)); + + EXPECT_CALL(mock_message_helper_, + CommonLanguageToString( + static_cast<hmi_apis::Common_Language::eType>(lang_code))) + .Times(0); + + EXPECT_CALL(mock_policy_handler_, OnGetSystemInfo("", "", "")); + + command->Run(); +} + +} // namespace get_system_info_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc new file mode 100644 index 0000000000..339a749909 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_response_test.cc @@ -0,0 +1,88 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_to_hmi.h" +#include "hmi/get_urls_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_urls_response { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::GetUrlsResponse; +using am::commands::ResponseToHMI; +using am::commands::CommandImpl; + +typedef std::shared_ptr<ResponseToHMI> ResponseToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class GetUrlResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(GetUrlResponseTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + + ResponseToHMIPtr command(CreateCommand<GetUrlsResponse>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace get_urls_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc new file mode 100644 index 0000000000..e39681498c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/get_urls_test.cc @@ -0,0 +1,334 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "application_manager/message.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "hmi/get_urls.h" +#include "application_manager/policies/policy_handler.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/request_from_hmi.h" +#include "policy/mock_policy_manager.h" +#include "application_manager/event_engine/event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace get_urls { + +using namespace hmi_apis; +using namespace policy; +using ::testing::NiceMock; +using ::testing::_; +using ::testing::SetArgReferee; +using ::test::components::application_manager_test::MockApplication; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestFromHMI; +using sdl_rpc_plugin::commands::GetUrls; +using am::commands::CommandImpl; +using policy::PolicyHandler; +using policy_test::MockPolicyHandlerInterface; + +typedef std::shared_ptr<RequestFromHMI> RequestFromHMIPtr; + +namespace { +const uint32_t kInvalidAppId_ = 0u; +const uint32_t kAppIdForSending = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kServiceType = 0u; +const std::string kInitialService = "0x0"; +const std::string kPolicyService = "7"; +const std::string kDefaultUrl = "URL is not found"; +const std::string kDefaultId = "default"; +const std::string kPolicyAppId = "policy_app_id"; +} // namespace + +class GetUrlsTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr command_msg_; + RequestFromHMIPtr request_command_; + + GetUrlsTest() { + command_msg_ = + CreateMessage(NsSmartDeviceLink::NsSmartObjects::SmartType_Map); + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kInitialService; + + request_command_ = CreateCommand<GetUrls>(command_msg_); + } +}; + +TEST_F(GetUrlsTest, RUN_SUCCESS) { + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + // EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(_, _)); + + request_command_->Run(); +} + +TEST_F(GetUrlsTest, RUN_PolicyNotEnabled_UNSUCCESS) { + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F(GetUrlsTest, RUN_EmptyEndpoints_UNSUCCESS) { + EndpointUrls endpoints_; + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +#ifdef EXTENDED_POLICY +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppIdForSending)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::SUCCESS, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); + + EXPECT_EQ(kAppIdForSending, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [strings::app_id].asInt()); + EXPECT_EQ(kDefaultUrl, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [strings::url].asString()); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_IncorrectIdForSending_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kInvalidAppId_)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, application(kInvalidAppId_)).Times(0); + + request_command_->Run(); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_ApplicationIsNotValid_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr invalid_mock_app; + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(invalid_mock_app)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::DATA_NOT_AVAILABLE, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} + +TEST_F(GetUrlsTest, ProcessPolicyServiceURLs_FoundURLForApplication_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_request::service] = + kPolicyService; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + data.app_id = kPolicyAppId; + endpoints_.push_back(data); + + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kPolicyService, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppIdForSending)); + + EXPECT_CALL(app_mngr_, application(kAppIdForSending)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, policy_app_id()).WillOnce(Return(kPolicyAppId)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(command_msg_)) + .WillOnce(Return(true)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + + EXPECT_EQ(am::MessageType::kResponse, + (*command_msg_)[strings::params][strings::message_type].asInt()); + EXPECT_EQ(Common_Result::SUCCESS, + (*command_msg_)[strings::params][am::hmi_response::code].asInt()); +} +#endif + +TEST_F(GetUrlsTest, DISABLED_ProcessServiceURLs_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = + kDefaultUrl; + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id] = "1"; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + data.app_id = "1"; + endpoints_.push_back(data); + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + EXPECT_EQ(kDefaultUrl, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::strings::url].asString()); + EXPECT_EQ(endpoints_[0].app_id, + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id].asString()); +} + +TEST_F(GetUrlsTest, ProcessServiceURLs_PolicyDefaultId_SUCCESS) { + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] = + kDefaultUrl; + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + [am::hmi_response::policy_app_id] = kDefaultId; + + EXPECT_CALL(mock_policy_handler_, PolicyEnabled()).WillOnce(Return(true)); + EndpointUrls endpoints_; + EndpointData data(kDefaultUrl); + endpoints_.push_back(data); + EXPECT_CALL(mock_policy_handler_, GetUpdateUrls(kServiceType, _)) + .WillOnce(SetArgReferee<1>(endpoints_)); + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(_)) + .WillOnce(Return(mock_app)); + request_command_->Run(); + + EXPECT_FALSE((*command_msg_)[am::strings::msg_params].keyExists( + am::hmi_request::service)); + EXPECT_TRUE( + (*command_msg_)[am::strings::msg_params][am::hmi_response::urls][0] + .keyExists(am::hmi_response::policy_app_id)); +} + +} // namespace get_urls +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc new file mode 100644 index 0000000000..fe82b16f3f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/hmi_notifications_test.cc @@ -0,0 +1,1856 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> +#include "gtest/gtest.h" +#include "application_manager/commands/commands_test.h" +#include "sdl_rpc_plugin/commands/hmi/on_button_event_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_navi_tbt_client_state_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_navi_way_point_change_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ui_command_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ui_keyboard_input_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ui_touch_event_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_permission_changed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_registered_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_audio_data_streaming_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_button_subscription_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_file_removed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_put_file_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_resume_audio_source_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_sdl_close_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_sdl_consent_needed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_sdl_persistence_complete_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_status_update_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_video_data_streaming_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_record_start_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_activated_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_deactivated_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_unregistered_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_button_press_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_event_changed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ready_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_tts_reset_timeout_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_tts_started_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_tts_stopped_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ui_reset_timeout_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_vr_started_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_vr_stopped_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_app_permission_consent_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ignition_cycle_over_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_policy_update.h" +#include "sdl_rpc_plugin/commands/hmi/on_received_policy_update.h" +#include "sdl_rpc_plugin/commands/hmi/on_system_error_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_system_info_changed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_allow_sdl_functionality_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_device_state_changed_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_exit_all_applications_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_exit_application_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_vr_command_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_vr_language_change_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_start_device_discovery.h" +#include "sdl_rpc_plugin/commands/hmi/on_device_chosen_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_system_context_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_system_request_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_tts_language_change_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_ui_language_change_notification.h" +#include "sdl_rpc_plugin/commands/hmi/on_driver_distraction_notification.h" + +#include "utils/lock.h" +#include "utils/data_accessor.h" +#include "utils/signals.h" + +#include "utils/file_system.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_rpc_plugin_manager.h" +#include "application_manager/mock_state_controller.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/hmi_capabilities_impl.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "transport_manager/mock_transport_manager.h" +#include "connection_handler/mock_connection_handler.h" +#include "connection_handler/mock_connection_handler_settings.h" +#include "test/application_manager/mock_application_manager_settings.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "protocol_handler/mock_session_observer.h" +#include "application_manager/mock_resume_ctrl.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace hmi_notifications_test { + +using ::testing::_; +using ::testing::Test; +using ::testing::Types; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::NiceMock; +using ::testing::InSequence; +using ::smart_objects::SmartObject; +using ::application_manager::commands::MessageSharedPtr; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::application_manager::MockMessageHelper; +using namespace sdl_rpc_plugin::commands; +using namespace am::commands; + +typedef std::shared_ptr<MockApplication> MockAppPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +#define MEDIA true +#define NOT_MEDIA false +#define VC true +#define NOT_VC false +#define NAVI true +#define NOT_NAVI false + +ACTION_P(GetEventId, event_id) { + *event_id = arg0.id(); +} +ACTION_P(GetArg, arg) { + *arg = arg0; +} + +ACTION_P(GetArg3, result) { + arg3 = *result; +} + +ACTION_P2(GetConnectIdPermissionConsent, connect_id, consent) { + *connect_id = arg0; + std::vector<policy::FunctionalGroupPermission>::const_iterator it = + arg1.group_permissions.begin(); + for (; it != arg1.group_permissions.end(); ++it) { + consent->group_permissions.push_back(*it); + } + consent->consent_source = arg1.consent_source; +} +ACTION_P2(GetBoolValueAndString, value, str) { + *value = arg0; + *str = arg1; +} +ACTION_P(GetMessage, message) { + (*message)[am::strings::params][am::strings::function_id] = + (*arg0)[am::strings::params][am::strings::function_id].asInt(); + (*message)[am::strings::params][am::strings::message_type] = + (*arg0)[am::strings::params][am::strings::message_type].asInt(); + (*message)[am::strings::params][am::strings::correlation_id] = + (*arg0)[am::strings::params][am::strings::correlation_id].asInt(); + (*message)[am::strings::params][am::strings::connection_key] = + (*arg0)[am::strings::params][am::strings::connection_key].asInt(); + return (*message)[am::strings::params][am::strings::correlation_id].asInt(); +} + +namespace { +const uint32_t kCountCommandsManageMobile_ = 22u; +const uint32_t kCountCommandsToHmi_ = 12u; +const int32_t kHmiProtocolType_ = 1; +const int32_t kMobileProtocolType_ = 0; +const int32_t kProtocolVersion_ = 3; +const uint32_t kCorrelationId_ = 1939u; +const uint32_t kAppId_ = 2014u; +} // namespace + +class HMICommandsNotificationsTest + : public components::commands_test::CommandsTest< + CommandsTestMocks::kIsNice> { + public: + HMICommandsNotificationsTest() + : applications_lock_(std::make_shared<sync_primitives::Lock>()) + , applications_(application_set_, applications_lock_) + , app_ptr_(NULL) {} + + ~HMICommandsNotificationsTest() { + // Fix DataAccessor release and WinQt crash + Mock::VerifyAndClearExpectations(&app_mngr_); + } + typedef Command CommandType; + + protected: + am::ApplicationSet application_set_; + std::shared_ptr<sync_primitives::Lock> applications_lock_; + DataAccessor<am::ApplicationSet> applications_; + + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; + + application_manager_test::MockStateController mock_state_controller_; + + am::ApplicationSharedPtr app_; + NiceMock<MockApplication>* app_ptr_; + + typedef IsNiceMock<connection_handler_test::MockConnectionHandler, + kMocksAreNice>::Result MockConnectionHandler; + + typedef IsNiceMock<protocol_handler_test::MockSessionObserver, + kMocksAreNice>::Result MockSessionObserver; + + MockConnectionHandler mock_connection_handler_; + MockSessionObserver mock_session_observer_; + + void InitCommand(const uint32_t& default_timeout) OVERRIDE { + app_ = ConfigureApp(&app_ptr_, kAppId_, NOT_MEDIA, NOT_NAVI, NOT_VC); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(default_timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)).WillByDefault(Return(app_)); + ON_CALL(*app_ptr_, app_id()).WillByDefault(Return(kAppId_)); + } + + am::ApplicationSharedPtr ConfigureApp(NiceMock<MockApplication>** app_mock, + uint32_t app_id, + bool media, + bool navi, + bool vc) { + *app_mock = new NiceMock<MockApplication>; + + Mock::AllowLeak(*app_mock); // WorkAround for gogletest bug + am::ApplicationSharedPtr app(*app_mock); + + ON_CALL(**app_mock, app_id()).WillByDefault(Return(app_id)); + ON_CALL(**app_mock, is_media_application()).WillByDefault(Return(media)); + ON_CALL(**app_mock, is_navi()).WillByDefault(Return(navi)); + ON_CALL(**app_mock, is_voice_communication_supported()) + .WillByDefault(Return(vc)); + ON_CALL(**app_mock, IsAudioApplication()) + .WillByDefault(Return(media || navi || vc)); + return app; + } +#if defined(OS_POSIX) + void SubscribeForSignal() { + sigset_t signal_set; + sigemptyset(&signal_set); + sigaddset(&signal_set, SIGINT); + sigaddset(&signal_set, SIGTERM); + pthread_sigmask(SIG_BLOCK, &signal_set, NULL); + } +#endif +}; + +namespace { +void sig_handler(int sig) { + switch (sig) { + case SIGINT: + break; + case SIGTERM: + break; + case SIGSEGV: + abort(); + default: + exit(EXIT_FAILURE); + } +} +} // namespace + +template <class Command> +class HMIOnNotificationsListToHMI + : public commands_test::CommandsTest<kIsNice> { + public: + typedef Command CommandType; +}; + +template <class CommandT, hmi_apis::FunctionID::eType kCommandId> +struct CommandPair { + typedef CommandT CommandType; + enum { kHMICommandId = kCommandId }; +}; + +template <class Command> +class HMIOnNotificationsEventDispatcher + : public commands_test::CommandsTest<kIsNice> { + public: + typedef Command CommandType; + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; +}; + +typedef Types<OnAppPermissionChangedNotification, + OnAudioDataStreamingNotification, + hmi::OnButtonSubscriptionNotification, + OnFileRemovedNotification, + OnPutFileNotification, + OnResumeAudioSourceNotification, + OnSDLCloseNotification, + OnSDLConsentNeededNotification, + OnSDLPersistenceCompleteNotification, + OnStatusUpdateNotification, + OnVideoDataStreamingNotification, + OnRecordStartdNotification> HMIOnNotificationsListToHMITypes; + +typedef Types< + CommandPair<OnAppActivatedNotification, + hmi_apis::FunctionID::BasicCommunication_OnAppActivated>, + CommandPair<OnAppDeactivatedNotification, + hmi_apis::FunctionID::BasicCommunication_OnAppDeactivated>, + CommandPair<OnEventChangedNotification, + hmi_apis::FunctionID::BasicCommunication_OnEventChanged>, + CommandPair<hmi::OnTTSResetTimeoutNotification, + hmi_apis::FunctionID::TTS_OnResetTimeout>, + CommandPair<OnTTSStartedNotification, hmi_apis::FunctionID::TTS_Started>, + CommandPair<OnTTSStoppedNotification, hmi_apis::FunctionID::TTS_Stopped>, + CommandPair<hmi::OnUIResetTimeoutNotification, + hmi_apis::FunctionID::UI_OnResetTimeout>, + CommandPair<OnVRStartedNotification, hmi_apis::FunctionID::VR_Started>, + CommandPair<OnVRStoppedNotification, hmi_apis::FunctionID::VR_Stopped> > + HMIOnNotificationsEventDispatcherTypes; + +TYPED_TEST_CASE(HMIOnNotificationsListToHMI, HMIOnNotificationsListToHMITypes); +TYPED_TEST_CASE(HMIOnNotificationsEventDispatcher, + HMIOnNotificationsEventDispatcherTypes); + +TYPED_TEST(HMIOnNotificationsListToHMI, CommandsSendNotificationToHmi) { + MessageSharedPtr message = + commands_test::CommandsTest<kIsNice>::CreateMessage(); + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(message); + EXPECT_CALL(commands_test::CommandsTest<kIsNice>::mock_rpc_service_, + SendMessageToHMI(_)); + command->Run(); + EXPECT_EQ( + static_cast<int32_t>(kHmiProtocolType_), + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kProtocolVersion_), + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TYPED_TEST(HMIOnNotificationsEventDispatcher, + CommandsNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = + commands_test::CommandsTest<kIsNice>::CreateMessage(); + std::shared_ptr<typename TestFixture::CommandType::CommandType> command = + this->template CreateCommand< + typename TestFixture::CommandType::CommandType>(message); + EXPECT_CALL(commands_test::CommandsTest<kIsNice>::app_mngr_, + event_dispatcher()) + .WillOnce(ReturnRef(this->mock_event_dispatcher_)); + EXPECT_CALL(this->mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(TestFixture::CommandType::kHMICommandId, event_id); +} + +// notifications(SendNotificationToMobile) +TEST_F(HMICommandsNotificationsTest, OnButtonEventSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<hmi::OnButtonEventNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnButtonEventID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnNaviTBTClientSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnNaviTBTClientStateNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnTBTClientStateID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnNaviWayPointChangeSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnNaviWayPointChangeNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnWayPointChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUICommandSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnUICommandNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::eType::OnCommandID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::TriggerSource::TS_MENU), + (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnUIKeyBoardInputSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<hmi::OnUIKeyBoardInputNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnKeyboardInputID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUITouchEventSendNotificationToMobile) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<hmi::OnUITouchEventNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnTouchEventID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppRegisteredNotificationSendNotificationToHmi) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnAppRegisteredNotification>(message); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered), + event_id); + EXPECT_EQ( + kHmiProtocolType_, + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + kProtocolVersion_, + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppUnregisteredNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnAppUnregisteredNotification>(message); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>( + hmi_apis::FunctionID::BasicCommunication_OnAppUnregistered), + event_id); + EXPECT_EQ( + kHmiProtocolType_, + (*message)[am::strings::params][am::strings::protocol_type].asInt()); + EXPECT_EQ( + kProtocolVersion_, + (*message)[am::strings::params][am::strings::protocol_version].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnButtonPressNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<hmi::OnButtonPressNotification>(message); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(hmi_apis::FunctionID::Buttons_OnButtonPress), + event_id); + EXPECT_EQ(static_cast<int>(mobile_apis::FunctionID::eType::OnButtonPressID), + (*message)[am::strings::params][am::strings::function_id].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnReadyNotificationEventDispatcher) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnReadyNotification>(message); + + EXPECT_CALL(app_mngr_, OnHMIStartedCooperation()); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + command->Run(); + EXPECT_EQ(hmi_apis::FunctionID::BasicCommunication_OnReady, event_id); +} + +// policy handler +TEST_F(HMICommandsNotificationsTest, + OnIgnitionCycleOverNotificationPolicyHandler) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnIgnitionCycleOverNotification>(message); + + EXPECT_CALL(mock_policy_handler_, OnIgnitionCycleOver()); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnPolicyUpdateNotificationPolicyHandler) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = CreateCommand<OnPolicyUpdate>(message); + + EXPECT_CALL(mock_policy_handler_, OnPTExchangeNeeded()); + command->Run(); +} + +#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE) +TEST_F(HMICommandsNotificationsTest, + OnReceivePolicyUpdateNotification_SUCCESS) { + const std::string kFile = "./test_file.txt"; + EXPECT_TRUE(file_system::CreateFile(kFile)); + uint8_t tmp[] = {1u, 2u, 3u, 4u}; + std::vector<uint8_t> data(tmp, tmp + 4); + EXPECT_TRUE(file_system::WriteBinaryFile(kFile, data)); + + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); + (*message)[am::strings::msg_params][am::hmi_notification::policyfile] = kFile; + std::shared_ptr<Command> command = + CreateCommand<OnReceivedPolicyUpdate>(message); + + EXPECT_CALL(mock_policy_handler_, ReceiveMessageFromSDK(kFile, data)); + command->Run(); + EXPECT_TRUE(file_system::DeleteFile(kFile)); +} +#endif + +TEST_F(HMICommandsNotificationsTest, + OnReceivePolicyUpdateNotification_UNSUCCESS) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_String); + std::shared_ptr<Command> command = + CreateCommand<OnReceivedPolicyUpdate>(message); + + EXPECT_CALL(mock_policy_handler_, ReceiveMessageFromSDK(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerNoAppId) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + SmartObject& applications = + (*message)[am::strings::msg_params]["consentedFunctions"]; + + smart_objects::SmartObject hmi_application_temp(smart_objects::SmartType_Map); + applications[0] = hmi_application_temp; + + std::shared_ptr<Command> command = + CreateCommand<OnAppPermissionConsentNotification>(message); + + int32_t connection_id = -1; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce(GetArg(&connection_id)); + command->Run(); + EXPECT_EQ(0, connection_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerWithAppId) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + smart_objects::SmartObjectSPtr consented_function = + std::make_shared<smart_objects::SmartObject>(); + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + std::shared_ptr<Command> command = + CreateCommand<OnAppPermissionConsentNotification>(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(kAppId_), connection_id); + std::vector<policy::FunctionalGroupPermission>::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(policy::kGroupUndefined, (*it).state); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowTrue) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["source"] = "test_content_source"; + + smart_objects::SmartObjectSPtr consented_function = + std::make_shared<smart_objects::SmartObject>(); + (*consented_function)["allowed"] = true; + (*consented_function)[am::strings::id] = 999; + (*consented_function)[am::strings::name] = "test_group_alias"; + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + std::shared_ptr<Command> command = + CreateCommand<OnAppPermissionConsentNotification>(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(kAppId_), connection_id); + + std::vector<policy::FunctionalGroupPermission>::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(999, (*it).group_id); + EXPECT_EQ("test_group_alias", (*it).group_alias); + EXPECT_EQ(policy::kGroupAllowed, (*it).state); + } + EXPECT_EQ("test_content_source", permission_consent.consent_source); +} + +TEST_F(HMICommandsNotificationsTest, + OnAppPermissionConsentNotificationPolicyHandlerAppIdAllowFalse) { + MessageSharedPtr message = CreateMessage(smart_objects::SmartType_Map); + (*message)[am::strings::msg_params]["consentedFunctions"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params]["source"] = "test_content_source"; + + smart_objects::SmartObjectSPtr consented_function = + std::make_shared<smart_objects::SmartObject>(); + (*consented_function)["allowed"] = false; + (*consented_function)[am::strings::id] = 999; + (*consented_function)[am::strings::name] = "test_group_alias"; + (*message)[am::strings::msg_params]["consentedFunctions"][0] = + *consented_function; + + std::shared_ptr<Command> command = + CreateCommand<OnAppPermissionConsentNotification>(message); + + int32_t connection_id = -1; + policy::PermissionConsent permission_consent; +#ifdef EXTERNAL_PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _, _)) +#else + EXPECT_CALL(mock_policy_handler_, OnAppPermissionConsent(_, _)) +#endif + .WillOnce( + GetConnectIdPermissionConsent(&connection_id, &permission_consent)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(kAppId_), connection_id); + + std::vector<policy::FunctionalGroupPermission>::const_iterator it = + permission_consent.group_permissions.begin(); + for (; it != permission_consent.group_permissions.end(); ++it) { + EXPECT_EQ(999, (*it).group_id); + EXPECT_EQ("test_group_alias", (*it).group_alias); + EXPECT_EQ(policy::kGroupDisallowed, (*it).state); + } + EXPECT_EQ("test_content_source", permission_consent.consent_source); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemErrorNotificationOnSystemErrorCode) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::error] = + hmi_apis::Common_SystemError::SYNC_REBOOTED; + + std::shared_ptr<Command> command = + CreateCommand<OnSystemErrorNotification>(message); + + int32_t code = hmi_apis::Common_SystemError::INVALID_ENUM; + EXPECT_CALL(mock_policy_handler_, OnSystemError(_)).WillOnce(GetArg(&code)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(hmi_apis::Common_SystemError::SYNC_REBOOTED), + code); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemInfoChangedNotificationCheckLanguage) { + const uint32_t kLangCode = 5u; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLangCode; + + std::shared_ptr<Command> command = + CreateCommand<OnSystemInfoChangedNotification>(message); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)); + EXPECT_CALL(mock_policy_handler_, OnSystemInfoChanged(_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnAllowSDLFunctionalityNotificationDeviceKeyNotExist) { + const std::string kDeviceId = ""; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; + std::shared_ptr<Command> command = + CreateCommand<OnAllowSDLFunctionalityNotification>(message); + + bool value = false; + std::string str; + EXPECT_CALL(mock_policy_handler_, OnAllowSDLFunctionalityNotification(_, _)) + .WillOnce(GetBoolValueAndString(&value, &str)); + command->Run(); + EXPECT_EQ(true, value); + EXPECT_EQ(kDeviceId, str); +} + +TEST_F(HMICommandsNotificationsTest, + OnAllowSDLFunctionalityNotificationDeviceKeyExist) { + const std::string kDeviceId = "device_id"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_response::allowed] = true; + (*message)[am::strings::msg_params]["device"]["id"] = kDeviceId; + std::shared_ptr<Command> command = + CreateCommand<OnAllowSDLFunctionalityNotification>(message); + + bool value; + std::string str; + EXPECT_CALL(mock_policy_handler_, OnAllowSDLFunctionalityNotification(_, _)) + .WillOnce(GetBoolValueAndString(&value, &str)); + command->Run(); + EXPECT_EQ(true, value); + EXPECT_EQ(kDeviceId, str); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateNotUnpaired) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::INVALID_ENUM; + std::shared_ptr<Command> command = + CreateCommand<OnDeviceStateChangedNotification>(message); + + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateUnpaired) { + // Random MAC adress for test. It must contain 12 symbols. + const std::string device_id = "AA15F2204D6B"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = device_id; + + std::shared_ptr<Command> command = + CreateCommand<OnDeviceStateChangedNotification>(message); + + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateEmptyDeviceId) { + const std::string empty_device_id = ""; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; + + std::shared_ptr<Command> command = + CreateCommand<OnDeviceStateChangedNotification>(message); + + std::string device_id = "default_id"; + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)) + .WillOnce(GetArg(&device_id)); + command->Run(); + EXPECT_EQ(empty_device_id, device_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceStateChangedNotificationDeviceStateDeviceIdFromId) { + const std::string empty_device_id = ""; + const std::string id = "id_string"; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params]["deviceState"] = + hmi_apis::Common_DeviceState::UNPAIRED; + (*message)[am::strings::msg_params]["deviceInternalId"] = empty_device_id; + (*message)[am::strings::msg_params]["deviceId"]["id"] = id; + + std::shared_ptr<Command> command = + CreateCommand<OnDeviceStateChangedNotification>(message); + + std::string device_id = "default_id"; + EXPECT_CALL(mock_policy_handler_, RemoveDevice(_)) + .WillOnce(GetArg(&device_id)); + command->Run(); + EXPECT_EQ(id, device_id); +} + +//~policy_handler +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonIgnitionOff) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::IGNITION_OFF; + + std::shared_ptr<Command> command = + CreateCommand<OnExitAllApplicationsNotification>(message); +#if defined(OS_POSIX) + am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason; + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)) + .WillOnce(GetArg(&mob_reason)); + EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); + + SubscribeForSignal(); + command->Run(); + utils::Signals::WaitTerminationSignals(sig_handler); + + EXPECT_EQ(am::mobile_api::AppInterfaceUnregisteredReason::IGNITION_OFF, + mob_reason); +#endif +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonMasterResetAndFactoryDefaults) { + MessageSharedPtr message = CreateMessage(); + + std::vector<hmi_apis::Common_ApplicationsCloseReason::eType> reason_list; + reason_list.push_back(hmi_apis::Common_ApplicationsCloseReason::MASTER_RESET); + reason_list.push_back( + hmi_apis::Common_ApplicationsCloseReason::FACTORY_DEFAULTS); + + std::vector<mobile_apis::AppInterfaceUnregisteredReason::eType> + mob_reason_list; + mob_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::MASTER_RESET); + mob_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::FACTORY_DEFAULTS); + + std::vector<hmi_apis::Common_ApplicationsCloseReason::eType>::iterator + it_reason = reason_list.begin(); + std::vector<mobile_apis::AppInterfaceUnregisteredReason::eType>::iterator + it_mob_reason = mob_reason_list.begin(); + + for (; it_reason != reason_list.end(); ++it_reason, ++it_mob_reason) { + (*message)[am::strings::msg_params][am::hmi_request::reason] = *it_reason; + + std::shared_ptr<Command> command = + CreateCommand<OnExitAllApplicationsNotification>(message); +#if defined(OS_POSIX) + am::mobile_api::AppInterfaceUnregisteredReason::eType mob_reason = + *it_mob_reason; + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(mob_reason)); + EXPECT_CALL(app_mngr_, HeadUnitReset(mob_reason)); + + SubscribeForSignal(); + command->Run(); + utils::Signals::WaitTerminationSignals(sig_handler); +#endif + } +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonSuspend) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::SUSPEND; + + std::shared_ptr<Command> command = + CreateCommand<OnExitAllApplicationsNotification>(message); + + MessageSharedPtr ethalon_message = + CreateMessage(smart_objects::SmartType_Map); + (*ethalon_message)[am::strings::params][am::strings::function_id] = + hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete; + (*ethalon_message)[am::strings::params][am::strings::message_type] = + am::MessageType::kNotification; + (*ethalon_message)[am::strings::params][am::strings::correlation_id] = + kCorrelationId_; + MessageSharedPtr temp_message = CreateMessage(); + + resumprion_test::MockResumeCtrl mock_resume_ctrl; + EXPECT_CALL(app_mngr_, resume_controller()) + .WillOnce(ReturnRef(mock_resume_ctrl)); + EXPECT_CALL(mock_resume_ctrl, OnSuspend()); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(GetMessage(temp_message)); + + command->Run(); + EXPECT_EQ( + static_cast<uint32_t>( + hmi_apis::FunctionID::BasicCommunication_OnSDLPersistenceComplete), + (*temp_message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<uint32_t>(am::MessageType::kNotification), + (*temp_message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ(static_cast<uint32_t>(kCorrelationId_), + (*temp_message)[am::strings::params][am::strings::correlation_id] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitAllApplicationsNotificationReasonInvalidEnum) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_request::reason] = + hmi_apis::Common_ApplicationsCloseReason::INVALID_ENUM; + + std::shared_ptr<Command> command = + CreateCommand<OnExitAllApplicationsNotification>(message); + + EXPECT_CALL(app_mngr_, SetUnregisterAllApplicationsReason(_)).Times(0); + EXPECT_CALL(app_mngr_, HeadUnitReset(_)).Times(0); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationManageMobileCommand) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast<int32_t>( + mobile_apis::FunctionID::OnAppInterfaceUnregisteredID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast<int32_t>(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + + std::vector<hmi_apis::Common_ApplicationExitReason::eType> reason_list; + reason_list.push_back(hmi_apis::Common_ApplicationExitReason:: + UNAUTHORIZED_TRANSPORT_REGISTRATION); + reason_list.push_back( + hmi_apis::Common_ApplicationExitReason::UNSUPPORTED_HMI_RESOURCE); + + std::vector<mobile_apis::AppInterfaceUnregisteredReason::eType> + mobile_reason_list; + mobile_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::APP_UNAUTHORIZED); + mobile_reason_list.push_back( + mobile_apis::AppInterfaceUnregisteredReason::UNSUPPORTED_HMI_RESOURCE); + + std::vector<mobile_apis::AppInterfaceUnregisteredReason::eType>::iterator + it_mobile_reason = mobile_reason_list.begin(); + std::vector<hmi_apis::Common_ApplicationExitReason::eType>::iterator + it_reason = reason_list.begin(); + + for (; it_reason != reason_list.end(); ++it_reason, ++it_mobile_reason) { + (*message)[am::strings::msg_params][am::strings::reason] = *it_reason; + std::shared_ptr<Command> command = + CreateCommand<OnExitApplicationNotification>(message); + + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast<int32_t>(*it_mobile_reason); + + am::plugin_manager::MockRPCPluginManager mock_rpc_plugin_manager_; + EXPECT_CALL(app_mngr_, GetPluginManager()) + .WillRepeatedly(ReturnRef(mock_rpc_plugin_manager_)); + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, *it_mobile_reason)).WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationUnhandledReason) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::INVALID_ENUM; + + std::shared_ptr<Command> command = + CreateCommand<OnExitApplicationNotification>(message); + + am::plugin_manager::MockRPCPluginManager mock_rpc_plugin_manager_; + + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, GetPluginManager()) + .WillOnce(ReturnRef(mock_rpc_plugin_manager_)); + EXPECT_CALL(mock_rpc_plugin_manager_, ForEachPlugin(_)).Times(1); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnExitApplicationNotificationInvalidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + + std::shared_ptr<Command> command = + CreateCommand<OnExitApplicationNotification>(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + DISABLED_OnExitApplicationNotificationDriverDistractionValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::DRIVER_DISTRACTION_VIOLATION; + std::shared_ptr<Command> command = + CreateCommand<OnExitApplicationNotification>(message); + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + false)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnExitApplicationNotificationrUserExitValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + (*message)[am::strings::msg_params][am::strings::reason] = + hmi_apis::Common_ApplicationExitReason::USER_EXIT; + std::shared_ptr<Command> command = + CreateCommand<OnExitApplicationNotification>(message); + am::plugin_manager::MockRPCPluginManager mock_rpc_plugin_manager_; + EXPECT_CALL(app_mngr_, GetPluginManager()) + .WillOnce(ReturnRef(mock_rpc_plugin_manager_)); + EXPECT_CALL(mock_rpc_plugin_manager_, ForEachPlugin(_)).Times(1); + EXPECT_CALL(app_mngr_, application(kAppId_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, UnregisterApplication(_, _, _, _)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, + mobile_apis::HMILevel::HMI_NONE, + mobile_apis::AudioStreamingState::NOT_AUDIBLE, + mobile_apis::VideoStreamingState::NOT_STREAMABLE, + false)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationSwitchedAndValidApp) { + const uint32_t cmd_id = 12u; + const uint32_t max_cmd_id = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = cmd_id; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(_, mobile_apis::HMILevel::HMI_FULL, true)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(max_cmd_id)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationSwitchedAndInvalidApp) { + const uint32_t kCmdId = 12u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(invalid_app)); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationCmdIdEqualToMaxCmdId) { + const uint32_t kCmdId = 11u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationCmdIdLessMaxCmdIsInvalidApp) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + am::ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationActivePerformIteraction) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + const uint32_t kIsPerformInteractionActive = 1u; + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) + .WillOnce(Return(kIsPerformInteractionActive)); + EXPECT_CALL(app_mngr_, event_dispatcher()); + EXPECT_CALL(mock_event_dispatcher_, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); + EXPECT_EQ(hmi_apis::FunctionID::VR_OnCommand, event_id); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRCommandNotificationNotActivePerformIteraction) { + const uint32_t kCmdId = 8u; + const uint32_t kMaxCmdId = 10u; + const uint32_t kIsPerformInteractionActive = 0u; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + (*message)[am::strings::msg_params][am::strings::function_id] = + mobile_apis::FunctionID::eType::OnCommandID; + std::shared_ptr<Command> command = + CreateCommand<OnVRCommandNotification>(message); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_settings_, max_cmd_id()).WillOnce(ReturnRef(kMaxCmdId)); + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + EXPECT_CALL(*app_ptr_, is_perform_interaction_active()) + .WillOnce(Return(kIsPerformInteractionActive)); + + EXPECT_CALL(app_mngr_, event_dispatcher()).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::eType::OnCommandID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::TriggerSource::TS_VR), + (*message)[am::strings::msg_params][am::strings::trigger_source].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnVRLanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnVRLanguageChangeNotification>(message); + + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRLanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnVRLanguageChangeNotification>(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnVRLanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + std::shared_ptr<Command> command = + CreateCommand<OnVRLanguageChangeNotification>(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast<int32_t>(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast<int32_t>( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + SetRegularState(app_, mobile_apis::HMILevel::HMI_NONE, false)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnStartDeviceDiscoveryRun) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnStartDeviceDiscovery>(message); + EXPECT_CALL(app_mngr_, StartDevicesDiscovery()); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceChosenNotificationDeviceInfoExists) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::device_info] + [am::strings::id] = "2014"; + std::shared_ptr<Command> command = + CreateCommand<OnDeviceChosenNotification>(message); + EXPECT_CALL(app_mngr_, + ConnectToDevice( + (*message)[am::strings::msg_params][am::strings::device_info] + [am::strings::id].asString())); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDeviceChosenNotificationDeviceInfoNotExists) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnDeviceChosenNotification>(message); + EXPECT_CALL(app_mngr_, ConnectToDevice(_)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationValidActiveApplication) { + MessageSharedPtr message = CreateMessage(); + std::vector<am::mobile_api::SystemContext::eType> system_context_list; + system_context_list.push_back( + am::mobile_api::SystemContext::SYSCTXT_VRSESSION); + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MENU); + system_context_list.push_back( + am::mobile_api::SystemContext::SYSCTXT_HMI_OBSCURED); + + std::vector<am::mobile_api::SystemContext::eType>::iterator it = + system_context_list.begin(); + for (; it != system_context_list.end(); ++it) { + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + *it; + std::shared_ptr<Command> command = + CreateCommand<OnSystemContextNotification>(message); + EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationInvalidActiveApplication) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::SYSCTXT_VRSESSION; + std::shared_ptr<Command> command = + CreateCommand<OnSystemContextNotification>(message); + ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, active_application()).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationInvalidSystemContext) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::INVALID_ENUM; + std::shared_ptr<Command> command = + CreateCommand<OnSystemContextNotification>(message); + EXPECT_CALL(app_mngr_, active_application()).Times(0); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationValidApplication) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + std::vector<am::mobile_api::SystemContext::eType> system_context_list; + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_ALERT); + system_context_list.push_back(am::mobile_api::SystemContext::SYSCTXT_MAIN); + + std::vector<am::mobile_api::SystemContext::eType>::iterator it = + system_context_list.begin(); + for (; it != system_context_list.end(); ++it) { + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + *it; + std::shared_ptr<Command> command = + CreateCommand<OnSystemContextNotification>(message); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, SetRegularState(app_, *it)); + command->Run(); + } +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemContextNotificationAppIdDoesntExists) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::system_context] = + am::mobile_api::SystemContext::SYSCTXT_ALERT; + std::shared_ptr<Command> command = + CreateCommand<OnSystemContextNotification>(message); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(app_mngr_, state_controller()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdExistsAndValidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + std::shared_ptr<Command> command = + CreateCommand<OnSystemRequestNotification>(message); + + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(app_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + const int32_t device_id = 1; + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), NULL, NULL, _, NULL)) + .WillByDefault(Return(device_id)); + + EXPECT_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillOnce(Return(policy::kDeviceAllowed)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdExistsAndInvalidApp) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::app_id] = kAppId_; + std::shared_ptr<Command> command = + CreateCommand<OnSystemRequestNotification>(message); + ApplicationSharedPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kAppId_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdDoesntExistsAndValidApp) { + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnSystemRequestNotification>(message); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kAppId_)); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + const int32_t device_id = 1; + ON_CALL( + mock_session_observer_, + GetDataOnDeviceID( + testing::An<transport_manager::DeviceHandle>(), NULL, NULL, _, NULL)) + .WillByDefault(Return(device_id)); + + EXPECT_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillOnce(Return(policy::kDeviceAllowed)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::FunctionID::eType::OnSystemRequestID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnSystemRequestNotificationAppIdDoesntExistsAndNullAppId) { + const uint32_t kNullApppId = 0u; + MessageSharedPtr message = CreateMessage(); + std::shared_ptr<Command> command = + CreateCommand<OnSystemRequestNotification>(message); + + EXPECT_CALL(mock_policy_handler_, GetAppIdForSending()) + .WillOnce(Return(kNullApppId)); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnTTSLanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnTTSLanguageChangeNotification>(message); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnTTSLanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnTTSLanguageChangeNotification>(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnTTSLanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + std::shared_ptr<Command> command = + CreateCommand<OnTTSLanguageChangeNotification>(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast<int32_t>(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast<int32_t>( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(hmi_apis::Common_Language::EN_AU), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnUILanguageChangeNotificationEmptyData) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnUILanguageChangeNotification>(message); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + EXPECT_CALL(*app_ptr_, ui_language()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnUILanguageChangeNotificationAppLangEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = kLang; + std::shared_ptr<Command> command = + CreateCommand<OnUILanguageChangeNotification>(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillOnce(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); + + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kLang), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, + OnUILanguageChangeNotificationAppLangNotEqualMessageLang) { + const mobile_apis::Language::eType& kLang = mobile_apis::Language::EN_GB; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::language] = + mobile_apis::Language::EN_US; + std::shared_ptr<Command> command = + CreateCommand<OnUILanguageChangeNotification>(message); + + application_set_.insert(app_); + smart_objects::SmartObjectSPtr notification = + std::make_shared<smart_objects::SmartObject>(); + (*notification)[am::strings::params][am::strings::function_id] = + static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID); + (*notification)[am::strings::params][am::strings::message_type] = + static_cast<int32_t>(am::MessageType::kNotification); + (*notification)[am::strings::params][am::strings::connection_key] = kAppId_; + (*notification)[am::strings::msg_params][am::strings::reason] = + static_cast<int32_t>( + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillOnce(Return(hmi_apis::Common_Language::EN_AU)); + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(_)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + EXPECT_CALL(*app_ptr_, ui_language()).WillRepeatedly(ReturnRef(kLang)); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kAppId_, + mobile_apis::AppInterfaceUnregisteredReason::LANGUAGE_CHANGE)) + .WillOnce(Return(notification)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(notification, Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kAppId_, mobile_apis::Result::SUCCESS, false, false)); + command->Run(); + EXPECT_EQ(static_cast<int32_t>(mobile_apis::FunctionID::OnLanguageChangeID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); + EXPECT_EQ( + static_cast<int32_t>(mobile_apis::Language::EN_US), + (*message)[am::strings::msg_params][am::strings::hmi_display_language] + .asInt()); +} + +TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationEmptyData) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + std::shared_ptr<Command> command = + CreateCommand<hmi::OnDriverDistractionNotification>(message); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(state)); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, + OnDriverDistractionNotificationInvalidApp) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::hmi_notification::state] = state; + std::shared_ptr<Command> command = + CreateCommand<hmi::OnDriverDistractionNotification>(message); + + ApplicationSharedPtr invalid_app; + application_set_.insert(invalid_app); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(*app_ptr_, app_id()).Times(0); + command->Run(); +} + +TEST_F(HMICommandsNotificationsTest, OnDriverDistractionNotificationValidApp) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::mobile_notification::state] = state; + std::shared_ptr<Command> command = + CreateCommand<hmi::OnDriverDistractionNotification>(message); + + application_set_.insert(app_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(applications_)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_)); + EXPECT_CALL(mock_policy_handler_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, Command::CommandSource::SOURCE_SDL)) + .WillOnce(GetMessage(message)); + EXPECT_CALL(*app_ptr_, app_id()).WillRepeatedly(Return(kAppId_)); + + command->Run(); + EXPECT_EQ( + static_cast<int32_t>(am::mobile_api::FunctionID::OnDriverDistractionID), + (*message)[am::strings::params][am::strings::function_id].asInt()); + EXPECT_EQ( + static_cast<int32_t>(kAppId_), + (*message)[am::strings::params][am::strings::connection_key].asInt()); + EXPECT_EQ(static_cast<int32_t>(am::MessageType::kNotification), + (*message)[am::strings::params][am::strings::message_type].asInt()); +} + +} // namespace hmi_notifications_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc new file mode 100644 index 0000000000..8164f957cb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_request_test.cc @@ -0,0 +1,89 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "hmi/mixing_audio_supported_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace mixing_audio_supported_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::MixingAudioSupportedRequest; +using am::commands::CommandImpl; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class MixingAudioSupportedRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(MixingAudioSupportedRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command( + CreateCommand<MixingAudioSupportedRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace mixing_audio_supported_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc new file mode 100644 index 0000000000..aa651c2dca --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/mixing_audio_supported_response_test.cc @@ -0,0 +1,100 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/response_from_hmi.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "sdl_rpc_plugin/commands/hmi/mixing_audio_supported_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace mixing_audio_supported_response { + +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::MixingAudioSupportedResponse; +using application_manager::commands::ResponseFromHMI; +using am::commands::CommandImpl; +using am::HMICapabilities; +namespace hmi_response = ::application_manager::hmi_response; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class MixingAudioSupportedResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(MixingAudioSupportedResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + ResponseFromHMIPtr command( + CreateCommand<MixingAudioSupportedResponse>(command_msg)); + + const bool hmiResponse = + (*command_msg)[strings::msg_params][hmi_response::attenuated_supported] + .asBool(); + + EXPECT_CALL(mock_hmi_capabilities_, set_attenuated_supported(hmiResponse)); + + command->Run(); +} + +} // namespace mixing_audio_supported_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc new file mode 100644 index 0000000000..d8454bb98e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_audio_start_stream_request_test.cc @@ -0,0 +1,121 @@ +/* + * 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 <utility> + +#include "hmi/navi_audio_start_stream_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_audio_start_stream_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = am::commands; +using commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::AudioStartStreamRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kHmiAppId = 13u; +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +class AudioStartStreamRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + AudioStartStreamRequestTest() { + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(start_stream_retry_amount_)); + msg_ = CreateMessage(); + command_ = CreateCommand<AudioStartStreamRequest>(msg_); + } + + std::pair<uint32_t, int32_t> start_stream_retry_amount_; + MessageSharedPtr msg_; + std::shared_ptr<AudioStartStreamRequest> command_; +}; + +TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(AudioStartStreamRequestTest, + Run_HmiInterfaceAvailableButNoApp_NoRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(AudioStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_audio_streaming_allowed(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg_)); + + command_->Run(); +} + +} // namespace navi_audio_start_stream_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc new file mode 100644 index 0000000000..1a03ecf523 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_request_test.cc @@ -0,0 +1,135 @@ +/* + * 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 "hmi/navi_is_ready_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviIsReadyRequest; +using am::event_engine::Event; + +namespace { +const hmi_apis::FunctionID::eType kEventID = + hmi_apis::FunctionID::Navigation_IsReady; +} // namespace + +typedef std::shared_ptr<NaviIsReadyRequest> NaviIsReadyRequestPtr; + +class NaviIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + NaviIsReadyRequestTest() : command_(CreateCommand<NaviIsReadyRequest>()) {} + + NaviIsReadyRequestPtr command_; +}; + +TEST_F(NaviIsReadyRequestTest, + OnEvent_HmiInterfaceIsAvailable_NaviCooperatingIsAvailable) { + const bool is_hmi_interface_available = true; + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::msg_params][am::strings::available] = + is_hmi_interface_available; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, + am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +TEST_F(NaviIsReadyRequestTest, + OnEvent_HmiInterfaceIsNotAvailable_NaviCooperatingIsNotAvailable) { + const bool is_hmi_interface_available = false; + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::msg_params][am::strings::available] = + is_hmi_interface_available; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation, + am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +TEST_F(NaviIsReadyRequestTest, + OnEvent_AvailabilityFieldMissing_NaviCooperatingIsNotAvailable) { + const bool is_hmi_interface_available = false; + + MessageSharedPtr event_msg = CreateMessage(); + Event event(kEventID); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_hmi_capabilities_, + set_is_navi_cooperating(is_hmi_interface_available)); + + command_->on_event(event); +} + +} // namespace navi_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc new file mode 100644 index 0000000000..23f01fac3f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_is_ready_response_test.cc @@ -0,0 +1,75 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "hmi/navi_is_ready_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_is_ready_responce { +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::ReturnRef; + +using application_manager::commands::ResponseFromHMI; +using test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; + +class NaviIsReadyResponseTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(NaviIsReadyResponseTest, NaviIsReadyResponse_Run_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand<commands::NaviIsReadyResponse>()); + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + command->Run(); +} + +} // namespace navi_is_ready_responce +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc new file mode 100644 index 0000000000..3110a11fd8 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_request_test.cc @@ -0,0 +1,216 @@ +/* + * 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 names of the copyright holders 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 <algorithm> + +#include "hmi/navi_set_video_config_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_set_video_config_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviSetVideoConfigRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kHmiAppId = 13u; +const hmi_apis::FunctionID::eType kEventID = + hmi_apis::FunctionID::Navigation_SetVideoConfig; +} // namespace + +typedef std::shared_ptr<NaviSetVideoConfigRequest> NaviSetVideoConfigRequestPtr; + +class NaviSetVideoConfigRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + NaviSetVideoConfigRequestTest() { + mock_app_ptr_ = CreateMockApp(); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_ptr_)); + ON_CALL(app_mngr_, application_by_hmi_app(_)) + .WillByDefault(Return(mock_app_ptr_)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(mock_event_dispatcher_)); + ON_CALL(*mock_app_ptr_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_ptr_, hmi_app_id()).WillByDefault(Return(kHmiAppId)); + } + + MOCK(am::MockHmiInterfaces) mock_hmi_interfaces_; + MockAppPtr mock_app_ptr_; + MockEventDispatcher mock_event_dispatcher_; +}; + +TEST_F(NaviSetVideoConfigRequestTest, OnEventWithSuccessResponse) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand<NaviSetVideoConfigRequest>(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector<std::string> empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, true, empty)) + .Times(1); + + command->on_event(event); +} + +static bool ValidateList(std::vector<std::string>& expected, + std::vector<std::string>& actual) { + std::sort(expected.begin(), expected.end()); + std::sort(actual.begin(), actual.end()); + return std::equal(expected.begin(), expected.end(), actual.begin()); +} + +TEST_F(NaviSetVideoConfigRequestTest, OnEventWithRejectedResponse) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*request_msg)[am::strings::msg_params][am::strings::config] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::protocol] = + hmi_apis::Common_VideoStreamingProtocol::RTP; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::codec] = + hmi_apis::Common_VideoStreamingCodec::H265; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::height] = 640; + (*request_msg)[am::strings::msg_params][am::strings::config] + [am::strings::width] = 480; + + NaviSetVideoConfigRequestPtr command = + CreateCommand<NaviSetVideoConfigRequest>(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + + (*event_msg)[am::strings::msg_params][am::strings::rejected_params] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*event_msg)[am::strings::msg_params][am::strings::rejected_params][0] = + "codec"; + (*event_msg)[am::strings::msg_params][am::strings::rejected_params][1] = + "protocol"; + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector<std::string> rejected_params; + EXPECT_CALL(app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, _)) + .WillOnce(SaveArg<3>(&rejected_params)); + + command->on_event(event); + + ASSERT_EQ(2u, rejected_params.size()); + std::vector<std::string> expected_list; + expected_list.push_back(std::string("protocol")); + expected_list.push_back(std::string("codec")); + ASSERT_TRUE(ValidateList(expected_list, rejected_params)); +} + +TEST_F(NaviSetVideoConfigRequestTest, + OnEventWithRejectedResponseWithoutParams) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand<NaviSetVideoConfigRequest>(request_msg); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + + Event event(kEventID); + event.set_smart_object(*event_msg); + + std::vector<std::string> empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) + .WillOnce(Return()); + + command->on_event(event); +} + +TEST_F(NaviSetVideoConfigRequestTest, OnTimeout) { + MessageSharedPtr request_msg = CreateMessage(); + (*request_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + + NaviSetVideoConfigRequestPtr command = + CreateCommand<NaviSetVideoConfigRequest>(request_msg); + + std::vector<std::string> empty; + EXPECT_CALL( + app_mngr_, + OnStreamingConfigured( + kAppId, protocol_handler::ServiceType::kMobileNav, false, empty)) + .WillOnce(Return()); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(1); + + command->onTimeOut(); +} + +} // namespace navi_set_video_config_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc new file mode 100644 index 0000000000..06fa61db29 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_set_video_config_response_test.cc @@ -0,0 +1,78 @@ +/* + * 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 names of the copyright holders 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 "application_manager/commands/commands_test.h" +#include "hmi/navi_set_video_config_response.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_set_video_config_response { + +using sdl_rpc_plugin::commands::NaviSetVideoConfigResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +class NaviSetVideoConfigResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(NaviSetVideoConfigResponseTest, RUN_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<NaviSetVideoConfigResponse> command( + CreateCommand<NaviSetVideoConfigResponse>(msg)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace navi_set_video_config_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc new file mode 100644 index 0000000000..a7f50504fb --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_start_stream_request_test.cc @@ -0,0 +1,120 @@ +/* + * 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 <utility> + +#include "hmi/navi_start_stream_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_start_stream_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = am::commands; +using commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::NaviStartStreamRequest; +using am::event_engine::Event; + +namespace { +const uint32_t kHmiAppId = 13u; +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +class NaviStartStreamRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + NaviStartStreamRequestTest() { + ON_CALL(app_mngr_settings_, start_stream_retry_amount()) + .WillByDefault(ReturnRef(start_stream_retry_amount_)); + msg_ = CreateMessage(); + command_ = CreateCommand<NaviStartStreamRequest>(msg_); + } + + std::pair<uint32_t, int32_t> start_stream_retry_amount_; + MessageSharedPtr msg_; + std::shared_ptr<NaviStartStreamRequest> command_; +}; + +TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(NaviStartStreamRequestTest, + Run_HmiInterfaceAvailableButNoApp_NoRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + command_->Run(); +} + +TEST_F(NaviStartStreamRequestTest, Run_HmiInterfaceAvailable_SentRequest) { + (*msg_)[am::strings::msg_params][am::strings::app_id] = kHmiAppId; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kHmiAppId)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_video_streaming_allowed(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(msg_)); + + command_->Run(); +} + +} // namespace navi_start_stream_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc new file mode 100644 index 0000000000..e4a79997fd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/navi_stop_stream_requests_test.cc @@ -0,0 +1,105 @@ +/* + * 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 "hmi/navi_stop_stream_request.h" +#include "hmi/navi_audio_stop_stream_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace navi_stop_stream_requests { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +namespace { +const am::HmiInterfaces::InterfaceID kHmiInterface = + am::HmiInterfaces::HMI_INTERFACE_Navigation; +} // namespace + +template <typename Command> +class NaviStopStreamRequestsTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + NaviStopStreamRequestsTest() { + ON_CALL(this->app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + msg_ = CreateMessage(); + command_ = CreateCommand<Command>(msg_); + } + + MessageSharedPtr msg_; + std::shared_ptr<Command> command_; +}; + +typedef testing::Types<commands::AudioStopStreamRequest, + commands::NaviStopStreamRequest> RequestCommandsList; +TYPED_TEST_CASE(NaviStopStreamRequestsTest, RequestCommandsList); + +TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceNotAvailable_NoRequest) { + EXPECT_CALL(TestFixture::mock_hmi_interfaces_, + GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(TestFixture::mock_rpc_service_, SendMessageToHMI(_)).Times(0); + + TestFixture::command_->Run(); +} + +TYPED_TEST(NaviStopStreamRequestsTest, Run_HmiInterfaceAvailable_SentRequest) { + EXPECT_CALL(TestFixture::mock_hmi_interfaces_, + GetInterfaceState(kHmiInterface)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(TestFixture::mock_rpc_service_, + SendMessageToHMI(TestFixture::msg_)); + + TestFixture::command_->Run(); +} + +} // namespace navi_stop_stream_requests +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc new file mode 100644 index 0000000000..fc3899e861 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_driver_distraction_notification_test.cc @@ -0,0 +1,159 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "utils/lock.h" +#include "utils/data_accessor.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/on_driver_distraction_notification.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_driver_distraction_notification { + +using ::testing::_; +using ::testing::Return; +using ::testing::Eq; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::hmi::OnDriverDistractionNotification; +using namespace am::commands; + +typedef std::shared_ptr<OnDriverDistractionNotification> NotificationPtr; + +class HMIOnDriverDistractionNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + HMIOnDriverDistractionNotificationTest() + : app_set_lock_(std::make_shared<sync_primitives::Lock>()) {} + std::shared_ptr<sync_primitives::Lock> app_set_lock_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; +}; + +MATCHER_P2(CheckNotificationParams, function_id, state, "") { + bool is_function_id_matched = + function_id == + static_cast<am::mobile_api::FunctionID::eType>( + (*arg)[am::strings::params][am::strings::function_id].asInt()); + bool is_state_matched = + state == + static_cast<hmi_apis::Common_DriverDistractionState::eType>( + (*arg)[am::strings::msg_params][am::mobile_notification::state] + .asInt()); + return is_function_id_matched && is_state_matched; +} + +ACTION_P(GetArg3, result) { + arg3 = *result; +} + +TEST_F(HMIOnDriverDistractionNotificationTest, Run_PushMobileMessage_SUCCESS) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + + NotificationPtr command( + CreateCommand<OnDriverDistractionNotification>(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + MockAppPtr mock_app = CreateMockApp(); + am::ApplicationSet app_set; + app_set.insert(mock_app); + + DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcDisallowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + + EXPECT_CALL(*mock_app, + PushMobileMessage(CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state))); + + command->Run(); +} + +TEST_F(HMIOnDriverDistractionNotificationTest, + Run_SendNotificationToMobile_SUCCESS) { + const hmi_apis::Common_DriverDistractionState::eType state = + hmi_apis::Common_DriverDistractionState::DD_ON; + MessageSharedPtr commands_msg(CreateMessage(smart_objects::SmartType_Map)); + (*commands_msg)[am::strings::msg_params][am::hmi_notification::state] = state; + + NotificationPtr command( + CreateCommand<OnDriverDistractionNotification>(commands_msg)); + + EXPECT_CALL(app_mngr_, set_driver_distraction_state(Eq(state))); + + MockAppPtr mock_app = CreateMockApp(); + am::ApplicationSet app_set; + app_set.insert(mock_app); + + DataAccessor<am::ApplicationSet> accessor(app_set, app_set_lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + policy::CheckPermissionResult result; + result.hmi_level_permitted = policy::kRpcAllowed; + EXPECT_CALL(app_mngr_, GetPolicyHandler()) + .WillOnce(ReturnRef(mock_policy_handler_interface_)); + EXPECT_CALL(mock_policy_handler_interface_, CheckPermissions(_, _, _, _)) + .WillOnce(GetArg3(&result)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckNotificationParams( + am::mobile_api::FunctionID::OnDriverDistractionID, state), + Command::CommandSource::SOURCE_SDL)); + + command->Run(); +} + +} // on_driver_distraction_notification +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_system_time_ready_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_system_time_ready_notification_test.cc new file mode 100644 index 0000000000..2d50ec2b72 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/on_system_time_ready_notification_test.cc @@ -0,0 +1,80 @@ +/* + * 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 names of the copyright holders 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 "application_manager/commands/commands_test.h" +#include "hmi/on_system_time_ready_notification.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/smart_object_keys.h" +#include "interfaces/HMI_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace on_system_time_ready_notification { + +using sdl_rpc_plugin::commands::OnSystemTimeReadyNotification; +using test::components::event_engine_test::MockEventDispatcher; +using testing::ReturnRef; + +class OnSystemTimeReadyNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +ACTION_P(GetEventId, event_id) { + *event_id = arg0.id(); +} + +TEST_F(OnSystemTimeReadyNotificationTest, Run_SUCCESS) { + int32_t event_id = hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr msg = CreateMessage(); + MockEventDispatcher mock_event_dispatcher; + + auto command(CreateCommand<OnSystemTimeReadyNotification>(msg)); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)) + .WillOnce(GetEventId(&event_id)); + + command->Run(); + + EXPECT_EQ(hmi_apis::FunctionID::BasicCommunication_OnSystemTimeReady, + event_id); +} + +} // namespace on_system_time_ready_notification +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc new file mode 100644 index 0000000000..8e62c1a409 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_response_test.cc @@ -0,0 +1,176 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/rc_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_get_capabilities_response { + +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::RCGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<RCGetCapabilitiesResponse> RCGetCapabilitiesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class RCGetCapabilitiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][strings::rc_capability] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(RCGetCapabilitiesResponseTest, RUN_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::rc_capability] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject& remote_control_capability = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::rc_capability]; + + remote_control_capability["climateControlCapabilities"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability["climateControlCapabilities"][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& climate_control_capability = + remote_control_capability["climateControlCapabilities"][0]; + + climate_control_capability["moduleName"] = "Climate"; + climate_control_capability["fanSpeedAvailable"] = true; + climate_control_capability["desiredTemperatureAvailable"] = true; + climate_control_capability["acEnableAvailable"] = true; + climate_control_capability["acMaxEnableAvailable"] = true; + climate_control_capability["circulateAirEnableAvailable"] = true; + climate_control_capability["autoModeEnableAvailable"] = true; + climate_control_capability["dualModeEnableAvailable"] = true; + + climate_control_capability["defrostZoneAvailable"] = true; + climate_control_capability["defrostZone"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + climate_control_capability["defrostZone"][0] = "ALL"; + + climate_control_capability["ventilationModeAvailable"] = true; + climate_control_capability["ventilationMode"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + climate_control_capability["ventilationMode"][0] = "BOTH"; + + remote_control_capability["radioControlCapabilities"] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability["radioControlCapabilities"][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& radio_control_capability = + remote_control_capability["radioControlCapabilities"][0]; + + radio_control_capability["moduleName"] = "Radio"; + radio_control_capability["radioEnableAvailable"] = true; + radio_control_capability["radioBandAvailable"] = true; + radio_control_capability["radioFrequencyAvailable"] = true; + radio_control_capability["hdChannelAvailable"] = true; + radio_control_capability["rdsDataAvailable"] = true; + radio_control_capability["availableHDsAvailable"] = true; + radio_control_capability["stateAvailable"] = true; + radio_control_capability["signalStrengthAvailable"] = true; + radio_control_capability["signalChangeThresholdAvailable"] = true; + + remote_control_capability[hmi_response::button_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + remote_control_capability[hmi_response::button_capabilities][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + smart_objects::SmartObject& button_capability = + remote_control_capability[hmi_response::button_capabilities][0]; + + button_capability[strings::button_name] = "OK"; + button_capability["shortPressAvailable"] = true; + button_capability["longPressAvailable"] = true; + button_capability["upDownAvailable"] = true; + + RCGetCapabilitiesResponsePtr command( + CreateCommand<RCGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject rc_capability_so = + (*command_msg)[strings::msg_params][strings::rc_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, set_rc_capability(rc_capability_so)); + EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(true)); + + command->Run(); +} + +} // namespace rc_get_capabilities_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc new file mode 100644 index 0000000000..030db2f424 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_request_test.cc @@ -0,0 +1,168 @@ +/* + * 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 "hmi/rc_is_ready_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::RCIsReadyRequest; +using am::event_engine::Event; + +typedef std::shared_ptr<RCIsReadyRequest> RCIsReadyRequestPtr; + +class RCIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + RCIsReadyRequestTest() : command_(CreateCommand<RCIsReadyRequest>()) {} + + void SetUpExpectations(bool is_rc_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_rc_cooperating(is_rc_cooperating_available)); + if (!is_rc_cooperating_available) { + EXPECT_CALL(mock_hmi_capabilities_, set_rc_supported(false)); + } + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_RC, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_RC)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::RC_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_rc_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_rc_cooperating_available; + } + event.set_smart_object(*msg); + } + + RCIsReadyRequestPtr command_; + am::MockHmiInterfaces mock_hmi_interfaces_; +}; + +TEST_F(RCIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_rc_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_rc_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_rc_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::RC_IsReady); + PrepareEvent(is_message_contain_param, event, is_rc_cooperating_available); + SetUpExpectations(is_rc_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(RCIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace rc_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc new file mode 100644 index 0000000000..a1a8c1c87e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_is_ready_response_test.cc @@ -0,0 +1,79 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "hmi/rc_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_is_ready_response { + +using ::testing::Return; + +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::RCIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr<RCIsReadyResponse> RCIsReadyResponsePtr; + +class RCIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +}; + +TEST_F(RCIsReadyResponseTest, RUN_SUCCESS) { + RCIsReadyResponsePtr command(CreateCommand<RCIsReadyResponse>()); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace rc_is_ready_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc new file mode 100644 index 0000000000..0b1f2df491 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/response_from_hmi_test.cc @@ -0,0 +1,131 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" +#include "application_manager/commands/command.h" +#include "application_manager/test/include/application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/response_from_hmi.h" +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace response_from_hmi { + +using ::testing::_; +using ::testing::Return; +using ::testing::SaveArg; +using ::testing::DoAll; +using ::test::components::event_engine_test::MockEventDispatcher; + +namespace am = ::application_manager; +using application_manager::commands::ResponseFromHMI; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; + +class ResponseFromHMITest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(ResponseFromHMITest, BasicMethodsOverloads_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand<ResponseFromHMI>()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(ResponseFromHMITest, SendResponseToMobile_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand<ResponseFromHMI>()); + + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(msg, _)); + + command->SendResponseToMobile(msg, app_mngr_); + + const application_manager::MessageType received_message_tipe = + static_cast<application_manager::MessageType>( + (*msg)[am::strings::params][am::strings::message_type].asInt()); + + EXPECT_EQ(application_manager::MessageType::kResponse, received_message_tipe); +} + +TEST_F(ResponseFromHMITest, CreateHMIRequest_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand<ResponseFromHMI>()); + + MessageSharedPtr result_msg; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(true))); + + const hmi_apis::FunctionID::eType posted_function_id = + hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr dummy_msg_params = CreateMessage(); + command->CreateHMIRequest(posted_function_id, *dummy_msg_params); + + ASSERT_TRUE((bool)result_msg); + + const application_manager::MessageType received_message_tipe = + static_cast<application_manager::MessageType>( + (*result_msg)[am::strings::params][am::strings::message_type] + .asInt()); + + EXPECT_EQ(am::MessageType::kRequest, received_message_tipe); + + const hmi_apis::FunctionID::eType received_function_id = + static_cast<hmi_apis::FunctionID::eType>( + (*result_msg)[am::strings::params][am::strings::function_id].asInt()); + + EXPECT_EQ(posted_function_id, received_function_id); +} + +TEST_F(ResponseFromHMITest, CreateHMIRequest_CantManageCommand_Covering) { + ResponseFromHMIPtr command(CreateCommand<ResponseFromHMI>()); + + MessageSharedPtr result_msg; + ON_CALL(app_mngr_, GetNextHMICorrelationID()).WillByDefault(Return(1u)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result_msg), Return(false))); + + const hmi_apis::FunctionID::eType posted_function_id = + hmi_apis::FunctionID::INVALID_ENUM; + MessageSharedPtr dummy_msg_params = CreateMessage(); + command->CreateHMIRequest(posted_function_id, *dummy_msg_params); +} + +} // namespace response_from_hmi +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc new file mode 100644 index 0000000000..38cbc7b069 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_request_test.cc @@ -0,0 +1,500 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "utils/lock.h" +#include "utils/helpers.h" +#include "hmi/sdl_activate_app_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/application_manager.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_state_controller.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_activate_app_request { + +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLActivateAppRequest; +using am::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::ReturnRef; +using testing::Mock; +using ::testing::NiceMock; +using policy_test::MockPolicyHandlerInterface; +using am::event_engine::Event; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const uint32_t kAppIDFirst = 1u; +const connection_handler::DeviceHandle kHandle = 2u; +} // namespace + +MATCHER_P2(CheckMsgParams, result, corr_id, "") { + const bool is_func_id_valid = + hmi_apis::FunctionID::SDL_ActivateApp == + static_cast<int32_t>( + (*arg)[strings::params][strings::function_id].asInt()); + + const bool is_result_code_valid = + hmi_apis::Common_Result::APPLICATION_NOT_REGISTERED == + static_cast<int32_t>( + (*arg)[strings::msg_params][strings::result_code].asInt()); + + const bool is_result_valid = + result == (*arg)[strings::msg_params][strings::success].asBool(); + + const bool is_corr_id_valid = + corr_id == ((*arg)[strings::params][strings::correlation_id].asUInt()); + + using namespace helpers; + return Compare<bool, EQ, ALL>(true, + is_func_id_valid, + is_result_code_valid, + is_result_valid, + is_corr_id_valid); +} + +class SDLActivateAppRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SDLActivateAppRequestTest() + : lock_(std::make_shared<sync_primitives::Lock>()) {} + + protected: + ~SDLActivateAppRequestTest() { + // Fix DataAccessor release and WinQt crash + Mock::VerifyAndClearExpectations(&app_mngr_); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + MockAppPtr mock_app = CreateMockApp(); + CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout); + ON_CALL((*mock_app), app_id()).WillByDefault(Return(kAppID)); + ON_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillByDefault(Return(mock_app)); + } + void SetCorrelationAndAppID(MessageSharedPtr msg) { + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + } + + ApplicationSet app_list_; + std::shared_ptr<sync_primitives::Lock> lock_; + policy_test::MockPolicyHandlerInterface policy_handler_; + application_manager_test::MockStateController mock_state_controller_; + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; +}; + +#ifdef EXTERNAL_PROPRIETARY_MODE + +TEST_F(SDLActivateAppRequestTest, Run_ActivateApp_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, DISABLED_Run_DactivateApp_REJECTED) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + (*msg)[strings::msg_params][strings::function_id] = + hmi_apis::FunctionID::SDL_ActivateApp; + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(true)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::SDL_ActivateApp))) + .WillOnce(Return(true)); + + command->Run(); +} +#else + +TEST_F(SDLActivateAppRequestTest, FindAppToRegister_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppID)).WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + ON_CALL(*mock_app, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + const std::string url = "url"; + ON_CALL(*mock_app_first, SchemaUrl()).WillByDefault(Return(url)); + const std::string package = "package"; + ON_CALL(*mock_app_first, PackageName()).WillByDefault(Return(package)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, AppIdNotFound_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kAppID)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(app_mngr_, WaitingApplicationByID(kAppID)) + .WillOnce(Return(ApplicationSharedPtr())); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, DevicesAppsEmpty_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + ON_CALL(*mock_app, device()).WillByDefault(Return(kHandle)); + + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + app_list_ = accessor.GetData(); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + app_list_ = accessor.GetData(); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppIDFirst)) + .WillByDefault(Return(mock_app_first)); + + app_list_.insert(mock_app_first); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(true)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppIsForeground_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + + const std::string schema("schema"); + mock_app->SetShemaUrl(schema); + const std::string package_name("package_name"); + mock_app->SetPackageName(package_name); + + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(*mock_app, IsRegistered()).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, schema, package_name, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotRegisteredAndEmpty_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillOnce(Return(false)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} + +TEST_F(SDLActivateAppRequestTest, FirstAppNotRegistered_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(kAppID)).WillByDefault(Return(mock_app)); + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, state_controller()) + .WillOnce(ReturnRef(mock_state_controller_)); + EXPECT_CALL(mock_state_controller_, + IsStateActive(am::HmiState::StateID::STATE_ID_DEACTIVATE_HMI)) + .WillOnce(Return(false)); + DataAccessor<ApplicationSet> accessor(app_list_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillRepeatedly(Return(accessor)); + + app_list_ = accessor.GetData(); + + MockAppPtr mock_app_first(CreateMockApp()); + ON_CALL(*mock_app_first, device()).WillByDefault(Return(kHandle)); + ON_CALL(*mock_app_first, is_foreground()).WillByDefault(Return(false)); + + app_list_.insert(mock_app_first); + ON_CALL(*mock_app_first, protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app_first, is_foreground()).WillRepeatedly(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendLaunchApp(_, _, _, _)); + + command->Run(); +} +#endif + +TEST_F(SDLActivateAppRequestTest, OnTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + SetCorrelationAndAppID(msg); + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + ON_CALL(mock_event_dispatcher_, remove_observer(_, _)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->onTimeOut(); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::params][strings::correlation_id] = kCorrelationID; + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>()); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*event_msg); + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).Times(0); + + command->on_event(event); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_InvalidAppId_UNSUCCESS) { + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::msg_params][strings::application][strings::app_id] = + kAppID; + + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>()); + + Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); + event.set_smart_object(*event_msg); + + MockAppPtr invalid_mock_app; + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)) + .WillOnce(Return(invalid_mock_app)); + + command->on_event(event); +} + +TEST_F(SDLActivateAppRequestTest, OnEvent_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + std::shared_ptr<SDLActivateAppRequest> command( + CreateCommand<SDLActivateAppRequest>(msg)); + + MessageSharedPtr event_msg = CreateMessage(); + (*event_msg)[strings::msg_params][strings::application][strings::app_id] = + kAppID; + + Event event(hmi_apis::FunctionID::BasicCommunication_OnAppRegistered); + event.set_smart_object(*event_msg); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application_by_hmi_app(_)).WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppID)); + + EXPECT_CALL(mock_policy_handler_, OnActivateApp(kAppID, kCorrelationID)); + + command->on_event(event); +} + +} // namespace sdl_activate_app_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc new file mode 100644 index 0000000000..bca316bcfa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_activate_app_response_test.cc @@ -0,0 +1,85 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "hmi/sdl_activate_app_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_activate_app_response { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::SDLActivateAppResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<SDLActivateAppResponse> SDLActivateAppResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class SDLActivateAppResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(SDLActivateAppResponseTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + + SDLActivateAppResponsePtr command( + CreateCommand<SDLActivateAppResponse>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace sdl_activate_app_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc new file mode 100644 index 0000000000..262ac5fc7d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_list_of_permisssions_request_test.cc @@ -0,0 +1,111 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "hmi/sdl_get_list_of_permissions_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_list_of_permissions_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetListOfPermissionsRequest; +using test::components::policy_test::MockPolicyHandlerInterface; +using smart_objects::SmartObject; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const uint32_t kConnectionKey = 0u; +} // namespace + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +class SDLGetListOfPermissionsRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout); + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); + } + MockAppPtr mock_app_; +}; + +TEST_F(SDLGetListOfPermissionsRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillOnce(Return(mock_app_)); + + std::shared_ptr<SDLGetListOfPermissionsRequest> command( + CreateCommand<SDLGetListOfPermissionsRequest>(msg)); + + EXPECT_CALL(mock_policy_handler_, + OnGetListOfPermissions(kAppID, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetListOfPermissionsRequestTest, Run_KeyDoesntExist_SUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Binary); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + + std::shared_ptr<SDLGetListOfPermissionsRequest> command( + CreateCommand<SDLGetListOfPermissionsRequest>(msg)); + + EXPECT_CALL(mock_policy_handler_, + OnGetListOfPermissions(kConnectionKey, kCorrelationID)); + + command->Run(); +} + +} // namespace sdl_get_list_of_permissions_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc new file mode 100644 index 0000000000..fca8ed840f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_status_update_request_test.cc @@ -0,0 +1,79 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "hmi/sdl_get_status_update_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_status_update_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetStatusUpdateRequest; +using test::components::policy_test::MockPolicyHandlerInterface; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +} // namespace + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +class SDLGetStatusUpdateRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(SDLGetStatusUpdateRequestTest, Run_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + + std::shared_ptr<SDLGetStatusUpdateRequest> command( + CreateCommand<SDLGetStatusUpdateRequest>(msg)); + + EXPECT_CALL(mock_policy_handler_, OnGetStatusUpdate(kCorrelationID)); + + command->Run(); +} + +} // namespace sdl_get_status_update_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_test.cc new file mode 100644 index 0000000000..b040f8ea40 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/sdl_get_user_friendly_message_request_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 <stdint.h> +#include <string> +#include <vector> + +#include "gtest/gtest.h" +#include "hmi/sdl_get_user_friendly_message_request.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_state_controller.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace sdl_get_user_friendly_message_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SDLGetUserFriendlyMessageRequest; +using application_manager::MockMessageHelper; +using test::components::policy_test::MockPolicyHandlerInterface; +using test::components::application_manager_test::MockHMICapabilities; +using testing::_; +using testing::Return; +using testing::ReturnRef; + +namespace { +const uint32_t kCorrelationID = 1u; +const uint32_t kAppID = 2u; +const std::string kLanguageDe = "de-de"; +const std::string kLanguageEn = "en-gb"; +const std::string kMessageCodes = "messageCodes"; +const hmi_apis::Common_Language::eType kLanguage = + hmi_apis::Common_Language::EN_GB; +} // namespace + +namespace strings = ::application_manager::strings; + +class SDLGetUserFriendlyMessageRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + } + + void InitCommand(const uint32_t& timeout) OVERRIDE { + CommandRequestTest<CommandsTestMocks::kIsNice>::InitCommand(timeout); + ON_CALL((*mock_app_), app_id()).WillByDefault(Return(kAppID)); + EXPECT_CALL(app_mngr_, application_by_hmi_app(kAppID)) + .WillOnce(Return(mock_app_)); + } + MockAppPtr mock_app_; +}; + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + (*msg)[strings::msg_params][strings::language] = kLanguage; + + std::shared_ptr<SDLGetUserFriendlyMessageRequest> command( + CreateCommand<SDLGetUserFriendlyMessageRequest>(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) + .WillOnce(Return(kLanguageEn)); + std::vector<std::string> msg_codes; + msg_codes.push_back(kLanguageDe); + msg_codes.push_back(kLanguageEn); + EXPECT_CALL(mock_policy_handler_, + OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + (*msg)[strings::msg_params][kMessageCodes] = + SmartObject(smart_objects::SmartType_Array); + (*msg)[strings::msg_params][kMessageCodes][0] = SmartObject(kLanguageDe); + (*msg)[strings::msg_params][kMessageCodes][1] = SmartObject(kLanguageEn); + + std::shared_ptr<SDLGetUserFriendlyMessageRequest> command( + CreateCommand<SDLGetUserFriendlyMessageRequest>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillOnce(Return(kLanguage)); + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(kLanguage)) + .WillOnce(Return(kLanguageEn)); + std::vector<std::string> msg_codes; + msg_codes.push_back(kLanguageDe); + msg_codes.push_back(kLanguageEn); + EXPECT_CALL(mock_policy_handler_, + OnGetUserFriendlyMessage(msg_codes, kLanguageEn, kCorrelationID)); + + command->Run(); +} + +TEST_F(SDLGetUserFriendlyMessageRequestTest, Run_NoMsgCodes_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::correlation_id] = kCorrelationID; + (*msg)[strings::msg_params][strings::app_id] = kAppID; + + std::shared_ptr<SDLGetUserFriendlyMessageRequest> command( + CreateCommand<SDLGetUserFriendlyMessageRequest>(msg)); + + EXPECT_CALL(mock_message_helper_, CommonLanguageToString(_)).Times(0); + EXPECT_CALL(mock_policy_handler_, OnGetUserFriendlyMessage(_, _, _)).Times(0); + + command->Run(); +} + +} // namespace sdl_get_user_friendly_message_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc new file mode 100644 index 0000000000..581913d3a5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_notifications_test.cc @@ -0,0 +1,78 @@ +/* + * 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 "application_manager/commands/commands_test.h" + +#include "application_manager/commands/notification_to_hmi.h" +#include "application_manager/commands/command_notification_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_notifications_test { + +using namespace application_manager; + +using ::testing::Types; +using commands::NotificationToHMI; +template <typename Command> +class SimpleNotificationsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +typedef Types<commands::CommandNotificationImpl, NotificationToHMI> + CommandsList; + +TYPED_TEST_CASE(SimpleNotificationsTest, CommandsList); + +TYPED_TEST(SimpleNotificationsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +} // namespace simple_notifications_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc new file mode 100644 index 0000000000..5c42d265c7 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_request_from_hmi_test.cc @@ -0,0 +1,96 @@ +/* + * 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 "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/request_from_hmi.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_requests_from_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; +using ::testing::NiceMock; +namespace commands = ::application_manager::commands; +using commands::MessageSharedPtr; +using ::application_manager::event_engine::EventObserver; +using ::test::components::event_engine_test::MockEventDispatcher; + +class RequestFromHMITest : public CommandsTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + } + NiceMock<event_engine_test::MockEventDispatcher> mock_event_dispatcher_; +}; + +TEST_F(RequestFromHMITest, BasicMethodsOverloads_SUCCESS) { + std::shared_ptr<commands::RequestFromHMI> command( + CreateCommand<commands::RequestFromHMI>()); + application_manager::event_engine::Event event( + hmi_apis::FunctionID::BasicCommunication_ActivateApp); + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); + EXPECT_NO_THROW(command->Run()); + EXPECT_NO_THROW(command->on_event(event)); +} + +TEST_F(RequestFromHMITest, SendResponse_SUCCESS) { + std::shared_ptr<commands::RequestFromHMI> command( + CreateCommand<commands::RequestFromHMI>()); + + const bool success = false; + const uint32_t correlation_id = 1u; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(NotNull())); + + command->SendResponse(success, + correlation_id, + hmi_apis::FunctionID::BasicCommunication_ActivateApp, + hmi_apis::Common_Result::SUCCESS); +} + +} // namespace simple_requests_to_hmi_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc new file mode 100644 index 0000000000..eabf5ed7cc --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_requests_to_hmi_test.cc @@ -0,0 +1,265 @@ +/* + * 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 copyright holders nor the names of their 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 "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/command.h" +#include "sdl_rpc_plugin/commands/hmi/allow_app_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_all_apps_request.h" +#include "sdl_rpc_plugin/commands/hmi/basic_communication_system_request.h" +#include "sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_alert_maneuver_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_audio_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_get_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_send_location_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_show_constant_tbt_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_subscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_unsubscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_update_turn_list_request.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h" +#include "sdl_rpc_plugin/commands/hmi/ui_scrollable_message_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_app_icon_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_display_layout_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_global_properties_request.h" +#include "application_manager/commands/request_to_hmi.h" +#include "sdl_rpc_plugin/commands/hmi/dial_number_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_set_global_properties_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_speak_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_stop_speaking_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/tts_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/close_popup_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_add_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_add_submenu_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_alert_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_delete_submenu_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_end_audio_pass_thru_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_perform_audio_pass_thru_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_perform_interaction_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_set_media_clock_timer_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_show_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_slider_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_add_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_change_registration_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_delete_command_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_supported_languages_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_get_language_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_is_ready_request.h" +#include "sdl_rpc_plugin/commands/hmi/vr_perform_interaction_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_all_apps_request.h" +#include "sdl_rpc_plugin/commands/hmi/basic_communication_system_request.h" +#include "sdl_rpc_plugin/commands/hmi/button_get_capabilities_request.h" +#include "sdl_rpc_plugin/commands/hmi/allow_app_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_send_location_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_unsubscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_update_turn_list_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_show_constant_tbt_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_stop_stream_request.h" +#include "sdl_rpc_plugin/commands/hmi/navi_subscribe_way_points_request.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_policy_update.h" +#include "sdl_rpc_plugin/commands/hmi/dial_number_request.h" +#include "sdl_rpc_plugin/commands/hmi/ui_send_haptic_data_request.h" + +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_requests_to_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; +namespace am_commands = application_manager::commands; +using am_commands::MessageSharedPtr; +using event_engine_test::MockEventDispatcher; + +class RequestToHMITest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(RequestToHMITest, BasicMethodsOverloads_SUCCESS) { + std::shared_ptr<am_commands::RequestToHMI> command( + CreateCommand<am_commands::RequestToHMI>()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_NO_THROW(command->Run()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(RequestToHMITest, SendRequest_SUCCESS) { + std::shared_ptr<am_commands::RequestToHMI> command( + CreateCommand<am_commands::RequestToHMI>()); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->SendRequest(); +} + +template <typename Command> +class RequestToHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +template <typename Command> +class RequestToHMICommandsTest2 : public RequestToHMICommandsTest<Command> {}; + +template <typename Command> +class RequestToHMICommandsTest3 + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +typedef Types<sdl_rpc_plugin::commands::hmi::DialNumberRequest, + sdl_rpc_plugin::commands::ClosePopupRequest, + sdl_rpc_plugin::commands::TTSSetGlobalPropertiesRequest, + sdl_rpc_plugin::commands::TTSSpeakRequest, + sdl_rpc_plugin::commands::TTSStopSpeakingRequest, + sdl_rpc_plugin::commands::TTSGetSupportedLanguagesRequest, + sdl_rpc_plugin::commands::UIAddCommandRequest, + sdl_rpc_plugin::commands::UIAddSubmenuRequest, + sdl_rpc_plugin::commands::UIAlertRequest, + sdl_rpc_plugin::commands::UIChangeRegistrationRequest, + sdl_rpc_plugin::commands::UIDeleteCommandRequest, + sdl_rpc_plugin::commands::UIDeleteSubmenuRequest, + sdl_rpc_plugin::commands::UIEndAudioPassThruRequest, + sdl_rpc_plugin::commands::UIGetCapabilitiesRequest, + sdl_rpc_plugin::commands::UIGetLanguageRequest, + sdl_rpc_plugin::commands::UIGetSupportedLanguagesRequest, + sdl_rpc_plugin::commands::UIPerformAudioPassThruRequest, + sdl_rpc_plugin::commands::UIPerformInteractionRequest, + sdl_rpc_plugin::commands::UISetMediaClockTimerRequest, + sdl_rpc_plugin::commands::UIShowRequest, + sdl_rpc_plugin::commands::VRAddCommandRequest, + sdl_rpc_plugin::commands::VRChangeRegistrationRequest, + sdl_rpc_plugin::commands::VRDeleteCommandRequest, + sdl_rpc_plugin::commands::UISliderRequest, + sdl_rpc_plugin::commands::TTSChangeRegistrationRequest, + sdl_rpc_plugin::commands::TTSGetCapabilitiesRequest, + sdl_rpc_plugin::commands::TTSGetLanguageRequest, + sdl_rpc_plugin::commands::AllowAllAppsRequest, + sdl_rpc_plugin::commands::BasicCommunicationSystemRequest, + sdl_rpc_plugin::commands::ButtonGetCapabilitiesRequest, + sdl_rpc_plugin::commands::NaviSendLocationRequest, + sdl_rpc_plugin::commands::NaviUnSubscribeWayPointsRequest, + sdl_rpc_plugin::commands::NaviUpdateTurnListRequest, + sdl_rpc_plugin::commands::NaviShowConstantTBTRequest, + sdl_rpc_plugin::commands::NaviStopStreamRequest, + sdl_rpc_plugin::commands::NaviSubscribeWayPointsRequest, + sdl_rpc_plugin::commands::NaviAlertManeuverRequest, + sdl_rpc_plugin::commands::AudioStopStreamRequest, + sdl_rpc_plugin::commands::NaviGetWayPointsRequest, + sdl_rpc_plugin::commands::UISetGlobalPropertiesRequest, + sdl_rpc_plugin::commands::UISendHapticDataRequest> + RequestCommandsList; + +typedef Types<sdl_rpc_plugin::commands::UIScrollableMessageRequest, + sdl_rpc_plugin::commands::VRGetCapabilitiesRequest, + sdl_rpc_plugin::commands::UISetAppIconRequest, + sdl_rpc_plugin::commands::UiSetDisplayLayoutRequest, + sdl_rpc_plugin::commands::VRGetSupportedLanguagesRequest, + sdl_rpc_plugin::commands::VRGetLanguageRequest, + sdl_rpc_plugin::commands::VRPerformInteractionRequest, + sdl_rpc_plugin::commands::AllowAppRequest, +// TODO (OKozlov). Need to clarify why UT fails +// for UISetIconRequest +// am_commands::UISetIconRequest, +#if defined(PROPRIETARY_MODE) || defined(EXTERNAL_PROPRIETARY_MODE) + sdl_rpc_plugin::commands::SDLPolicyUpdate, +#endif + sdl_rpc_plugin::commands::hmi::DialNumberRequest> + RequestCommandsList2; + +typedef Types<sdl_rpc_plugin::commands::TTSIsReadyRequest, + sdl_rpc_plugin::commands::UIIsReadyRequest, + sdl_rpc_plugin::commands::NaviIsReadyRequest, + sdl_rpc_plugin::commands::VRIsReadyRequest> RequestCommandsList3; + +TYPED_TEST_CASE(RequestToHMICommandsTest, RequestCommandsList); +TYPED_TEST_CASE(RequestToHMICommandsTest2, RequestCommandsList2); +TYPED_TEST_CASE(RequestToHMICommandsTest3, RequestCommandsList3); + +TYPED_TEST(RequestToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +TYPED_TEST(RequestToHMICommandsTest2, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +TYPED_TEST(RequestToHMICommandsTest3, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +} // namespace simple_requests_to_hmi_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc new file mode 100644 index 0000000000..4a86fa9458 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_from_hmi_test.cc @@ -0,0 +1,324 @@ +/* + * 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 copyright holders nor the names of their 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 <stdint.h> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command.h" +#include "hmi/activate_app_response.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/navi_alert_maneuver_response.h" +#include "hmi/navi_audio_start_stream_response.h" +#include "hmi/navi_audio_stop_stream_response.h" +#include "hmi/navi_get_way_points_response.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_stop_stream_response.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/ui_set_app_icon_response.h" +#include "hmi/ui_set_display_layout_response.h" +#include "hmi/ui_set_global_properties_response.h" +#include "hmi/ui_scrollable_message_response.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/dial_number_response.h" +#include "hmi/close_popup_response.h" +#include "hmi/tts_set_global_properties_response.h" +#include "hmi/tts_speak_response.h" +#include "hmi/tts_stop_speaking_response.h" +#include "hmi/tts_change_registration_response.h" +#include "hmi/ui_add_command_response.h" +#include "hmi/ui_add_submenu_response.h" +#include "hmi/ui_alert_response.h" +#include "hmi/ui_change_registration_response.h" +#include "hmi/ui_delete_command_response.h" +#include "hmi/ui_delete_submenu_response.h" +#include "hmi/ui_end_audio_pass_thru_response.h" +#include "hmi/ui_perform_audio_pass_thru_response.h" +#include "hmi/ui_perform_interaction_response.h" +#include "hmi/ui_set_media_clock_timer_response.h" +#include "hmi/ui_show_response.h" +#include "hmi/ui_slider_response.h" +#include "hmi/vr_add_command_response.h" +#include "hmi/vr_change_registration_response.h" +#include "hmi/vr_delete_command_response.h" +#include "hmi/vr_perform_interaction_response.h" +#include "hmi/activate_app_response.h" +#include "hmi/basic_communication_system_response.h" +#include "hmi/navi_unsubscribe_way_points_response.h" +#include "hmi/navi_update_turn_list_response.h" +#include "hmi/navi_send_location_response.h" +#include "hmi/navi_show_constant_tbt_response.h" +#include "hmi/navi_start_stream_response.h" +#include "hmi/navi_subscribe_way_points_response.h" +#include "hmi/on_find_applications.h" +#include "hmi/on_update_device_list.h" +#include "hmi/sdl_policy_update_response.h" +#include "hmi/update_app_list_response.h" +#include "hmi/update_device_list_response.h" +#include "application_manager/commands/notification_from_hmi.h" +#include "hmi/ui_send_haptic_data_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_response_from_hmi_test { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::Types; +using ::testing::Eq; +using ::test::components::event_engine_test::MockEventDispatcher; + +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; +using am::commands::MessageSharedPtr; +template <class CommandD> +class ResponseFromHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef CommandD CommandData; + MockEventDispatcher event_dispatcher_; + + ResponseFromHMICommandsTest() { + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + } +}; + +template <class Command> +class EmptyResponseFromHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +template <class Command, hmi_apis::FunctionID::eType kExpectedEventId> +struct CommandData { + typedef Command CommandType; + enum { kEventId = kExpectedEventId }; +}; + +typedef Types< + CommandData<sdl_rpc_plugin::commands::TTSSpeakResponse, + hmi_apis::FunctionID::TTS_Speak>, + CommandData<sdl_rpc_plugin::commands::hmi::DialNumberResponse, + hmi_apis::FunctionID::BasicCommunication_DialNumber>, + CommandData<sdl_rpc_plugin::commands::UIDeleteSubmenuResponse, + hmi_apis::FunctionID::UI_DeleteSubMenu>, + CommandData<sdl_rpc_plugin::commands::UIEndAudioPassThruResponse, + hmi_apis::FunctionID::UI_EndAudioPassThru>, + CommandData<sdl_rpc_plugin::commands::TTSSetGlobalPropertiesResponse, + hmi_apis::FunctionID::TTS_SetGlobalProperties>, + CommandData<sdl_rpc_plugin::commands::TTSStopSpeakingResponse, + hmi_apis::FunctionID::TTS_StopSpeaking>, + CommandData<sdl_rpc_plugin::commands::UIAddCommandResponse, + hmi_apis::FunctionID::UI_AddCommand>, + CommandData<sdl_rpc_plugin::commands::UIAddSubmenuResponse, + hmi_apis::FunctionID::UI_AddSubMenu>, + CommandData<sdl_rpc_plugin::commands::UIAlertResponse, + hmi_apis::FunctionID::UI_Alert>, + CommandData<sdl_rpc_plugin::commands::UIChangeRegistratioResponse, + hmi_apis::FunctionID::UI_ChangeRegistration>, + CommandData<sdl_rpc_plugin::commands::UIDeleteCommandResponse, + hmi_apis::FunctionID::UI_DeleteCommand>, + CommandData<sdl_rpc_plugin::commands::UIPerformAudioPassThruResponse, + hmi_apis::FunctionID::UI_PerformAudioPassThru>, + CommandData<sdl_rpc_plugin::commands::UIPerformInteractionResponse, + hmi_apis::FunctionID::UI_PerformInteraction>, + CommandData<sdl_rpc_plugin::commands::UIDeleteSubmenuResponse, + hmi_apis::FunctionID::UI_DeleteSubMenu>, + CommandData<sdl_rpc_plugin::commands::UIEndAudioPassThruResponse, + hmi_apis::FunctionID::UI_EndAudioPassThru>, + CommandData<sdl_rpc_plugin::commands::UISetMediaClockTimerResponse, + hmi_apis::FunctionID::UI_SetMediaClockTimer>, + CommandData<sdl_rpc_plugin::commands::UIShowResponse, + hmi_apis::FunctionID::UI_Show>, + CommandData<sdl_rpc_plugin::commands::VRAddCommandResponse, + hmi_apis::FunctionID::VR_AddCommand>, + CommandData<sdl_rpc_plugin::commands::VRChangeRegistrationResponse, + hmi_apis::FunctionID::VR_ChangeRegistration>, + CommandData<sdl_rpc_plugin::commands::VRDeleteCommandResponse, + hmi_apis::FunctionID::VR_DeleteCommand>, + CommandData<sdl_rpc_plugin::commands::UISliderResponse, + hmi_apis::FunctionID::UI_Slider>, + CommandData<sdl_rpc_plugin::commands::TTSChangeRegistratioResponse, + hmi_apis::FunctionID::TTS_ChangeRegistration>, + CommandData<sdl_rpc_plugin::commands::ActivateAppResponse, + hmi_apis::FunctionID::BasicCommunication_ActivateApp>, + CommandData<sdl_rpc_plugin::commands::BasicCommunicationSystemResponse, + hmi_apis::FunctionID::BasicCommunication_SystemRequest>, + CommandData<sdl_rpc_plugin::commands::NaviAlertManeuverResponse, + hmi_apis::FunctionID::Navigation_AlertManeuver>, + CommandData<sdl_rpc_plugin::commands::AudioStartStreamResponse, + hmi_apis::FunctionID::Navigation_StartAudioStream>, + CommandData<sdl_rpc_plugin::commands::NaviGetWayPointsResponse, + hmi_apis::FunctionID::Navigation_GetWayPoints>, + CommandData<sdl_rpc_plugin::commands::NaviSendLocationResponse, + hmi_apis::FunctionID::Navigation_SendLocation>, + CommandData<sdl_rpc_plugin::commands::NaviShowConstantTBTResponse, + hmi_apis::FunctionID::Navigation_ShowConstantTBT>, + CommandData<sdl_rpc_plugin::commands::NaviStartStreamResponse, + hmi_apis::FunctionID::Navigation_StartStream>, + CommandData<sdl_rpc_plugin::commands::NaviSubscribeWayPointsResponse, + hmi_apis::FunctionID::Navigation_SubscribeWayPoints>, + CommandData<sdl_rpc_plugin::commands::NaviUnsubscribeWayPointsResponse, + hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints>, + CommandData<sdl_rpc_plugin::commands::NaviUpdateTurnListResponse, + hmi_apis::FunctionID::Navigation_UpdateTurnList>, + CommandData<sdl_rpc_plugin::commands::UISetAppIconResponse, + hmi_apis::FunctionID::UI_SetAppIcon>, + CommandData<sdl_rpc_plugin::commands::UiSetDisplayLayoutResponse, + hmi_apis::FunctionID::UI_SetDisplayLayout>, + CommandData<sdl_rpc_plugin::commands::UISetGlobalPropertiesResponse, + hmi_apis::FunctionID::UI_SetGlobalProperties>, + CommandData<sdl_rpc_plugin::commands::UISetGlobalPropertiesResponse, + hmi_apis::FunctionID::UI_SetGlobalProperties>, + CommandData<sdl_rpc_plugin::commands::VRPerformInteractionResponse, + hmi_apis::FunctionID::VR_PerformInteraction>, + CommandData<sdl_rpc_plugin::commands::UIScrollableMessageResponse, + hmi_apis::FunctionID::UI_ScrollableMessage>, + CommandData<sdl_rpc_plugin::commands::UISendHapticDataResponse, + hmi_apis::FunctionID::UI_SendHapticData> > ResponseCommandsList; + +typedef Types<sdl_rpc_plugin::commands::AudioStopStreamResponse, + sdl_rpc_plugin::commands::NaviStopStreamResponse, + sdl_rpc_plugin::commands::OnFindApplications, + sdl_rpc_plugin::commands::OnUpdateDeviceList, + sdl_rpc_plugin::commands::SDLPolicyUpdateResponse, + sdl_rpc_plugin::commands::UpdateAppListResponse, + sdl_rpc_plugin::commands::UpdateDeviceListResponse> + EmptyResponseCommandsList; + +TYPED_TEST_CASE(ResponseFromHMICommandsTest, ResponseCommandsList); + +TYPED_TEST_CASE(EmptyResponseFromHMICommandsTest, EmptyResponseCommandsList); + +MATCHER_P(EventIdIsEqualTo, function_id, "") { + return static_cast<hmi_apis::FunctionID::eType>(function_id) == arg.id(); +} + +TYPED_TEST(ResponseFromHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandData CommandData; + typedef typename CommandData::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + + EXPECT_CALL(this->event_dispatcher_, + raise_event(EventIdIsEqualTo(CommandData::kEventId))); + + command->Run(); +} + +TYPED_TEST(EmptyResponseFromHMICommandsTest, Run_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + + command->Run(); +} + +class OtherResponseFromHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P(VehicleTypeIsEqualTo, vehicle_type, "") { + return (*vehicle_type) == arg.asString(); +} + +MATCHER_P(CheckMsgType, msg_type, "") { + return msg_type == + static_cast<int32_t>( + (*arg)[am::strings::params][am::strings::message_type].asInt()); +} + +class NotificationFromHMITest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(NotificationFromHMITest, BasicMethodsOverloads_SUCCESS) { + std::shared_ptr<application_manager::commands::NotificationFromHMI> command( + CreateCommand<application_manager::commands::NotificationFromHMI>()); + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); + EXPECT_NO_THROW(command->Run()); +} + +TEST_F(NotificationFromHMITest, SendNotificationToMobile_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::message_type] = + static_cast<int32_t>(am::MessageType::kNotification); + + std::shared_ptr<application_manager::commands::NotificationFromHMI> command( + CreateCommand<application_manager::commands::NotificationFromHMI>()); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMsgType(am::MessageType::kNotification), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command->SendNotificationToMobile(command_msg); +} + +TEST_F(NotificationFromHMITest, CreateHMIRequest_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params] = 0; + std::shared_ptr<application_manager::commands::NotificationFromHMI> command( + CreateCommand<application_manager::commands::NotificationFromHMI>( + command_msg)); + + const uint32_t correlation_id = 1u; + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(correlation_id)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(CheckMsgType(am::MessageType::kRequest))) + .WillOnce(Return(false)); + + command->CreateHMIRequest(hmi_apis::FunctionID::INVALID_ENUM, + (*command_msg)[am::strings::msg_params]); +} + +} // namespace simple_response_from_hmi_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc new file mode 100644 index 0000000000..643e21d818 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/simple_response_to_hmi_test.cc @@ -0,0 +1,103 @@ +/* + * 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 "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command.h" +#include "application_manager/commands/commands_test.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_activate_app_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_list_of_permissions_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_status_update_response.h" +#include "sdl_rpc_plugin/commands/hmi/sdl_get_user_friendly_message_response.h" +#include "application_manager/commands/response_to_hmi.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace simple_response_to_hmi_test { + +using ::testing::_; +using ::testing::Types; +using ::testing::NotNull; +namespace commands = sdl_rpc_plugin::commands; +using application_manager::commands::MessageSharedPtr; + +template <class Command> +class ResponseToHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +typedef Types<commands::SDLActivateAppResponse, + commands::SDLGetListOfPermissionsResponse, + commands::SDLGetStatusUpdateResponse, + commands::SDLGetUserFriendlyMessageResponse> ResponseCommandsList; + +TYPED_TEST_CASE(ResponseToHMICommandsTest, ResponseCommandsList); + +TYPED_TEST(ResponseToHMICommandsTest, Run_SendMessageToHMI_SUCCESS) { + typedef typename TestFixture::CommandType CommandType; + + std::shared_ptr<CommandType> command = + this->template CreateCommand<CommandType>(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +class ResponseToHMITest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(ResponseToHMITest, BasicMethodsOverloads_SUCCESS) { + std::shared_ptr<application_manager::commands::ResponseToHMI> command( + CreateCommand<application_manager::commands::ResponseToHMI>()); + + // Current implementation always return `true` + EXPECT_TRUE(command->Init()); + EXPECT_TRUE(command->CleanUp()); +} + +TEST_F(ResponseToHMITest, Run_SUCCESS) { + std::shared_ptr<application_manager::commands::ResponseToHMI> command( + CreateCommand<application_manager::commands::ResponseToHMI>()); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(NotNull())); + + command->Run(); +} + +} // namespace simple_response_to_hmi_test +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc new file mode 100644 index 0000000000..bc9d262e6d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_response_test.cc @@ -0,0 +1,125 @@ +/* + * 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 <string> + +#include "gtest/gtest.h" +#include "hmi/tts_get_capabilities_response.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_capabilities_response { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::TTSGetCapabilitiesResponse; +using test::components::application_manager_test::MockHMICapabilities; + +using testing::_; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const std::string kText = "TEXT"; +} + +class TTSGetCapabilitiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(TTSGetCapabilitiesResponseTest, Run_BothExist_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; + (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = + kText; + + EXPECT_CALL(mock_hmi_capabilities_, + set_speech_capabilities(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, + set_prerecorded_speech(SmartObject(kText))); + + std::shared_ptr<TTSGetCapabilitiesResponse> command( + CreateCommand<TTSGetCapabilitiesResponse>(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlySpeech_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::speech_capabilities] = kText; + + EXPECT_CALL(mock_hmi_capabilities_, + set_speech_capabilities(SmartObject(kText))); + EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + + std::shared_ptr<TTSGetCapabilitiesResponse> command( + CreateCommand<TTSGetCapabilitiesResponse>(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_OnlyPrerecorded_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::prerecorded_speech_capabilities] = + kText; + + EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, + set_prerecorded_speech(SmartObject(kText))); + + std::shared_ptr<TTSGetCapabilitiesResponse> command( + CreateCommand<TTSGetCapabilitiesResponse>(msg)); + + command->Run(); +} + +TEST_F(TTSGetCapabilitiesResponseTest, Run_Nothing_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + EXPECT_CALL(mock_hmi_capabilities_, set_speech_capabilities(_)).Times(0); + EXPECT_CALL(mock_hmi_capabilities_, set_prerecorded_speech(_)).Times(0); + + std::shared_ptr<TTSGetCapabilitiesResponse> command( + CreateCommand<TTSGetCapabilitiesResponse>(msg)); + + command->Run(); +} + +} // namespace tts_get_capabilities_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc new file mode 100644 index 0000000000..0d22500f48 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_response_test.cc @@ -0,0 +1,102 @@ +/* + * 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 "hmi/tts_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_language_response { + +using sdl_rpc_plugin::commands::TTSGetLanguageResponse; +using test::components::application_manager_test::MockHMICapabilities; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +namespace { +const Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class TTSGetLanguageResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(TTSGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + std::shared_ptr<TTSGetLanguageResponse> command( + CreateCommand<TTSGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_tts_language(kLanguage)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +TEST_F(TTSGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<TTSGetLanguageResponse> command( + CreateCommand<TTSGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_tts_language(Common_Language::INVALID_ENUM)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace tts_get_language_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..417b8e1898 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_response_test.cc @@ -0,0 +1,128 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/tts_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_supported_languages_response { + +using ::testing::_; +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class TTSGetSupportedLanguageResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + SmartObject capabilities_; +}; + +TEST_F(TTSGetSupportedLanguageResponseTest, RUN_SUCCESS) { + smart_objects::SmartObject supported_languages("EN_US"); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + ResponseFromHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_tts_supported_languages(( + *command_msg)[strings::msg_params][hmi_response::languages])); + + command->Run(); +} +TEST_F(TTSGetSupportedLanguageResponseTest, RUN_UNSUCCESS) { + smart_objects::SmartObject supported_languages("EN_US"); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + ResponseFromHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_tts_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace tts_get_supported_languages_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc new file mode 100644 index 0000000000..2fae8a6819 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_response_test.cc @@ -0,0 +1,97 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/commands/response_from_hmi.h" +#include "hmi/tts_is_ready_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_is_ready_response { + +using ::testing::_; +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::TTSIsReadyResponse; +using am::commands::CommandImpl; +using test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const bool kIsAvailable = true; +const bool kIsNotAvailable = false; +} // namespace + +class TTSIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MockHMICapabilities mock_hmi_capabilities_; + SmartObject capabilities_; +}; + +TEST_F(TTSIsReadyResponseTest, RUN_SUCCESS) { + ResponseFromHMIPtr command(CreateCommand<TTSIsReadyResponse>()); + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace tts_is_ready_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc new file mode 100644 index 0000000000..31e4860d4a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_response_test.cc @@ -0,0 +1,311 @@ +/* + * 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 copyright holders nor the names of their 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 <stdint.h> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/ui_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_capabilities_response { + +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using application_manager::commands::ResponseFromHMI; +using sdl_rpc_plugin::commands::UIGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<ResponseFromHMI> ResponseFromHMIPtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class UIGetCapabilitiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(UIGetCapabilitiesResponseTest, RUN_SetDisplay_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] + [hmi_response::display_type] = "GEN2_8_DMA"; + (*command_msg)[strings::msg_params][hmi_response::display_capabilities] + [hmi_response::display_name] = "GENERIC_DISPLAY"; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject display_capabilities_so = + (*command_msg)[strings::msg_params][hmi_response::display_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_display_capabilities(display_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetSoftButton_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][hmi_response::soft_button_capabilities] + [hmi_response::image_supported] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject soft_button_capabilities_so = (*command_msg) + [strings::msg_params][hmi_response::soft_button_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_soft_button_capabilities(soft_button_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetHmiZone_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities][0] = + "FRONT"; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject hmi_zone_capabilities_so = + (*command_msg)[strings::msg_params][hmi_response::hmi_zone_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_hmi_zone_capabilities(hmi_zone_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetAudioPassThru_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::audio_pass_thru_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject audio_pass_thru_capabilities_so = (*command_msg) + [strings::msg_params][strings::audio_pass_thru_capabilities]; + EXPECT_CALL( + mock_hmi_capabilities_, + set_audio_pass_thru_capabilities(audio_pass_thru_capabilities_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetNavigation_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::navigation] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_navigation_supported( + hmi_capabilities_so[strings::navigation].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetPhoneCall_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::phone_call] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_phone_call_supported( + hmi_capabilities_so[strings::phone_call].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreaming_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + (*command_msg)[strings::msg_params][strings::hmi_capabilities] + [strings::video_streaming] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject hmi_capabilities_so = + (*command_msg)[strings::msg_params][strings::hmi_capabilities]; + EXPECT_CALL(mock_hmi_capabilities_, + set_video_streaming_supported( + hmi_capabilities_so[strings::video_streaming].asBool())); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetNavigationCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]["sendLocationEnabled"] = true; + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]["getWayPointsEnabled"] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject navigation_capability_so = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::navigation_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_navigation_capability(navigation_capability_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetPhonenCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::phone_capability]["dialNumberEnabled"] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject phone_capability_so = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::phone_capability]; + + EXPECT_CALL(mock_hmi_capabilities_, + set_phone_capability(phone_capability_so)); + + command->Run(); +} + +TEST_F(UIGetCapabilitiesResponseTest, SetVideoStreamingCapability_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::system_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::video_streaming_capability] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + smart_objects::SmartObject& video_streaming_capability = + (*command_msg)[strings::msg_params][strings::system_capabilities] + [strings::video_streaming_capability]; + + video_streaming_capability[strings::preferred_resolution] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + video_streaming_capability[strings::preferred_resolution] + [strings::resolution_width] = 800; + video_streaming_capability[strings::preferred_resolution] + [strings::resolution_height] = 350; + + video_streaming_capability[strings::max_bitrate] = 10000; + + video_streaming_capability[strings::supported_formats] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + video_streaming_capability[strings::supported_formats][0] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + + video_streaming_capability[strings::supported_formats][0][strings::protocol] = + hmi_apis::Common_VideoStreamingProtocol::RAW; + + video_streaming_capability[strings::supported_formats][0][strings::codec] = + hmi_apis::Common_VideoStreamingCodec::H264; + + video_streaming_capability[strings::haptic_spatial_data_supported] = true; + + ResponseFromHMIPtr command( + CreateCommand<UIGetCapabilitiesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_video_streaming_capability(video_streaming_capability)); + + command->Run(); +} + +} // namespace ui_get_capabilities_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc new file mode 100644 index 0000000000..de69c5de5c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_response_test.cc @@ -0,0 +1,106 @@ +/* + * 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 "hmi/ui_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_language_response { + +using sdl_rpc_plugin::commands::UIGetLanguageResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class UIGetLanguageResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(UIGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + std::shared_ptr<UIGetLanguageResponse> command( + CreateCommand<UIGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_ui_language(kLanguage)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +TEST_F(UIGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<UIGetLanguageResponse> command( + CreateCommand<UIGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_ui_language(Common_Language::INVALID_ENUM)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace ui_get_language_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..5626e2b0ee --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_response_test.cc @@ -0,0 +1,122 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "hmi/ui_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_supported_languages_response { + +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::UIGetSupportedLanguagesResponse; + +typedef std::shared_ptr<UIGetSupportedLanguagesResponse> + UIGetSupportedLanguagesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const std::string kLanguage = "EN_US"; +const smart_objects::SmartObject supported_languages(kLanguage); +} // namespace + +class UIGetSupportedLanguagesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + SmartObject capabilities_; +}; + +TEST_F(UIGetSupportedLanguagesResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand<UIGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_ui_supported_languages((supported_languages))); + + command->Run(); +} +TEST_F(UIGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + UIGetSupportedLanguagesResponsePtr command( + CreateCommand<UIGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_ui_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace ui_get_supported_languages_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc new file mode 100644 index 0000000000..fe0d8a8470 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_request_test.cc @@ -0,0 +1,199 @@ +/* + * 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 "hmi/ui_is_ready_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_is_ready_request { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::UIIsReadyRequest; +using am::event_engine::Event; + +typedef std::shared_ptr<UIIsReadyRequest> UIIsReadyRequestPtr; + +class UIIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + UIIsReadyRequestTest() : command_(CreateCommand<UIIsReadyRequest>()) {} + + void SetUpExpectations(bool is_ui_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + EXPECT_CALL(mock_hmi_capabilities_, + set_is_ui_cooperating(is_ui_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(state)); + + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(); + } + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr get_language(CreateMessage()); + (*get_language)[am::strings::params][am::strings::message_type] = + static_cast<int>(am::MessageType::kRequest); + (*get_language)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetLanguage, _)) + .WillOnce(Return(get_language)); + + smart_objects::SmartObjectSPtr get_all_language(CreateMessage()); + (*get_all_language)[am::strings::params][am::strings::message_type] = + static_cast<int>(am::MessageType::kRequest); + (*get_all_language)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetSupportedLanguages, _)) + .WillOnce(Return(get_all_language)); + + smart_objects::SmartObjectSPtr get_capabilities(CreateMessage()); + (*get_capabilities)[am::strings::params][am::strings::message_type] = + static_cast<int>(am::MessageType::kRequest); + (*get_capabilities)[am::strings::msg_params] = + smart_objects::SmartObject(smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::UI_GetCapabilities, _)) + .WillOnce(Return(get_capabilities)); + + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*get_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_all_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(get_capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_ui_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_ui_cooperating_available; + } + event.set_smart_object(*msg); + } + + UIIsReadyRequestPtr command_; + policy_test::MockPolicyHandlerInterface mock_policy_handler_interface_; +}; + +TEST_F(UIIsReadyRequestTest, + OnEvent_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_ui_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, + OnEvent_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_ui_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, OnEvent_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_ui_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::UI_IsReady); + PrepareEvent(is_message_contain_param, event, is_ui_cooperating_available); + SetUpExpectations(is_ui_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(UIIsReadyRequestTest, OnTimeout_SUCCESS) { + ExpectSendMessagesToHMI(); + command_->onTimeOut(); +} + +} // namespace ui_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc new file mode 100644 index 0000000000..cccdbdc44d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_is_ready_response_test.cc @@ -0,0 +1,90 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "hmi/ui_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_is_ready_response { + +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::UIIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr<UIIsReadyResponse> UIIsReadyResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const bool kIsAvailable = true; +const bool kIsNotAvailable = false; +} // namespace + +class UIIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MockHMICapabilities mock_hmi_capabilities_; + SmartObject capabilities_; +}; + +TEST_F(UIIsReadyResponseTest, RUN_SUCCESS) { + UIIsReadyResponsePtr command(CreateCommand<UIIsReadyResponse>()); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace ui_is_ready_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc new file mode 100644 index 0000000000..c566702998 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_device_list_request_test.cc @@ -0,0 +1,171 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "interfaces/HMI_API.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/application_manager.h" +#include "application_manager/application_manager_impl.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/request_controller_settings.h" +#include "application_manager/mock_application_manager_settings.h" +#include "hmi/update_device_list_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_device_list_request { + +using testing::_; +using testing::ReturnRef; +using testing::Return; +using test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::UpdateDeviceListRequest; +using am::commands::CommandImpl; + +typedef std::shared_ptr<UpdateDeviceListRequest> UpdateDeviceListRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class UpdateDeviceListRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + return command_msg; + } + + MockApplicationManagerSettings settings_; + MockEventDispatcher mock_event_dispatcher_; +}; + +TEST_F(UpdateDeviceListRequestTest, RUN_LaunchHMIReturnsFalse) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command( + CreateCommand<UpdateDeviceListRequest>(command_msg)); + + EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); + + EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(false)); + + EXPECT_CALL(app_mngr_, IsHMICooperating()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +TEST_F(UpdateDeviceListRequestTest, RUN_HMICooperatingReturnsTrue_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command( + CreateCommand<UpdateDeviceListRequest>(command_msg)); + + EXPECT_CALL(app_mngr_, get_settings()).WillOnce(ReturnRef(settings_)); + + EXPECT_CALL(settings_, launch_hmi()).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, IsHMICooperating()).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +TEST_F(UpdateDeviceListRequestTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command(CreateCommand<UpdateDeviceListRequest>()); + + command->on_event(event); +} + +TEST_F(UpdateDeviceListRequestTest, OnEvent_SUCCESS) { + Event event(Event::EventID::BasicCommunication_OnReady); + + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher_)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_, _)); + EXPECT_CALL(mock_event_dispatcher_, remove_observer(_)); + + UpdateDeviceListRequestPtr command(CreateCommand<UpdateDeviceListRequest>()); + + command->on_event(event); +} + +} // namespace update_device_list_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc new file mode 100644 index 0000000000..af3b9bebf6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_request_test.cc @@ -0,0 +1,86 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "hmi/update_sdl_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_sdl_request { + +using ::testing::ReturnRef; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::UpdateSDLRequest; + +typedef std::shared_ptr<UpdateSDLRequest> UpdateSDLRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 1u; +const std::string kStrNumber = "123"; +} // namespace + +class UpdateSDLRequestTest : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(UpdateSDLRequestTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][strings::correlation_id] = kCorrelationId; + + UpdateSDLRequestPtr command(CreateCommand<UpdateSDLRequest>(command_msg)); + + EXPECT_CALL(mock_policy_handler_, PTExchangeAtUserRequest(kCorrelationId)); + + command->Run(); + + EXPECT_EQ(kCorrelationId, + (*command_msg)[strings::params][strings::correlation_id].asUInt()); +} + +} // namespace update_sdl_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc new file mode 100644 index 0000000000..93c49724ce --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/update_sdl_response_test.cc @@ -0,0 +1,84 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/application.h" +#include "hmi/update_sdl_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace update_sdl_response { + +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using sdl_rpc_plugin::commands::UpdateSDLResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<UpdateSDLResponse> UpdateSDLResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class UpdateSDLResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +}; + +TEST_F(UpdateSDLResponseTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + + UpdateSDLResponsePtr command(CreateCommand<UpdateSDLResponse>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + + command->Run(); + + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_type].asInt(), + CommandImpl::hmi_protocol_type_); + EXPECT_EQ((*command_msg)[strings::params][strings::protocol_version].asInt(), + CommandImpl::protocol_version_); +} + +} // namespace update_sdl_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc new file mode 100644 index 0000000000..15d38d4ef3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_response_test.cc @@ -0,0 +1,106 @@ +/* + * 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 <stdint.h> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "hmi/vr_get_capabilities_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_capabilities_response { + +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = am::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRGetCapabilitiesResponse; +using am::commands::CommandImpl; + +typedef std::shared_ptr<VRGetCapabilitiesResponse> VRGetCapabilitiesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class VRGetCapabilitiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = "123"; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + return command_msg; + } + + SmartObject capabilities_; +}; + +TEST_F(VRGetCapabilitiesResponseTest, RUN_SUCCESSS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + (*command_msg)[strings::msg_params][strings::vr_capabilities] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + (*command_msg)[strings::msg_params][strings::vr_capabilities][0] = + "vrCapabilities"; + + VRGetCapabilitiesResponsePtr command( + CreateCommand<VRGetCapabilitiesResponse>(command_msg)); + + smart_objects::SmartObject vr_capabilities_so = + (*command_msg)[strings::msg_params][strings::vr_capabilities]; + + EXPECT_CALL(mock_hmi_capabilities_, set_vr_capabilities(vr_capabilities_so)); + + command->Run(); +} + +} // namespace vr_get_capabilities_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc new file mode 100644 index 0000000000..05ed186963 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_response_test.cc @@ -0,0 +1,106 @@ +/* + * 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 "hmi/vr_get_language_response.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_event_dispatcher.h" +#include "application_manager/mock_application_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_language_response { + +using sdl_rpc_plugin::commands::VRGetLanguageResponse; +using test::components::event_engine_test::MockEventDispatcher; +using testing::_; +using testing::ReturnRef; +using ::testing::NiceMock; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +using namespace hmi_apis; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::Common_Language::eType kLanguage = Common_Language::EN_GB; +} // namespace + +class VRGetLanguageResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(VRGetLanguageResponseTest, Run_LanguageSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::msg_params][hmi_response::language] = kLanguage; + + std::shared_ptr<VRGetLanguageResponse> command( + CreateCommand<VRGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, set_active_vr_language(kLanguage)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +TEST_F(VRGetLanguageResponseTest, Run_LanguageNotSet_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<VRGetLanguageResponse> command( + CreateCommand<VRGetLanguageResponse>(msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_active_vr_language(Common_Language::INVALID_ENUM)); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace vr_get_language_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc new file mode 100644 index 0000000000..56b11ad440 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_response_test.cc @@ -0,0 +1,122 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_application_manager.h" +#include "hmi/vr_get_supported_languages_response.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_supported_languages_response { + +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRGetSupportedLanguagesResponse; + +typedef std::shared_ptr<VRGetSupportedLanguagesResponse> + VRGetSupportedLanguagesResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStringNum = "123"; +const std::string kLanguage = "EN_US"; +const smart_objects::SmartObject supported_languages(kLanguage); +} // namespace + +class VRGetSupportedLanguagesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + SmartObject capabilities_; +}; + +TEST_F(VRGetSupportedLanguagesResponseTest, RUN_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + (*command_msg)[strings::msg_params][hmi_response::languages] = + supported_languages; + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand<VRGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_vr_supported_languages((supported_languages))); + + command->Run(); +} +TEST_F(VRGetSupportedLanguagesResponseTest, RUN_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStringNum; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::WRONG_LANGUAGE; + (*command_msg)[strings::msg_params][hmi_response::capabilities] = + (capabilities_); + + VRGetSupportedLanguagesResponsePtr command( + CreateCommand<VRGetSupportedLanguagesResponse>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + set_vr_supported_languages(supported_languages)).Times(0); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + am::hmi_response::languages)); +} + +} // namespace vr_get_supported_languages_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc new file mode 100644 index 0000000000..5aa00e0264 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_request_test.cc @@ -0,0 +1,182 @@ +/* + * 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 "hmi/vr_is_ready_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::VRIsReadyRequest; +using am::event_engine::Event; + +typedef std::shared_ptr<VRIsReadyRequest> VRIsReadyRequestPtr; + +class VRIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + VRIsReadyRequestTest() : command_(CreateCommand<VRIsReadyRequest>()) {} + + void SetUpExpectations(bool is_vr_cooperating_available, + bool is_send_message_to_hmi, + bool is_message_contain_param, + am::HmiInterfaces::InterfaceState state) { + const bool is_send_message_by_timeout = false; + if (is_send_message_to_hmi) { + ExpectSendMessagesToHMI(is_send_message_by_timeout); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_vr_cooperating(is_vr_cooperating_available)); + + if (is_message_contain_param) { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR, state)); + } else { + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillOnce(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL(mock_hmi_interfaces_, SetInterfaceState(_, _)).Times(0); + } + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI(bool is_send_message_by_timeout) { + smart_objects::SmartObjectSPtr language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetLanguage, _)) + .WillOnce(Return(language)); + EXPECT_CALL(mock_hmi_capabilities_, set_handle_response_for(*language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(language)); + + smart_objects::SmartObjectSPtr support_language( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(support_language)); + + smart_objects::SmartObjectSPtr capabilities( + new smart_objects::SmartObject(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::VR_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities)); + } + + void PrepareEvent(bool is_message_contain_param, + Event& event, + bool is_vr_cooperating_available = false) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (is_message_contain_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_vr_cooperating_available; + } + event.set_smart_object(*msg); + } + + VRIsReadyRequestPtr command_; +}; + +TEST_F(VRIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = false; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_RESPONSE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { + const bool is_vr_cooperating_available = false; + const bool is_send_message_to_hmi = false; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_NOT_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { + const bool is_vr_cooperating_available = true; + const bool is_send_message_to_hmi = true; + const bool is_message_contain_param = true; + Event event(hmi_apis::FunctionID::VR_IsReady); + PrepareEvent(is_message_contain_param, event, is_vr_cooperating_available); + SetUpExpectations(is_vr_cooperating_available, + is_send_message_to_hmi, + is_message_contain_param, + am::HmiInterfaces::STATE_AVAILABLE); + command_->on_event(event); +} + +TEST_F(VRIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { + const bool is_send_message_by_timeout = true; + ExpectSendMessagesToHMI(is_send_message_by_timeout); + command_->onTimeOut(); +} + +} // namespace vr_is_ready_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc new file mode 100644 index 0000000000..0e56f5b483 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_is_ready_response_test.cc @@ -0,0 +1,77 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "hmi/vr_is_ready_response.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_is_ready_response { + +using ::testing::Return; +using ::testing::NiceMock; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +using sdl_rpc_plugin::commands::VRIsReadyResponse; +using test::components::event_engine_test::MockEventDispatcher; + +typedef std::shared_ptr<VRIsReadyResponse> VRIsReadyResponsePtr; + +class VRIsReadyResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +}; + +TEST_F(VRIsReadyResponseTest, RUN_SUCCESS) { + VRIsReadyResponsePtr command(CreateCommand<VRIsReadyResponse>()); + + MockEventDispatcher mock_event_dispatcher; + EXPECT_CALL(app_mngr_, event_dispatcher()) + .WillOnce(ReturnRef(mock_event_dispatcher)); + EXPECT_CALL(mock_event_dispatcher, raise_event(_)); + + command->Run(); +} + +} // namespace vr_is_ready_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc new file mode 100644 index 0000000000..dfcceea889 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_command_request_test.cc @@ -0,0 +1,1154 @@ +/* + * 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 <stdint.h> +#include <memory> +#include <string> +#include <set> + +#include "mobile/add_command_request.h" + +#include "gtest/gtest.h" + +#include "utils/helpers.h" + +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_help_prompt_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace add_command_request { + +namespace am = application_manager; +namespace am_test = application_manager_test; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using ::testing::_; +using ::testing::Return; +using ::testing::InSequence; +using sdl_rpc_plugin::commands::AddCommandRequest; +using NsSmartDeviceLink::NsSmartObjects::SmartObjectSPtr; +using ::test::components::application_manager_test::MockApplication; +using am::event_engine::EventObserver; +using namespace smart_objects; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace mobile_result = mobile_apis::Result; +namespace hmi_response = ::application_manager::hmi_response; +namespace hmi_request = ::application_manager::hmi_request; +using namespace strings; + +namespace { +const hmi_apis::FunctionID::eType kInvalidFunctionId = + hmi_apis::FunctionID::INVALID_ENUM; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const std::string kMenuName = "LG"; +const uint32_t kFirstParentId = 10u; +const uint32_t kSecondParentId = 1u; +const std::string kErroredVRCommand = "l\namer"; +const std::string kFirstVrCommand = "lamer"; +const std::string kSecondVrCommand = "hacker"; +const uint32_t kFirstCommandId = 10u; +const uint32_t kSecondCommandId = 11u; +const int32_t kType = 34; +const int32_t kGrammarId = 12; +const int32_t kPosition = 10; +} // namespace + +class AddCommandRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + AddCommandRequestTest() + : msg_(CreateMessage()) + , default_app_name_("test_default_app_name_") + , lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , mock_help_prompt_manager_( + std::make_shared<am_test::MockHelpPromptManager>()) + , mock_app_(CreateMockApp()) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + InitGetters(); + InitBasicMessage(); + } + + protected: + void InitBasicMessage() { + (*msg_)[params][connection_key] = kConnectionKey; + (*msg_)[msg_params][app_id] = kAppId; + (*msg_)[msg_params][app_name] = default_app_name_; + } + + void InitGetters() { + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app_, FindCommand(kCmdId)) + .WillByDefault(Return(so_ptr_.get())); + } + + void CreateBasicParamsUIRequest() { + SmartObject menu_params = SmartObject(SmartType_Map); + menu_params[position] = kPosition; + menu_params[menu_name] = kMenuName; + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[cmd_id] = kCmdId; + msg_params[strings::menu_params] = menu_params; + msg_params[cmd_icon] = 1; + msg_params[cmd_icon][value] = "10"; + msg_params[info] = "UI info"; + } + + void CreateBasicParamsVRRequest() { + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[cmd_id] = kCmdId; + msg_params[vr_commands] = SmartObject(SmartType_Array); + msg_params[vr_commands][0] = kFirstVrCommand; + msg_params[type] = kPosition; + msg_params[grammar_id] = kGrammarId; + msg_params[info] = "VR info"; + } + + const am::CommandsMap CreateCommandsMap(SmartObject& first_command, + SmartObject& second_command) { + second_command[menu_params] = SmartObject(SmartType_Map); + second_command[menu_params][hmi_request::parent_id] = kFirstParentId; + second_command[menu_params][menu_name] = kMenuName; + second_command[vr_commands] = SmartObject(SmartType_Array); + second_command[vr_commands][0] = kSecondVrCommand; + am::CommandsMap commands_map; + commands_map.insert(std::make_pair(kFirstCommandId, &first_command)); + commands_map.insert(std::make_pair(kSecondCommandId, &second_command)); + return commands_map; + } + + void CheckOnTimeOutCommandDeletion( + const hmi_apis::FunctionID::eType incoming_cmd, + const hmi_apis::FunctionID::eType cmd_to_delete) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)) + .WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + so_ptr_ = std::make_shared<SmartObject>(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + Event event(incoming_cmd); + event.set_smart_object(*msg_); + request_ptr->on_event(event); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(cmd_to_delete))) + + .WillOnce(Return(true)); + SmartObjectSPtr response = std::make_shared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(response, + am::commands::Command::CommandSource::SOURCE_SDL)); + std::shared_ptr<CommandRequestImpl> base_class_request = + static_cast<std::shared_ptr<CommandRequestImpl> >(request_ptr); + base_class_request->onTimeOut(); + } + + MessageSharedPtr msg_; + SmartObjectSPtr so_ptr_; + const utils::custom_string::CustomString default_app_name_; + std::shared_ptr<sync_primitives::Lock> lock_ptr_; + std::shared_ptr<am_test::MockHelpPromptManager> mock_help_prompt_manager_; + MockAppPtr mock_app_; +}; + +TEST_F(AddCommandRequestTest, Run_AppNotExisted_EXPECT_AppNotRegistered) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_ImageVerificationFailed_EXPECT_INVALID_DATA) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_ImageVerificationFailed_EXPECT_WARNINGS) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::WARNINGS)); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_MenuNameHasSyntaxError_EXPECT_INVALID_DATA) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; + const std::string errored_menu_name = "L\nG"; + msg_params[menu_params][menu_name] = errored_menu_name; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + SmartObject parent = SmartObject(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kFirstParentId)) + .WillOnce(Return(&parent)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_VRCommandsHaveSyntaxError_EXPECT_INVALID_DATA) { + CreateBasicParamsVRRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[vr_commands][0] = kErroredVRCommand; + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_CMDIconHasError_EXPECT_INVALID_DATA) { + MessageSharedPtr msg = CreateMessage(); + SmartObject& msg_params = (*msg)[strings::msg_params]; + (*msg)[params][connection_key] = kConnectionKey; + msg_params[cmd_id] = kCmdId; + msg_params[cmd_icon] = 1; + const std::string errored_cmd_icon_value = "1\n0"; + msg_params[cmd_icon][value] = errored_cmd_icon_value; + msg_params[vr_commands][0] = kFirstVrCommand; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_CommandIDAlreadyExists_EXPECT_INVALID_ID) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + so_ptr_ = std::make_shared<SmartObject>(SmartType_Map); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CommandNameAlreadyExists_EXPECT_DUPLICATE_NAME) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kFirstParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsgParentIDsAreDifferentSubmenuNotExisted_EXPECT_INVALID_ID) { + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_ID), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsgVrSynonymsAreTheSame_EXPECT_DUPLICATE_NAME) { + CreateBasicParamsVRRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + msg_params[vr_commands][0] = kSecondVrCommand; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + so_ptr_ = std::make_shared<SmartObject>(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::DUPLICATE_NAME), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, Run_MsgDataEmpty_EXPECT_INVALID_DATA) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[params][connection_key] = kConnectionKey; + SmartObject& msg_params = (*msg)[strings::msg_params]; + msg_params[app_id] = kAppId; + msg_params[cmd_id] = kCmdId; + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, + Run_CmdAndMsg_UI_and_Vr_AreCorrect_EXPECT_VR_AND_UI_SENT) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + SmartObject& image = msg_params[cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + so_ptr_ = std::make_shared<SmartObject>(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, GetRunMethods_SUCCESS) { + CreateBasicParamsUIRequest(); + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); +} + +TEST_F(AddCommandRequestTest, OnEvent_UI_SUCCESS) { + CreateBasicParamsUIRequest(); + (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly( + Return(DataAccessor<am::CommandsMap>(commands_map, lock_ptr_))); + + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandAdded(kCmdId, (*msg_)[msg_params], false)); + + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnEvent_VR_SUCCESS) { + CreateBasicParamsVRRequest(); + MessageSharedPtr msg = CreateMessage(SmartType_Map); + (*msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + (*msg)[msg_params][cmd_id] = kCmdId; + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg); + EXPECT_CALL(*mock_app_, AddCommand(kCmdId, (*msg_)[msg_params])); + + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly( + Return(DataAccessor<am::CommandsMap>(commands_map, lock_ptr_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandAdded(kCmdId, (*msg_)[msg_params], false)); + + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_VR_DeleteCommand) { + CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::VR_AddCommand, + hmi_apis::FunctionID::VR_DeleteCommand); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_EXPECT_UI_DeleteCommand) { + CheckOnTimeOutCommandDeletion(hmi_apis::FunctionID::UI_AddCommand, + hmi_apis::FunctionID::UI_DeleteCommand); +} + +TEST_F(AddCommandRequestTest, OnEvent_BothSend_SUCCESS) { + MessageSharedPtr command_msg = CreateMessage(SmartType_Map); + (*command_msg)[params][connection_key] = kConnectionKey; + MessageSharedPtr event_msg = CreateMessage(SmartType_Map); + (*event_msg)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + (*event_msg)[msg_params][cmd_id] = kCmdId; + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*event_msg); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); + + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(command_msg); + request_ptr->Run(); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, OnEvent_AppNotExisted_UNSUCCESS) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + Event event(hmi_apis::FunctionID::UI_AddCommand); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_HmiResponseCodeIsRejected_ExpectUICommandRemoved) { + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::REJECTED; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::REJECTED), _)); + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_HmiResponseCodeIsWarnings_ExpectCommandUpdated) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::WARNINGS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::WARNINGS), _)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, OnVrCommandAdded(kCmdId, _, false)); + + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_HmiResponseCodeIsGenericError_VR_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); + (*msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_vr)[msg_params][cmd_id] = kCmdId; + event_vr.set_smart_object(*msg_vr); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_VR_HmiResponseCodeIsGenericError_UI_HmiResponseCodeIsUnsupportedResourse_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::GENERIC_ERROR; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_vr); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); + (*msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_ui)[msg_params][cmd_id] = kCmdId; + event_ui.set_smart_object(*msg_ui); + request_ptr->on_event(event_ui); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_UI_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_VR_HmiResponseCodeIsUnsupportedResourse_VR_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_UI_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::UI_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F( + AddCommandRequestTest, + OnEvent_VR_HmiResponseCodeIsUnsupportedResource_NotAvailableInterfaceState_ExpectCommandRemoved) { + CreateBasicParamsVRRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceState::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg_); + request_ptr->on_event(event); +} + +TEST_F(AddCommandRequestTest, + OnEvent_UI_EventWithNotSuccesResponseCode_ExpectVRCommandDelete) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + MessageSharedPtr msg_ui = CreateMessage(SmartType_Map); + (*msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*msg_ui)[msg_params][cmd_id] = kCmdId; + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_ui); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + event_vr.set_smart_object(*msg_); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); + request_ptr->on_event(event_ui); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, + OnEvent_UI_VR_Events_VRErrorPresent_ExpectRemoveCommand) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& params = (*msg_)[strings::params]; + params[hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + SmartObject& image = (*msg_)[msg_params][cmd_icon]; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + am::CommandsMap commands_map; + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), _)); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + + Event event_ui(hmi_apis::FunctionID::UI_AddCommand); + event_ui.set_smart_object(*msg_); + request_ptr->on_event(event_ui); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(2); + Event event_vr(hmi_apis::FunctionID::VR_AddCommand); + MessageSharedPtr msg_vr = CreateMessage(SmartType_Map); + (*msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*msg_vr)[msg_params][cmd_id] = kCmdId; + event_vr.set_smart_object(*msg_vr); + request_ptr->on_event(event_vr); +} + +TEST_F(AddCommandRequestTest, + OnTimeOut_AppNotExisted_NoAppRemoveCommandCalled) { + CreateBasicParamsUIRequest(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)).Times(0); + SmartObjectSPtr response = std::make_shared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + response, am::commands::Command::CommandSource::SOURCE_SDL)); + std::shared_ptr<CommandRequestImpl> base_class_request = + static_cast<std::shared_ptr<CommandRequestImpl> >( + CreateCommand<AddCommandRequest>(msg_)); + base_class_request->onTimeOut(); +} + +TEST_F(AddCommandRequestTest, OnTimeOut_AppRemoveCommandCalled) { + CreateBasicParamsVRRequest(); + CreateBasicParamsUIRequest(); + SmartObject& msg_params = (*msg_)[strings::msg_params]; + SmartObject& image = msg_params[cmd_icon]; + msg_params[menu_params][hmi_request::parent_id] = kSecondParentId; + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, FindCommand(kCmdId)).WillOnce(Return(so_ptr_.get())); + SmartObject first_command = SmartObject(SmartType_Map); + SmartObject second_command = SmartObject(SmartType_Map); + const am::CommandsMap commands_map = + CreateCommandsMap(first_command, second_command); + EXPECT_CALL(*mock_app_, commands_map()) + .WillRepeatedly(Return(DataAccessor<application_manager::CommandsMap>( + commands_map, lock_ptr_))); + so_ptr_ = std::make_shared<SmartObject>(SmartType_Map); + EXPECT_CALL(*mock_app_, FindSubMenu(kSecondParentId)) + .WillOnce(Return(so_ptr_.get())); + { + InSequence dummy; + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_AddCommand))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_AddCommand))) + .WillOnce(Return(true)); + } + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + std::shared_ptr<AddCommandRequest> request_ptr = + CreateCommand<AddCommandRequest>(msg_); + request_ptr->Run(); + EXPECT_CALL(*mock_app_, RemoveCommand(kCmdId)); + SmartObjectSPtr response = std::make_shared<SmartObject>(SmartType_Map); + (*response)[strings::msg_params][strings::info] = "info"; + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(response)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + response, am::commands::Command::CommandSource::SOURCE_SDL)); + std::shared_ptr<CommandRequestImpl> base_class_request = + static_cast<std::shared_ptr<CommandRequestImpl> >(request_ptr); + base_class_request->onTimeOut(); +} + +} // namespace add_command_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc new file mode 100644 index 0000000000..ecaa436529 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/add_sub_menu_request_test.cc @@ -0,0 +1,158 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "mobile/add_sub_menu_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace add_sub_menu_request { + +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::AddSubMenuRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using ::testing::_; +using ::testing::Return; + +typedef std::shared_ptr<AddSubMenuRequest> AddSubMenuPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kAppId = 1u; +} // namespace + +class AddSubMenuRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + AddSubMenuRequestTest() : mock_app(CreateMockApp()) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + } + + MockAppPtr mock_app; + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + return msg; + } +}; + +TEST_F(AddSubMenuRequestTest, Run_ImageVerificationFailed_EXPECT_INVALID_DATA) { + const uint32_t menu_id = 10u; + MessageSharedPtr msg = CreateMsgParams(); + SmartObject& msg_params = (*msg)[am::strings::msg_params]; + + msg_params[am::strings::menu_icon] = 1; + msg_params[am::strings::menu_icon][am::strings::value] = "10"; + msg_params[am::strings::menu_id] = menu_id; + msg_params[am::strings::menu_name] = "test"; + SmartObject& image = msg_params[am::strings::menu_icon]; + + EXPECT_CALL(mock_message_helper_, VerifyImage(image, _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + std::shared_ptr<AddSubMenuRequest> request_ptr = + CreateCommand<AddSubMenuRequest>(msg); + + request_ptr->Run(); +} + +TEST_F(AddSubMenuRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + const uint32_t menu_id = 10u; + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::menu_id] = menu_id; + + std::shared_ptr<AddSubMenuRequest> command = + CreateCommand<AddSubMenuRequest>(msg); + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + EXPECT_CALL(*mock_app, AddSubMenu(menu_id, _)); + EXPECT_CALL(*mock_app, UpdateHash()); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_AddSubMenu); + event.set_smart_object(*ev_msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + command->Init(); + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace add_sub_menu_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc new file mode 100644 index 0000000000..7d2dd0b2c2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_maneuver_request_test.cc @@ -0,0 +1,256 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "mobile/alert_maneuver_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace alert_maneuver_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::AlertManeuverRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +typedef std::shared_ptr<AlertManeuverRequest> CommandPtr; + +class AlertManeuverRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = hmi_response; + (*response)[am::strings::msg_params][am::strings::info] = "test"; + + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*response); + + std::shared_ptr<AlertManeuverRequest> command = + CreateCommand<AlertManeuverRequest>(response); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->on_event(event); + + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + success); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_response)); + } +}; + +TEST_F(AlertManeuverRequestTest, Run_RequiredFieldsDoesNotExist_UNSUCCESS) { + CommandPtr command(CreateCommand<AlertManeuverRequest>()); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::INVALID_DATA, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::tts_chunks] = 0; + + CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; + + CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + const mobile_apis::Result::eType kProcessingResult = + mobile_apis::Result::ABORTED; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) + .WillOnce(Return(kProcessingResult)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(kProcessingResult, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, Run_IsWhiteSpaceExist_UNSUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons] = 0; + (*msg)[am::strings::msg_params][am::strings::tts_chunks] = + SmartObject(smart_objects::SmartType_Array); + + SmartObject tts_chunk(smart_objects::SmartType_Map); + tts_chunk[am::strings::text] = "wrong chunk syntax\t\n"; + + (*msg)[am::strings::msg_params][am::strings::tts_chunks].asArray()->push_back( + tts_chunk); + + CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::INVALID_DATA, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, Run_ProcessingResult_SUCCESS) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::text] = "text"; + + CommandPtr command(CreateCommand<AlertManeuverRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillRepeatedly( + Return(am::HmiInterfaces::InterfaceID::HMI_INTERFACE_TTS)); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command))); + EXPECT_EQ(hmi_apis::FunctionID::Navigation_AlertManeuver, + static_cast<hmi_apis::FunctionID::eType>( + (*result_msg)[am::strings::params][am::strings::function_id] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { + CommandPtr command(CreateCommand<AlertManeuverRequest>()); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event))); + EXPECT_EQ(mobile_apis::Result::INVALID_ENUM, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_SUCCESS) { + CheckExpectations(hmi_apis::Common_Result::SUCCESS, + mobile_apis::Result::SUCCESS, + am::HmiInterfaces::STATE_AVAILABLE, + true); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_UNSUPPORTED_RESOURCE) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + false); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_WARNINGS) { + CheckExpectations(hmi_apis::Common_Result::WARNINGS, + mobile_apis::Result::WARNINGS, + am::HmiInterfaces::STATE_NOT_RESPONSE, + true); +} + +TEST_F(AlertManeuverRequestTest, OnEvent_GENERIC_ERROR) { + CheckExpectations(hmi_apis::Common_Result::GENERIC_ERROR, + mobile_apis::Result::GENERIC_ERROR, + am::HmiInterfaces::STATE_NOT_RESPONSE, + false); +} + +} // namespace alert_maneuver_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc new file mode 100644 index 0000000000..e32cc2b335 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/alert_request_test.cc @@ -0,0 +1,809 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/alert_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace alert_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::AlertRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using am::event_engine::Event; +using policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef std::shared_ptr<AlertRequest> CommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kDefaultTimeout = 1000u; +const uint32_t kCorrelationId = 2u; +const mobile_apis::FunctionID::eType kFunctionId = + mobile_apis::FunctionID::AlertID; +} // namespace + +class AlertRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + AlertRequestTest() : mock_app_(CreateMockApp()), msg_(CreateMessage()) {} + + protected: + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault( + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault( + Return(am::HmiInterfaces::InterfaceState::STATE_AVAILABLE)); + } + + void Expectations() { + (*msg_)[am::strings::params][am::strings::function_id] = kFunctionId; + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL( + *mock_app_, + AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) + .WillByDefault(Return(false)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_BACKGROUND)); + } + + void AddAlertTextsToMsg() { + (*msg_)[am::strings::msg_params][am::strings::alert_text1] = "alert_text1"; + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = "alert_text2"; + (*msg_)[am::strings::msg_params][am::strings::alert_text3] = "alert_text3"; + } + void AddTTSChunkToMsg() { + (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "tts_chunk_text"; + } + + void ExpectCallHmiLevel(const mobile_apis::HMILevel::eType level) { + EXPECT_CALL(*mock_app_, hmi_level()).WillRepeatedly(Return(level)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + void ExpectManageHmiCommandTTSAndUI() { + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Alert))) + .WillOnce(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + } + sync_primitives::Lock lock_; + + MockAppPtr mock_app_; + MessageSharedPtr msg_; +}; + +TEST_F(AlertRequestTest, OnTimeout_GENERIC_ERROR) { + PreConditions(); + MessageSharedPtr command_msg = CreateMessage(smart_objects::SmartType_Map); + (*command_msg)[am::strings::msg_params][am::strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*command_msg)[am::strings::msg_params][am::strings::success] = false; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + std::shared_ptr<AlertRequest> command = CreateCommand<AlertRequest>(); + + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(command_msg)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->onTimeOut(); + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(AlertRequestTest, OnEvent_UI_HmiSendSuccess_UNSUPPORTED_RESOURCE) { + PreConditions(); + MessageSharedPtr command_msg = CreateFullParamsUISO(); + (*command_msg)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = 10u; + (*command_msg)[am::strings::msg_params][am::strings::menu_params] + [am::strings::menu_name] = "menu_name"; + + std::shared_ptr<AlertRequest> command = + CreateCommand<AlertRequest>(command_msg); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + MessageSharedPtr msg_tts = CreateMessage(); + (*msg_tts)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::TTS_Speak); + event_vr.set_smart_object(*msg_tts); + + command->on_event(event_vr); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +class CallOnTimeOut { + public: + CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} + + void operator()() { + command_.onTimeOut(); + } + + CommandRequestImpl& command_; +}; + +TEST_F(AlertRequestTest, Init_DurationExists_SUCCESS) { + Expectations(); + (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(AlertRequestTest, Init_DurationNotExists_SUCCESS) { + Expectations(); + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(AlertRequestTest, OnTimeOut_SUCCESS) { + Expectations(); + MessageSharedPtr result_msg(CreateMessage(smart_objects::SmartType_Null)); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, mobile_apis::Result::GENERIC_ERROR)) + .WillOnce(Return(result_msg)); + + CommandPtr command(CreateCommand<AlertRequest>()); + MessageSharedPtr received_result_msg( + CatchMobileCommandResult(CallOnTimeOut(*command))); + EXPECT_EQ(result_msg, received_result_msg); +} + +TEST_F(AlertRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + Expectations(); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_AlertFrequencyIsTooHigh_UNSUCCESS) { + Expectations(); + EXPECT_CALL( + *mock_app_, + AreCommandLimitsExceeded(kFunctionId, am::TLimitSource::POLICY_TABLE)) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::REJECTED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertRequestTest, Run_FailToProcessSoftButtons_UNSUCCESS) { + Expectations(); + const mobile_apis::Result::eType result_code = + mobile_apis::Result::INVALID_ENUM; + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(result_code)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(result_code, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(AlertRequestTest, Run_MandatoryParametersAreMissed_UNSUCCESS) { + Expectations(); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_MandatoryParametersAreInvalid_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = + "invalid\t\nParam"; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + (*msg_)[am::strings::msg_params][am::strings::progress_indicator] = + "progress_indicator"; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageHmiCommandTTSAndUI(); + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + Expectations(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_UI_OnResetTimeout_SUCCESS) { + PreConditions(); + Expectations(); + AddAlertTextsToMsg(); + + (*msg_)[am::strings::msg_params][am::strings::duration] = kDefaultTimeout; + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + EXPECT_TRUE(command->Init()); + + EXPECT_CALL( + app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_ENUM); + + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_UIAlertHasHmiResponsesToWait_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + ExpectManageHmiCommandTTSAndUI(); + + command->Run(); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg_); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))); + + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarnings_SUCCESS) { + PreConditions(); + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSUnsupportedResource_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + PreConditions(); + + command->on_event(event); +} + +TEST_F(AlertRequestTest, + DISABLED_OnEvent_TTSUnsupportedResourceUiAlertSent_SUCCESS) { + PreConditions(); + + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_TTSUnsupportedResourceUiAlertSuccess_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons] = "soft_buttons"; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton( + (*msg_)[am::strings::msg_params], _, kFunctionId)); + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, OnEvent_TTSSuccesUiAlertInvalidEnum_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::INVALID_ENUM; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSAbortedUiAlertNotSent_SUCCESS) { + Expectations(); + AddTTSChunkToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))) + .WillOnce(Return(true)); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::INVALID_ENUM; + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, DISABLED_OnEvent_TTSWarningUiAlertWarning_SUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::WARNINGS; + (*msg_)[am::strings::msg_params][am::strings::play_tone] = true; + + ExpectCallHmiLevel(mobile_apis::HMILevel::HMI_FULL); + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*msg_)[am::strings::msg_params], _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ExpectManageHmiCommandTTSAndUI(); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(true)); + + Event ui_event(hmi_apis::FunctionID::UI_Alert); + ui_event.set_smart_object(*msg_); + command->on_event(ui_event); + + Event tts_stop_event(hmi_apis::FunctionID::TTS_StopSpeaking); + tts_stop_event.set_smart_object(*msg_); + command->on_event(tts_stop_event); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::WARNINGS); + + Event event(hmi_apis::FunctionID::TTS_Speak); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(AlertRequestTest, Run_InvalidAlert2_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text2] = + "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_InvalidAlert3_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::alert_text3] = + "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +TEST_F(AlertRequestTest, Run_InvalidTTSChunk_UNSUCCESS) { + Expectations(); + AddAlertTextsToMsg(); + (*msg_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "invalid_text_with_empty_str\\n"; + + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand<AlertRequest>(msg_)); + command->Run(); +} + +} // namespace alert_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc new file mode 100644 index 0000000000..58755c8b36 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/change_registration_test.cc @@ -0,0 +1,559 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/change_registration_request.h" + +#include "gtest/gtest.h" +#include "utils/helpers.h" +#include "utils/custom_string.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "policy/policy_regular/policy/usage_statistics/mock_statistics_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace change_registration_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SetArgPointee; +using sdl_rpc_plugin::commands::ChangeRegistrationRequest; +using policy_test::MockPolicyHandlerInterface; +using ::test::components::application_manager_test::MockApplication; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class ChangeRegistrationRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + ChangeRegistrationRequestTest() + : app_set_lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , mock_app_(CreateMockApp()) + , supported_languages_(CreateMessage(smart_objects::SmartType_Array)) {} + + MessageSharedPtr CreateMsgFromMobile() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::hmi_display_language] = mobile_apis::Language::EN_US; + msg_params[strings::language] = mobile_apis::Language::EN_US; + (*msg)[strings::msg_params] = msg_params; + return msg; + } + void PrepareExpectationBeforeRun() { + (*supported_languages_)[0] = + static_cast<int32_t>(mobile_apis::Language::EN_US); + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success, + const hmi_apis::Common_Result::eType ui_hmi_response = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + const hmi_apis::Common_Result::eType vr_hmi_response = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + + std::shared_ptr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor<am::ApplicationSet> accessor(application_set, + app_set_lock_ptr_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + PrepareExpectationBeforeRun(); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI(ui_response, ui_hmi_response, "ui_info"); + CreateResponseFromHMI(vr_response, vr_hmi_response, "unsupported_resource"); + + (*tts_response)[strings::params][hmi_response::code] = hmi_response; + (*tts_response)[strings::msg_params] = 0; + + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr( + hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_ui); + command->on_event(event_vr); + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + success); + EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_response)); + } + + void CreateResponseFromHMI(MessageSharedPtr msg, + hmi_apis::Common_Result::eType result, + const std::string& info) { + (*msg)[strings::params][hmi_response::code] = static_cast<int32_t>(result); + (*msg)[strings::msg_params][strings::info] = info; + } + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ExpectationsHmiCapabilities( + smart_objects::SmartObjectSPtr supported_languages) { + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages.get())); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + typedef TypeIf<kMocksAreNice, + NiceMock<application_manager_test::MockHMICapabilities>, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + std::shared_ptr<sync_primitives::Lock> app_set_lock_ptr_; + MockHMICapabilities hmi_capabilities_; + MockAppPtr mock_app_; + MessageSharedPtr supported_languages_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +typedef ChangeRegistrationRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + std::shared_ptr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); + + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor<am::ApplicationSet> accessor(application_set, app_set_lock_ptr_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + smart_objects::SmartObjectSPtr supported_languages( + CreateMessage(smart_objects::SmartType_Array)); + (*supported_languages)[0] = + static_cast<int32_t>(mobile_apis::Language::EN_US); + + ExpectationsHmiCapabilities(supported_languages); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI( + ui_response, hmi_apis::Common_Result::WARNINGS, "ui_info"); + CreateResponseFromHMI(vr_response, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "VR is not supported by system"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*tts_response)[am::strings::msg_params][am::strings::app_id] = + kConnectionKey; + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_ui); + command->on_event(event_tts); + command->on_event(event_vr); + + ResultCommandExpectations(response_to_mobile, + "ui_info, VR is not supported by system, tts_info"); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + std::shared_ptr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(1)); + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + DataAccessor<am::ApplicationSet> accessor(application_set, app_set_lock_ptr_); + application_set.insert(app); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + (*supported_languages_)[0] = + static_cast<int32_t>(mobile_apis::Language::EN_US); + EXPECT_CALL(mock_hmi_capabilities_, ui_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, vr_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + EXPECT_CALL(mock_hmi_capabilities_, tts_supported_languages()) + .WillOnce(Return(supported_languages_.get())); + + EXPECT_CALL(app_mngr_, hmi_interfaces()) + .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + command->Run(); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::UNSUPPORTED_RESOURCE)); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_RESPONSE, + false); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + false); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_UNSUPPORTED_RESOURCE_SUCCESS_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_SUCCESS_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::SUCCESS, + mobile_apis::Result::SUCCESS, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_WRONG_LANGUAGE_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::WRONG_LANGUAGE, + mobile_apis::Result::WRONG_LANGUAGE, + am::HmiInterfaces::STATE_AVAILABLE, + true, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_TTS_INVALID_DATA_STATE_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::INVALID_DATA, + mobile_apis::Result::INVALID_DATA, + am::HmiInterfaces::STATE_AVAILABLE, + false, + hmi_apis::Common_Result::SUCCESS, + hmi_apis::Common_Result::SUCCESS); +} + +TEST_F(ChangeRegistrationRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = CreateMsgFromMobile(); + + std::shared_ptr<ChangeRegistrationRequest> command = + CreateCommand<ChangeRegistrationRequest>(msg_from_mobile); + + am::ApplicationSet application_set; + const utils::custom_string::CustomString name("name"); + MockAppPtr app = CreateMockApp(); + app->set_name(name); + + DataAccessor<am::ApplicationSet> accessor(application_set, app_set_lock_ptr_); + + application_set.insert(app); + + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + EXPECT_CALL(*app, name()).WillOnce(ReturnRef(name)); + + smart_objects::SmartObjectSPtr supported_languages( + CreateMessage(smart_objects::SmartType_Array)); + (*supported_languages)[0] = + static_cast<int32_t>(mobile_apis::Language::EN_US); + + ExpectationsHmiCapabilities(supported_languages); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + command->Run(); + + MessageSharedPtr ui_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr vr_response = CreateMessage(smart_objects::SmartType_Map); + MessageSharedPtr tts_response = CreateMessage(smart_objects::SmartType_Map); + CreateResponseFromHMI(ui_response, + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + "unsupported_resource"); + CreateResponseFromHMI( + vr_response, hmi_apis::Common_Result::WARNINGS, "vr_info"); + CreateResponseFromHMI( + tts_response, hmi_apis::Common_Result::SUCCESS, "tts_info"); + (*ui_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*vr_response)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*tts_response)[am::strings::msg_params][am::strings::app_id] = + kConnectionKey; + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_ChangeRegistration); + event_ui.set_smart_object(*ui_response); + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_ChangeRegistration); + event_vr.set_smart_object(*vr_response); + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_ChangeRegistration); + event_tts.set_smart_object(*tts_response); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_tts); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "unsupported_resource, vr_info, tts_info"); +} + +} // namespace change_registration_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc new file mode 100644 index 0000000000..c42be48e57 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/create_interaction_choice_set_test.cc @@ -0,0 +1,923 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/create_interaction_choice_set_request.h" +#include "mobile/create_interaction_choice_set_response.h" + +#include "gtest/gtest.h" +#include "utils/helpers.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace create_interaction_choice_set_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::AtLeast; +using sdl_rpc_plugin::commands::CreateInteractionChoiceSetRequest; +using sdl_rpc_plugin::commands::CreateInteractionChoiceSetResponse; +using ::test::components::application_manager_test::MockApplication; + +namespace custom_str = utils::custom_string; +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +typedef std::shared_ptr<CreateInteractionChoiceSetRequest> + CreateInteractionChoiceSetRequestPtr; +typedef std::shared_ptr<CreateInteractionChoiceSetResponse> + CreateInteractionChoiceSetResponsePtr; + +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const hmi_apis::FunctionID::eType kInvalidFunctionId = + hmi_apis::FunctionID::INVALID_ENUM; +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +const uint32_t kGrammarId = 10u; +const int32_t kMenuId = 5; +const uint32_t kChoiceSetId = 1u; +const uint32_t kChoiceId1 = 2u; +const uint32_t kChoiceId2 = 3u; +const std::string kImage = "image"; +const std::string kSecondImage = "second_image"; +const std::string kVrCommands1 = "vr_commands_1"; +const std::string kVrCommands2 = "vr_commands_2"; +const std::string kMenuName = "menu_name"; + +} // namespace + +class CreateInteractionChoiceSetRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + CreateInteractionChoiceSetRequestTest() + : message_(CreateMessage()) + , command_(CreateCommand<CreateInteractionChoiceSetRequest>(message_)) + , mock_app_(CreateMockApp()) + , lock_(std::make_shared<sync_primitives::Lock>()) {} + + MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[strings::cmd_id] = kCmdId; + msg_params[strings::vr_commands] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params[strings::vr_commands][0] = "lamer"; + msg_params[strings::type] = 34; + msg_params[strings::grammar_id] = 12; + msg_params[strings::app_id] = kAppId; + (*msg)[strings::msg_params] = msg_params; + + return msg; + } + + void FillMessageFieldsItem1(MessageSharedPtr message) { + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + } + void FillMessageFieldsItem2(MessageSharedPtr message) { + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands2; + (*message)[am::strings::msg_params] + [am::strings::interaction_choice_set_id] = kChoiceSetId; + } + + MessageSharedPtr message_; + CreateInteractionChoiceSetRequestPtr command_; + MockAppPtr mock_app_; + std::shared_ptr<sync_primitives::Lock> lock_; +}; + +class CreateInteractionChoiceSetResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeout_GENERIC_ERROR) { + MessageSharedPtr msg_vr = CreateMessage(smart_objects::SmartType_Map); + (*msg_vr)[strings::msg_params][strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*msg_vr)[strings::msg_params][strings::success] = false; + + std::shared_ptr<CreateInteractionChoiceSetRequest> req_vr = + CreateCommand<CreateInteractionChoiceSetRequest>(); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, RemoveCommand(_)).WillByDefault(Return()); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + req_vr->onTimeOut(); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_VR_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsVRSO(); + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::choice_id] = + 10; + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::menu_name] = + "menu_name"; + (*msg_vr)[strings::msg_params][strings::choice_set][0][strings::vr_commands] + [0] = kVrCommands1; + (*msg_vr)[strings::msg_params][strings::interaction_choice_set_id] = 11; + std::shared_ptr<CreateInteractionChoiceSetRequest> req_vr = + CreateCommand<CreateInteractionChoiceSetRequest>(msg_vr); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + smart_objects::SmartObject* null_obj = NULL; + ON_CALL(*mock_app_, FindChoiceSet(_)).WillByDefault(Return(null_obj)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[strings::msg_params][strings::info] = "VR is not supported by system"; + (*msg)[strings::msg_params][strings::cmd_id] = kCommandId; + + am::event_engine::Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*msg); + + smart_objects::SmartObject* ptr = NULL; + ON_CALL(*mock_app_, FindCommand(kCmdId)).WillByDefault(Return(ptr)); + EXPECT_EQ(NULL, ptr); + + am::CommandsMap commands_map; + ON_CALL(*mock_app_, commands_map()) + .WillByDefault( + Return(DataAccessor<am::CommandsMap>(commands_map, lock_))); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault( + Return(am::HmiInterfaces::HMI_INTERFACE_BasicCommunication)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + req_vr->Run(); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + req_vr->on_event(event); + + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*vr_command_result)[strings::msg_params].keyExists(strings::info)) { + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::info].asString(), + (*msg)[strings::msg_params][strings::info].asString()); + } +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_VerifyImageFail_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image] = kSecondImage; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::INVALID_DATA)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_FindChoiceSetFail_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* invalid_choice_set_id = + &((*message_)[am::strings::msg_params] + [am::strings::interaction_choice_set_id]); + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(invalid_choice_set_id)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_CheckChoiceSet_InvalidChoiceId_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + + FillMessageFieldsItem2(message_); + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][1] = " kVrCommands2\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands1; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_IsWhiteSpaceVRCommandsExist_InvalidMenuName_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = "menu_name\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_text] = "secondary_text\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::tertiary_text] = "tertiary_text\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = "image\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = + "second_image\t"; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = "vr_commands_1\t"; + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillRepeatedly(Return(choice_set_id)); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::menu_name)) { + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::secondary_text)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::tertiary_text)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_text] = "secondary_text"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::vr_commands)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::tertiary_text] = "tertiary_text"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::image)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = "vr_commands"; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } + if ((*message_)[am::strings::msg_params][am::strings::choice_set][0] + .keyExists(am::strings::secondary_image)) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + CreateInteractionChoiceSetRequestPtr command( + CreateCommand<CreateInteractionChoiceSetRequest>(message_)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + command->Run(); + } +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_ValidAmountVrCommands_SUCCESS) { + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .Times(AtLeast(2)) + .WillOnce(Return(kConnectionKey)) + .WillOnce(Return(kConnectionKey)); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_EmptyAmountVrCommands_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::vr_commands][0] = kVrCommands2; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_WithoutVrCommands_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillOnce(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::NONE)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + // No VR commands + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + Run_WithMixedVrCommands_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::image][am::strings::value] = kImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::choice_id] = kChoiceId1; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::secondary_image][am::strings::value] = kSecondImage; + (*message_)[am::strings::msg_params][am::strings::choice_set][0] + [am::strings::vr_commands][0] = kVrCommands1; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::choice_id] = kChoiceId2; + (*message_)[am::strings::msg_params][am::strings::choice_set][1] + [am::strings::menu_name] = kMenuName; + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillOnce(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::MIXED)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).Times(0); + + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(0); + + command_->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InvalidEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InvalidVrCommand_UNSUCCESS) { + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnEvent_ValidVrNoError_SUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + event.set_smart_object(*message_); + + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_InValidVrNoError_UNSUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_DATA; + + FillMessageFieldsItem1(message_); + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(0); + event.set_smart_object(*message_); + + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnEvent_ValidVrNoErrorAndExpectedChoiceLessThanReceiveChoice_SUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::WARNINGS; + + FillMessageFieldsItem1(message_); + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + event.set_smart_object(*message_); + command_->on_event(event); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_InvalidErrorFromHMI_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), + am::commands::Command::SOURCE_SDL)); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_ValidErrorFromHMI_SUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_ENUM; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + command_->on_event(event); + + EXPECT_CALL(*mock_app_, RemoveChoiceSet(kChoiceSetId)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, OnTimeOut_InvalidApp_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::INVALID_ENUM; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)).Times(2); + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + command_->on_event(event); + + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)).Times(0); + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, + OnTimeOut_SuccessfulResponseReceived_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + FillMessageFieldsItem1(message_); + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::SUCCESS)); + + smart_objects::SmartObject* choice_set_id = NULL; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + EXPECT_CALL(app_mngr_, GenerateGrammarID()).WillOnce(Return(kGrammarId)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillOnce(Return(choice_set_id)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + + Event event(hmi_apis::FunctionID::VR_AddCommand); + event.set_smart_object(*message_); + + command_->on_event(event); + + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, RemoveChoiceSet(_)); + + command_->onTimeOut(); +} + +TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessFalse_UNSUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::success] = false; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::INVALID_ENUM; + CreateInteractionChoiceSetResponsePtr command( + CreateCommand<CreateInteractionChoiceSetResponse>(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, false)); + command->Run(); +} + +TEST_F(CreateInteractionChoiceSetResponseTest, Run_SuccessTrue_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::success] = true; + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + CreateInteractionChoiceSetResponsePtr command( + CreateCommand<CreateInteractionChoiceSetResponse>(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, false)); + command->Run(); +} + +TEST_F(CreateInteractionChoiceSetRequestTest, Run_ErrorFromHmiFalse_UNSUCCESS) { + Event event(hmi_apis::FunctionID::VR_AddCommand); + + (*message_)[am::strings::params][am::strings::correlation_id] = + kCorrelationId; + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + + FillMessageFieldsItem1(message_); + + (*message_)[am::strings::msg_params][am::strings::interaction_choice_set_id] = + kChoiceSetId; + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillRepeatedly(Return(mobile_apis::Result::GENERIC_ERROR)); + + smart_objects::SmartObject* choice_set_id = NULL; + EXPECT_CALL(*mock_app_, FindChoiceSet(kChoiceSetId)) + .WillRepeatedly(Return(choice_set_id)); + + ON_CALL(mock_message_helper_, CheckChoiceSetVRCommands(_)) + .WillByDefault(Return(am::MessageHelper::ChoiceSetVRCommandsStatus::ALL)); + + EXPECT_CALL(app_mngr_, GenerateGrammarID()) + .WillRepeatedly(Return(kGrammarId)); + EXPECT_CALL(*mock_app_, AddChoiceSet(kChoiceSetId, _)).Times(2); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + + command_->Run(); + + FillMessageFieldsItem2(message_); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::GENERIC_ERROR), + am::commands::Command::SOURCE_SDL)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, TerminateRequest(_, _, _)); + event.set_smart_object(*message_); + command_->on_event(event); + command_->Run(); +} + +} // namespace create_interaction_choice_set_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc new file mode 100644 index 0000000000..a87d172923 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_command_request_test.cc @@ -0,0 +1,272 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "mobile/delete_command_request.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_help_prompt_manager.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_command_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace am_test = application_manager_test; +using sdl_rpc_plugin::commands::DeleteCommandRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; +using am::MockHmiInterfaces; + +typedef std::shared_ptr<DeleteCommandRequest> DeleteCommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class DeleteCommandRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + DeleteCommandRequestTest() + : mock_help_prompt_manager_( + std::make_shared<am_test::MockHelpPromptManager>()) + , mock_app_(CreateMockApp()) {} + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateFullParamsVRSO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::vr_commands] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params[am::strings::vr_commands][0] = "lamer"; + msg_params[am::strings::type] = 34; + msg_params[am::strings::grammar_id] = 12; + msg_params[am::strings::app_id] = kAppId; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(hmi_interfaces_)); + } + + NiceMock<MockHmiInterfaces> hmi_interfaces_; + std::shared_ptr<am_test::MockHelpPromptManager> mock_help_prompt_manager_; + MockAppPtr mock_app_; +}; + +TEST_F(DeleteCommandRequestTest, + OnEvent_VrHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr command_msg = CreateFullParamsVRSO(); + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DeleteCommandPtr command(CreateCommand<DeleteCommandRequest>(command_msg)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + + MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); + (*test_msg)[am::strings::vr_commands] = 0; + (*test_msg)[am::strings::menu_params] = 0; + + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(*mock_app_, FindCommand(kCommandId)) + .WillByDefault(Return(test_msg.get())); + ON_CALL(*mock_app_, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); + event_ui.set_smart_object(*msg); + command->Init(); + command->Run(); + command->on_event(event_ui); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::msg_params][am::strings::info] = + "VR is not supported by system"; + Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); + event_vr.set_smart_object(*event_msg); + + EXPECT_CALL(*mock_app_, RemoveCommand(kCommandId)); + + EXPECT_CALL(*mock_app_, UpdateHash()); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandDeleted(kCommandId, false)); + + command->on_event(event_vr); + + ResultCommandExpectations(vr_command_result, "VR is not supported by system"); +} + +TEST_F(DeleteCommandRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr command_msg = CreateFullParamsUISO(); + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DeleteCommandPtr command(CreateCommand<DeleteCommandRequest>(command_msg)); + + MockAppPtr app = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + MessageSharedPtr test_msg(CreateMessage(smart_objects::SmartType_Map)); + (*test_msg)[am::strings::vr_commands] = 0; + (*test_msg)[am::strings::menu_params] = 0; + + ON_CALL(hmi_interfaces_, GetInterfaceFromFunction(_)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(*app, FindCommand(kCommandId)).WillByDefault(Return(test_msg.get())); + ON_CALL(*app, get_grammar_id()).WillByDefault(Return(kConnectionKey)); + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::VR_DeleteCommand); + event_vr.set_smart_object(*msg); + + command->Init(); + command->Run(); + command->on_event(event_vr); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + Event event_ui(hmi_apis::FunctionID::UI_DeleteCommand); + event_ui.set_smart_object(*event_msg); + + EXPECT_CALL(*app, RemoveCommand(kCommandId)); + + EXPECT_CALL(*app, UpdateHash()); + + EXPECT_CALL(*app, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnVrCommandDeleted(kCommandId, false)); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event_ui))); + + ASSERT_TRUE((bool)result_msg); + + ResultCommandExpectations(result_msg, "UI is not supported by system"); +} + +} // namespace delete_command_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc new file mode 100644 index 0000000000..0ed7a92fa4 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_file_test.cc @@ -0,0 +1,250 @@ +/* + * 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 <stdint.h> +#include <vector> +#include <string> +#include <map> + +#include "mobile/delete_file_request.h" +#include "mobile/delete_file_response.h" + +#include "gtest/gtest.h" + +#include "utils/file_system.h" +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_application_manager_settings.h" + +#include "interfaces/MOBILE_API.h" +#include "application_manager/policies/policy_handler_interface.h" +#include "application_manager/policies/policy_handler.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_file { + +using ::testing::_; +using ::testing::Test; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SetArgReferee; +using ::testing::AtLeast; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::DeleteFileRequest; +using sdl_rpc_plugin::commands::DeleteFileResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef std::shared_ptr<DeleteFileRequest> DeleteFileRequestPtr; +typedef std::shared_ptr<DeleteFileResponse> DeleteFileResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +ACTION_TEMPLATE(SetArgPointer, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_1_VALUE_PARAMS(vec)) { + *std::tr1::get<k>(args) = *vec; +} + +MATCHER_P(CheckMessageResultCode, result_code, "") { + return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + result_code; +} + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kCorrelationId = 10u; +const int32_t kMenuId = 5; +} // namespace + +class DeleteFileRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand<DeleteFileRequest>(message_); + mock_app_ = CreateMockApp(); + } + DeleteFileRequestPtr command_; + MessageSharedPtr message_; + MockAppPtr mock_app_; +}; + +class DeleteFileResponseTest : public CommandsTest<CommandsTestMocks::kIsNice> { +}; + +TEST_F(DeleteFileRequestTest, 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_mngr_, get_settings()).Times(0); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_HMILevelNone_UNSUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const uint32_t num = 0; + EXPECT_CALL(app_mngr_settings_, delete_file_in_none()) + .WillOnce(ReturnRef(num)); + EXPECT_CALL(*mock_app_, delete_file_in_none_count()).WillOnce(Return(1)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::REJECTED), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_ValidFileName_SUCCESS) { + const std::string file_name = "test_file.txt"; + EXPECT_TRUE(file_system::CreateFile(file_name)); + (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kFullFilePath)); + + am::AppFile file; + file.file_name = file_name; + file.file_type = mobile_apis::FileType::BINARY; + + EXPECT_CALL(*mock_app_, GetFile(_)).WillOnce(Return(&file)); + EXPECT_CALL(*mock_app_, DeleteFile(_)); + EXPECT_CALL(*mock_app_, increment_delete_file_in_none_count()); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode(mobile_apis::Result::SUCCESS), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command_->Run(); +} + +TEST_F(DeleteFileRequestTest, Run_InvalidFile_UNSUCCESS) { + const std::string file_name = "test_file.txt"; + (*message_)[am::strings::msg_params][am::strings::sync_file_name] = file_name; + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + const std::string kFullFilePath = file_system::CurrentWorkingDirectory(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kFullFilePath)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::REJECTED), + am::commands::Command::CommandSource::SOURCE_SDL)); + command_->Run(); +} + +TEST_F(DeleteFileResponseTest, Run_InvalidApp_UNSUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + DeleteFileResponsePtr command = CreateCommand<DeleteFileResponse>(message); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(CheckMessageResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED), + false)); + + command->Run(); +} + +TEST_F(DeleteFileResponseTest, Run_ValidApp_SUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*message)[am::strings::msg_params][am::strings::success] = true; + + DeleteFileResponsePtr command = CreateCommand<DeleteFileResponse>(message); + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + const uint32_t kAvailableDiskSpace = 10u; + EXPECT_CALL(*app, GetAvailableDiskSpace()) + .WillOnce(Return(kAvailableDiskSpace)); + + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile( + CheckMessageResultCode(mobile_apis::Result::SUCCESS), _)); + + command->Run(); +} + +} // namespace delete_file +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc new file mode 100644 index 0000000000..43c30809e5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_interaction_choice_set_test.cc @@ -0,0 +1,296 @@ +/* + * 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 <stdint.h> +#include <map> + +#include "mobile/delete_interaction_choice_set_request.h" +#include "mobile/delete_interaction_choice_set_response.h" + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_interaction_choice_set { + +using ::testing::_; +using ::testing::Return; +using ::testing::InSequence; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetRequest; +using sdl_rpc_plugin::commands::DeleteInteractionChoiceSetResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; + +typedef std::shared_ptr<DeleteInteractionChoiceSetRequest> + DeleteInteractionChoiceSetRequestPtr; +typedef std::shared_ptr<DeleteInteractionChoiceSetResponse> + 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<CommandsTestMocks::kIsNice> { + public: + DeleteInteractionChoiceSetRequestTest() + : performinteraction_choice_set_lock_( + std::make_shared<sync_primitives::Lock>()) + , 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<sync_primitives::Lock> + performinteraction_choice_set_lock_; + DataAccessor<am::PerformChoiceSetMap> accessor_; + + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand<DeleteInteractionChoiceSetRequest>(message_); + app_ = CreateMockApp(); + } + + DeleteInteractionChoiceSetRequestPtr command_; + MessageSharedPtr message_; + MockAppPtr app_; +}; + +class DeleteInteractionChoiceSetResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + protected: + void SetUp() OVERRIDE { + message_ = CreateMessage(); + command_ = CreateCommand<DeleteInteractionChoiceSetResponse>(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 = 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 = 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()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); + EXPECT_CALL(*app_, UpdateHash()); + } + + DeleteInteractionChoiceSetRequestPtr command = + CreateCommand<DeleteInteractionChoiceSetRequest>(message_); + + command->Init(); + command->Run(); +} + +TEST_F(DeleteInteractionChoiceSetRequestTest, Run_SendVrDeleteCommand_SUCCESS) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*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]); + + 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)) + .WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveChoiceSet(kChoiceSetId)); + EXPECT_CALL(*app_, UpdateHash()); + } + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + DeleteInteractionChoiceSetRequestPtr command = + CreateCommand<DeleteInteractionChoiceSetRequest>(message_); + + command->Init(); + command->Run(); +} + +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 diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc new file mode 100644 index 0000000000..f1c44f86ac --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/delete_sub_menu_test.cc @@ -0,0 +1,375 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "mobile/delete_sub_menu_request.h" +#include "mobile/delete_sub_menu_response.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_help_prompt_manager.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace delete_sub_menu_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::InSequence; +namespace am = ::application_manager; +namespace am_test = application_manager_test; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockHmiInterfaces; +using am::MockMessageHelper; + +using sdl_rpc_plugin::commands::DeleteSubMenuRequest; +using sdl_rpc_plugin::commands::DeleteSubMenuResponse; + +typedef std::shared_ptr<DeleteSubMenuRequest> DeleteSubMenuRequestPtr; +typedef std::shared_ptr<DeleteSubMenuResponse> DeleteSubMenuResponsePtr; + +MATCHER_P(CheckMessageResultCode, result_code, "") { + return (*arg)[am::strings::msg_params][am::strings::result_code].asInt() == + result_code; +} + +MATCHER_P(CheckMessageConnectionKey, connection_key, "") { + return (*arg)[am::strings::msg_params][am::strings::connection_key].asInt() == + connection_key; +} + +ACTION_P(DeleteCommand, commands_map) { + am::CommandsMap::iterator it = (*commands_map).begin(); + if ((*commands_map).end() != it) { + (*commands_map).erase(it); + } +} + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +const uint32_t kMenuId = 100u; +const uint32_t kGrammarId = 101u; +const int32_t kCmdId = 102; +} // namespace + +class DeleteSubMenuRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + DeleteSubMenuRequestTest() + : commands_lock_(std::make_shared<sync_primitives::Lock>()) + , accessor_(commands_map_, commands_lock_) + , message_(CreateMessage()) + , command_(CreateCommand<DeleteSubMenuRequest>(message_)) + , mock_help_prompt_manager_( + std::make_shared<am_test::MockHelpPromptManager>()) + , app_(CreateMockApp()) {} + + am::CommandsMap commands_map_; + mutable std::shared_ptr<sync_primitives::Lock> commands_lock_; + DataAccessor<am::CommandsMap> accessor_; + + MessageSharedPtr message_; + DeleteSubMenuRequestPtr command_; + std::shared_ptr<am_test::MockHelpPromptManager> mock_help_prompt_manager_; + MockAppPtr app_; +}; + +class DeleteSubMenuResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(DeleteSubMenuRequestTest, DISABLED_OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::menu_id] = 10u; + + std::shared_ptr<DeleteSubMenuRequest> command = + CreateCommand<DeleteSubMenuRequest>(msg); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + EXPECT_CALL(*mock_app, RemoveSubMenu(_)); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + event.set_smart_object(*ev_msg); + + MockHmiInterfaces hmi_interfaces; + ON_CALL(app_mngr_, hmi_interfaces()).WillByDefault(ReturnRef(hmi_interfaces)); + EXPECT_CALL(hmi_interfaces, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillOnce(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + am::CommandsMap commands_map; + smart_objects::SmartObject commands_msg(smart_objects::SmartType_Map); + commands_map.insert(std::pair<uint32_t, SmartObject*>(1u, &commands_msg)); + DataAccessor<am::CommandsMap> accessor( + commands_map, std::make_shared<sync_primitives::Lock>()); + EXPECT_CALL(*mock_app, commands_map()) + .WillOnce(Return(accessor)) + .WillOnce(Return(accessor)); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(DeleteSubMenuRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(CheckMessageResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED), + am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_, FindSubMenu(_)).Times(0); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, Run_FindSubMenuFalse_UNSUCCESS) { + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject* invalid_sub_menu = NULL; + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(invalid_sub_menu)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + CheckMessageResultCode(mobile_apis::Result::INVALID_ID), + am::commands::Command::CommandSource::SOURCE_SDL)); + EXPECT_CALL(*app_, app_id()).Times(0); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, Run_SendHMIRequest_SUCCESS) { + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject* sub_menu = + &((*message_)[am::strings::msg_params][am::strings::menu_id]); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app_)); + EXPECT_CALL(*app_, FindSubMenu(kMenuId)).WillOnce(Return(sub_menu)); + + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteSubMenu))) + .WillOnce(Return(true)); + command_->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_UnknownEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(app_mngr_, application(_)).Times(0); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_InvalidApp_UNSUCCESS) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + event.set_smart_object(*message_); + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + EXPECT_CALL(*app_, RemoveSubMenu(_)).Times(0); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, OnEvent_DeleteSubmenu_SUCCESS) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::msg_params][am::strings::vr_commands] = + "vr_commands"; + (*message_)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + (*message_)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = kMenuId; + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*message_)[am::strings::params][am::hmi_response::code] = result_code; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + + InSequence seq; + EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, get_grammar_id()).WillOnce(Return(kGrammarId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::VR_DeleteCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*app_, commands_map()).WillOnce(Return(accessor_)); + EXPECT_CALL(*app_, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(*app_, RemoveCommand(_)).WillOnce(DeleteCommand(&commands_map_)); + EXPECT_CALL(*app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_)); + EXPECT_CALL(*mock_help_prompt_manager_, OnVrCommandDeleted(kCmdId, false)); + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_DeleteCommand))) + .WillOnce(Return(true)); + + EXPECT_CALL(*app_, RemoveSubMenu(_)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + EXPECT_CALL(*app_, UpdateHash()); + + DeleteSubMenuRequestPtr command = + CreateCommand<DeleteSubMenuRequest>(message_); + + command->Init(); + command->on_event(event); +} + +TEST_F(DeleteSubMenuResponseTest, Run_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + (*message)[am::strings::msg_params][am::strings::connection_key] = + kConnectionKey; + DeleteSubMenuResponsePtr command( + CreateCommand<DeleteSubMenuResponse>(message)); + + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(CheckMessageConnectionKey(kConnectionKey), _)); + command->Run(); +} + +TEST_F(DeleteSubMenuRequestTest, + DeleteSubmenu_CommandhaventVrCommadsAndMenuParams_DontSendHMIRequest) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + am::mobile_api::Result::SUCCESS; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); + EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + command_->on_event(event); +} + +TEST_F(DeleteSubMenuRequestTest, + DeleteSubmenu_NotAChildOfMenupartam_DontSendHMIRequest) { + Event event(hmi_apis::FunctionID::UI_DeleteSubMenu); + (*message_)[am::strings::msg_params][am::strings::menu_id] = kMenuId; + (*message_)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = kMenuId + 1; + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*message_)[am::strings::params][am::hmi_response::code] = + am::mobile_api::Result::SUCCESS; + event.set_smart_object(*message_); + + commands_map_.insert( + std::make_pair(0, &((*message_)[am::strings::msg_params]))); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app_)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*app_, commands_map()).Times(2).WillRepeatedly(Return(accessor_)); + EXPECT_CALL(*app_, RemoveCommand(_)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_SDL)); + command_->on_event(event); +} + +} // namespace delete_sub_menu_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc new file mode 100644 index 0000000000..5d6c6dc89e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dial_number_request_test.cc @@ -0,0 +1,187 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/event_engine/event.h" +#include "mobile/dial_number_request.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace dial_number_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::DialNumberRequest; +using am::event_engine::Event; +namespace mobile_result = mobile_apis::Result; + +typedef std::shared_ptr<DialNumberRequest> DialNumberRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + +class DialNumberRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(DialNumberRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(DialNumberRequestTest, Run_InvalidNumber_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "\t\n"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(DialNumberRequestTest, Run_EmptyNumber_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "NotANumber"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(DialNumberRequestTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = "123"; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_DialNumber))); + + command->Run(); +} + +TEST_F(DialNumberRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>(command_msg)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)).WillOnce(Return(app)); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->on_event(event); +} + +TEST_F(DialNumberRequestTest, OnEvent_SUCCESS) { + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::SUCCESS; + (*event_msg)[am::strings::params][am::strings::info] = "test_info"; + + Event event(hmi_apis::FunctionID::BasicCommunication_DialNumber); + event.set_smart_object(*event_msg); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(app)); + ON_CALL(app_mngr_, GetRPCService()) + .WillByDefault(ReturnRef(mock_rpc_service_)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + DialNumberRequestPtr command(CreateCommand<DialNumberRequest>(command_msg)); + command->on_event(event); +} + +} // namespace dial_number_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc new file mode 100644 index 0000000000..c6601d6352 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/dummy_mobile_commands_test.cc @@ -0,0 +1,315 @@ +/* + * 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 "application_manager/commands/command_request_test.h" + +#include <stdint.h> +#include <string> +#include <vector> +#include "gtest/gtest.h" + +#include "mobile/add_command_request.h" +#include "mobile/add_command_response.h" +#include "mobile/add_sub_menu_request.h" +#include "mobile/add_sub_menu_response.h" +#include "mobile/alert_maneuver_request.h" +#include "mobile/alert_maneuver_response.h" +#include "mobile/alert_request.h" +#include "mobile/alert_response.h" +#include "mobile/change_registration_request.h" +#include "mobile/change_registration_response.h" +#include "mobile/create_interaction_choice_set_request.h" +#include "mobile/create_interaction_choice_set_response.h" +#include "mobile/delete_command_request.h" +#include "mobile/delete_command_response.h" +#include "mobile/delete_file_request.h" +#include "mobile/delete_file_response.h" +#include "mobile/delete_interaction_choice_set_request.h" +#include "mobile/delete_interaction_choice_set_response.h" +#include "mobile/delete_sub_menu_request.h" +#include "mobile/delete_sub_menu_response.h" +#include "mobile/dial_number_request.h" +#include "mobile/dial_number_response.h" +#include "mobile/end_audio_pass_thru_request.h" +#include "mobile/end_audio_pass_thru_response.h" +#include "mobile/generic_response.h" +#include "mobile/get_way_points_request.h" +#include "mobile/get_way_points_response.h" +#include "mobile/list_files_request.h" +#include "mobile/list_files_response.h" +#include "mobile/on_app_interface_unregistered_notification.h" +#include "mobile/on_audio_pass_thru_notification.h" +#include "mobile/on_button_event_notification.h" +#include "mobile/on_button_press_notification.h" +#include "mobile/on_command_notification.h" +#include "mobile/on_driver_distraction_notification.h" +#include "mobile/on_hash_change_notification.h" +#include "mobile/on_hmi_status_notification.h" +#include "mobile/on_hmi_status_notification_from_mobile.h" +#include "mobile/on_keyboard_input_notification.h" +#include "mobile/on_language_change_notification.h" +#include "mobile/on_permissions_change_notification.h" +#include "mobile/on_system_request_notification.h" +#include "mobile/on_tbt_client_state_notification.h" +#include "mobile/on_touch_event_notification.h" +#include "mobile/on_way_point_change_notification.h" +#include "mobile/perform_audio_pass_thru_request.h" +#include "mobile/perform_audio_pass_thru_response.h" +#include "mobile/perform_interaction_request.h" +#include "mobile/perform_interaction_response.h" +#include "mobile/put_file_request.h" +#include "mobile/put_file_response.h" +#include "mobile/register_app_interface_request.h" +#include "mobile/register_app_interface_response.h" +#include "mobile/reset_global_properties_request.h" +#include "mobile/reset_global_properties_response.h" +#include "mobile/scrollable_message_request.h" +#include "mobile/scrollable_message_response.h" +#include "mobile/send_location_request.h" +#include "mobile/send_location_response.h" +#include "mobile/set_app_icon_request.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/set_display_layout_request.h" +#include "mobile/set_display_layout_response.h" +#include "mobile/set_global_properties_request.h" +#include "mobile/set_global_properties_response.h" +#include "mobile/set_media_clock_timer_request.h" +#include "mobile/set_media_clock_timer_response.h" +#include "mobile/show_constant_tbt_request.h" +#include "mobile/show_constant_tbt_response.h" +#include "mobile/show_request.h" +#include "mobile/show_response.h" +#include "mobile/slider_request.h" +#include "mobile/slider_response.h" +#include "mobile/speak_request.h" +#include "mobile/speak_response.h" +#include "mobile/subscribe_button_request.h" +#include "mobile/subscribe_button_response.h" +#include "mobile/subscribe_way_points_request.h" +#include "mobile/subscribe_way_points_response.h" +#include "mobile/system_response.h" +#include "mobile/unregister_app_interface_request.h" +#include "mobile/unregister_app_interface_response.h" +#include "mobile/unsubscribe_button_request.h" +#include "mobile/unsubscribe_button_response.h" +#include "mobile/unsubscribe_way_points_request.h" +#include "mobile/unsubscribe_way_points_response.h" +#include "mobile/update_turn_list_request.h" +#include "mobile/update_turn_list_response.h" + +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "test/application_manager/mock_application_manager_settings.h" +#include "application_manager/mock_event_dispatcher.h" + +namespace am = application_manager; + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace dummy_mobile_commands_test { + +namespace commands = sdl_rpc_plugin::commands; +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; +using am::commands::MessageSharedPtr; +using ::test::components::event_engine_test::MockEventDispatcher; +using ::test::components::application_manager_test::MockApplicationManager; +using ::test::components::application_manager_test:: + MockApplicationManagerSettings; +using ::application_manager::ApplicationSharedPtr; +using ::test::components::application_manager_test::MockApplication; + +namespace { +const std::string kEmptyString_ = ""; +} // namespace + +template <class Command> +class MobileCommandsTest : public components::commands_test::CommandRequestTest< + CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; + + void InitCommand(const uint32_t& timeout) OVERRIDE { + EXPECT_CALL(app_mngr_settings_, default_timeout()) + .WillOnce(ReturnRef(timeout)); + ON_CALL(app_mngr_, event_dispatcher()) + .WillByDefault(ReturnRef(event_dispatcher_)); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(kEmptyString_)); + } +}; + +template <class Command> +class MobileCommandsTestFirst : public MobileCommandsTest<Command> { + public: + using typename MobileCommandsTest<Command>::CommandType; +}; + +template <class Command> +class MobileCommandsTestSecond : public MobileCommandsTest<Command> { + public: + using typename MobileCommandsTest<Command>::CommandType; +}; + +template <class Command> +class MobileCommandsTestThird : public MobileCommandsTest<Command> { + public: + using typename MobileCommandsTest<Command>::CommandType; +}; + +/* macro TYPED_TEST_CASE takes max 50 args. That is why there are few + * TYPED_TEST_CASE for HMI and mobile commands + */ + +typedef Types<commands::AddCommandRequest, + commands::AddCommandResponse, + commands::AddSubMenuRequest, + commands::AddSubMenuResponse, + commands::AlertManeuverRequest, + commands::AlertManeuverResponse, + commands::AlertRequest, + commands::AlertResponse, + commands::ChangeRegistrationRequest, + commands::ChangeRegistrationResponse, + commands::CreateInteractionChoiceSetRequest, + commands::CreateInteractionChoiceSetResponse, + commands::DeleteCommandRequest, + commands::DeleteCommandResponse, + commands::DeleteFileRequest, + commands::DeleteFileResponse, + commands::DeleteInteractionChoiceSetRequest, + commands::DeleteInteractionChoiceSetResponse, + commands::DeleteSubMenuRequest, + commands::DeleteSubMenuResponse, + commands::DialNumberRequest, + commands::DialNumberResponse, + commands::EndAudioPassThruRequest, + commands::EndAudioPassThruResponse, + commands::GenericResponse, + commands::GetWayPointsRequest, + commands::GetWayPointsResponse, + commands::ListFilesRequest, + commands::ListFilesResponse, + commands::OnAppInterfaceUnregisteredNotification, + commands::OnAudioPassThruNotification, + commands::mobile::OnButtonEventNotification, + commands::mobile::OnButtonPressNotification, + commands::OnCommandNotification, + commands::mobile::OnDriverDistractionNotification, + commands::mobile::OnHashChangeNotification, + commands::OnHMIStatusNotification, + commands::OnHMIStatusNotificationFromMobile, + commands::mobile::OnKeyBoardInputNotification, + commands::OnLanguageChangeNotification, + commands::OnPermissionsChangeNotification, + commands::mobile::OnSystemRequestNotification, + commands::OnTBTClientStateNotification, + commands::mobile::OnTouchEventNotification> + MobileCommandsListFirst; + +typedef Types<commands::OnWayPointChangeNotification, + commands::PerformAudioPassThruRequest, + commands::PerformAudioPassThruResponse, + commands::PerformInteractionRequest, + commands::PerformInteractionResponse, + commands::PutFileRequest, + commands::PutFileResponse, + commands::RegisterAppInterfaceRequest, + commands::RegisterAppInterfaceResponse, + commands::ResetGlobalPropertiesRequest, + commands::ResetGlobalPropertiesResponse, + commands::ScrollableMessageRequest, + commands::ScrollableMessageResponse, + commands::SendLocationRequest, + commands::SendLocationResponse, + commands::SetAppIconRequest, + commands::SetAppIconResponse, + commands::SetDisplayLayoutRequest, + commands::SetDisplayLayoutResponse, + commands::SetGlobalPropertiesRequest, + commands::SetGlobalPropertiesResponse, + commands::SetMediaClockRequest, + commands::SetMediaClockTimerResponse, + commands::ShowConstantTBTRequest, + commands::ShowConstantTBTResponse, + commands::ShowRequest, + commands::ShowResponse, + commands::SliderRequest, + commands::SliderResponse, + commands::SpeakRequest, + commands::SpeakResponse, + commands::SubscribeButtonRequest, + commands::SubscribeButtonResponse, + commands::SubscribeWayPointsRequest, + commands::SubscribeWayPointsResponse, + commands::SystemResponse, + commands::UnregisterAppInterfaceRequest, + commands::UnregisterAppInterfaceResponse, + commands::UnsubscribeButtonRequest, + commands::UnsubscribeButtonResponse> MobileCommandsListSecond; + +typedef Types<commands::UnSubscribeWayPointsRequest, + commands::UnsubscribeWayPointsResponse, + commands::UpdateTurnListRequest, + commands::UpdateTurnListResponse> MobileCommandsListThird; + +TYPED_TEST_CASE(MobileCommandsTestFirst, MobileCommandsListFirst); +TYPED_TEST_CASE(MobileCommandsTestSecond, MobileCommandsListSecond); +TYPED_TEST_CASE(MobileCommandsTestThird, MobileCommandsListThird); + +TYPED_TEST(MobileCommandsTestFirst, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +TYPED_TEST(MobileCommandsTestSecond, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} +TYPED_TEST(MobileCommandsTestThird, CtorAndDtorCall) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + UNUSED(command); +} + +} // namespace dummy_mobile_commands_test +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc new file mode 100644 index 0000000000..304cf13ffd --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/end_audio_pass_thru_request_test.cc @@ -0,0 +1,120 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> + +#include "mobile/end_audio_pass_thru_request.h" + +#include "gtest/gtest.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace end_audio_pass_thru_request { + +namespace am = ::application_manager; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::EndAudioPassThruRequest; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef std::shared_ptr<EndAudioPassThruRequest> EndAudioPassThruRequestPtr; + +class EndAudioPassThruRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(EndAudioPassThruRequestTest, OnEvent_UI_UNSUPPORTED_RESOUCRE) { + const uint32_t kConnectionKey = 2u; + const uint32_t app_id = kConnectionKey; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + EndAudioPassThruRequestPtr command( + CreateCommand<EndAudioPassThruRequest>(command_msg)); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::msg_params] = 0; + (*event_msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::UNSUPPORTED_RESOURCE; + + Event event(hmi_apis::FunctionID::UI_EndAudioPassThru); + event.set_smart_object(*event_msg); + + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace end_audio_pass_thru_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc new file mode 100644 index 0000000000..09a3336a10 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/get_way_points_request_test.cc @@ -0,0 +1,282 @@ +/* + * 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 "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "mobile/get_way_points_request.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_message_helper.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace get_way_points_request { + +using namespace mobile_apis::Result; +using ::testing::Return; +using ::testing::_; +using sdl_rpc_plugin::commands::GetWayPointsRequest; +using application_manager::MockMessageHelper; +using application_manager::MockHmiInterfaces; + +typedef std::shared_ptr<GetWayPointsRequest> CommandPtr; +typedef mobile_apis::Result::eType MobileResult; +typedef hmi_apis::Common_Result::eType HmiResult; + +namespace { +const uint32_t kCorrelationId = 2u; +const uint32_t kAppId = 3u; +const uint32_t kConnectionKey = kAppId; +const std::string kMethodName = "Navigation.GetWayPoints"; +} + +class GetWayPointsRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + GetWayPointsRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + message_ = std::make_shared<SmartObject>(::smart_objects::SmartType_Map); + (*message_)[am::strings::msg_params] = + ::smart_objects::SmartObject(::smart_objects::SmartType_Map); + + command_sptr_ = CreateCommand<GetWayPointsRequest>(message_); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + } + + MockAppPtr mock_app_; + MessageSharedPtr message_; + std::shared_ptr<GetWayPointsRequest> command_sptr_; +}; + +class GetWayPointsRequestOnEventTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + GetWayPointsRequestOnEventTest() : app_(CreateMockApp()) {} + + void CheckOnEventResponse(const std::string& wayPointsParam, + const HmiResult ResultCode, + const bool success) { + Event event(Event::EventID::Navigation_GetWayPoints); + CommandPtr command(CreateCommand<GetWayPointsRequest>()); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = ResultCode; + if ("0" == wayPointsParam) { + (*event_msg)[am::strings::msg_params] = 0; + } else { + (*event_msg)[am::strings::msg_params][am::strings::way_points][0]["123"] = + wayPointsParam; + } + + event.set_smart_object(*event_msg); + + const MobileResult mobile_result = static_cast<MobileResult>(ResultCode); + + MessageSharedPtr result_msg( + CatchMobileCommandResult(CallOnEvent(*command, event))); + EXPECT_EQ( + mobile_result, + static_cast<MobileResult>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); + EXPECT_EQ( + success, + (*result_msg)[am::strings::msg_params][am::strings::success].asBool()); + } + + protected: + MockAppPtr app_; + MockHmiInterfaces hmi_interfaces_; +}; + +TEST_F(GetWayPointsRequestTest, + Run_InvalidApp_ApplicationNotRegisteredResponce) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + std::shared_ptr<am::Application> null_application_sptr; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(null_application_sptr)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast<mobile_apis::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, result); +} + +TEST_F(GetWayPointsRequestTest, Run_ApplicationRegistered_Success) { + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + MockAppPtr application_sptr = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + EXPECT_CALL(*application_sptr, app_id()).WillOnce(Return(1)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + + CallRun caller(*command_sptr_); + + MessageSharedPtr result_message = CatchHMICommandResult(caller); + + const hmi_apis::FunctionID::eType result_function_id = + static_cast<hmi_apis::FunctionID::eType>( + (*result_message)[am::strings::params][am::strings::function_id] + .asInt()); + + EXPECT_EQ(hmi_apis::FunctionID::Navigation_GetWayPoints, result_function_id); + EXPECT_EQ(kCorrelationId, + (*result_message)[am::strings::params][am::strings::correlation_id] + .asUInt()); +} + +TEST_F(GetWayPointsRequestTest, + OnEvent_NavigationGetWayPointsEvent_SendResponse) { + am::event_engine::Event event(hmi_apis::FunctionID::Navigation_GetWayPoints); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + event.set_smart_object(*message_); + + CallOnEvent caller(*command_sptr_, event); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const mobile_apis::Result::eType result = + static_cast<mobile_apis::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, result); +} + +TEST_F(GetWayPointsRequestTest, OnEvent_DefaultCase) { + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + + event.set_smart_object(*message_); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + CommandPtr command(CreateCommand<GetWayPointsRequest>()); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->on_event(event); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case1) { + CheckOnEventResponse("0", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case2) { + CheckOnEventResponse("", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_SUCCESS_Case3) { + CheckOnEventResponse("test", HmiResult::SUCCESS, true); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case1) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse(" ", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case2) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\t", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case3) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\n", HmiResult::GENERIC_ERROR, false); +} + +TEST_F(GetWayPointsRequestOnEventTest, OnEvent_Expect_GENERIC_ERROR_Case4) { + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_Navigation)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + CheckOnEventResponse("test\t\n", HmiResult::GENERIC_ERROR, false); +} + +} // namespace get_way_points_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc new file mode 100644 index 0000000000..3fcc4225f3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/list_files_request_test.cc @@ -0,0 +1,145 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "mobile/list_files_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace list_files_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::ListFilesRequest; +using am::commands::MessageSharedPtr; + +class ListFilesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + ListFilesRequestTest() : kStoragePath_("storage"), kResponseSize_(1) {} + const std::string kStoragePath_; + const uint32_t kResponseSize_; +}; + +TEST_F(ListFilesRequestTest, Run_AppNotRegistered_UNSUCCESS) { + std::shared_ptr<ListFilesRequest> command(CreateCommand<ListFilesRequest>()); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(std::shared_ptr<am::Application>())); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(ListFilesRequestTest, Run_TooManyHmiNone_UNSUCCESS) { + MockAppPtr app(CreateMockApp()); + std::shared_ptr<ListFilesRequest> command(CreateCommand<ListFilesRequest>()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_NONE)); + + const uint32_t kListFilesInNoneAllowed = 1u; + const uint32_t kListFilesInNoneCount = 2u; + + EXPECT_CALL(app_mngr_, get_settings()) + .WillOnce(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, list_files_in_none()) + .WillByDefault(ReturnRef(kListFilesInNoneAllowed)); + ON_CALL(*app, list_files_in_none_count()) + .WillByDefault(Return(kListFilesInNoneCount)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::REJECTED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(ListFilesRequestTest, Run_SUCCESS) { + MockAppPtr app(CreateMockApp()); + std::shared_ptr<ListFilesRequest> command(CreateCommand<ListFilesRequest>()); + + EXPECT_CALL(app_mngr_, get_settings()) + .WillRepeatedly(ReturnRef(app_mngr_settings_)); + + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStoragePath_)); + + ON_CALL(app_mngr_settings_, list_files_response_size()) + .WillByDefault(ReturnRef(kResponseSize_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(*app, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + + ON_CALL(*app, increment_list_files_in_none_count()).WillByDefault(Return()); + + ON_CALL(*app, GetAvailableDiskSpace()).WillByDefault(Return(0)); + + am::AppFilesMap files_map; + ON_CALL(*app, getAppFiles()).WillByDefault(ReturnRef(files_map)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +} // namespace list_files_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc new file mode 100644 index 0000000000..a0e41cf728 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_button_notification_commands_test.cc @@ -0,0 +1,337 @@ +/* + * 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 <stdint.h> +#include <string> + +#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 <class NotificationT, + mobile_apis::FunctionID::eType kExpectedFunctionId> +struct NotificationData { + typedef NotificationT Notification; + enum { kFunctionId = kExpectedFunctionId }; +}; + +template <class NotificationDataT> +class OnButtonNotificationCommandsTest + : public CommandsTest<CommandsTestMocks::kNotNice>, + public NotificationDataT {}; + +typedef Types<NotificationData<OnButtonEventNotification, + mobile_apis::FunctionID::OnButtonEventID>, + NotificationData<OnButtonPressNotification, + mobile_apis::FunctionID::OnButtonPressID> > + 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<Notification> command( + this->template CreateCommand<Notification>(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<Notification> command( + this->template CreateCommand<Notification>(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<Notification> command( + this->template CreateCommand<Notification>(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<Notification> command( + this->template CreateCommand<Notification>(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<Notification> command( + this->template CreateCommand<Notification>(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<Notification> command( + this->template CreateCommand<Notification>(notification_msg)); + + const std::vector<ApplicationSharedPtr> 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<Notification> command( + this->template CreateCommand<Notification>(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector<ApplicationSharedPtr> 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<Notification> command( + this->template CreateCommand<Notification>(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector<ApplicationSharedPtr> 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<Notification> command( + this->template CreateCommand<Notification>(notification_msg)); + + typename TestFixture::MockAppPtr mock_app = this->CreateMockApp(); + std::vector<ApplicationSharedPtr> 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 diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc new file mode 100644 index 0000000000..2fd6f6137d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_command_notification_test.cc @@ -0,0 +1,137 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "mobile/on_command_notification.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_command_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnCommandNotification; + +typedef std::shared_ptr<OnCommandNotification> CommandPtr; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCommandId = 5u; +} // namespace + +class OnCommandNotificationTest + : public CommandsTest<CommandsTestMocks::kNotNice> {}; + +TEST_F(OnCommandNotificationTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand<OnCommandNotification>()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->Run(); +} + +TEST_F(OnCommandNotificationTest, Run_NoAppsForTheCommand_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + CommandPtr command(CreateCommand<OnCommandNotification>(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, FindCommand(kCommandId)) + .WillOnce(Return(static_cast<SmartObject*>(NULL))); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command->Run(); +} + +MATCHER(CheckNotificationMessage, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + return kIsMobileProtocolTypeCorrect && kIsProtocolVersionCorrect && + kIsNotificationCorrect; +} + +TEST_F(OnCommandNotificationTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*command_msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + CommandPtr command(CreateCommand<OnCommandNotification>(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kAppId)).WillOnce(Return(mock_app)); + + MessageSharedPtr dummy_msg(CreateMessage()); + EXPECT_CALL(*mock_app, FindCommand(kCommandId)) + .WillOnce(Return(dummy_msg.get())); + EXPECT_CALL(mock_rpc_service_, + SendMessageToMobile(CheckNotificationMessage(), _)); + + command->Run(); +} + +} // namespace on_command_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc new file mode 100644 index 0000000000..1d6711e36f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hash_change_notification_test.cc @@ -0,0 +1,119 @@ +/* + * 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 <string> + +#include "gtest/gtest.h" +#include "mobile/on_hash_change_notification.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hash_change_notification { + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::mobile::OnHashChangeNotification; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using testing::Mock; +using testing::Return; +using testing::ReturnRef; +using testing::_; + +class OnHashChangeNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(OnHashChangeNotificationTest, Run_ValidApp_SUCCESS) { + const uint32_t kConnectionKey = 1u; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + + std::shared_ptr<OnHashChangeNotification> command = + CreateCommand<OnHashChangeNotification>(msg); + + std::string return_string = "1234"; + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, curHash()).WillOnce(ReturnRef(return_string)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + ASSERT_EQ(return_string, + (*msg)[strings::msg_params][strings::hash_id].asString()); +} + +TEST_F(OnHashChangeNotificationTest, Run_InvalidApp_NoNotification) { + const uint32_t kConnectionKey = 1u; + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + + std::shared_ptr<OnHashChangeNotification> command = + CreateCommand<OnHashChangeNotification>(msg); + + std::string return_string; + MockAppPtr mock_app = CreateMockApp(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app, curHash()).Times(0); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +} // namespace on_hash_change_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc new file mode 100644 index 0000000000..333c204d57 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_from_mobile_test.cc @@ -0,0 +1,284 @@ +/* + * 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 "mobile/on_hmi_status_notification_from_mobile.h" +#include "application_manager/commands/commands_test.h" +#include <application_manager/smart_object_keys.h> +#include "application_manager/message.h" +#include "application_manager/application_manager.h" +#include "application_manager/mock_message_helper.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hmi_status_notification_from_mobile { + +namespace { +const uint32_t kConnectionKey = 1u; +const connection_handler::DeviceHandle kHandle = 2u; +} // namespace + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::OnHMIStatusNotificationFromMobile; +using protocol_handler::MajorProtocolVersion; +using application_manager::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnHMIStatusNotificationFromMobileTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnHMIStatusNotificationFromMobileTest() + : lock_(std::make_shared<sync_primitives::Lock>()) {} + MessageSharedPtr CreateMsgParams( + const mobile_apis::HMILevel::eType kHMIState) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; + return msg; + } + ApplicationSet app_set_; + std::shared_ptr<sync_primitives::Lock> lock_; +}; + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_CurrentStateForeground_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor<ApplicationSet> accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app, set_foreground(true)).Times(0); + + EXPECT_CALL(*mock_app, device()).Times(0); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).Times(0); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()).Times(0); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_CurrentStateNotForeground_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(false)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor<ApplicationSet> accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(true)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_ProtocolVersionKV3_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_BACKGROUND); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(false)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor<ApplicationSet> accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AppNotRequestedBeforeAndKV3_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_3)); + EXPECT_CALL(*mock_app, is_foreground()).Times(0); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AppNotRequestedBefore_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(false)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillOnce( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + + EXPECT_CALL(app_mngr_, applications()).Times(0); + + EXPECT_CALL(*mock_app, is_foreground()).WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, SendQueryApps(kConnectionKey, _)); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +TEST_F(OnHMIStatusNotificationFromMobileTest, + Run_AnotherForegroundSDLApp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotificationFromMobile> command = + CreateCommand<OnHMIStatusNotificationFromMobile>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, set_foreground(true)); + + EXPECT_CALL(*mock_app, device()).WillOnce(Return(kHandle)); + EXPECT_CALL(app_mngr_, IsAppsQueriedFrom(kHandle)).WillOnce(Return(true)); + + DataAccessor<ApplicationSet> accessor(app_set_, lock_); + EXPECT_CALL(app_mngr_, applications()).WillOnce(Return(accessor)); + + EXPECT_CALL(*mock_app, protocol_version()) + .WillRepeatedly( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_5)); + EXPECT_CALL(*mock_app, is_foreground()).WillRepeatedly(Return(false)); + + EXPECT_CALL(app_mngr_, MarkAppsGreyOut(kHandle, false)); + EXPECT_CALL(app_mngr_, SendUpdateAppList()); + + command->Run(); + + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); +} + +} // namespace on_hmi_status_notification_from_mobile +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc new file mode 100644 index 0000000000..ba3b1e8f1d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_hmi_status_notification_test.cc @@ -0,0 +1,166 @@ +/* + * 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 "mobile/on_hmi_status_notification.h" +#include "application_manager/test/include/application_manager/commands/commands_test.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_hmi_status_notification { + +namespace { +const uint32_t kConnectionKey = 1u; +} // namespace + +namespace strings = application_manager::strings; +using sdl_rpc_plugin::commands::OnHMIStatusNotification; +using protocol_handler::MajorProtocolVersion; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnHMIStatusNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateMsgParams( + const mobile_apis::HMILevel::eType kHMIState) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::hmi_level] = kHMIState; + return msg; + } + + void SetSendNotificationExpectations(MessageSharedPtr& msg) { + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + } + + void VerifySendNotificationData(MessageSharedPtr& msg) { + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + } +}; + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotification> command = + CreateCommand<OnHMIStatusNotification>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).Times(0); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(_)).Times(0); + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)) + .Times(0); + + command->Run(); +} + +TEST_F(OnHMIStatusNotificationTest, Run_InvalidEnum_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::INVALID_ENUM); + + std::shared_ptr<OnHMIStatusNotification> command = + CreateCommand<OnHMIStatusNotification>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndFalseProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotification> command = + CreateCommand<OnHMIStatusNotification>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(false)); + EXPECT_CALL(*mock_app, set_tts_properties_in_full(true)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + EXPECT_CALL(app_mngr_, AddAppToTTSGlobalPropertiesList(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +TEST_F(OnHMIStatusNotificationTest, Run_FullAndTrueProperties_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(mobile_apis::HMILevel::HMI_FULL); + + std::shared_ptr<OnHMIStatusNotification> command = + CreateCommand<OnHMIStatusNotification>(msg); + + MockAppPtr mock_app = CreateMockApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(*mock_app, tts_properties_in_full()).WillOnce(Return(true)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + VerifySendNotificationData(msg); +} + +} // namespace on_hmi_status_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc new file mode 100644 index 0000000000..04f88e2b13 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_keyboard_input_notification_test.cc @@ -0,0 +1,167 @@ +/* + * 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 "mobile/on_keyboard_input_notification.h" +#include "application_manager/commands/commands_test.h" +#include <application_manager/smart_object_keys.h> +#include "application_manager/message.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_keyboard_input_notification { + +namespace strings = application_manager::strings; + +namespace { +const uint32_t kConnectionKey = 1u; +} // namespace + +using sdl_rpc_plugin::commands::mobile::OnKeyBoardInputNotification; +using application_manager::MockMessageHelper; +using application_manager::commands::CommandImpl; +using application_manager::ApplicationSet; +using testing::Mock; +using testing::Return; +using testing::_; + +class OnKeyBoardInputNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnKeyBoardInputNotificationTest() + : lock_(std::make_shared<sync_primitives::Lock>()) {} + void SetSendNotificationExpectations(MessageSharedPtr msg) { + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + } + + void SetSendNotificationVariables(MessageSharedPtr msg) { + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); + } + + MockAppPtr InitAppSetDataAccessor(std::shared_ptr<ApplicationSet>& app_set) { + app_set = (!app_set ? std::make_shared<ApplicationSet>() : app_set); + MockAppPtr app(CreateMockApp()); + app_set->insert(app); + EXPECT_CALL(app_mngr_, applications()) + .WillOnce(Return(DataAccessor<ApplicationSet>(*app_set, lock_))); + return app; + } + + std::shared_ptr<ApplicationSet> app_set_; + std::shared_ptr<sync_primitives::Lock> lock_; +}; + +TEST_F(OnKeyBoardInputNotificationTest, Run_ActionActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<OnKeyBoardInputNotification> command = + CreateCommand<OnKeyBoardInputNotification>(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()).WillOnce(Return(1)); + EXPECT_CALL(*mock_app, perform_interaction_layout()) + .WillOnce(Return(mobile_apis::LayoutMode::KEYBOARD)); + EXPECT_CALL(*mock_app, hmi_level()).Times(0); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + SetSendNotificationVariables(msg); + + ASSERT_EQ(kConnectionKey, + (*msg)[strings::params][strings::connection_key].asInt()); +} + +TEST_F(OnKeyBoardInputNotificationTest, Run_ActionNotActive_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<OnKeyBoardInputNotification> command = + CreateCommand<OnKeyBoardInputNotification>(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_FULL)); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kConnectionKey)); + + SetSendNotificationExpectations(msg); + + command->Run(); + + SetSendNotificationVariables(msg); + + ASSERT_EQ(kConnectionKey, + (*msg)[strings::params][strings::connection_key].asInt()); +} + +TEST_F(OnKeyBoardInputNotificationTest, Run_InvalidApp_NoNotification) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<OnKeyBoardInputNotification> command = + CreateCommand<OnKeyBoardInputNotification>(msg); + + MockAppPtr mock_app(InitAppSetDataAccessor(app_set_)); + EXPECT_CALL(*mock_app, is_perform_interaction_active()) + .WillRepeatedly(Return(0)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::eType::HMI_BACKGROUND)); + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); +} + +} // namespace on_keyboard_input_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc new file mode 100644 index 0000000000..4981301e07 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_system_request_notification_test.cc @@ -0,0 +1,273 @@ +/* + * 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 <string> + +#include "gtest/gtest.h" +#include "mobile/on_system_request_notification.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_system_request_notification { + +namespace strings = application_manager::strings; + +using sdl_rpc_plugin::commands::mobile::OnSystemRequestNotification; +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; +using testing::_; + +namespace { +const uint32_t kConnectionKey = 1u; +const std::string kPolicyAppId = "fake-app-id"; +} // namespace + +class OnSystemRequestNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnSystemRequestNotificationTest() : mock_app_(CreateMockApp()) {} + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, policy_app_id()).WillByDefault(Return(kPolicyAppId)); + } + + protected: + MockAppPtr mock_app_; +}; + +TEST_F(OnSystemRequestNotificationTest, Run_ProprietaryType_SUCCESS) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::PROPRIETARY; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + std::shared_ptr<OnSystemRequestNotification> command = + CreateCommand<OnSystemRequestNotification>(msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, + IsRequestTypeAllowed(kPolicyAppId, request_type)) + .WillRepeatedly(Return(true)); + +#ifdef PROPRIETARY_MODE + EXPECT_CALL(mock_policy_handler_, TimeoutExchangeSec()).WillOnce(Return(5u)); +#endif // PROPRIETARY_MODE + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(FileType::JSON, + (*msg)[strings::msg_params][strings::file_type].asInt()); + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(OnSystemRequestNotificationTest, Run_HTTPType_SUCCESS) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + std::shared_ptr<OnSystemRequestNotification> command = + CreateCommand<OnSystemRequestNotification>(msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)); + + command->Run(); + + ASSERT_EQ(FileType::BINARY, + (*msg)[strings::msg_params][strings::file_type].asInt()); + ASSERT_EQ(application_manager::MessageType::kNotification, + (*msg)[strings::params][strings::message_type].asInt()); + ASSERT_EQ(CommandImpl::mobile_protocol_type_, + (*msg)[strings::params][strings::protocol_type].asInt()); + ASSERT_EQ(CommandImpl::protocol_version_, + (*msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(OnSystemRequestNotificationTest, Run_InvalidApp_NoNotification) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + std::shared_ptr<OnSystemRequestNotification> command = + CreateCommand<OnSystemRequestNotification>(msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app_, policy_app_id()).Times(0); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)).Times(0); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + command->Run(); +} + +TEST_F(OnSystemRequestNotificationTest, Run_RequestNotAllowed_NoNotification) { + const mobile_apis::RequestType::eType request_type = + mobile_apis::RequestType::HTTP; + + MessageSharedPtr msg = CreateMessage(); + (*msg)[strings::params][strings::connection_key] = kConnectionKey; + (*msg)[strings::msg_params][strings::request_type] = request_type; + + std::shared_ptr<OnSystemRequestNotification> command = + CreateCommand<OnSystemRequestNotification>(msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, policy_app_id()).WillOnce(Return(kPolicyAppId)); + EXPECT_CALL(mock_policy_handler_, IsRequestTypeAllowed(_, _)) + .WillOnce(Return(false)); + + EXPECT_CALL(mock_message_helper_, PrintSmartObject(_)).Times(0); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(msg, _)).Times(0); + + 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(mock_rpc_service_, 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(mock_rpc_service_, 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 +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc new file mode 100644 index 0000000000..3d989db478 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_tbt_client_state_notification_test.cc @@ -0,0 +1,138 @@ +/* + * 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 <stdint.h> +#include <vector> + +#include "gtest/gtest.h" +#include "mobile/on_tbt_client_state_notification.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_tbt_client_state_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnTBTClientStateNotification; + +typedef std::shared_ptr<OnTBTClientStateNotification> NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnTBTClientStateNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnTBTClientStateNotificationTest() + : command_(CreateCommand<OnTBTClientStateNotification>()) {} + + NotificationPtr command_; +}; + +TEST_F(OnTBTClientStateNotificationTest, Run_HmiLevelNone_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector<ApplicationSharedPtr> applications_with_navi; + applications_with_navi.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); + + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + command_->Run(); +} + +MATCHER(CheckMessageData, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + const bool kIsConnectionKeyCorrect = + (*arg)[am::strings::params][am::strings::connection_key].asUInt() == + kAppId; + + using namespace helpers; + return Compare<bool, EQ, ALL>(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnTBTClientStateNotificationTest, + Run_NotEmptyListOfAppsWithNavi_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector<ApplicationSharedPtr> applications_with_navi; + applications_with_navi.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(*mock_app, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_FULL)); + + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + + command_->Run(); +} + +} // namespace on_tbt_client_state_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc new file mode 100644 index 0000000000..f69dd5da2e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_touch_event_notification_test.cc @@ -0,0 +1,148 @@ +/* + * 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 <stdint.h> +#include <vector> + +#include "gtest/gtest.h" +#include "mobile/on_touch_event_notification.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_touch_event_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::mobile::OnTouchEventNotification; + +typedef std::shared_ptr<OnTouchEventNotification> NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnTouchEventNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnTouchEventNotificationTest() + : command_(CreateCommand<OnTouchEventNotification>()) {} + + NotificationPtr command_; +}; + +TEST_F(OnTouchEventNotificationTest, Run_AppIsNotFullscreen_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector<ApplicationSharedPtr> applications_with_navi; + applications_with_navi.push_back(mock_app); + + std::vector<ApplicationSharedPtr> applications_with_mobile_projection; + applications_with_mobile_projection.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) + .WillOnce(Return(applications_with_mobile_projection)); + + EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(false)); + + EXPECT_CALL(*mock_app, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(_, _)).Times(0); + + command_->Run(); +} + +MATCHER(CheckMessageData, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + const bool kIsConnectionKeyCorrect = + (*arg)[am::strings::params][am::strings::connection_key].asUInt() == + kAppId; + + using namespace helpers; + return Compare<bool, EQ, ALL>(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnTouchEventNotificationTest, Run_NotEmptyListOfAppsWithNavi_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + std::vector<ApplicationSharedPtr> applications_with_navi; + applications_with_navi.push_back(mock_app); + + std::vector<ApplicationSharedPtr> applications_with_mobile_projection; + applications_with_mobile_projection.push_back(mock_app); + + EXPECT_CALL(app_mngr_, applications_with_navi()) + .WillOnce(Return(applications_with_navi)); + + EXPECT_CALL(app_mngr_, applications_with_mobile_projection()) + .WillOnce(Return(applications_with_mobile_projection)); + + EXPECT_CALL(*mock_app, IsFullscreen()).WillRepeatedly(Return(true)); + + EXPECT_CALL(*mock_app, app_id()).WillRepeatedly(Return(kAppId)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)) + .Times(2); + + command_->Run(); +} + +} // namespace on_touch_event_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc new file mode 100644 index 0000000000..97a290e792 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/on_way_point_change_notification_test.cc @@ -0,0 +1,115 @@ +/* + * 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 <stdint.h> +#include <set> + +#include "gtest/gtest.h" +#include "mobile/on_way_point_change_notification.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_impl.h" +#include "utils/helpers.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace on_way_point_change_notification { + +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::Return; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::OnWayPointChangeNotification; + +typedef std::shared_ptr<OnWayPointChangeNotification> NotificationPtr; + +namespace { +const uint32_t kAppId = 1u; +} // namespace + +class OnWayPointChangeNotificationTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + OnWayPointChangeNotificationTest() + : command_(CreateCommand<OnWayPointChangeNotification>()) {} + + NotificationPtr command_; +}; + +MATCHER(CheckMessageData, "") { + const bool kIsMobileProtocolTypeCorrect = + (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_; + + const bool kIsProtocolVersionCorrect = + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_; + + const bool kIsNotificationCorrect = + (*arg)[am::strings::params][am::strings::message_type].asInt() == + am::MessageType::kNotification; + + const bool kIsConnectionKeyCorrect = + (*arg)[am::strings::params][am::strings::connection_key].asUInt() == + kAppId; + + using namespace helpers; + return Compare<bool, EQ, ALL>(true, + kIsMobileProtocolTypeCorrect, + kIsProtocolVersionCorrect, + kIsNotificationCorrect, + kIsConnectionKeyCorrect); +} + +TEST_F(OnWayPointChangeNotificationTest, + Run_NotEmptyListOfAppsSubscribedForWayPoints_SUCCESS) { + std::set<int32_t> apps_subscribed_for_way_points; + apps_subscribed_for_way_points.insert(kAppId); + + EXPECT_CALL(app_mngr_, GetAppsSubscribedForWayPoints()) + .WillOnce(Return(apps_subscribed_for_way_points)); + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(CheckMessageData(), _)); + + command_->Run(); +} + +} // namespace on_way_point_change_notification +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc new file mode 100644 index 0000000000..f51f1aa655 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_audio_pass_thru_test.cc @@ -0,0 +1,834 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/perform_audio_pass_thru_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace perform_audio_pass_thru_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::PerformAudioPassThruRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::InSequence; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 2u; +const std::string kCorrectPrompt = "CorrectPrompt"; +const std::string kCorrectType = "CorrectType"; +const std::string kCorrectDisplayText1 = "CorrectDisplayText1"; +const std::string kCorrectDisplayText2 = "CorrectDisplayText2"; +const std::string kFunctionId = "FunctionId"; +const uint32_t kTimeoutForTTSSpeak = 1u; +} // namespace + +class PerformAudioPassThruRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + PerformAudioPassThruRequestTest() + : mock_app_(CreateMockApp()) + , message_(std::make_shared<SmartObject>(::smart_objects::SmartType_Map)) + , msg_params_((*message_)[am::strings::msg_params]) {} + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void TestWrongSyntaxInField(const std::string& field) { + if (field == am::strings::initial_prompt) { + msg_params_[field][0][am::strings::text] = "prompt\\n"; + } else { + msg_params_[field] = "prompt\\n"; + } + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast<am::mobile_api::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(am::mobile_api::Result::INVALID_DATA, result); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + (*message_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + command_sptr_ = CreateCommand<PerformAudioPassThruRequest>(message_); + + application_sptr_ = CreateMockApp(); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(application_sptr_)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; + MessageSharedPtr message_; + ::smart_objects::SmartObject& msg_params_; + std::shared_ptr<PerformAudioPassThruRequest> command_sptr_; + MockAppPtr application_sptr_; +}; + +TEST_F(PerformAudioPassThruRequestTest, OnTimeout_GENERIC_ERROR) { + MessageSharedPtr msg_ui = CreateMessage(smart_objects::SmartType_Map); + (*msg_ui)[am::strings::msg_params][am::strings::result_code] = + am::mobile_api::Result::GENERIC_ERROR; + (*msg_ui)[am::strings::msg_params][am::strings::success] = false; + + MessageSharedPtr message = + std::make_shared<SmartObject>(::smart_objects::SmartType_Map); + (*message)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + std::shared_ptr<PerformAudioPassThruRequest> command = + CreateCommand<PerformAudioPassThruRequest>(message); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(msg_ui)); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + command->onTimeOut(); + EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(PerformAudioPassThruRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr mobile_request = CreateFullParamsUISO(); + (*mobile_request)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + smart_objects::SmartObject initial_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + initial_prompt[0] = smart_objects::SmartObject(smart_objects::SmartType_Map); + initial_prompt[0][am::strings::text] = "tts chunk text"; + initial_prompt[0][am::strings::type] = 0; + (*mobile_request)[am::strings::msg_params][am::strings::initial_prompt] = + initial_prompt; + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + std::shared_ptr<PerformAudioPassThruRequest> command = + CreateCommand<PerformAudioPassThruRequest>(mobile_request); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_msg_tts = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_tts)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response_msg_tts)[am::strings::msg_params][am::strings::cmd_id] = kCmdId; + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_msg_tts); + + MessageSharedPtr response_ui = CreateMessage(smart_objects::SmartType_Map); + (*response_ui)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_ui)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*response_ui)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_PerformAudioPassThru); + event_ui.set_smart_object(*response_ui); + + MessageSharedPtr response_to_mobile; + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillRepeatedly(Return(true)); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles((*mobile_request)[am::strings::msg_params] + [am::strings::initial_prompt], + _, + _)).WillOnce(Return(mobile_apis::Result::SUCCESS)); + + command->Run(); + command->on_event(event_tts); + command->on_event(event_ui); + + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::info] + .asString(), + "UI is not supported by system"); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InvalidApp_ApplicationNotRegisteredResponce) { + std::shared_ptr<am::Application> null_application_sptr; + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(null_application_sptr)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast<am::mobile_api::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + EXPECT_EQ(am::mobile_api::Result::APPLICATION_NOT_REGISTERED, result); +} + +TEST_F(PerformAudioPassThruRequestTest, Run_HmiLevelNone_Rejected) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_NONE)); + + CallRun caller(*command_sptr_); + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result = + static_cast<am::mobile_api::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + EXPECT_EQ(am::mobile_api::Result::REJECTED, result); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInInitialPrompt_InvalidData) { + TestWrongSyntaxInField(am::strings::initial_prompt); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInAudioPassDisplayText1_InvalidData) { + TestWrongSyntaxInField(am::strings::audio_pass_display_text1); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_WhitespaceInAudioPassDisplayText2_InvalidData) { + TestWrongSyntaxInField(am::strings::audio_pass_display_text2); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_TTSSpeakIsAbsent) { + // First we need to call SendSpeakRequest() + // to enable the "is_active_tts_speak" key + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + // Send speak request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun run_caller(*command_sptr_); + run_caller(); + + const ::smart_objects::SmartObject& speak_msg_params = + (*speak_reqeust_result_msg)[am::strings::msg_params]; + + const std::string result_initial_prompt = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] + .asString(); + const std::string result_prompt_type = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] + .asString(); + + EXPECT_EQ(kCorrectPrompt, result_initial_prompt); + EXPECT_EQ(kCorrectType, result_prompt_type); + + // Now we recieve on_event() + + am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::GENERIC_ERROR; + event.set_smart_object(*message_); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_StopSpeaking)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + CallOnEvent on_event_caller(*command_sptr_, event); + MessageSharedPtr command_result = CatchHMICommandResult(on_event_caller); + + const hmi_apis::FunctionID::eType result_function_id = + static_cast<hmi_apis::FunctionID::eType>( + (*command_result)[am::strings::params][am::strings::function_id] + .asInt()); + + EXPECT_EQ(hmi_apis::FunctionID::TTS_StopSpeaking, result_function_id); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteTrue) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + msg_params_[am::strings::audio_pass_display_text1] = kCorrectDisplayText1; + msg_params_[am::strings::audio_pass_display_text2] = kCorrectDisplayText2; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun caller(*command_sptr_); + caller(); + + const ::smart_objects::SmartObject& speak_msg_params = + (*speak_reqeust_result_msg)[am::strings::msg_params]; + const ::smart_objects::SmartObject& perform_msg_params = + (*perform_result_msg)[am::strings::msg_params]; + + const std::string result_initial_prompt = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::text] + .asString(); + const std::string result_prompt_type = + speak_msg_params[am::hmi_request::tts_chunks][0][am::strings::type] + .asString(); + const std::string result_display_text_1 = + perform_msg_params[am::hmi_request::audio_pass_display_texts][0] + [am::hmi_request::field_text].asString(); + const std::string result_display_text_2 = + perform_msg_params[am::hmi_request::audio_pass_display_texts][1] + [am::hmi_request::field_text].asString(); + + EXPECT_EQ(kCorrectPrompt, result_initial_prompt); + EXPECT_EQ(kCorrectType, result_prompt_type); + EXPECT_EQ(kCorrectDisplayText1, result_display_text_1); + EXPECT_EQ(kCorrectDisplayText2, result_display_text_2); + + EXPECT_EQ(true, perform_msg_params[am::strings::mute_audio].asBool()); +} + +TEST_F(PerformAudioPassThruRequestTest, + Run_InitPromptCorrect_SpeakAndPerformAPTRequestsSendMuteFalse) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + const bool muted = false; + + msg_params_[am::strings::mute_audio] = muted; + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + } + CallRun caller(*command_sptr_); + caller(); + + EXPECT_EQ( + muted, + (*perform_result_msg)[am::strings::msg_params][am::strings::mute_audio] + .asBool()); +} + +TEST_F( + PerformAudioPassThruRequestTest, + Run_InitPromptEmpty_PerformAndRecordStartNotificationsAndStartRecording) { + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + MessageSharedPtr start_record_result_msg; + MessageSharedPtr perform_result_msg; + { + InSequence dummy; + + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // Perform audio path thru request sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_OnRecordStart)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // Start recording notification sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&start_record_result_msg), Return(true))); + } + + // Start microphone recording cals + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); + EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); + + CallRun caller(*command_sptr_); + caller(); + + const hmi_apis::FunctionID::eType start_record_result_function_id = + static_cast<hmi_apis::FunctionID::eType>( + (*start_record_result_msg)[am::strings::params] + [am::strings::function_id].asInt()); + EXPECT_EQ(hmi_apis::FunctionID::UI_OnRecordStart, + start_record_result_function_id); +} + +TEST_F(PerformAudioPassThruRequestTest, OnEvent_UIPAPT_Rejected) { + am::event_engine::Event event(hmi_apis::FunctionID::UI_PerformAudioPassThru); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::REJECTED; + event.set_smart_object(*message_); + + CallOnEvent caller(*command_sptr_, event); + + MessageSharedPtr result_message = CatchMobileCommandResult(caller); + + const am::mobile_api::Result::eType result_code = + static_cast<am::mobile_api::Result::eType>( + (*result_message)[am::strings::msg_params][am::strings::result_code] + .asInt()); + + EXPECT_EQ(am::mobile_api::Result::REJECTED, result_code); +} + +TEST_F(PerformAudioPassThruRequestTest, + OnEvent_TTSSpeakSuccess_UpdateRequestTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + event.set_smart_object(*message_); + + // Start recording notification sending + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + // Start microphone recording cals + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)); + EXPECT_CALL(app_mngr_, StartAudioPassThruThread(_, _, _, _, _, _)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_PAPTunsupportedResource_CorrectInfo) { + const std::string return_info = "Unsupported phoneme type sent in a prompt"; + + am::event_engine::Event event_speak(hmi_apis::FunctionID::TTS_Speak); + am::event_engine::Event event_perform( + hmi_apis::FunctionID::UI_PerformAudioPassThru); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + event_speak.set_smart_object(*message_); + + (*message_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + event_perform.set_smart_object(*message_); + + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + // First call on_event for setting result_tts_speak_ to UNSUPPORTED_RESOURCE + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + CallOnEvent caller_speak(*command_sptr_, event_speak); + caller_speak(); + + // Second call for test correct behavior of UI_PerformAudioPassThru event + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(false)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)).Times(0); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller_perform(*command_sptr_, event_perform); + + MessageSharedPtr perform_event_result = + CatchMobileCommandResult(caller_perform); + + EXPECT_EQ(return_info, + (*perform_event_result)[am::strings::msg_params][am::strings::info] + .asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_TTSSpeak_UpdateTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_Speak); + + msg_params_[am::strings::connection_key] = kConnectionKey; + msg_params_[am::strings::function_id] = kFunctionId; + msg_params_[am::strings::correlation_id] = kCorrelationId; + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); + + EXPECT_CALL( + app_mngr_, + StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller(*command_sptr_, event); + caller(); + + EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); + EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_OnEvent_TTSOnResetTimeout_UpdateTimeout) { + am::event_engine::Event event(hmi_apis::FunctionID::TTS_OnResetTimeout); + + msg_params_[am::strings::connection_key] = kConnectionKey; + msg_params_[am::strings::function_id] = kFunctionId; + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, BeginAudioPassThru(app_id)).WillOnce(Return(true)); + + EXPECT_CALL( + app_mngr_, + StartAudioPassThruThread(kConnectionKey, kCorrelationId, _, _, _, _)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + CallOnEvent caller(*command_sptr_, event); + caller(); + + EXPECT_EQ(kConnectionKey, msg_params_[am::strings::connection_key].asUInt()); + EXPECT_EQ(kFunctionId, msg_params_[am::strings::function_id].asString()); +} + +TEST_F(PerformAudioPassThruRequestTest, OnEvent_DefaultCase) { + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).Times(0); + + CallOnEvent caller(*command_sptr_, event); + caller(); +} + +TEST_F(PerformAudioPassThruRequestTest, Init_CorrectTimeout) { + const uint32_t kDefaultTimeout = command_sptr_->default_timeout(); + const uint32_t kMaxDuration = 10000u; + + msg_params_[am::strings::max_duration] = kMaxDuration; + + command_sptr_->Init(); + + EXPECT_EQ(kDefaultTimeout + kMaxDuration, command_sptr_->default_timeout()); +} + +TEST_F(PerformAudioPassThruRequestTest, + onTimeOut_ttsSpeakNotActive_DontSendHMIReqeust) { + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + // For setting current_state_ -> kCompleted + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + command_sptr_->onTimeOut(); +} + +TEST_F(PerformAudioPassThruRequestTest, + DISABLED_onTimeOut_ttsSpeakActive_SendHMIReqeust) { + uint32_t app_id = kConnectionKey; + EXPECT_CALL(app_mngr_, EndAudioPassThru(app_id)).WillOnce(Return(true)); + EXPECT_CALL(app_mngr_, StopAudioPassThru(_)); + + EXPECT_CALL(*application_sptr_, hmi_level()) + .WillOnce(Return(am::mobile_api::HMILevel::HMI_FULL)); + + msg_params_[am::strings::initial_prompt][0][am::strings::text] = + kCorrectPrompt; + msg_params_[am::strings::initial_prompt][0][am::strings::type] = kCorrectType; + + EXPECT_CALL(mock_message_helper_, + VerifyTtsFiles(msg_params_[am::strings::initial_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + MessageSharedPtr speak_reqeust_result_msg; + MessageSharedPtr perform_result_msg; + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_Speak)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&speak_reqeust_result_msg), Return(true))); + + // Perform audio path thru request sending + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_PerformAudioPassThru)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&perform_result_msg), Return(true))); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(msg)); + + // For setting is_active_tts_speak -> true + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .Times(2) + .WillRepeatedly(Return(false)); + CallRun caller(*command_sptr_); + caller(); + + // For setting current_state_ -> kCompleted + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)); + command_sptr_->SendResponse(true, am::mobile_api::Result::SUCCESS); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_StopSpeaking))) + .WillOnce(Return(false)); + + command_sptr_->onTimeOut(); +} + +} // namespace perform_audio_pass_thru_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc new file mode 100644 index 0000000000..3b68d3ea72 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/perform_interaction_test.cc @@ -0,0 +1,261 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/perform_interaction_request.h" + +#include "gtest/gtest.h" +#include "utils/helpers.h" +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace perform_interaction_request { + +namespace am = application_manager; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using sdl_rpc_plugin::commands::PerformInteractionRequest; +using ::test::components::application_manager_test::MockApplication; + +namespace strings = ::application_manager::strings; +namespace hmi_response = ::application_manager::hmi_response; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class PerformInteractionRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + PerformInteractionRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +TEST_F(PerformInteractionRequestTest, OnTimeout_VR_GENERIC_ERROR) { + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + static_cast<uint64_t>(hmi_apis::Common_Result::SUCCESS); + (*response_msg_vr)[strings::msg_params][strings::info] = "info"; + MessageSharedPtr request_msg = CreateMessage(smart_objects::SmartType_Map); + (*request_msg)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::BOTH; + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(request_msg); + MockAppPtr mock_app; + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + Event event(hmi_apis::FunctionID::VR_PerformInteraction); + event.set_smart_object(*response_msg_vr); + + command->Init(); + command->on_event(event); + MessageSharedPtr response_to_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*response_to_mobile)[strings::msg_params][strings::result_code] = + static_cast<uint64_t>(am::mobile_api::Result::GENERIC_ERROR); + EXPECT_CALL( + mock_message_helper_, + CreateNegativeResponse(_, _, _, am::mobile_api::Result::GENERIC_ERROR)) + .WillOnce(Return(response_to_mobile)); + + MessageSharedPtr vr_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + command->onTimeOut(); + + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::success].asBool(), + false); + EXPECT_EQ( + (*vr_command_result)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(am::mobile_api::Result::GENERIC_ERROR)); +} + +TEST_F(PerformInteractionRequestTest, + OnEvent_VRHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::VR_ONLY; + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + command->Init(); + + MockAppPtr mock_app; + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app)); + + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_msg_vr)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_vr)[am::strings::msg_params][am::strings::info] = + "VR is not supported by system"; + + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "VR is not supported by system"); +} + +TEST_F(PerformInteractionRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_from_mobile = + CreateMessage(smart_objects::SmartType_Map); + (*msg_from_mobile)[strings::params][strings::connection_key] = kConnectionKey; + (*msg_from_mobile)[strings::msg_params][strings::interaction_mode] = + mobile_apis::InteractionMode::VR_ONLY; + std::shared_ptr<PerformInteractionRequest> command = + CreateCommand<PerformInteractionRequest>(msg_from_mobile); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VR)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + MessageSharedPtr response_msg_vr = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_vr)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + am::event_engine::Event event_vr(hmi_apis::FunctionID::VR_PerformInteraction); + event_vr.set_smart_object(*response_msg_vr); + + MessageSharedPtr response_msg_ui = + CreateMessage(smart_objects::SmartType_Map); + (*response_msg_ui)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*response_msg_ui)[strings::msg_params][strings::cmd_id] = kCommandId; + (*response_msg_ui)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + am::event_engine::Event event_ui(hmi_apis::FunctionID::UI_PerformInteraction); + event_ui.set_smart_object(*response_msg_ui); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_vr); + + EXPECT_CALL(*mock_app_, is_perform_interaction_active()) + .WillOnce(Return(false)); + EXPECT_CALL(*mock_app_, DeletePerformInteractionChoiceSet(_)); + + command->on_event(event_ui); + + ResultCommandExpectations(response_to_mobile, + "UI is not supported by system"); +} + +} // namespace perform_interaction_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc new file mode 100644 index 0000000000..df4f69f0d0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/put_file_test.cc @@ -0,0 +1,406 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> + +#include "gtest/gtest.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" + +#include "mobile/put_file_response.h" +#include "mobile/put_file_request.h" + +#include "utils/file_system.h" +#include "smart_objects/smart_object.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/application.h" +#include "application_manager/mock_application.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace put_file { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::AtLeast; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::PutFileRequest; +using sdl_rpc_plugin::commands::PutFileResponse; +using am::commands::MessageSharedPtr; +using policy_test::MockPolicyHandlerInterface; + +typedef std::shared_ptr<PutFileRequest> PutFileRequestPtr; +typedef std::shared_ptr<PutFileResponse> PutFileResponsePtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const std::string kFileName = "sync_file_name.txt"; +const int64_t kOffset = 10u; +const int64_t kZeroOffset = 0u; +const std::string kStorageFolder = "./storage"; +const std::string kFolder = "folder"; +const std::string kAppFolder = "app_folder"; +} + +class PutFileRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + PutFileRequestTest() + : msg_(CreateMessage(::smart_objects::SmartType_Map)) + , mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + binary_data_.push_back(1u); + + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::sync_file_name] = kFileName; + (*msg_)[am::strings::msg_params][am::strings::persistent_file] = true; + (*msg_)[am::strings::msg_params][am::strings::file_type] = + mobile_apis::FileType::JSON; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, hmi_level()) + .WillByDefault(Return(mobile_apis::HMILevel::HMI_FULL)); + } + + void ExpectReceiveMessageFromSDK() { + EXPECT_CALL(mock_policy_handler_, + ReceiveMessageFromSDK(kFileName, binary_data_)) + .WillOnce(Return(false)); + } + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; + std::vector<uint8_t> binary_data_; +}; + +class PutFileResponceTest : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + PutFileResponceTest() : message_(CreateMessage()) {} + + void SetUp() OVERRIDE { + command_sptr_ = CreateCommand<PutFileResponse>(message_); + } + + MessageSharedPtr message_; + std::shared_ptr<PutFileResponse> command_sptr_; +}; + +TEST_F(PutFileResponceTest, Run_InvalidApp_ApplicationNotRegisteredResponce) { + ::smart_objects::SmartObject& message_ref = *message_; + + message_ref[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + std::shared_ptr<am::Application> null_application_sptr; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(null_application_sptr)); + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile( + MobileResultCodeIs(mobile_apis::Result::APPLICATION_NOT_REGISTERED), + _)); + command_sptr_->Run(); +} + +TEST_F(PutFileResponceTest, Run_ApplicationRegistered_Success) { + ::smart_objects::SmartObject& message_ref = *message_; + + message_ref[am::strings::params][am::strings::connection_key] = + kConnectionKey; + message_ref[am::strings::msg_params][am::strings::success] = true; + + std::shared_ptr<am::Application> application_sptr = + std::make_shared<MockApplication>(); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(application_sptr)); + EXPECT_CALL( + mock_rpc_service_, + SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + command_sptr_->Run(); +} + +TEST_F(PutFileRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_HmiLevelNone_UNSUCCESS) { + EXPECT_CALL(*mock_app_, hmi_level()) + .WillOnce(Return(mobile_apis::HMILevel::HMI_NONE)); + + const uint32_t settings_put_file_in_none = 1u; + const uint32_t app_put_file_in_none_count = 2u; + EXPECT_CALL(app_mngr_settings_, put_file_in_none()) + .WillOnce(ReturnRef(settings_put_file_in_none)); + EXPECT_CALL(*mock_app_, put_file_in_none_count()) + .WillOnce(Return(app_put_file_in_none_count)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_BinaryDataDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::params].erase(am::strings::binary_data); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_SyncFileNameDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::msg_params].erase(am::strings::sync_file_name); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_FileTypeDoesNotExists_UNSUCCESS) { + (*msg_)[am::strings::msg_params].erase(am::strings::file_type); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_BinaryDataGreaterThanAvaliableSpace_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 0u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::OUT_OF_MEMORY); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_IvalidCreationDirectory_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + + const std::string storage_folder = "/storage"; + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(storage_folder)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::GENERIC_ERROR); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_IvalidUpdateFile_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 2u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)) + .WillOnce(Return(avaliable_space)); + + const std::string file_path = kStorageFolder + "/" + kAppFolder; + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(false)); + EXPECT_CALL(*mock_app_, UpdateFile(_)).WillOnce(Return(false)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_AddFile_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = false; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, app_storage_folder()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(*mock_app_, folder_name()).WillOnce(Return(kAppFolder)); + + const uint32_t avaliable_space = 2u; + EXPECT_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillOnce(Return(avaliable_space)) + .WillOnce(Return(avaliable_space)); + + const std::string file_path = kStorageFolder + "/" + kAppFolder; + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, file_path, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, AddFile(_)).WillOnce(Return(true)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_SendOnPutFileNotification_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnPutFile))) + .WillOnce(Return(true)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_InvalidPutFile_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::offset] = kZeroOffset; + (*msg_)[am::strings::msg_params][am::strings::system_file] = true; + + ExpectReceiveMessageFromSDK(); + EXPECT_CALL(app_mngr_settings_, system_files_path()) + .WillOnce(ReturnRef(kStorageFolder)); + EXPECT_CALL(app_mngr_, + SaveBinary(binary_data_, kStorageFolder, kFileName, kZeroOffset)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + command->Run(); +} + +TEST_F(PutFileRequestTest, Run_CrcSumEqual_SendSuccessResponse) { + binary_data_ = {1u}; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + const uint32_t correct_crc_sum = + 2768625435u; // calculated using the GetCrc32CheckSum method + (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = + correct_crc_sum; + + ExpectReceiveMessageFromSDK(); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStorageFolder)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); + const size_t available_space = binary_data_.size() + 1; + ON_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillByDefault(Return(available_space)); + ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); + + const std::string file_path = kStorageFolder + "/" + kFolder; + EXPECT_CALL(app_mngr_, SaveBinary(binary_data_, file_path, kFileName, 0u)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, increment_put_file_in_none_count()); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::SUCCESS); + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + ASSERT_TRUE(command->Init()); + command->Run(); + // The folder was created in the "Run" method + EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); +} + +TEST_F(PutFileRequestTest, Run_CrcSumUnequal_SendCorruptedDataResponse) { + binary_data_ = {1u}; + (*msg_)[am::strings::params][am::strings::binary_data] = binary_data_; + const uint32_t incorrect_crc_sum = 0u; + (*msg_)[am::strings::msg_params][am::strings::crc32_check_sum] = + incorrect_crc_sum; + + ExpectReceiveMessageFromSDK(); + ON_CALL(app_mngr_, get_settings()) + .WillByDefault(ReturnRef(app_mngr_settings_)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kStorageFolder)); + ON_CALL(*mock_app_, folder_name()).WillByDefault(Return(kFolder)); + const size_t available_space = binary_data_.size() + 1; + ON_CALL(*mock_app_, GetAvailableDiskSpace()) + .WillByDefault(Return(available_space)); + ON_CALL(*mock_app_, AddFile(_)).WillByDefault(Return(true)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::CORRUPTED_DATA); + EXPECT_CALL(app_mngr_, SaveBinary(_, _, _, _)).Times(0); + PutFileRequestPtr command(CreateCommand<PutFileRequest>(msg_)); + ASSERT_TRUE(command->Init()); + command->Run(); + // The folder was created in the "Run" method + EXPECT_TRUE(file_system::RemoveDirectory(kStorageFolder, true)); +} + +} // namespace put_file +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc new file mode 100644 index 0000000000..7dab16fe35 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/register_app_interface_request_test.cc @@ -0,0 +1,536 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> + +#include "gtest/gtest.h" +#include "mobile/register_app_interface_request.h" +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_helper.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "protocol_handler/mock_session_observer.h" +#include "connection_handler/mock_connection_handler.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_resume_ctrl.h" +#include "application_manager/mock_hmi_interface.h" +#include "utils/data_accessor.h" +#include "utils/custom_string.h" +#include "utils/lock.h" +#include "utils/macro.h" +#include "utils/semantic_version.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace register_app_interface_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; + +namespace am = ::application_manager; + +using am::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::RegisterAppInterfaceRequest; + +namespace { +const uint32_t kConnectionKey = 1u; +const hmi_apis::Common_Language::eType kHmiLanguage = + hmi_apis::Common_Language::EN_US; +const mobile_apis::Language::eType kMobileLanguage = + mobile_apis::Language::EN_US; +const std::string kMacAddress = "test_mac_address"; +const std::string kAppId = "test_app_id"; +const std::string kFullAppId = "test_app_id_long"; +const std::string kDummyString = "test_string"; +const std::vector<uint32_t> kDummyDiagModes; +const utils::SemanticVersion mock_semantic_version(1, 0, 0); +} // namespace + +class RegisterAppInterfaceRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + RegisterAppInterfaceRequestTest() + : msg_(CreateMessage()) + , command_(CreateCommand<RegisterAppInterfaceRequest>(msg_)) + , app_name_("test_app_name_") + , lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , mock_application_helper_( + application_manager_test::MockApplicationHelper:: + application_helper_mock()) { + InitGetters(); + InitLanguage(); + } + + void SetUp() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + + void TearDown() OVERRIDE { + testing::Mock::VerifyAndClearExpectations(&mock_application_helper_); + } + + void InitBasicMessage() { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::app_id] = kAppId; + (*msg_)[am::strings::msg_params][am::strings::full_app_id] = kFullAppId; + (*msg_)[am::strings::msg_params][am::strings::app_name] = app_name_; + (*msg_)[am::strings::msg_params][am::strings::language_desired] = + kHmiLanguage; + (*msg_)[am::strings::msg_params] + [am::strings::hmi_display_language_desired] = kHmiLanguage; + (*msg_)[am::strings::msg_params][am::strings::sync_msg_version] + [am::strings::major_version] = 4; + (*msg_)[am::strings::msg_params][am::strings::sync_msg_version] + [am::strings::minor_version] = 0; + (*msg_)[am::strings::msg_params][am::strings::sync_msg_version] + [am::strings::patch_version] = 0; + } + + MockAppPtr CreateBasicMockedApp() { + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(*mock_app, name()).WillByDefault(ReturnRef(app_name_)); + ON_CALL(*mock_app, mac_address()).WillByDefault(ReturnRef(kMacAddress)); + ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(kDummyString)); + ON_CALL(*mock_app, language()).WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(*mock_app, ui_language()).WillByDefault(ReturnRef(kMobileLanguage)); + ON_CALL(*mock_app, policy_app_id()).WillByDefault(Return(kAppId)); + ON_CALL(*mock_app, msg_version()) + .WillByDefault(ReturnRef(mock_semantic_version)); + return mock_app; + } + + void InitLanguage( + hmi_apis::Common_Language::eType ui_language = kHmiLanguage, + hmi_apis::Common_Language::eType vr_language = kHmiLanguage, + hmi_apis::Common_Language::eType tts_language = kHmiLanguage) { + ON_CALL(mock_hmi_capabilities_, active_vr_language()) + .WillByDefault(Return(vr_language)); + ON_CALL(mock_hmi_capabilities_, active_ui_language()) + .WillByDefault(Return(ui_language)); + ON_CALL(mock_hmi_capabilities_, active_tts_language()) + .WillByDefault(Return(tts_language)); + } + + void InitGetters() { + ON_CALL(app_mngr_, GetCorrectMobileIDFromMessage(msg_)) + .WillByDefault(Return(kAppId)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(true)); + ON_CALL(app_mngr_, resume_controller()) + .WillByDefault(ReturnRef(mock_resume_crt_)); + ON_CALL(app_mngr_, connection_handler()) + .WillByDefault(ReturnRef(mock_connection_handler_)); + ON_CALL(mock_connection_handler_, get_session_observer()) + .WillByDefault(ReturnRef(mock_session_observer_)); + ON_CALL(app_mngr_settings_, sdl_version()) + .WillByDefault(ReturnRef(kDummyString)); + ON_CALL(mock_hmi_capabilities_, ccpu_version()) + .WillByDefault(ReturnRef(kDummyString)); + ON_CALL(app_mngr_settings_, supported_diag_modes()) + .WillByDefault(ReturnRef(kDummyDiagModes)); + ON_CALL(mock_policy_handler_, GetAppRequestTypes(_)) + .WillByDefault(Return(std::vector<std::string>())); + ON_CALL(mock_policy_handler_, GetAppRequestTypeState(_)) + .WillByDefault(Return(policy::RequestType::State::EMPTY)); + ON_CALL(mock_policy_handler_, GetAppRequestSubTypes(_)) + .WillByDefault(Return(std::vector<std::string>())); + ON_CALL(mock_policy_handler_, GetAppRequestSubTypeState(_)) + .WillByDefault(Return(policy::RequestSubType::State::EMPTY)); + ON_CALL(mock_policy_handler_, GetUserConsentForDevice(_)) + .WillByDefault(Return(policy::DeviceConsent::kDeviceAllowed)); + ON_CALL(app_mngr_, GetDeviceTransportType(_)) + .WillByDefault(Return(hmi_apis::Common_TransportType::WIFI)); + ON_CALL(app_mngr_, IsAppInReconnectMode(_)).WillByDefault(Return(false)); + ON_CALL(app_mngr_, application_by_policy_id(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + ON_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::VR_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_VR)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_ChangeRegistration)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + } + + void SetCommonExpectionsOnSwitchedApplication( + MockAppPtr mock_app, mobile_apis::Result::eType response_result_code) { + EXPECT_CALL(mock_policy_handler_, AddApplication(_, _)).Times(0); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(response_result_code), _)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_ChangeRegistration))).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_ChangeRegistration))).Times(0); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::VR_ChangeRegistration))).Times(0); + + EXPECT_CALL(app_mngr_, + OnApplicationSwitched( + std::static_pointer_cast<application_manager::Application>( + mock_app))); + } + + MessageSharedPtr msg_; + std::shared_ptr<RegisterAppInterfaceRequest> command_; + + const utils::custom_string::CustomString app_name_; + std::shared_ptr<sync_primitives::Lock> lock_ptr_; + am::ApplicationSet app_set_; + + typedef IsNiceMock<policy_test::MockPolicyHandlerInterface, + kMocksAreNice>::Result MockPolicyHandlerInterface; + + typedef IsNiceMock<resumprion_test::MockResumeCtrl, kMocksAreNice>::Result + MockResumeCtrl; + + typedef IsNiceMock<connection_handler_test::MockConnectionHandler, + kMocksAreNice>::Result MockConnectionHandler; + + typedef IsNiceMock<protocol_handler_test::MockSessionObserver, + kMocksAreNice>::Result MockSessionObserver; + + typedef IsNiceMock<application_manager_test::MockHMICapabilities, + kMocksAreNice>::Result MockHMICapabilities; + + MockResumeCtrl mock_resume_crt_; + MockConnectionHandler mock_connection_handler_; + MockSessionObserver mock_session_observer_; + application_manager_test::MockApplicationHelper& mock_application_helper_; +}; + +TEST_F(RegisterAppInterfaceRequestTest, Init_SUCCESS) { + EXPECT_TRUE(command_->Init()); +} + +TEST_F(RegisterAppInterfaceRequestTest, Run_MinimalData_SUCCESS) { + InitBasicMessage(); + (*msg_)[am::strings::msg_params][am::strings::hash_id] = kAppId; + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())) + .WillRepeatedly(Return(mock_app)); + + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + std::make_shared<utils::CallNothing>(); + ON_CALL(mock_policy_handler_, AddApplication(_, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + command_->Run(); +} + +MATCHER_P(CheckHMIInterfacesRealtedData, expected_data, "") { + const bool is_result_id_correct = + mobile_apis::Result::SUCCESS == + static_cast<mobile_apis::Result::eType>( + (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); + + const bool are_ui_related_data_exist = + (*arg)[am::strings::msg_params].keyExists( + am::hmi_response::display_capabilities); + + const bool are_vi_related_data_exist = + (*arg)[am::strings::msg_params][am::hmi_response::vehicle_type] == + (*expected_data)[am::hmi_response::vehicle_type]; + + const bool are_vr_related_data_exist = + (*arg)[am::strings::msg_params][am::strings::vr_capabilities] == + (*expected_data)[am::strings::vr_capabilities]; + + return is_result_id_correct && are_ui_related_data_exist && + are_vi_related_data_exist && are_vr_related_data_exist; +} + +TEST_F(RegisterAppInterfaceRequestTest, + Run_HmiInterfacesStateAvailable_SUCCESS) { + InitBasicMessage(); + + EXPECT_CALL(app_mngr_, IsStopping()) + .WillOnce(Return(false)) + .WillOnce(Return(true)) + .WillOnce(Return(false)); + ON_CALL(app_mngr_, IsHMICooperating()).WillByDefault(Return(false)); + EXPECT_CALL(app_mngr_, updateRequestTimeout(_, _, _)); + EXPECT_CALL(app_mngr_, IsApplicationForbidden(_, _)).WillOnce(Return(false)); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())) + .WillRepeatedly(Return(mock_app)); + + MessageSharedPtr expected_message = + CreateMessage(smart_objects::SmartType_Map); + + (*expected_message)[am::hmi_response::vehicle_type] = "test_vehicle_type"; + (*expected_message)[am::strings::vr_capabilities] = "test_vr_capabilities"; + (*expected_message)[am::hmi_response::display_capabilities] = 0; + SmartObject& display_capabilities = + (*expected_message)[am::hmi_response::display_capabilities]; + display_capabilities[am::hmi_response::display_type] = "test_display_type"; + display_capabilities[am::hmi_response::display_name] = "GENERIC_DISPLAY"; + display_capabilities[am::hmi_response::text_fields] = "test_text_fields"; + display_capabilities[am::hmi_response::image_fields] = "test_image_fields"; + display_capabilities[am::hmi_response::media_clock_formats] = + "test_media_clock_ptr_formats"; + display_capabilities[am::hmi_response::num_custom_presets_available] = + "test_num_custom_presets_available"; + display_capabilities[am::hmi_response::graphic_supported] = + "test_graphic_supported"; + display_capabilities[am::hmi_response::templates_available] = + "test_templates_available"; + display_capabilities[am::hmi_response::screen_params] = "test_screen_params"; + + ON_CALL(mock_hmi_capabilities_, vehicle_type()) + .WillByDefault( + Return(&(*expected_message)[am::hmi_response::vehicle_type])); + ON_CALL(mock_hmi_capabilities_, vr_capabilities()) + .WillByDefault( + Return(&(*expected_message)[am::strings::vr_capabilities])); + ON_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillByDefault( + Return(&(*expected_message)[am::hmi_response::display_capabilities])); + + ON_CALL(app_mngr_, applications()) + .WillByDefault( + Return(DataAccessor<am::ApplicationSet>(app_set_, lock_ptr_))); + ON_CALL(mock_policy_handler_, PolicyEnabled()).WillByDefault(Return(true)); + ON_CALL(mock_policy_handler_, GetInitialAppData(kAppId, _, _)) + .WillByDefault(Return(true)); + policy::StatusNotifier notify_upd_manager = + std::make_shared<utils::CallNothing>(); + ON_CALL(mock_policy_handler_, AddApplication(_, _)) + .WillByDefault(Return(notify_upd_manager)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::BasicCommunication_OnAppRegistered))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::VR_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_ChangeRegistration))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .Times(2); + EXPECT_CALL(app_mngr_, SendDriverDistractionState(_)); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_CorrectHash_ExpectNoCleanupSuccess) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + std::static_pointer_cast<application_manager::Application>(mock_app), + request_hash_id)).WillOnce(Return(true)); + + EXPECT_CALL(mock_resume_crt_, RemoveApplicationFromSaved(_)).Times(0); + + EXPECT_CALL(mock_application_helper_, RecallApplicationData(_, _)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::SUCCESS); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_WrongHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + const std::string request_hash_id = "abc123"; + (*msg_)[am::strings::msg_params][am::strings::hash_id] = request_hash_id; + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_resume_crt_, + CheckApplicationHash( + std::static_pointer_cast<application_manager::Application>(mock_app), + request_hash_id)).WillOnce(Return(false)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + std::static_pointer_cast<application_manager::Application>(mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + +TEST_F(RegisterAppInterfaceRequestTest, + SwitchApplication_NoHash_ExpectCleanupResumeFailed) { + InitBasicMessage(); + + MockAppPtr mock_app = CreateBasicMockedApp(); + EXPECT_CALL(app_mngr_, application_by_policy_id(kAppId)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(app_mngr_, IsAppInReconnectMode(kAppId)).WillOnce(Return(true)); + + EXPECT_CALL(app_mngr_, ProcessReconnection(_, kConnectionKey)); + + EXPECT_CALL( + mock_application_helper_, + RecallApplicationData( + std::static_pointer_cast<application_manager::Application>(mock_app), + _)); + + EXPECT_CALL(app_mngr_, RegisterApplication(msg_)).Times(0); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + SetCommonExpectionsOnSwitchedApplication(mock_app, + mobile_apis::Result::RESUME_FAILED); + + command_->Run(); +} + +} // namespace register_app_interface_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc new file mode 100644 index 0000000000..0e3cd685fa --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/reset_global_properties_test.cc @@ -0,0 +1,575 @@ +/* + * 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 <stdint.h> +#include <string> +#include <vector> + +#include "mobile/reset_global_properties_request.h" +#include "mobile/reset_global_properties_response.h" + +#include "gtest/gtest.h" +#include "smart_objects/smart_object.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace reset_global_properties { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::ResetGlobalPropertiesRequest; +using sdl_rpc_plugin::commands::ResetGlobalPropertiesResponse; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; + +typedef std::shared_ptr<ResetGlobalPropertiesRequest> + ResetGlobalPropertiesRequestPtr; +typedef std::shared_ptr<ResetGlobalPropertiesResponse> + ResetGlobalPropertiesResponsePtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 10u; +} // namespace + +class ResetGlobalPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + protected: + ResetGlobalPropertiesRequestTest() + : msg_(CreateMessage()), mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + command_ = CreateCommand<ResetGlobalPropertiesRequest>(msg_); + + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillByDefault(Return(kCorrelationId)); + } + + MessageSharedPtr msg_; + MockAppPtr mock_app_; + ResetGlobalPropertiesRequestPtr command_; +}; + +class ResetGlobalPropertiesResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidApp_UNSUCCESS) { + MockAppPtr invalid_app; + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(invalid_app)); + + MessageSharedPtr command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&command_result), Return(true))); + + command_->Run(); + EXPECT_EQ( + (*command_result)[am::strings::msg_params][am::strings::success].asBool(), + false); + EXPECT_EQ( + (*command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_apis::Result::APPLICATION_NOT_REGISTERED)); +} + +TEST_F(ResetGlobalPropertiesRequestTest, Run_InvalidVrHelp_UNSUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::HELPPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][2] = + mobile_apis::GlobalProperty::VRHELPTITLE; + (*msg_)[am::strings::msg_params][am::strings::properties][3] = + mobile_apis::GlobalProperty::MENUNAME; + (*msg_)[am::strings::msg_params][am::strings::properties][4] = + mobile_apis::GlobalProperty::MENUICON; + (*msg_)[am::strings::msg_params][am::strings::properties][5] = + mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + smart_objects::SmartObject so_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + smart_objects::SmartObject timeout_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + timeout_prompt[am::strings::text] = time_out_prompt[0]; + timeout_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + + smart_objects::SmartObject so_time_out_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + so_time_out_prompt[0] = timeout_prompt; + + EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help; // = NULL; + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + command_->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, Run_SUCCESS) { + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::HELPPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][2] = + mobile_apis::GlobalProperty::VRHELPTITLE; + (*msg_)[am::strings::msg_params][am::strings::properties][3] = + mobile_apis::GlobalProperty::MENUNAME; + (*msg_)[am::strings::msg_params][am::strings::properties][4] = + mobile_apis::GlobalProperty::MENUICON; + (*msg_)[am::strings::msg_params][am::strings::properties][5] = + mobile_apis::GlobalProperty::KEYBOARDPROPERTIES; + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + smart_objects::SmartObject so_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(*mock_app_, set_help_prompt(so_prompt)); + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + smart_objects::SmartObject timeout_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Map); + timeout_prompt[am::strings::text] = time_out_prompt[0]; + timeout_prompt[am::strings::type] = + hmi_apis::Common_SpeechCapabilities::SC_TEXT; + + smart_objects::SmartObject so_time_out_prompt = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + so_time_out_prompt[0] = timeout_prompt; + + EXPECT_CALL(*mock_app_, set_timeout_prompt(so_time_out_prompt)); + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::hmi_request::menu_title] = ""; + + EXPECT_CALL(*mock_app_, + set_menu_title(msg_params[am::hmi_request::menu_title])); + + const smart_objects::SmartObjectSPtr so_help_prompt = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(so_help_prompt.get())); + EXPECT_CALL(*mock_app_, timeout_prompt()) + .WillOnce(Return(so_help_prompt.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_UI_SetGlobalProperties_SUCCESS) { + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*msg_)[am::strings::params][am::hmi_response::code] = result_code; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::VRHELPTITLE; + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + smart_objects::SmartObjectSPtr vr_help = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + + event.set_smart_object(*msg_); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + OnEvent_TTS_SetGlobalProperties_SUCCESS) { + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + std::make_shared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + MessageSharedPtr ui_msg = CreateMessage(); + (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*ui_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); + ui_event.set_smart_object(*ui_msg); + + command_->Run(); + command_->on_event(ui_event); + event.set_smart_object(*msg_); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::WARNINGS), + am::commands::Command::SOURCE_SDL)); + + command_->on_event(event); +} + +TEST_F(ResetGlobalPropertiesResponseTest, Run_Sendmsg_SUCCESS) { + MessageSharedPtr message(CreateMessage()); + ResetGlobalPropertiesResponsePtr command( + CreateCommand<ResetGlobalPropertiesResponse>(message)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToMobile(message, _)); + command->Run(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, OnEvent_InvalidApp_NoHashUpdate) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::VRHELPTITLE; + + EXPECT_CALL(*mock_app_, reset_vr_help_title()); + EXPECT_CALL(*mock_app_, reset_vr_help()); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + smart_objects::SmartObjectSPtr vr_help = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, CreateAppVrHelp(_)) + .WillOnce(Return(vr_help)); + + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + ResetGlobalPropertiesRequestPtr command = + CreateCommand<ResetGlobalPropertiesRequest>(msg_); + command->Run(); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), + am::commands::Command::SOURCE_SDL)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitTTS_Timeout_GENERIC_ERROR_TTSNotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + std::make_shared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + ResetGlobalPropertiesRequestPtr command = + CreateCommand<ResetGlobalPropertiesRequest>(msg_); + command->Run(); + + // Received response only from UI + MessageSharedPtr ui_msg = CreateMessage(); + (*ui_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*ui_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*ui_msg)[am::strings::msg_params] = + SmartObject(smart_objects::SmartType_Map); + Event ui_event(hmi_apis::FunctionID::UI_SetGlobalProperties); + ui_event.set_smart_object(*ui_msg); + command->on_event(ui_event); + + // TTS doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + std::make_shared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + const std::string info = "TTS component does not respond"; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUI_Timeout_GENERIC_ERROR_UINotRespond) { + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + std::make_shared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + + // Received response only from TTS + MessageSharedPtr tts_msg = CreateMessage(); + (*tts_msg)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + (*tts_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + + Event tts_event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + tts_event.set_smart_object(*tts_msg); + command_->on_event(tts_event); + + // UI doesn't respond, so timeout should send generic error + smart_objects::SmartObjectSPtr response = + std::make_shared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + + const std::string info = "UI component does not respond"; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command_->onTimeOut(); +} + +TEST_F(ResetGlobalPropertiesRequestTest, + Run_WaitUIAndTTS_Timeout_GENERIC_ERROR_TTSAndUINotRespond) { + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::UNSUPPORTED_RESOURCE; + + (*msg_)[am::strings::msg_params][am::strings::properties][0] = + mobile_apis::GlobalProperty::TIMEOUTPROMPT; + (*msg_)[am::strings::msg_params][am::strings::properties][1] = + mobile_apis::GlobalProperty::MENUICON; + + std::vector<std::string> time_out_prompt; + time_out_prompt.push_back("time_out"); + EXPECT_CALL(app_mngr_settings_, time_out_promt()) + .WillOnce(ReturnRef(time_out_prompt)); + + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)); + + smart_objects::SmartObjectSPtr prompt = + std::make_shared<smart_objects::SmartObject>(); + *prompt = "prompt"; + + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(prompt.get())); + + EXPECT_CALL(*mock_app_, set_reset_global_properties_active(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + + command_->Run(); + // TTS and UI don't respond, so timeout should send generic error + std::string info = "TTS, UI component does not respond"; + smart_objects::SmartObjectSPtr response = + std::make_shared<smart_objects::SmartObject>(); + (*response)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::GENERIC_ERROR; + EXPECT_CALL(mock_message_helper_, CreateNegativeResponse(_, _, _, _)) + .WillOnce(Return(response)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResponseIs(mobile_apis::Result::GENERIC_ERROR, info, false), + am::commands::Command::SOURCE_SDL)); + command_->onTimeOut(); +} + +} // namespace reset_global_properties +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc new file mode 100644 index 0000000000..cf25a82972 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/scrollable_message_test.cc @@ -0,0 +1,285 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/scrollable_message_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace scrollable_message_request { + +namespace am = application_manager; +namespace hmi_response = am::hmi_response; +namespace mobile_result = mobile_apis::Result; +namespace am = ::application_manager; + +using sdl_rpc_plugin::commands::ScrollableMessageRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Eq; +using ::testing::Ref; +using ::testing::Return; +using ::testing::ReturnRef; + +using namespace am::strings; +using test::components::policy_test::MockPolicyHandlerInterface; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kTimeOut = 30000u; +const uint32_t kCorrelationId = 10u; +const uint32_t kFunctionID = 3u; +} // namespace + +class ScrollableMessageRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + typedef TypeIf<kMocksAreNice, + NiceMock<application_manager_test::MockHMICapabilities>, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + sync_primitives::Lock lock_; + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void SetUp() OVERRIDE { + mock_app_ = CreateMockApp(); + command_ = CreateCommand<ScrollableMessageRequest>(msg_); + } + + MockAppPtr mock_app_; + MessageSharedPtr msg_; + std::shared_ptr<ScrollableMessageRequest> command_; +}; + +typedef ScrollableMessageRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(ScrollableMessageRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + std::shared_ptr<ScrollableMessageRequest> command = + CreateCommand<ScrollableMessageRequest>(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info1"; + + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_SUCCESS) { + (*msg_)[msg_params][timeout] = kTimeOut; + (*msg_)[msg_params][interaction_mode] = + mobile_apis::InteractionMode::MANUAL_ONLY; + EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + command_->Init(); + EXPECT_EQ(kTimeOut, command_->default_timeout()); +} + +TEST_F(ScrollableMessageRequestTest, Init_CorrectTimeout_UNSUCCESS) { + (*msg_)[msg_params][interaction_mode] = + mobile_apis::InteractionMode::MANUAL_ONLY; + EXPECT_EQ(kDefaultTimeout_, command_->default_timeout()); + command_->Init(); + EXPECT_EQ(kTimeOut, command_->default_timeout()); +} + +TEST_F(ScrollableMessageRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + command_->Run(); +} + +TEST_F(ScrollableMessageRequestTest, + Run_SoftButtonProcessingResultWrogParameters_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + const mobile_apis::Result::eType processing_result = + mobile_apis::Result::ABORTED; + smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; + EXPECT_CALL( + mock_message_helper_, + ProcessSoftButtons( + msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) + .WillOnce(Return(processing_result)); + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command_))); + EXPECT_EQ(processing_result, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][result_code].asInt())); +} + +TEST_F(ScrollableMessageRequestTest, Run_SoftButtonProcessingResult_SUCCESS) { + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app_)); + smart_objects::SmartObject& msg_params = (*msg_)[am::strings::msg_params]; + (*msg_)[am::strings::params][am::strings::function_id] = kFunctionID; + (*msg_)[am::strings::msg_params][am::strings::soft_buttons][0] + [am::strings::soft_button_id] = 0; + EXPECT_CALL( + mock_message_helper_, + ProcessSoftButtons( + msg_params, Eq(mock_app_), Ref(mock_policy_handler_), Ref(app_mngr_))) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); + EXPECT_EQ(hmi_apis::FunctionID::UI_ScrollableMessage, + static_cast<hmi_apis::FunctionID::eType>( + (*result_msg)[params][function_id].asInt())); +} + +TEST_F(ScrollableMessageRequestTest, OnEvent_ReceivedUnknownEvent_UNSUCCESS) { + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + Event event(hmi_apis::FunctionID::INVALID_ENUM); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + OnEvent_ReceivedUIOnResetTimeoutEvent_SUCCESS) { + (*msg_)[params][connection_key] = kConnectionKey; + (*msg_)[params][correlation_id] = kCorrelationId; + EXPECT_CALL( + app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, kDefaultTimeout_)); + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + DISABLED_OnEvent_ReceivedUIScrollableMessage_SUCCESS) { + (*msg_)[params][hmi_response::code] = hmi_apis::Common_Result::SUCCESS; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +TEST_F(ScrollableMessageRequestTest, + DISABLED_OnEvent_UnsupportedRCAndUICoop_SUCCESS) { + (*msg_)[params][hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::UNSUPPORTED_RESOURCE), _)); + Event event(hmi_apis::FunctionID::UI_ScrollableMessage); + event.set_smart_object(*msg_); + command_->on_event(event); +} + +} // namespace scrollable_message_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc new file mode 100644 index 0000000000..6c7127e48c --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_haptic_data_test.cc @@ -0,0 +1,164 @@ +/* + * 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 "application_manager/commands/commands_test.h" +#include "application_manager/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 sdl_rpc_plugin::commands::SendHapticDataRequest; +using sdl_rpc_plugin::commands::SendHapticDataResponse; +using am::commands::MessageSharedPtr; + +typedef std::shared_ptr<SendHapticDataRequest> SendHapticDataRequestPtr; +typedef std::shared_ptr<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_; + std::shared_ptr<SendHapticDataResponse> command_sptr_; +}; + +TEST_F(SendHapticDataRequestTest, Run_SUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand( + HMIResultCodeIs(hmi_apis::FunctionID::UI_SendHapticData))) + .WillOnce(Return(true)); + + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->Init(); + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, Run_DISALLOWED) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(*mock_app_, is_navi()).WillOnce(Return(false)); + + EXPECT_CALL(*mock_app_, mobile_projection_enabled()).WillOnce(Return(false)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(Return(true)); + + SendHapticDataRequestPtr command(CreateCommand<SendHapticDataRequest>(msg_)); + + command->Init(); + command->Run(); +} + +TEST_F(SendHapticDataRequestTest, OnEvent_SUCCESS) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), + am::commands::Command::SOURCE_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->Init(); + 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( + mock_rpc_service_, + SendMessageToMobile(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + command_sptr_->Init(); + command_sptr_->Run(); +} + +} // namespace send_haptic_data +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc new file mode 100644 index 0000000000..4f44293fc9 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/send_location_request_test.cc @@ -0,0 +1,421 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "mobile/send_location_request.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" + +#include "application_manager/commands/command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace send_location_request { + +using application_manager::commands::MessageSharedPtr; +using sdl_rpc_plugin::commands::SendLocationRequest; +using application_manager::MockMessageHelper; +using test::components::application_manager_test::MockHMICapabilities; +using smart_objects::SmartObject; + +using testing::_; +using testing::Return; +using testing::ReturnRef; + +namespace strings = application_manager::strings; +namespace hmi_response = application_manager::hmi_response; +namespace Common_TextFieldName = hmi_apis::Common_TextFieldName; + +namespace { +const uint32_t kConnectionKey = 1u; +const uint32_t kFunctionID = 2u; +const uint32_t kAppID = 3u; +const double kLongitudeDegrees = 13.4; +const std::string kLocationDescription = "Location_Description"; +const std::string kNewLine = "\\n"; +const std::string kAddressLine = "Address_Line"; +const std::string kPhoneNumber = "Phone_number"; +const std::string kCorrectAddress = "Correct address"; +const std::string kEmptyAddress = ""; +const std::string kAddressWithWrongSyntax = "Wrong Syntax\\n"; +} // namespace + +class SendLocationRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + class UnwrappedSendLocationRequest : public SendLocationRequest { + public: + UnwrappedSendLocationRequest( + const MessageSharedPtr& message, + application_manager::ApplicationManager& application_manager, + app_mngr::rpc_service::RPCService& rpc_service, + app_mngr::HMICapabilities& hmi_capabilities, + policy::PolicyHandlerInterface& policy_handler) + : SendLocationRequest(message, + application_manager, + rpc_service, + hmi_capabilities, + policy_handler) {} + ::application_manager::CommandParametersPermissions& + get_parameters_permissions() { + return parameters_permissions_; + } + }; + + typedef std::shared_ptr<UnwrappedSendLocationRequest> CommandSPrt; + + SendLocationRequestTest() { + mock_app_ = CreateMockApp(); + disp_cap_ = std::make_shared<SmartObject>(smart_objects::SmartType_Map); + message_ = CreateMessage(); + command_ = CreateCommand<UnwrappedSendLocationRequest>(message_); + } + + void InitialSetup(MessageSharedPtr message_) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + (*message_)[strings::params][strings::function_id] = kFunctionID; + (*message_)[strings::msg_params] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::address] = kCorrectAddress; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + AllowMandatoryFields(); + } + + void HMICapabilitiesSetupHelper() { + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + } + + void HMICapabilitiesSetupWithArguments( + Common_TextFieldName::eType field_name) { + HMICapabilitiesSetupHelper(); + (*disp_cap_)[hmi_response::text_fields] = + SmartObject(smart_objects::SmartType_Array); + (*disp_cap_)[hmi_response::text_fields][0] = + SmartObject(smart_objects::SmartType_Map); + (*disp_cap_)[hmi_response::text_fields][0][strings::name] = field_name; + EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) + .Times(2) + .WillRepeatedly(Return(disp_cap_.get())); + } + + void FinishSetup() { + EXPECT_CALL(*mock_app_, hmi_app_id()).WillOnce(Return(kAppID)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Navigation_SendLocation))); + } + + void FinishSetupCancelled(mobile_apis::Result::eType result) { + EXPECT_CALL(*mock_app_, hmi_app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(result), _)); + } + + void AllowMandatoryFields() { + application_manager::CommandParametersPermissions& permissions = + command_->get_parameters_permissions(); + permissions.allowed_params.insert(strings::longitude_degrees); + permissions.allowed_params.insert(strings::latitude_degrees); + } + + MockAppPtr mock_app_; + std::shared_ptr<SmartObject> disp_cap_; + MessageSharedPtr message_; + CommandSPrt command_; +}; + +TEST_F(SendLocationRequestTest, Run_InvalidApp_Success) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + FinishSetupCancelled(mobile_apis::Result::APPLICATION_NOT_REGISTERED); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_DeliveryMode_Success) { + InitialSetup(message_); + SmartObject msg_params = (*message_)[strings::msg_params]; + msg_params[strings::delivery_mode] = SmartObject(); + (*message_)[strings::msg_params] = msg_params; + msg_params.erase(strings::delivery_mode); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationNameWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_name] = "Location_Name\\n"; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationName); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationDescriptionWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_description] = + kLocationDescription + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::locationDescription); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesAreAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesAreNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = kAddressLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressLinesWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address_lines] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address_lines][0] = + kAddressLine + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::addressLines); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberIsAllowed_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberIsNotAllowed_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::INVALID_ENUM); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_PhoneNumberWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = + kPhoneNumber + kNewLine; + HMICapabilitiesSetupWithArguments(Common_TextFieldName::phoneNumber); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_AddressesContainWrongSyntax_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::address] = + SmartObject(smart_objects::SmartType_Array); + (*message_)[strings::msg_params][strings::address]["Address 1"] = + kCorrectAddress; + (*message_)[strings::msg_params][strings::address]["Address 2"] = + kAddressWithWrongSyntax; + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationImageValid_Success) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_image] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::location_image][strings::value] = + "1"; + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*message_)[strings::msg_params][strings::location_image], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationImageValid_Warnings) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_image] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::location_image][strings::value] = + "notavailable"; + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*message_)[strings::msg_params][strings::location_image], _, _)) + .WillOnce(Return(mobile_apis::Result::WARNINGS)); + FinishSetup(); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_LocationImageInvalid_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::location_image] = + SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::location_image][strings::value] = + "1"; + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*message_)[strings::msg_params][strings::location_image], _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + FinishSetupCancelled(mobile_apis::Result::INVALID_DATA); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, Run_HMIUINotCoop_Cancelled) { + InitialSetup(message_); + (*message_)[strings::msg_params][strings::phone_number] = kPhoneNumber; + (*disp_cap_)[hmi_response::text_fields] = + SmartObject(smart_objects::SmartType_Array); + (*disp_cap_)[hmi_response::text_fields][0] = + SmartObject(smart_objects::SmartType_Map); + (*disp_cap_)[hmi_response::text_fields][0][strings::name] = + Common_TextFieldName::phoneNumber; + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(false)); + FinishSetupCancelled(mobile_apis::Result::UNSUPPORTED_RESOURCE); + command_->Run(); +} + +TEST_F(SendLocationRequestTest, OnEvent_Success) { + mobile_apis::Result::eType response_code = mobile_apis::Result::SUCCESS; + (*message_)[strings::params][hmi_response::code] = response_code; + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + + Event event(hmi_apis::FunctionID::Navigation_SendLocation); + event.set_smart_object(*message_); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .WillOnce(Return(false)); + command_->on_event(event); +} + +TEST_F(SendLocationRequestTest, OnEvent_Cancelled) { + (*message_)[strings::params][hmi_response::code] = + mobile_apis::Result::SUCCESS; + Event event(hmi_apis::FunctionID::Navigation_OnWayPointChange); + event.set_smart_object(*message_); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)) + .Times(0); + command_->on_event(event); +} + +TEST_F(SendLocationRequestTest, Run_MandatoryParamsDisallowed_InvalidData) { + (*message_)[strings::params][strings::connection_key] = kConnectionKey; + (*message_)[strings::params][strings::function_id] = kFunctionID; + (*message_)[strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + (*message_)[strings::msg_params][strings::address] = kCorrectAddress; + (*message_)[strings::msg_params][strings::longitude_degrees] = + kLongitudeDegrees; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + application_manager::CommandParametersPermissions& permissions = + command_->get_parameters_permissions(); + // 1st one allowed + permissions.allowed_params.insert(strings::longitude_degrees); + // 2nd one disallowed + permissions.disallowed_params.insert(strings::latitude_degrees); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), _)); + command_->Run(); +} + +} // namespace send_location_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc new file mode 100644 index 0000000000..d8d1faca47 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_app_icon_test.cc @@ -0,0 +1,173 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/set_app_icon_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "protocol_handler/mock_protocol_handler.h" +#include "protocol_handler/mock_protocol_handler_settings.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_app_icon_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SetAppIconRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using am::MockHmiInterfaces; +using test::components::protocol_handler_test::MockProtocolHandler; +using test::components::protocol_handler_test::MockProtocolHandlerSettings; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +} // namespace + +class SetAppIconRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + NiceMock<MockHmiInterfaces> hmi_interfaces_; + protocol_handler_test::MockProtocolHandler mock_protocol_handler_; + protocol_handler_test::MockProtocolHandlerSettings + mock_protocol_handler_settings_; +}; + +TEST_F(SetAppIconRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + const std::string file_path = "file_path"; + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_vr)[am::strings::msg_params][am::strings::sync_file_name] + [am::strings::value] = file_path; + + const std::string dir_path = "./"; + ON_CALL(app_mngr_settings_, app_icons_folder()) + .WillByDefault(ReturnRef(dir_path)); + + std::shared_ptr<SetAppIconRequest> req_vr = + CreateCommand<SetAppIconRequest>(msg_vr); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(hmi_interfaces_)); + ON_CALL(hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + ON_CALL(app_mngr_, protocol_handler()) + .WillByDefault(ReturnRef(mock_protocol_handler_)); + ON_CALL(mock_protocol_handler_, get_settings()) + .WillByDefault(ReturnRef(mock_protocol_handler_settings_)); + + ON_CALL(mock_protocol_handler_settings_, max_supported_protocol_version()) + .WillByDefault( + Return(protocol_handler::MajorProtocolVersion::PROTOCOL_VERSION_4)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(*mock_app, set_app_icon_path(_)).WillByDefault(Return(true)); + ON_CALL(*mock_app, app_icon_path()).WillByDefault(ReturnRef(file_path)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info1"; + + Event event(hmi_apis::FunctionID::UI_SetAppIcon); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + req_vr->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +} // namespace set_app_icon_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc new file mode 100644 index 0000000000..cd6af1512d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_display_layout_test.cc @@ -0,0 +1,249 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/set_display_layout_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_hmi_capabilities.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_display_layout_request { + +namespace am = application_manager; +namespace mobile_result = mobile_apis::Result; +using sdl_rpc_plugin::commands::SetDisplayLayoutRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef std::shared_ptr<SetDisplayLayoutRequest> CommandPtr; + +namespace { +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationKey = 2u; +const std::string kLayout = "media"; +} // namespace + +MATCHER_P(CheckMshCorrId, corr_id, "") { + return (*arg)[am::strings::params][am::strings::correlation_id].asUInt() == + corr_id; +} + +class SetDisplayLayoutRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SetDisplayLayoutRequestTest() : mock_app_(CreateMockApp()) { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + typedef TypeIf<kMocksAreNice, + NiceMock<application_manager_test::MockHMICapabilities>, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + false); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + sync_primitives::Lock lock_; + MockAppPtr mock_app_; +}; + +typedef SetDisplayLayoutRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(SetDisplayLayoutRequestTest, + OnEvent_UIHmiUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + std::shared_ptr<SetDisplayLayoutRequest> command = + CreateCommand<SetDisplayLayoutRequest>(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); + event.set_smart_object(*msg); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetDisplayLayoutRequestTest, Run_InvalidApp_UNSUCCESS) { + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + + MockAppPtr invalid_mock_app; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(invalid_mock_app)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), + am::commands::Command::CommandSource::SOURCE_SDL)); + + command->Run(); +} + +TEST_F(SetDisplayLayoutRequestTest, Run_SUCCESS) { + MessageSharedPtr msg(CreateMessage(smart_objects::SmartType_Map)); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, display_layout()).WillOnce(ReturnRef(kLayout)); + EXPECT_CALL(*mock_app, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationKey)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetDisplayLayout)) + .WillRepeatedly(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(CheckMshCorrId(kCorrelationKey))) + .WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_InvalidEventId_UNSUCCESS) { + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>()); + am::event_engine::Event event(hmi_apis::FunctionID::INVALID_ENUM); + SmartObject msg(smart_objects::SmartType_Map); + + event.set_smart_object(msg); + + command->on_event(event); +} + +TEST_F(SetDisplayLayoutRequestTest, OnEvent_SUCCESS) { + am::event_engine::Event event(hmi_apis::FunctionID::UI_SetDisplayLayout); + MessageSharedPtr msg = CreateMessage(); + + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params][am::hmi_response::display_capabilities] = 0; + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + event.set_smart_object(*msg); + + MessageSharedPtr dispaly_capabilities_msg = CreateMessage(); + (*dispaly_capabilities_msg)[am::hmi_response::templates_available] = + "templates_available"; + + EXPECT_CALL(mock_hmi_capabilities_, display_capabilities()) + .WillOnce(Return(dispaly_capabilities_msg.get())); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), + am::commands::Command::CommandSource::SOURCE_SDL)); + + CommandPtr command(CreateCommand<SetDisplayLayoutRequest>(msg)); + command->on_event(event); +} + +} // namespace set_display_layout_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc new file mode 100644 index 0000000000..03aa5d85a1 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_global_properties_test.cc @@ -0,0 +1,1375 @@ +/* + * 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 <stdint.h> +#include <memory> +#include <string> +#include <set> + +#include "mobile/set_global_properties_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_help_prompt_manager.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_global_properties_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SetGlobalPropertiesRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using am::CommandsMap; +using utils::custom_string::CustomString; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 1u; +const std::string kText = "one"; +const uint32_t kPosition = 1u; +} // namespace + +class SetGlobalPropertiesRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SetGlobalPropertiesRequestTest() + : lock_ptr_(std::make_shared<sync_primitives::Lock>()) + , mock_app_(CreateMockApp()) { + mock_help_prompt_manager_ = + std::shared_ptr<application_manager_test::MockHelpPromptManager>( + new application_manager_test::MockHelpPromptManager()); + } + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + msg_params[am::strings::vr_help_title] = "vr_help_title"; + msg_params[am::strings::vr_help][0][am::strings::text] = "vr_help"; + msg_params[am::strings::vr_help][0][am::strings::position] = 1u; + msg_params[am::strings::help_prompt][0][am::strings::text] = "help_promt"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + return msg; + } + + void VRArraySetupHelper(MessageSharedPtr msg, + SmartObject& vr_help_title, + SmartObject& vr_help_array) { + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + } + + void OnEventUISetupHelper( + MessageSharedPtr msg, + std::shared_ptr<SetGlobalPropertiesRequest> command) { + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + EXPECT_CALL(mock_message_helper_, + VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, + RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + command->Run(); + } + + void OnEventTTSSetupHelper( + MessageSharedPtr msg, + std::shared_ptr<SetGlobalPropertiesRequest> command) { + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = + timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, + RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + command->Run(); + } + + void EmptyExpectationsSetupHelper() { + EXPECT_CALL(*mock_app_, set_vr_help_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_vr_help(_)).Times(0); + EXPECT_CALL(*mock_app_, vr_help_title()).Times(0); + EXPECT_CALL(*mock_app_, vr_help()).Times(0); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + } + + void ExpectInvalidData() { + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::INVALID_DATA), + am::commands::Command::SOURCE_SDL)); + } + + void ExpectVerifyImageVrHelpSuccess(SmartObject& smart_obj) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(smart_obj, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void ExpectVerifyImageVrHelpUnsuccess() { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void ExpectVerifyImageSuccess(SmartObject& smart_obj) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(smart_obj, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + } + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + void ExpectationsHmiInterface_Run() { + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + } + std::shared_ptr<sync_primitives::Lock> lock_ptr_; + MockAppPtr mock_app_; + std::shared_ptr<application_manager_test::MockHelpPromptManager> + mock_help_prompt_manager_; +}; + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_UIHmiSendSuccess_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::msg_params][am::strings::vr_commands][0] = + "vr_command"; + + std::shared_ptr<SetGlobalPropertiesRequest> command = + CreateCommand<SetGlobalPropertiesRequest>(msg_vr); + + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + const smart_objects::SmartObject* vr_help_title = + &((*msg_vr)[am::strings::msg_params][am::strings::vr_help_title]); + const smart_objects::SmartObject* vr_help = + &((*msg_vr)[am::strings::msg_params][am::strings::vr_help]); + const smart_objects::SmartObject* vr_help_prompt = + &((*msg_vr)[am::strings::msg_params][am::strings::help_prompt]); + ON_CALL(*mock_app_, vr_help_title()).WillByDefault(Return(vr_help_title)); + ON_CALL(*mock_app_, vr_help()).WillByDefault(Return(vr_help)); + ON_CALL(*mock_app_, help_prompt()).WillByDefault(Return(vr_help_prompt)); + + ExpectationsHmiInterface_Run(); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + (*msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + ON_CALL(mock_message_helper_, + VerifyImageVrHelpItems( + (*msg_vr)[am::strings::msg_params][am::strings::vr_help], _, _)) + .WillByDefault(Return(mobile_apis::Result::SUCCESS)); + + ON_CALL(mock_message_helper_, VerifyImage(_, _, _)) + .WillByDefault(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)).Times(2); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*msg_vr)[am::strings::msg_params][am::strings::help_prompt], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::UI_SetGlobalProperties))) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::TTS_SetGlobalProperties))) + .WillOnce(Return(true)); + (*msg_vr)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + Event event_vr(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event_vr.set_smart_object(*msg_vr); + + command->Run(); + + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + command->on_event(event_vr); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_SUCCESS_Expect_MessageNotSend) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response)[am::strings::msg_params][am::strings::info] = "test"; + + am::event_engine::Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*response); + + std::shared_ptr<SetGlobalPropertiesRequest> command = + CreateCommand<SetGlobalPropertiesRequest>(response); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + EXPECT_CALL(*mock_app, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .Times(0); + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_Expect_false) { + MessageSharedPtr response = CreateMessage(smart_objects::SmartType_Map); + (*response)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*response)[am::strings::msg_params][am::strings::info] = "qwe"; + + am::event_engine::Event event_tts( + hmi_apis::FunctionID::TTS_SetGlobalProperties); + event_tts.set_smart_object(*response); + am::event_engine::Event event_ui( + hmi_apis::FunctionID::UI_SetGlobalProperties); + event_tts.set_smart_object(*response); + std::shared_ptr<SetGlobalPropertiesRequest> command = + CreateCommand<SetGlobalPropertiesRequest>(response); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillRepeatedly(ReturnRef(*mock_help_prompt_manager_.get())); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->Run(); + + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)).Times(2); + command->on_event(event_ui); + command->on_event(event_tts); + + EXPECT_EQ((*response_to_mobile)[am::strings::msg_params][am::strings::success] + .asBool(), + false); + EXPECT_EQ( + (*response_to_mobile)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_apis::Result::INVALID_DATA)); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRNoMenuAndKeyboard_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + OnEventUISetupHelper(msg, command); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRWithMenuAndKeyboard_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, + Run_VRWithMenuAndKeyboard_Menu_WARNINGS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::WARNINGS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRWithMenuAndKeyboard_VR_WARNINGS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::WARNINGS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenMenuIcon_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = " 1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::ABORTED))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EmptyExpectationsSetupHelper(); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRBrokenVRHelp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::ABORTED))); + EmptyExpectationsSetupHelper(); + + EXPECT_CALL(*mock_app_, vr_help_title()).WillOnce(Return(&vr_help_title)); + EXPECT_CALL(*mock_app_, vr_help()).WillOnce(Return(&vr_help_array)); + EXPECT_CALL(*mock_app_, set_vr_help_title(vr_help_title)); + EXPECT_CALL(*mock_app_, set_vr_help(vr_help_array)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(menu_icon)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRIncorrectSyntax_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::app_id] = kAppId; + SmartObject vr_help_title("wrong syntax string\\n"); + SmartObject menu_icon(smart_objects::SmartType_Map); + menu_icon[am::strings::value] = "1"; + (*msg)[am::strings::msg_params][am::hmi_request::menu_icon] = menu_icon; + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + + EXPECT_CALL(mock_message_helper_, VerifyImage(menu_icon, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(_)).Times(0); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingTitle_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_array(smart_objects::SmartType_Array); + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRMissingArray_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + (*msg)[am::strings::msg_params][am::strings::vr_help_title] = vr_help_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRWrongOrder_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help_title("yes"); + SmartObject vr_help_array(smart_objects::SmartType_Array); + VRArraySetupHelper(msg, vr_help_title, vr_help_array); + vr_help_array[1] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[1][am::strings::text] = "two"; + vr_help_array[1][am::strings::position] = 3u; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help_array; + + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(vr_help_array, _, _)) + .WillOnce((Return(mobile_apis::Result::SUCCESS))); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVR_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_VRCouldNotGenerate_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + SmartObject menu_title("Menu_Title"); + (*msg)[am::strings::msg_params][am::hmi_request::menu_title] = menu_title; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_menu_title(menu_title)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataNoDefault_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(_)); + EXPECT_CALL(*mock_app_, app_id()); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataDefaultCreated_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoVRNoDataFromSynonyms_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject keyboard_properties(smart_objects::SmartType_Map); + (*msg)[am::strings::msg_params][am::hmi_request::keyboard_properties] = + keyboard_properties; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + + SmartObject vr_help_array(smart_objects::SmartType_Array); + vr_help_array[0] = SmartObject(smart_objects::SmartType_Map); + vr_help_array[0][am::strings::text] = kText; + vr_help_array[0][am::strings::position] = kPosition; + SmartObject vr_synonyms(smart_objects::SmartType_Array); + vr_synonyms[0] = vr_help_array; + EXPECT_CALL(*mock_app_, set_menu_title(_)).Times(0); + EXPECT_CALL(*mock_app_, set_menu_icon(_)).Times(0); + EXPECT_CALL(*mock_app_, set_keyboard_props(keyboard_properties)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSHelpAndTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyHelp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = "Help_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(help_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_help_prompt(help_prompt)); + EXPECT_CALL(*mock_app_, help_prompt()).WillOnce(Return(&help_prompt)); + EXPECT_CALL(*mock_app_, set_timeout_prompt(_)).Times(0); + EXPECT_CALL(*mock_app_, timeout_prompt()).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSOnlyTimeout_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EXPECT_CALL(mock_message_helper_, VerifyTtsFiles(timeout_prompt, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(app_mngr_, RemoveAppFromTTSGlobalPropertiesList(kConnectionKey)); + EXPECT_CALL(*mock_app_, set_help_prompt(_)).Times(0); + EXPECT_CALL(*mock_app_, help_prompt()).Times(0); + EXPECT_CALL(*mock_app_, set_timeout_prompt(timeout_prompt)); + EXPECT_CALL(*mock_app_, timeout_prompt()).WillOnce(Return(&timeout_prompt)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + EXPECT_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillOnce(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, false)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_TTSIncorrectSyntax_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject timeout_prompt(smart_objects::SmartType_Array); + timeout_prompt[0][am::strings::text] = "Timeout_Prompt_One\\n"; + (*msg)[am::strings::msg_params][am::strings::timeout_prompt] = timeout_prompt; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImageVrHelpItems(_, _, _)).Times(0); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidHelpPromptText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject help_prompt(smart_objects::SmartType_Array); + help_prompt[0][am::strings::text] = + "invalid help prompt text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::help_prompt] = help_prompt; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidVrHelpText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help(smart_objects::SmartType_Array); + vr_help[0][am::strings::text] = + "invalid vr_help text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; + + ExpectVerifyImageVrHelpSuccess(vr_help); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidImageValue_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject vr_help(smart_objects::SmartType_Array); + vr_help[0][am::strings::text] = "vr_help"; + vr_help[0][am::strings::image][am::strings::value] = + "invalid value text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::vr_help] = vr_help; + + ExpectVerifyImageVrHelpSuccess(vr_help); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuIcon_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject menu_icon(smart_objects::SmartType_Array); + menu_icon[am::strings::value] = + "invalid menu icon text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::menu_icon] = menu_icon; + + ExpectVerifyImageSuccess(menu_icon); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidMenuTitle_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject menu_title(smart_objects::SmartType_Array); + menu_title = "invalid menu title text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::menu_title] = menu_title; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, + Run_InvalidLimitedCharacterList_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject limited_character_list(smart_objects::SmartType_Array); + limited_character_list[0] = + "invalid limited character list text with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::keyboard_properties] + [am::strings::limited_character_list] = limited_character_list; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, + Run_InvalidAutoCompleteText_INVALID_DATA) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject auto_complete_text(smart_objects::SmartType_Array); + auto_complete_text = + "invalid auto completetext with empty line in the end\\n"; + (*msg)[am::strings::msg_params][am::strings::keyboard_properties] + [am::strings::auto_complete_text] = auto_complete_text; + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + ExpectInvalidData(); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_NoData_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + ExpectVerifyImageVrHelpUnsuccess(); + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + ExpectVerifyImageVrHelpUnsuccess(); + + EmptyExpectationsSetupHelper(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + command->Run(); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_PendingRequest_UNSUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndSuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + OnEventUISetupHelper(msg, command); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_UIAndWarningResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + OnEventUISetupHelper(msg, command); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + OnEventUISetupHelper(msg, command); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(MockAppPtr())); + + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + Event event(hmi_apis::FunctionID::UI_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, OnEvent_InvalidEventID_Canceled) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, UpdateHash()).Times(0); + + Event event(hmi_apis::FunctionID::TTS_Stopped); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_TTSAndSuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + OnEventTTSSetupHelper(msg, command); + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::SOURCE_SDL)) + .WillOnce(Return(true)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); +} + +TEST_F(SetGlobalPropertiesRequestTest, + OnEvent_TTSAndWarningsResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + const hmi_apis::Common_Result::eType response_code = + hmi_apis::Common_Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::code] = response_code; + ON_CALL( + mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::TTS_SetGlobalProperties)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_TTS)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS)) + .WillByDefault(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + std::shared_ptr<SetGlobalPropertiesRequest> command( + CreateCommand<SetGlobalPropertiesRequest>(msg)); + + OnEventTTSSetupHelper(msg, command); + + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_AVAILABLE)); + + EXPECT_CALL(*mock_app_, help_prompt_manager()) + .WillOnce(ReturnRef(*mock_help_prompt_manager_.get())); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_help_prompt_manager_, + OnSetGlobalPropertiesReceived(_, true)); + + Event event(hmi_apis::FunctionID::TTS_SetGlobalProperties); + event.set_smart_object(*msg); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::WARNINGS)); +} + +} // namespace set_global_properties_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc new file mode 100644 index 0000000000..a69d3d741b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/set_media_clock_timer_test.cc @@ -0,0 +1,365 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "mobile/set_media_clock_timer_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace set_media_clock_timer_request { + +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SetMediaClockRequest; +using am::commands::MessageSharedPtr; +using am::event_engine::Event; +using am::MockMessageHelper; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace UpdateMode = mobile_apis::UpdateMode; +namespace AudioStreamingIndicator = mobile_apis::AudioStreamingIndicator; + +typedef std::shared_ptr<SetMediaClockRequest> SetMediaClockRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const uint32_t kCorrelationId = 2u; +const uint32_t kAppID = 2u; +const uint32_t kHours = 2u; +const uint32_t kMinutes = 26u; +const uint32_t kSeconds = 1u; +} // namespace + +class SetMediaClockRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SetMediaClockRequestTest() : mock_app_(CreateMockApp()) {} + + void SetUp() OVERRIDE { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ResultCommandExpectations(MessageSharedPtr msg, + const std::string& info) { + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::success].asBool(), + true); + EXPECT_EQ( + (*msg)[am::strings::msg_params][am::strings::result_code].asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + EXPECT_EQ((*msg)[am::strings::msg_params][am::strings::info].asString(), + info); + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + return msg; + } + + void ExpectationsSetupHelper(bool is_media) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(is_media)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(SetMediaClockRequestTest, + OnEvent_UIHmiSendUnsupportedResource_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + std::shared_ptr<SetMediaClockRequest> command = + CreateCommand<SetMediaClockRequest>(msg); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*ev_msg)[am::strings::msg_params][am::strings::info] = + "UI is not supported by system"; + + Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); + event.set_smart_object(*ev_msg); + + EXPECT_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillRepeatedly(Return(am::HmiInterfaces::STATE_NOT_RESPONSE)); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + ResultCommandExpectations(ui_command_result, "UI is not supported by system"); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountUp_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTUP; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = + kSeconds; + (*msg)[am::strings::msg_params][am::strings::audioStreamingIndicator] = + AudioStreamingIndicator::PLAY; + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountDown_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::seconds] = kSeconds; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::audioStreamingIndicator] = + AudioStreamingIndicator::PLAY; + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppID)); + EXPECT_CALL(app_mngr_, GetNextHMICorrelationID()) + .WillOnce(Return(kCorrelationId)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceFromFunction(hmi_apis::FunctionID::UI_SetMediaClockTimer)) + .WillByDefault(Return(am::HmiInterfaces::HMI_INTERFACE_UI)); + ON_CALL(mock_hmi_interfaces_, + GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_UI)) + .WillByDefault(Return(am::HmiInterfaces::STATE_AVAILABLE)); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).WillOnce(Return(true)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountUpWrongTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTUP; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::seconds] = kSeconds; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::audioStreamingIndicator] = + AudioStreamingIndicator::PLAY_PAUSE; + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_UpdateCountDownWrongTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + (*msg)[am::strings::msg_params][am::strings::start_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::start_time] + [am::strings::minutes] = kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::hours] = + kHours; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::minutes] = + kMinutes; + (*msg)[am::strings::msg_params][am::strings::end_time][am::strings::seconds] = + kSeconds; + (*msg)[am::strings::msg_params][am::strings::audioStreamingIndicator] = + AudioStreamingIndicator::PLAY_PAUSE; + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, is_media_application()).WillOnce(Return(true)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NoStartTime_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + (*msg)[am::strings::msg_params][am::strings::update_mode] = + UpdateMode::COUNTDOWN; + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NoUpdateMode_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + ExpectationsSetupHelper(true); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_NotMediaApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + ExpectationsSetupHelper(false); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(*mock_app_, is_media_application()).Times(0); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + command->Run(); +} + +TEST_F(SetMediaClockRequestTest, OnEvent_Success) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Null); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + MockAppPtr app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(app)); + + Event event(hmi_apis::FunctionID::UI_SetMediaClockTimer); + event.set_smart_object(*msg); + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + command->on_event(event); +} + +TEST_F(SetMediaClockRequestTest, OnEvent_Canceled) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<SetMediaClockRequest> command( + CreateCommand<SetMediaClockRequest>(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg); + + command->on_event(event); +} + +} // namespace set_media_clock_timer_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc new file mode 100644 index 0000000000..4725af4671 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/show_test.cc @@ -0,0 +1,974 @@ +/* + * 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 <stdint.h> +#include <memory> +#include <string> +#include <set> + +#include "mobile/show_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace show_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::ShowRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using test::components::policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kFunctionID = 3u; +} // namespace + +class ShowRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + ShowRequestTest() { + mock_app_ = CreateMockApp(); + } + sync_primitives::Lock lock_; + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + MessageSharedPtr CreateMsgParams() { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + return msg; + } + + void TestSetupHelper(MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + msg_params[field] = text_field_; + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + msg_params.erase(field); + msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_name] = + static_cast<int32_t>(field_name); + msg_params[am::hmi_request::show_strings][0][am::hmi_request::field_text] = + text_field_; + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + } + + void TestSetupHelperWrongSyntax( + MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + msg_params[field] = text_field_; + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + } + + void TestSetupHelperWithMetadata( + MessageSharedPtr msg, + hmi_apis::Common_TextFieldName::eType field_name, + const char* field, + size_t num_tags, + int32_t* field_tags, + bool set_field_text = true) { + SmartObject msg_params(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::params][am::strings::function_id] = kFunctionID; + if (set_field_text) { + msg_params[field] = text_field_; + } + msg_params[am::strings::metadata_tags][field] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + for (size_t i = 0; i < num_tags; ++i) { + const int32_t current_tag = field_tags[i]; + msg_params[am::strings::metadata_tags][field][i] = current_tag; + } + (*msg)[am::strings::msg_params] = msg_params; + + EXPECT_EQ((*msg)[am::strings::msg_params], msg_params); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params.erase(field); + msg_params.erase(am::strings::metadata_tags); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + if (set_field_text) { + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_name] = + static_cast<int32_t>(field_name); + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_text] = text_field_; + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_types] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + for (size_t i = 0; i < num_tags; ++i) { + const int32_t current_tag = field_tags[i]; + msg_params[am::hmi_request::show_strings][0] + [am::hmi_request::field_types][i] = current_tag; + } + } + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + } + + MockAppPtr mock_app_; + std::string text_field_; +}; + +TEST_F(ShowRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_vr = CreateFullParamsUISO(); + (*msg_vr)[am::strings::msg_params][am::strings::menu_params] + [am::hmi_request::parent_id] = 10u; + (*msg_vr)[am::strings::msg_params][am::strings::menu_params] + [am::strings::menu_name] = "menu_name"; + + std::shared_ptr<ShowRequest> command = CreateCommand<ShowRequest>(msg_vr); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::cmd_id] = kCommandId; + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + MessageSharedPtr vr_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&vr_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*vr_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*vr_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*vr_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*vr_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +TEST_F(ShowRequestTest, Run_SoftButtonExists_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = "Soft_Buttons"; + (*msg)[am::strings::msg_params] = msg_params; + SmartObject creation_msg_params(msg_params); + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL( + mock_message_helper_, + SubscribeApplicationToSoftButton(creation_msg_params, _, kFunctionID)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SoftButtonNotExists_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = ""; + (*msg)[am::strings::msg_params] = msg_params; + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(_, _, _, _)).Times(0); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(*mock_app_, UnsubscribeFromSoftButtons(kFunctionID)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SoftButtonExists_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::soft_buttons] = "Soft_Buttons"; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, ProcessSoftButtons(msg_params, _, _, _)) + .WillOnce(Return(mobile_apis::Result::ABORTED)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_message_helper_, SubscribeApplicationToSoftButton(_, _, _)) + .Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_WARNINGS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::WARNINGS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Graphic_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "\\n"; + msg_params[am::strings::graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(_, _, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_WARNINGS) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::WARNINGS)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = "1"; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)) + .WillOnce(Return(mobile_apis::Result::INVALID_DATA)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_SecondaryGraphic_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject graphic(smart_objects::SmartType_Map); + graphic[am::strings::value] = ""; + msg_params[am::strings::secondary_graphic] = graphic; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_message_helper_, VerifyImage(graphic, _, _)).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_1"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_1\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_2"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_2\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_3"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_3\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_4"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_4\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MultipleMetadataTags) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 5; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaTitle, + hmi_apis::Common_MetadataType::mediaArtist, + hmi_apis::Common_MetadataType::rating, + hmi_apis::Common_MetadataType::humidity, + hmi_apis::Common_MetadataType::currentTemperature}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField2_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_2"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField2, + am::strings::main_field_2, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField3_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_3"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField3, + am::strings::main_field_3, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField4_MetadataTag) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_4"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField4, + am::strings::main_field_4, + num_tags, + tags); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MainField1_MetadataTagWithNoFieldData) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Main_Field_1"; + const size_t num_tags = 1; + int32_t tags[num_tags] = {hmi_apis::Common_MetadataType::mediaArtist}; + TestSetupHelperWithMetadata(msg, + hmi_apis::Common_TextFieldName::mainField1, + am::strings::main_field_1, + num_tags, + tags, + false); + command->Run(); + + MessageSharedPtr ev_msg = CreateMessage(smart_objects::SmartType_Map); + (*ev_msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*ev_msg)[am::strings::msg_params][am::strings::app_id] = kConnectionKey; + (*ev_msg)[am::strings::msg_params][am::strings::info] = ""; + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*ev_msg); + + MessageSharedPtr ui_command_result; + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_apis::Result::WARNINGS)); +} + +TEST_F(ShowRequestTest, Run_MediaClock_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Media_Clock"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mediaClock, + am::strings::media_clock); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaClock_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Media_Clock\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mediaClock, + am::strings::media_clock); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaTrack_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Media_Track"; + TestSetupHelper(msg, + hmi_apis::Common_TextFieldName::mediaTrack, + am::strings::media_track); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_MediaTrack_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Media_Track\\n"; + TestSetupHelperWrongSyntax(msg, + hmi_apis::Common_TextFieldName::mediaTrack, + am::strings::media_track); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_StatusBar_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Status_Bar"; + TestSetupHelper( + msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_StatusBar_WrongSyntax) { + MessageSharedPtr msg = CreateMessage(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + text_field_ = "Status_Bar\\n"; + TestSetupHelperWrongSyntax( + msg, hmi_apis::Common_TextFieldName::statusBar, am::strings::status_bar); + command->Run(); +} + +TEST_F(ShowRequestTest, Run_Alignment_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + msg_params[am::strings::alignment] = "Alignment"; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_CustomPresets_SUCCESS) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject custom_presets(smart_objects::SmartType_Array); + custom_presets[0] = "Custom_Presets"; + msg_params[am::strings::custom_presets] = custom_presets; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(*mock_app_, app_id()).WillOnce(Return(kAppId)); + + msg_params[am::strings::app_id] = kAppId; + msg_params[am::hmi_request::show_strings] = + smart_objects::SmartObject(smart_objects::SmartType_Array); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)); + EXPECT_CALL(*mock_app_, set_show_command(msg_params)); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_CustomPresets_WrongSyntax) { + MessageSharedPtr msg = CreateMsgParams(); + SmartObject msg_params(smart_objects::SmartType_Map); + SmartObject custom_presets(smart_objects::SmartType_Array); + custom_presets[0] = "Custom_Presets\\t"; + msg_params[am::strings::custom_presets] = custom_presets; + (*msg)[am::strings::msg_params] = msg_params; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_InvalidApp_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(MockAppPtr())); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, Run_EmptyParams_Canceled) { + MessageSharedPtr msg = CreateMsgParams(); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*mock_app_, app_id()).Times(0); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)).Times(0); + EXPECT_CALL(*mock_app_, set_show_command(_)).Times(0); + + command->Run(); +} + +TEST_F(ShowRequestTest, OnEvent_SuccessResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::eType::SUCCESS; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::eType::SUCCESS), _)); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, OnEvent_WarningsResultCode_SUCCESS) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::WARNINGS; + (*msg)[am::strings::params][am::hmi_response::message] = "Response Info"; + (*msg)[am::strings::msg_params] = SmartObject(smart_objects::SmartType_Map); + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + + Event event(hmi_apis::FunctionID::UI_Show); + event.set_smart_object(*msg); + + EXPECT_CALL(app_mngr_, application(_)).WillRepeatedly(Return(mock_app_)); + + command->on_event(event); +} + +TEST_F(ShowRequestTest, OnEvent_WrongFunctionID_Canceled) { + MessageSharedPtr msg = CreateMessage(); + (*msg)[am::strings::params][am::hmi_response::code] = + mobile_apis::Result::SUCCESS; + + std::shared_ptr<ShowRequest> command(CreateCommand<ShowRequest>(msg)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::UI_Alert); + event.set_smart_object(*msg); + + command->on_event(event); +} + +} // namespace show_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc new file mode 100644 index 0000000000..d96a9d7643 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_notification_commands_test.cc @@ -0,0 +1,99 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/commands/command_impl.h" +#include "application_manager/commands/commands_test.h" +#include "mobile/on_app_interface_unregistered_notification.h" +#include "mobile/on_audio_pass_thru_notification.h" +#include "mobile/on_driver_distraction_notification.h" +#include "mobile/on_language_change_notification.h" +#include "mobile/on_permissions_change_notification.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace simple_notification_commands_test { + +namespace am = ::application_manager; +namespace commands = sdl_rpc_plugin::commands; + +using ::testing::_; +using ::testing::Types; +using ::testing::Return; + +template <class Command> +class MobileNotificationCommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +typedef Types<commands::OnAppInterfaceUnregisteredNotification, + commands::OnAudioPassThruNotification, + commands::OnLanguageChangeNotification, + commands::OnPermissionsChangeNotification, + commands::mobile::OnDriverDistractionNotification> + NotificationCommandsList; + +MATCHER(CheckNotificationMessage, "") { + return (*arg)[am::strings::params][am::strings::protocol_type].asInt() == + am::commands::CommandImpl::mobile_protocol_type_ && + (*arg)[am::strings::params][am::strings::protocol_version].asInt() == + am::commands::CommandImpl::protocol_version_ && + (*arg)[am::strings::params][am::strings::message_type].asInt() == + application_manager::MessageType::kNotification; +} + +TYPED_TEST_CASE(MobileNotificationCommandsTest, NotificationCommandsList); + +TYPED_TEST(MobileNotificationCommandsTest, Run_SendMessageToMobile_SUCCESS) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + EXPECT_CALL(this->mock_rpc_service_, + SendMessageToMobile(CheckNotificationMessage(), _)); + command->Run(); +} + +} // namespace simple_notification_commands_test +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc new file mode 100644 index 0000000000..bbd39874e0 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/simple_response_commands_test.cc @@ -0,0 +1,189 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "utils/helpers.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/mock_application_manager.h" +#include "mobile/delete_command_response.h" +#include "mobile/alert_maneuver_response.h" +#include "mobile/alert_response.h" +#include "mobile/list_files_response.h" +#include "mobile/subscribe_button_response.h" +#include "mobile/add_sub_menu_response.h" +#include "mobile/dial_number_response.h" +#include "mobile/end_audio_pass_thru_response.h" +#include "mobile/unregister_app_interface_response.h" +#include "mobile/unsubscribe_button_response.h" +#include "mobile/unsubscribe_way_points_response.h" +#include "mobile/update_turn_list_response.h" +#include "mobile/slider_response.h" +#include "mobile/speak_response.h" +#include "mobile/subscribe_way_points_response.h" +#include "mobile/system_response.h" +#include "mobile/get_way_points_response.h" +#include "mobile/perform_interaction_response.h" +#include "mobile/perform_audio_pass_thru_response.h" +#include "mobile/set_global_properties_response.h" +#include "mobile/set_media_clock_timer_response.h" +#include "mobile/show_constant_tbt_response.h" +#include "mobile/show_response.h" +#include "mobile/add_command_response.h" +#include "mobile/send_location_response.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/set_display_layout_response.h" +#include "mobile/generic_response.h" +#include "mobile/set_app_icon_response.h" +#include "mobile/scrollable_message_response.h" +#include "mobile/change_registration_response.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace simple_response_commands_test { + +namespace commands = sdl_rpc_plugin::commands; +namespace am = ::application_manager; + +using ::testing::_; +using ::testing::NotNull; +using ::testing::Types; + +using am::commands::MessageSharedPtr; + +template <class Command> +class MobileResponseCommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + typedef Command CommandType; +}; + +typedef Types<commands::ListFilesResponse, + commands::DeleteCommandResponse, + commands::AlertManeuverResponse, + commands::AlertResponse, + commands::SubscribeButtonResponse, + commands::AddSubMenuResponse, + commands::DialNumberResponse, + commands::EndAudioPassThruResponse, + commands::UnregisterAppInterfaceResponse, + commands::UnsubscribeWayPointsResponse, + commands::UpdateTurnListResponse, + commands::UnsubscribeButtonResponse, + commands::SliderResponse, + commands::SpeakResponse, + commands::SubscribeWayPointsResponse, + commands::SystemResponse, + commands::GetWayPointsResponse, + commands::PerformInteractionResponse, + commands::PerformAudioPassThruResponse, + commands::SetGlobalPropertiesResponse, + commands::SetMediaClockTimerResponse, + commands::ShowConstantTBTResponse, + commands::ShowResponse, + commands::SystemResponse, + commands::AddCommandResponse, + commands::SendLocationResponse, + commands::SetAppIconResponse, + commands::SetDisplayLayoutResponse, + commands::ChangeRegistrationResponse> ResponseCommandsList; + +TYPED_TEST_CASE(MobileResponseCommandsTest, ResponseCommandsList); + +TYPED_TEST(MobileResponseCommandsTest, Run_SendResponseToMobile_SUCCESS) { + std::shared_ptr<typename TestFixture::CommandType> command = + this->template CreateCommand<typename TestFixture::CommandType>(); + EXPECT_CALL(this->mock_rpc_service_, SendMessageToMobile(NotNull(), _)); + command->Run(); +} + +class GenericResponseFromHMICommandsTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +MATCHER_P2(CheckMessageParams, success, result, "") { + const bool is_msg_type_correct = + (am::MessageType::kResponse) == + static_cast<int32_t>( + (*arg)[am::strings::params][am::strings::message_type].asInt()); + const bool is_success_correct = + success == (*arg)[am::strings::msg_params][am::strings::success].asBool(); + const bool is_result_code_correct = + result == + static_cast<int32_t>( + (*arg)[am::strings::msg_params][am::strings::result_code].asInt()); + + using namespace helpers; + return Compare<bool, EQ, ALL>( + true, is_msg_type_correct, is_success_correct, is_result_code_correct); +} + +TEST_F(GenericResponseFromHMICommandsTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + + std::shared_ptr<commands::GenericResponse> command( + CreateCommand<commands::GenericResponse>(command_msg)); + + EXPECT_CALL( + this->mock_rpc_service_, + SendMessageToMobile( + CheckMessageParams(false, mobile_apis::Result::INVALID_DATA), false)); + + command->Run(); +} + +class ScrollableMessageResponseTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(ScrollableMessageResponseTest, Run_SUCCESS) { + MessageSharedPtr message = CreateMessage(); + (*message)[am::strings::msg_params][am::strings::result_code] = + mobile_apis::Result::SUCCESS; + + MockAppPtr app(CreateMockApp()); + + std::shared_ptr<commands::ScrollableMessageResponse> command( + CreateCommand<commands::ScrollableMessageResponse>(message)); + EXPECT_CALL(app_mngr_, application(_)).WillOnce(Return(app)); + EXPECT_CALL(*app, UnsubscribeFromSoftButtons(_)); + command->Run(); +} + +} // namespace simple_response_commands_test +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc new file mode 100644 index 0000000000..be14aebc8f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/slider_test.cc @@ -0,0 +1,340 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "mobile/slider_request.h" + +#include "gtest/gtest.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace slider_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SliderRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockMessageHelper; +using policy_test::MockPolicyHandlerInterface; +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; + +typedef std::shared_ptr<SliderRequest> CommandPtr; + +namespace { +const int32_t kCommandId = 1; +const uint32_t kAppId = 1u; +const uint32_t kCmdId = 1u; +const uint32_t kConnectionKey = 2u; +const uint32_t kDefaultTimeout = 1000u; +const uint32_t kCorrelationId = 2u; +const uint32_t kFunctionId = 3u; +const uint32_t kNumTicks = 2u; +const uint32_t kPositionGreaterTicks = 3u; +const uint32_t kPositionLessTicks = 1u; +} // namespace + +class SliderRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SliderRequestTest() + : mock_app_(CreateMockApp()) + , msg_(CreateMessage(smart_objects::SmartType_Map)) {} + + MessageSharedPtr CreateFullParamsUISO() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + smart_objects::SmartObject menu_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + menu_params[am::strings::position] = 10; + menu_params[am::strings::menu_name] = "LG"; + + smart_objects::SmartObject msg_params = + smart_objects::SmartObject(smart_objects::SmartType_Map); + msg_params[am::strings::cmd_id] = kCmdId; + msg_params[am::strings::menu_params] = menu_params; + msg_params[am::strings::app_id] = kAppId; + msg_params[am::strings::cmd_icon] = 1; + msg_params[am::strings::cmd_icon][am::strings::value] = "10"; + (*msg)[am::strings::msg_params] = msg_params; + + return msg; + } + + void PreConditions() { + (*msg_)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg_)[am::strings::msg_params][am::strings::num_ticks] = kNumTicks; + (*msg_)[am::strings::msg_params][am::strings::position] = + kPositionLessTicks; + (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = + "slider_footer1"; + (*msg_)[am::strings::msg_params][am::strings::slider_footer][1] = + "slider_footer2"; + (*msg_)[am::strings::msg_params][am::strings::slider_header] = + "slider_header"; + + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + ON_CALL(*mock_app_, app_id()).WillByDefault(Return(kConnectionKey)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + sync_primitives::Lock lock_; + + MockAppPtr mock_app_; + MessageSharedPtr msg_; + MockPolicyHandlerInterface mock_policy_handler_; +}; + +TEST_F(SliderRequestTest, OnEvent_UI_UNSUPPORTED_RESOURCE) { + MessageSharedPtr msg_ui = CreateFullParamsUISO(); + (*msg_ui)[am::strings::params][am::strings::connection_key] = kConnectionKey; + + std::shared_ptr<SliderRequest> command = CreateCommand<SliderRequest>(msg_ui); + + MockAppPtr mock_app = CreateMockApp(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app)); + + ON_CALL(*mock_app, app_id()).WillByDefault(Return(kConnectionKey)); + + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + (*msg)[am::strings::msg_params][am::strings::info] = "info"; + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg); + + MessageSharedPtr ui_command_result; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&ui_command_result), Return(true))); + + command->on_event(event); + + EXPECT_EQ((*ui_command_result)[am::strings::msg_params][am::strings::success] + .asBool(), + true); + EXPECT_EQ( + (*ui_command_result)[am::strings::msg_params][am::strings::result_code] + .asInt(), + static_cast<int32_t>(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE)); + if ((*ui_command_result)[am::strings::msg_params].keyExists( + am::strings::info)) { + EXPECT_FALSE( + (*ui_command_result)[am::strings::msg_params][am::strings::info] + .asString() + .empty()); + } +} + +class CallOnTimeOut { + public: + CallOnTimeOut(CommandRequestImpl& command) : command_(command) {} + + void operator()() { + command_.onTimeOut(); + } + + CommandRequestImpl& command_; +}; + +TEST_F(SliderRequestTest, Init_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + EXPECT_TRUE(command->Init()); +} + +TEST_F(SliderRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + PreConditions(); + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(ApplicationSharedPtr())); + ExpectManageMobileCommandWithResultCode( + mobile_apis::Result::APPLICATION_NOT_REGISTERED); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_PositionGreaterTicks_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::position] = + kPositionGreaterTicks; + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_SliderFooterNotEqToNumticks_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_footer][2] = + "slider_footer3"; + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_InvalidSliderHeader_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_header] = + "invalid_test_with_empty_str\\n"; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_InvalidSliderFooter_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::slider_footer][0] = + "invalid_test_with_empty_str\\n"; + + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app_)); + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::INVALID_DATA); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, Run_SUCCESS) { + PreConditions(); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::UI_Slider))); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->Run(); +} + +TEST_F(SliderRequestTest, OnEvent_UI_OnResetTimeout_UNSUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::strings::correlation_id] = kCorrelationId; + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + EXPECT_TRUE(command->Init()); + + EXPECT_CALL(app_mngr_, + updateRequestTimeout(kConnectionKey, kCorrelationId, _)); + + Event event(hmi_apis::FunctionID::UI_OnResetTimeout); + event.set_smart_object(*msg_); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UI_UnknownEventId_UNSUCCESS) { + PreConditions(); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UISliderPositionExists_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::TIMED_OUT; + (*msg_)[am::strings::params][am::strings::data] + [am::strings::slider_position] = "position"; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::TIMED_OUT); + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->on_event(event); +} + +TEST_F(SliderRequestTest, OnEvent_UISliderAborted_SUCCESS) { + PreConditions(); + (*msg_)[am::strings::msg_params][am::strings::timeout] = kDefaultTimeout; + (*msg_)[am::strings::params][am::hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::ABORTED); + + Event event(hmi_apis::FunctionID::UI_Slider); + event.set_smart_object(*msg_); + + CommandPtr command(CreateCommand<SliderRequest>(msg_)); + command->on_event(event); +} + +} // namespace slider_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace tests diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc new file mode 100644 index 0000000000..9eb23eeee3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/speak_request_test.cc @@ -0,0 +1,406 @@ +/* + + 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 <string> +#include "gtest/gtest.h" +#include "mobile/speak_request.h" + +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" + +#include "utils/helpers.h" + +#include "smart_objects/smart_object.h" +#include "utils/custom_string.h" +#include "application_manager/application.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace speak_request { + +namespace am = application_manager; +namespace mobile_result = mobile_apis::Result; +namespace hmi_response = ::application_manager::hmi_response; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::ApplicationManager; +using am::commands::MessageSharedPtr; +using am::ApplicationSharedPtr; +using am::MockMessageHelper; +using ::testing::_; + +using ::testing::Return; +using ::testing::ReturnRef; +using sdl_rpc_plugin::commands::SpeakRequest; +using ::test::components::application_manager_test::MockApplication; + +typedef std::shared_ptr<SpeakRequest> CommandPtr; + +namespace { +const uint32_t kAppId = 10u; +const uint32_t kConnectionKey = 5u; +} + +class SpeakRequestTest : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SpeakRequestTest() + : request_(CreateMessage(smart_objects::SmartType_Map)) + , response_(CreateMessage(smart_objects::SmartType_Map)) + , app_(CreateMockApp()) {} + + void CheckExpectations(const hmi_apis::Common_Result::eType hmi_response, + const mobile_apis::Result::eType mobile_response, + const am::HmiInterfaces::InterfaceState state, + const bool success) { + std::shared_ptr<SpeakRequest> command = + CreateCommand<SpeakRequest>(request_); + + (*response_)[strings::params][hmi_response::code] = hmi_response; + (*response_)[strings::msg_params] = 0; + + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + MessageSharedPtr response_to_mobile; + EXPECT_CALL(mock_hmi_interfaces_, GetInterfaceState(_)) + .WillRepeatedly(Return(state)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + _, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + success); + EXPECT_EQ((*response_to_mobile)[strings::msg_params][strings::result_code] + .asInt(), + static_cast<int32_t>(mobile_response)); + } + + MessageSharedPtr request_; + MessageSharedPtr response_; + MockAppPtr app_; +}; + +TEST_F(SpeakRequestTest, OnEvent_SUCCESS_Expect_true) { + std::shared_ptr<SpeakRequest> command = CreateCommand<SpeakRequest>(request_); + + (*response_)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + (*response_)[strings::msg_params] = 0; + + am::event_engine::Event event_tts(hmi_apis::FunctionID::TTS_Speak); + event_tts.set_smart_object(*response_); + + MockAppPtr mock_app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(mock_app)); + + MessageSharedPtr response_to_mobile; + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(_, am::commands::Command::CommandSource::SOURCE_SDL)) + .WillOnce(DoAll(SaveArg<0>(&response_to_mobile), Return(true))); + + command->on_event(event_tts); + + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::success].asBool(), + true); + EXPECT_EQ( + (*response_to_mobile)[strings::msg_params][strings::result_code].asInt(), + static_cast<int32_t>(mobile_apis::Result::SUCCESS)); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_AVAILABLE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_AVAILABLE, + true); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_AVAILABLE_Expect_false) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_AVAILABLE, + false); +} + +TEST_F(SpeakRequestTest, + OnEvent_UNSUPPORTED_RESOURCE_STATE_NOT_RESPONSE_Expect_true) { + CheckExpectations(hmi_apis::Common_Result::UNSUPPORTED_RESOURCE, + mobile_apis::Result::UNSUPPORTED_RESOURCE, + am::HmiInterfaces::STATE_NOT_RESPONSE, + true); +} + +TEST_F(SpeakRequestTest, Run_ApplicationIsNotRegistered) { + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithWhiteSpace_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = " "; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar1_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\\t"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar2_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\\n"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar3_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\tdf"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectChar4_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "sd\n rer"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithIncorrectCharInfirstPlace_InvalidData) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "\n"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgWithEmptyString_Success) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = ""; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); + + command->Run(); +} + +TEST_F(SpeakRequestTest, Run_MsgCorrect_Success) { + (*request_)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "asda"; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + EXPECT_CALL( + mock_message_helper_, + VerifyTtsFiles( + (*request_)[am::strings::msg_params][am::strings::tts_chunks], _, _)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + ON_CALL(*app_, app_id()).WillByDefault(Return(kAppId)); + + EXPECT_CALL( + mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs(hmi_apis::FunctionID::TTS_Speak))); + + command->Run(); +} + +TEST_F(SpeakRequestTest, OnEvent_WrongEventId_UNSUCCESS) { + Event event(Event::EventID::INVALID_ENUM); + CommandPtr command(CreateCommand<SpeakRequest>()); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_Speak_SUCCESS) { + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::SUCCESS; + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "1234"; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_SpeakWithWarning_WarningWithSuccess) { + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + hmi_apis::Common_Result::eType hmi_result = hmi_apis::Common_Result::WARNINGS; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "asda"; + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand<SpeakRequest>()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app_)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::WARNINGS), _)); + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_TTS_OnResetTimeout_UpdateTimeout) { + Event event(Event::EventID::TTS_OnResetTimeout); + (*request_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*request_)[am::strings::params][am::strings::correlation_id] = kAppId; + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + EXPECT_CALL(app_mngr_, updateRequestTimeout(kConnectionKey, kAppId, _)); + + command->on_event(event); +} + +TEST_F(SpeakRequestTest, OnEvent_ApplicationIsNotRegistered_UNSUCCESS) { + const hmi_apis::Common_Result::eType hmi_result = + hmi_apis::Common_Result::SUCCESS; + + Event event(Event::EventID::TTS_Speak); + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::msg_params][am::strings::tts_chunks][0] + [am::strings::text] = "text"; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_result; + (*event_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + event.set_smart_object(*event_msg); + CommandPtr command(CreateCommand<SpeakRequest>(request_)); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + command->on_event(event); +} + +} // namespace speak_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace component +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc new file mode 100644 index 0000000000..bbc18504a6 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_button_request_test.cc @@ -0,0 +1,202 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "mobile/subscribe_button_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace subscribe_button_request { + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SubscribeButtonRequest; +using am::commands::MessageSharedPtr; + +typedef std::shared_ptr<SubscribeButtonRequest> CommandPtr; + +class SubscribeButtonRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + typedef TypeIf<kMocksAreNice, + NiceMock<application_manager_test::MockHMICapabilities>, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; +}; + +typedef SubscribeButtonRequestTest::MockHMICapabilities MockHMICapabilities; + +TEST_F(SubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand<SubscribeButtonRequest>()); + + ON_CALL(app_mngr_, application(_)) + .WillByDefault(Return(std::shared_ptr<am::Application>())); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::APPLICATION_NOT_REGISTERED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_SubscriptionNotAllowed_UNSUCCESS) { + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = + mobile_apis::ButtonName::SEEKLEFT; + CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(false)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::REJECTED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_UiIsNotSupported_UNSUCCESS) { + CommandPtr command(CreateCommand<SubscribeButtonRequest>()); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(false)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::UNSUPPORTED_RESOURCE, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_IsSubscribedToButton_UNSUCCESS) { + const mobile_apis::ButtonName::eType kButtonName = + mobile_apis::ButtonName::SEEKLEFT; + + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; + CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; + + ON_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillByDefault(Return(button_caps_ptr.get())); + + ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(true)); + + MessageSharedPtr result_msg(CatchMobileCommandResult(CallRun(*command))); + EXPECT_EQ(mobile_apis::Result::IGNORED, + static_cast<mobile_apis::Result::eType>( + (*result_msg)[am::strings::msg_params][am::strings::result_code] + .asInt())); +} + +TEST_F(SubscribeButtonRequestTest, Run_SUCCESS) { + const mobile_apis::ButtonName::eType kButtonName = + mobile_apis::ButtonName::SEEKLEFT; + + MessageSharedPtr msg(CreateMessage()); + (*msg)[am::strings::msg_params][am::strings::button_name] = kButtonName; + CommandPtr command(CreateCommand<SubscribeButtonRequest>(msg)); + + MockAppPtr app(CreateMockApp()); + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(*app, is_media_application()).WillByDefault(Return(true)); + + ON_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillByDefault(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonName; + + ON_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillByDefault(Return(button_caps_ptr.get())); + + ON_CALL(*app, IsSubscribedToButton(_)).WillByDefault(Return(false)); + + MessageSharedPtr hmi_result_msg; + + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&hmi_result_msg), Return(true))); + + MessageSharedPtr mobile_result_msg; + EXPECT_CALL(this->mock_rpc_service_, ManageMobileCommand(_, _)) + .WillOnce(DoAll(SaveArg<0>(&mobile_result_msg), Return(true))); + ASSERT_TRUE(command->Init()); + command->Run(); + + EXPECT_EQ(hmi_apis::FunctionID::Buttons_OnButtonSubscription, + static_cast<hmi_apis::FunctionID::eType>( + (*hmi_result_msg)[am::strings::params][am::strings::function_id] + .asInt())); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast<mobile_apis::Result::eType>( + (*mobile_result_msg)[am::strings::msg_params] + [am::strings::result_code].asInt())); +} + +} // namespace subscribe_button_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc new file mode 100644 index 0000000000..d08c13b3f3 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/subscribe_way_points_request_test.cc @@ -0,0 +1,130 @@ +/* + * 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 "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "mobile/subscribe_way_points_request.h" +#include "interfaces/MOBILE_API.h" +#include "application_manager/smart_object_keys.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace subscribe_way_points_request { + +using ::testing::_; +using ::testing::A; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::DoAll; +using ::testing::SaveArg; +using ::testing::InSequence; +namespace am = ::application_manager; +using sdl_rpc_plugin::commands::SubscribeWayPointsRequest; +using am::commands::MessageSharedPtr; + +typedef std::shared_ptr<SubscribeWayPointsRequest> CommandPtr; + +class SubscribeWayPointsRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(SubscribeWayPointsRequestTest, Run_SUCCESS) { + CommandPtr command(CreateCommand<SubscribeWayPointsRequest>()); + MockAppPtr app(CreateMockApp()); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + ON_CALL(app_mngr_, IsAppSubscribedForWayPoints(A<am::ApplicationSharedPtr>())) + .WillByDefault(Return(false)); + ON_CALL(app_mngr_, IsAnyAppSubscribedForWayPoints()) + .WillByDefault(Return(true)); + + { + InSequence dummy; + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); + EXPECT_CALL(*app, UpdateHash()); + } + + command->Init(); + MessageSharedPtr mobile_result_msg( + CatchMobileCommandResult(CallRun(*command))); + + EXPECT_EQ(mobile_apis::Result::SUCCESS, + static_cast<mobile_apis::Result::eType>( + (*mobile_result_msg)[am::strings::msg_params] + [am::strings::result_code].asInt())); +} + +TEST_F(SubscribeWayPointsRequestTest, OnEvent_SUCCESS) { + CommandPtr command(CreateCommand<SubscribeWayPointsRequest>()); + MockAppPtr app(CreateMockApp()); + Event event(hmi_apis::FunctionID::Navigation_SubscribeWayPoints); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + const hmi_apis::Common_Result::eType result_code = + hmi_apis::Common_Result::SUCCESS; + (*event_msg)[am::strings::params][am::hmi_response::code] = result_code; + (*event_msg)[am::strings::msg_params] = 0; + + event.set_smart_object(*event_msg); + + ON_CALL(app_mngr_, application(_)).WillByDefault(Return(app)); + + { + InSequence dummy; + EXPECT_CALL(app_mngr_, + SubscribeAppForWayPoints(A<am::ApplicationSharedPtr>())); + EXPECT_CALL(mock_message_helper_, HMIToMobileResult(result_code)) + .WillOnce(Return(mobile_apis::Result::SUCCESS)); + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)); + EXPECT_CALL(*app, UpdateHash()); + } + + command->Init(); + command->on_event(event); +} + +} // namespace subscribe_way_points_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc new file mode 100644 index 0000000000..9e6bc8f505 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/system_request_test.cc @@ -0,0 +1,236 @@ +/* + * 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 <stdint.h> +#include <string> +#include <set> + +#include "gtest/gtest.h" + +#include "mobile/system_request.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/policies/mock_policy_handler_interface.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace system_request { + +namespace am = application_manager; +using sdl_rpc_plugin::commands::SystemRequest; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::MockHmiInterfaces; +using am::event_engine::Event; +using am::MessageType; +using policy_test::MockPolicyHandlerInterface; + +using ::testing::_; +using ::testing::DoAll; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::SaveArg; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kAppPolicyId = "fake-app-id"; +const uint32_t kDefaultTimeout = 1000u; +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 + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SystemRequestTest() : mock_app_(CreateMockApp()) {} + + protected: + MessageSharedPtr CreateIVSUMessage() { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + (*msg)[am::strings::params][am::strings::connection_key] = kConnectionKey; + (*msg)[am::strings::msg_params][am::strings::request_type] = + mobile_apis::RequestType::HTTP; + (*msg)[am::strings::msg_params][am::strings::file_name] = kFileName; + return msg; + } + + void PreConditions() { + ON_CALL(app_mngr_, application(kConnectionKey)) + .WillByDefault(Return(mock_app_)); + + 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)); + ON_CALL(app_mngr_settings_, app_storage_folder()) + .WillByDefault(ReturnRef(kAppStorageFolder)); + + ON_CALL(mock_policy_handler_, IsRequestTypeAllowed(kAppPolicyId, _)) + .WillByDefault(Return(true)); + } + + void ExpectManageMobileCommandWithResultCode( + const mobile_apis::Result::eType code) { + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(code), + am::commands::Command::CommandSource::SOURCE_SDL)); + } + + MockAppPtr mock_app_; +}; + +TEST_F(SystemRequestTest, Run_HTTP_FileName_no_binary_data_REJECTED) { + PreConditions(); + MessageSharedPtr msg = CreateIVSUMessage(); + + ExpectManageMobileCommandWithResultCode(mobile_apis::Result::REJECTED); + + std::shared_ptr<SystemRequest> command(CreateCommand<SystemRequest>(msg)); + 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(mock_rpc_service_, ManageHMICommand(_)) + .WillOnce(DoAll(SaveArg<0>(&result), Return(true))); + + std::shared_ptr<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(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + std::shared_ptr<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(mock_rpc_service_, ManageHMICommand(_)).Times(0); + + std::shared_ptr<SystemRequest> command(CreateCommand<SystemRequest>(msg)); + ASSERT_TRUE(command->Init()); + command->Run(); +} + +} // namespace system_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc new file mode 100644 index 0000000000..771374348b --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unregister_app_interface_request_test.cc @@ -0,0 +1,118 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "mobile/unregister_app_interface_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unregister_app_interface_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; + +using sdl_rpc_plugin::commands::UnregisterAppInterfaceRequest; +using am::commands::MessageSharedPtr; + +typedef std::shared_ptr<UnregisterAppInterfaceRequest> CommandPtr; + +class UnregisterAppInterfaceRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(UnregisterAppInterfaceRequestTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand<UnregisterAppInterfaceRequest>()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(UnregisterAppInterfaceRequestTest, Run_SUCCESS) { + const uint32_t kConnectionKey = 1u; + + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + CommandPtr command(CreateCommand<UnregisterAppInterfaceRequest>(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + const mobile_apis::AppInterfaceUnregisteredReason::eType kUnregisterReason = + mobile_apis::AppInterfaceUnregisteredReason::INVALID_ENUM; + + MessageSharedPtr dummy_msg(CreateMessage()); + EXPECT_CALL(mock_message_helper_, + GetOnAppInterfaceUnregisteredNotificationToMobile( + kConnectionKey, kUnregisterReason)) + .WillOnce(Return(dummy_msg)); + { + ::testing::InSequence sequence; + + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(dummy_msg, _)); + + EXPECT_CALL(app_mngr_, + UnregisterApplication( + kConnectionKey, mobile_apis::Result::SUCCESS, _, _)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_apis::Result::SUCCESS), _)); + } + + command->Run(); +} + +} // namespace unregister_app_interface_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc new file mode 100644 index 0000000000..e363567c64 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_button_request_test.cc @@ -0,0 +1,150 @@ +#include <stdint.h> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "mobile/unsubscribe_button_request.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unsubscribe_button_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; + +using sdl_rpc_plugin::commands::UnsubscribeButtonRequest; +using am::commands::MessageSharedPtr; + +typedef std::shared_ptr<UnsubscribeButtonRequest> CommandPtr; + +namespace { +const uint32_t kConnectionKey = 1u; +const mobile_apis::ButtonName::eType kButtonId = mobile_apis::ButtonName::OK; +} // namespace + +class UnsubscribeButtonRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + typedef TypeIf<kMocksAreNice, + NiceMock<application_manager_test::MockHMICapabilities>, + application_manager_test::MockHMICapabilities>::Result + MockHMICapabilities; +}; + +TEST_F(UnsubscribeButtonRequestTest, Run_AppNotRegistered_UNSUCCESS) { + CommandPtr command(CreateCommand<UnsubscribeButtonRequest>()); + + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeButtonRequestTest, + Run_UnsubscribeNotSubscribedButton_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][am::strings::button_name] = kButtonId; + + CommandPtr command(CreateCommand<UnsubscribeButtonRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) + .WillOnce(Return(false)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command->Run(); +} + +TEST_F(UnsubscribeButtonRequestTest, + Run_UnsubscribeNotAllowedByHmiCapabilities_UNSUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][am::strings::button_name] = kButtonId; + CommandPtr command(CreateCommand<UnsubscribeButtonRequest>(command_msg)); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::UNSUPPORTED_RESOURCE), _)); + + command->Run(); +} + +TEST_F(UnsubscribeButtonRequestTest, Run_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg)[am::strings::msg_params][am::strings::button_name] = kButtonId; + + CommandPtr command(CreateCommand<UnsubscribeButtonRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, is_ui_cooperating()) + .WillOnce(Return(true)); + + MessageSharedPtr button_caps_ptr(CreateMessage(smart_objects::SmartType_Map)); + (*button_caps_ptr)[0][am::hmi_response::button_name] = kButtonId; + EXPECT_CALL(mock_hmi_capabilities_, button_capabilities()) + .WillOnce(Return(button_caps_ptr.get())); + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + EXPECT_CALL(*mock_app, UnsubscribeFromButton(kButtonId)) + .WillOnce(Return(true)); + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Buttons_OnButtonSubscription))); + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + EXPECT_CALL(*mock_app, UpdateHash()); + command->Init(); + command->Run(); +} + +} // namespace unsubscribe_button_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc new file mode 100644 index 0000000000..042604b672 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/unsubscribe_way_points_request_test.cc @@ -0,0 +1,171 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "mobile/unsubscribe_way_points_request.h" +#include "interfaces/MOBILE_API.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace unsubscribe_way_points_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; +using ::testing::Return; + +using sdl_rpc_plugin::commands::UnSubscribeWayPointsRequest; +using am::commands::MessageSharedPtr; + +namespace { +const uint32_t kConnectionKey = 3u; +const uint32_t kAppId = 5u; +} // namespace + +class UnSubscribeWayPointsRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + UnSubscribeWayPointsRequestTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand<UnSubscribeWayPointsRequest>(command_msg_)) { + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + } + + MessageSharedPtr command_msg_; + std::shared_ptr<UnSubscribeWayPointsRequest> command_; +}; + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(_)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + Run_AppIsNotSubscribedForWayPoints_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) + .WillOnce(Return(false)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::IGNORED), _)); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, Run_AppSubscribedForWayPoints_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(app_mngr_, + IsAppSubscribedForWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))) + .WillOnce(Return(true)); + + EXPECT_CALL(mock_rpc_service_, + ManageHMICommand(HMIResultCodeIs( + hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints))); + + command_->Run(); +} + +TEST_F(UnSubscribeWayPointsRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + Event event(hmi_apis::FunctionID::INVALID_ENUM); + + command_->on_event(event); +} + +TEST_F(UnSubscribeWayPointsRequestTest, + OnEvent_ReceivedNavigationUnSubscribeWayPointsEvent_SUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillRepeatedly(Return(mock_app)); + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::msg_params] = 0; + (*event_msg)[am::strings::params][am::hmi_response::code] = + mobile_result::SUCCESS; + Event event(hmi_apis::FunctionID::Navigation_UnsubscribeWayPoints); + event.set_smart_object(*event_msg); + + EXPECT_CALL(app_mngr_, + UnsubscribeAppFromWayPoints( + ::testing::Matcher<am::ApplicationSharedPtr>(mock_app))); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::SUCCESS), _)); + + command_->on_event(event); +} + +} // namespace unsubscribe_way_points_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc new file mode 100644 index 0000000000..78fca8681a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/mobile/update_turn_list_request_test.cc @@ -0,0 +1,352 @@ +/* + * 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 <stdint.h> +#include <string> + +#include "gtest/gtest.h" +#include "mobile/update_turn_list_request.h" +#include "interfaces/MOBILE_API.h" + +#include "smart_objects/smart_object.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/command_request_test.h" +#include "application_manager/application.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_application.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/smart_object_keys.h" +#include "application_manager/event_engine/event.h" + +namespace test { +namespace components { +namespace commands_test { +namespace mobile_commands_test { +namespace update_turn_list_request { + +namespace am = ::application_manager; +namespace mobile_result = mobile_apis::Result; + +using ::testing::_; +using ::testing::Return; +using ::testing::ReturnRef; +using ::testing::Ref; +using ::testing::Eq; + +using sdl_rpc_plugin::commands::UpdateTurnListRequest; +using am::commands::MessageSharedPtr; +using application_manager_test::MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 3u; +const hmi_apis::FunctionID::eType kFunctionId = + hmi_apis::FunctionID::Buttons_OnButtonEvent; +const uint32_t kAppId = 5u; +} // namespace + +class UpdateTurnListRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + UpdateTurnListRequestTest() + : command_msg_(CreateMessage(smart_objects::SmartType_Map)) + , command_(CreateCommand<UpdateTurnListRequest>(command_msg_)) { + (*command_msg_)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + (*command_msg_)[am::strings::params][am::strings::function_id] = + kFunctionId; + } + + MessageSharedPtr command_msg_; + std::shared_ptr<UpdateTurnListRequest> command_; +}; + +TEST_F(UpdateTurnListRequestTest, Run_ApplicationIsNotRegistered_UNSUCCESS) { + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(ApplicationSharedPtr())); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand( + MobileResultCodeIs(mobile_result::APPLICATION_NOT_REGISTERED), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_InvalidNavigationText_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "invalid_navigation_text\t\n"; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_InvalidTurnIcon_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "valid_navigation_text"; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "invalid_turn_icon\t\n"; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, + Run_ProcessSoftButtonsNotSucceeded_UNSUCCESS) { + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = "valid_navigation_text"; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "valid_turn_icon"; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + const mobile_result::eType kExpectedResult = mobile_result::INVALID_ENUM; + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(kExpectedResult)); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(kExpectedResult), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_NoTurnList_UNSUCCESS) { + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL( + mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_result::INVALID_DATA), _)); + + command_->Run(); +} + +TEST_F(UpdateTurnListRequestTest, Run_ValidTurnList_SUCCESS) { + const std::string kNavigationText = "valid_navigation_text"; + + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = kNavigationText; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "valid_turn_icon"; + (*command_msg_)[am::strings::msg_params][am::strings::soft_buttons] = 0; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon], + Eq(mock_app), + Ref(app_mngr_))).WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton(_, _, kFunctionId)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); + ASSERT_TRUE((bool)result_msg); + EXPECT_EQ( + hmi_apis::FunctionID::Navigation_UpdateTurnList, + (*result_msg)[am::strings::params][am::strings::function_id].asInt()); + + ASSERT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + .keyExists(am::hmi_request::navi_text)); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_name)); + EXPECT_EQ( + hmi_apis::Common_TextFieldName::turnText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_name] + .asInt()); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_text)); + EXPECT_EQ( + kNavigationText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_text] + .asString()); +} + +TEST_F(UpdateTurnListRequestTest, Run_ValidTurnList_WARNINGS) { + const std::string kNavigationText = "valid_navigation_text"; + + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::navigation_text] = kNavigationText; + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon][am::strings::value] = + "valid_turn_icon"; + (*command_msg_)[am::strings::msg_params][am::strings::soft_buttons] = 0; + + MockAppPtr mock_app(CreateMockApp()); + EXPECT_CALL(app_mngr_, application(kConnectionKey)) + .WillOnce(Return(mock_app)); + + EXPECT_CALL(mock_message_helper_, + ProcessSoftButtons((*command_msg_)[am::strings::msg_params], + Eq(mock_app), + Ref(mock_policy_handler_), + Ref(app_mngr_))) + .WillOnce(Return(mobile_result::SUCCESS)); + + EXPECT_CALL( + mock_message_helper_, + VerifyImage( + (*command_msg_)[am::strings::msg_params][am::strings::turn_list][0] + [am::strings::turn_icon], + Eq(mock_app), + Ref(app_mngr_))).WillOnce(Return(mobile_result::WARNINGS)); + + EXPECT_CALL(mock_message_helper_, + SubscribeApplicationToSoftButton(_, _, kFunctionId)); + + MessageSharedPtr result_msg(CatchHMICommandResult(CallRun(*command_))); + ASSERT_TRUE(result_msg != nullptr); + EXPECT_EQ( + hmi_apis::FunctionID::Navigation_UpdateTurnList, + (*result_msg)[am::strings::params][am::strings::function_id].asInt()); + + ASSERT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + .keyExists(am::hmi_request::navi_text)); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_name)); + EXPECT_EQ( + hmi_apis::Common_TextFieldName::turnText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_name] + .asInt()); + + EXPECT_TRUE((*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text].keyExists( + am::hmi_request::field_text)); + EXPECT_EQ( + kNavigationText, + (*result_msg)[am::strings::msg_params][am::strings::turn_list][0] + [am::hmi_request::navi_text][am::hmi_request::field_text] + .asString()); +} + +TEST_F(UpdateTurnListRequestTest, OnEvent_UnknownEvent_UNSUCCESS) { + Event event(hmi_apis::FunctionID::INVALID_ENUM); + EXPECT_CALL(mock_rpc_service_, ManageMobileCommand(_, _)).Times(0); + + command_->on_event(event); +} + +TEST_F(UpdateTurnListRequestTest, OnEvent_UnsupportedResource_SUCCESS) { + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::UNSUPPORTED_RESOURCE; + const mobile_result::eType mobile_response_code = + mobile_result::UNSUPPORTED_RESOURCE; + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; + (*event_msg)[am::strings::msg_params] = 0; + + Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + command_->on_event(event); +} + +TEST_F(UpdateTurnListRequestTest, + OnEvent_ReceivedNavigationUpdateTurnListEvent_SUCCESS) { + const hmi_apis::Common_Result::eType hmi_response_code = + hmi_apis::Common_Result::SUCCESS; + const mobile_result::eType mobile_response_code = mobile_result::SUCCESS; + + MessageSharedPtr event_msg(CreateMessage(smart_objects::SmartType_Map)); + (*event_msg)[am::strings::params][am::hmi_response::code] = hmi_response_code; + (*event_msg)[am::strings::msg_params] = 0; + + Event event(hmi_apis::FunctionID::Navigation_UpdateTurnList); + event.set_smart_object(*event_msg); + + EXPECT_CALL(mock_rpc_service_, + ManageMobileCommand(MobileResultCodeIs(mobile_response_code), _)); + + command_->on_event(event); +} + +} // namespace update_turn_list_request +} // namespace mobile_commands_test +} // namespace commands_test +} // namespace components +} // namespace test |