diff options
Diffstat (limited to 'src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi')
56 files changed, 9616 insertions, 0 deletions
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 |