diff options
author | Yevhenii Dementieiev (GitHub) <ydementieiev@luxoft.com> | 2020-03-20 14:39:55 +0200 |
---|---|---|
committer | Ira Lytvynenko (GitHub) <ILytvynenko@luxoft.com> | 2020-03-31 16:20:08 +0300 |
commit | a90d9696af59f8050d8902ebb781a57e52c992be (patch) | |
tree | 196a36ddb7c03353c0f433bb675a6dfdc9b0b6c8 | |
parent | 142f8630b5c828dda7de87a31154f854b8433138 (diff) | |
download | sdl_core-feature/persisting_hmi_capabilities.tar.gz |
Increase unit tests coverage on persistence HMI capabilitiesfeature/persisting_hmi_capabilities
16 files changed, 1989 insertions, 90 deletions
diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc new file mode 100644 index 0000000000..375576ff12 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/button_get_capabilities_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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/button_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace button_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::ButtonGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class ButtonGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(ButtonGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<ButtonGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(ButtonGetCapabilitiesRequestTest, + onTimeOut_ButtonsGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<ButtonGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::Buttons_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace button_get_capabilities_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_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc new file mode 100644 index 0000000000..4f9c07a1a5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/rc_get_capabilities_request_test.cc @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2020, 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_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace rc_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::RCGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class RCGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> {}; + +TEST_F(RCGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand<RCGetCapabilitiesRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(RCGetCapabilitiesRequestTest, + onTimeOut_OnCapabilityInitialized_RemoveButtonsGetCapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + RequestToHMIPtr command(CreateCommand<RCGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::RC_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); +} + +} // namespace rc_get_capabilities_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/tts_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc new file mode 100644 index 0000000000..2717fcd5a5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_capabilities_request_test.cc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2020, 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/tts_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class TTSGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetCapabilitiesRequestTest, onTimeOut_TTSGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_capabilities_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/tts_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc new file mode 100644 index 0000000000..43ab217abe --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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/tts_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class TTSGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<TTSGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetLanguageRequestTest, onTimeOut_TTSGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<TTSGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_language_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/tts_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..2092b794c5 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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/tts_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::TTSGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class TTSGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(TTSGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSGetSupportedLanguagesRequestTest, + onTimeOut_TTSGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<TTSGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::TTS_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace tts_get_supported_languages_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/tts_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc new file mode 100644 index 0000000000..db4786e34f --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/tts_is_ready_request_test.cc @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2020, 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/tts_is_ready_request.h" + +#include <memory> +#include <set> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/event_engine/event.h" +#include "application_manager/hmi_interfaces.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_hmi_interface.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace tts_is_ready_request { + +using ::testing::_; +using ::testing::ReturnRef; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; +using am::event_engine::Event; +using sdl_rpc_plugin::commands::TTSIsReadyRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; +typedef std::shared_ptr<TTSIsReadyRequest> TTSIsReadyRequestPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class TTSIsReadyRequestTest + : public CommandRequestTest<CommandsTestMocks::kIsNice> { + public: + TTSIsReadyRequestTest() : command_(CreateCommand<TTSIsReadyRequest>()) {} + + void SetUpExpectations(const bool is_tts_cooperating_available, + const bool should_message_be_sent, + const bool message_contains_param, + const am::HmiInterfaces::InterfaceState state) { + if (should_message_be_sent) { + ExpectSendMessagesToHMI(); + } + EXPECT_CALL(mock_hmi_capabilities_, + set_is_tts_cooperating(is_tts_cooperating_available)); + + if (message_contains_param) { + ON_CALL(app_mngr_, hmi_interfaces()) + .WillByDefault(ReturnRef(mock_hmi_interfaces_)); + EXPECT_CALL( + mock_hmi_interfaces_, + SetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_TTS, 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_TTS)) + .WillOnce(Return(state)); + } + + void ExpectSendMessagesToHMI() { + smart_objects::SmartObjectSPtr language = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL(mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_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 = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetSupportedLanguages, _)) + .WillOnce(Return(support_language)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(support_language, _)); + + smart_objects::SmartObjectSPtr capabilities = + std::make_shared<smart_objects::SmartObject>( + smart_objects::SmartType_Map); + EXPECT_CALL( + mock_message_helper_, + CreateModuleInfoSO(hmi_apis::FunctionID::TTS_GetCapabilities, _)) + .WillOnce(Return(capabilities)); + EXPECT_CALL(mock_rpc_service_, ManageHMICommand(capabilities, _)); + } + + void PrepareEvent(const bool message_contains_param, + const bool is_tts_cooperating_available, + Event& out_event) { + MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); + if (message_contains_param) { + (*msg)[am::strings::msg_params][am::strings::available] = + is_tts_cooperating_available; + } + out_event.set_smart_object(*msg); + } + + void HMICapabilitiesExpectations() { + std::set<hmi_apis::FunctionID::eType> interfaces_to_update{ + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities}; + EXPECT_CALL(mock_hmi_capabilities_, GetRequestsRequiredForCapabilities()) + .WillOnce(Return(interfaces_to_update)); + } + + TTSIsReadyRequestPtr command_; +}; + +TEST_F(TTSIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::msg_params][am::strings::number] = kStrNumber; + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + + RequestToHMIPtr command(CreateCommand<TTSIsReadyRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(TTSIsReadyRequestTest, + Run_NoKeyAvailableInMessage_HmiInterfacesIgnored_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_NOT_RESPONSE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToFalse_StateNotAvailable_CacheIsAbsent) { + const bool is_tts_cooperating_available = false; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_NOT_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_KeyAvailableEqualToTrue_StateAvailable_CacheIsAbsnet) { + const bool is_tts_cooperating_available = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_AVAILABLE; + Event event(hmi_apis::FunctionID::TTS_IsReady); + PrepareEvent(message_contains_param, is_tts_cooperating_available, event); + HMICapabilitiesExpectations(); + SetUpExpectations(is_tts_cooperating_available, + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->on_event(event); +} + +TEST_F(TTSIsReadyRequestTest, + Run_HMIDoestRespond_SendMessageToHMIByTimeout_CacheIsAbsent) { + std::set<hmi_apis::FunctionID::eType> interfaces_to_update{ + hmi_apis::FunctionID::TTS_GetLanguage, + hmi_apis::FunctionID::TTS_GetSupportedLanguages, + hmi_apis::FunctionID::TTS_GetCapabilities}; + EXPECT_CALL(mock_hmi_capabilities_, GetRequestsRequiredForCapabilities()) + .WillOnce(Return(interfaces_to_update)); + ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); + command_->onTimeOut(); +} + +} // namespace tts_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_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc new file mode 100644 index 0000000000..944a5ee286 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class UIGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetCapabilitiesRequestTest, onTimeOut_UIGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_capabilities_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_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc new file mode 100644 index 0000000000..1412eb9856 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class UIGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetLanguageRequestTest, onTimeOut_UIGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<UIGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_language_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_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..da518dafe2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/ui_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace ui_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::UIGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class UIGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(UIGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<UIGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(UIGetSupportedLanguagesRequestTest, + onTimeOut_UIGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<UIGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace ui_get_supported_languages_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_get_capabilities_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc new file mode 100644 index 0000000000..b21dbe578a --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_capabilities_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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_get_capabilities_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_capabilities_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetCapabilitiesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class VRGetCapabilitiesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetCapabilitiesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetCapabilitiesRequestTest, onTimeOut_VRGetCapabilitiesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetCapabilitiesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetCapabilities)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_capabilities_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_get_language_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc new file mode 100644 index 0000000000..01d7ba659d --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_language_request_test.cc @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020, 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_get_language_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_language_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetLanguageRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class VRGetLanguageRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetLanguageRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetLanguageRequestTest, onTimeOut_VRGetLanguageUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command(CreateCommand<VRGetLanguageRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetLanguage)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_language_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_get_supported_languages_request_test.cc b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc new file mode 100644 index 0000000000..ab2f59852e --- /dev/null +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/commands/hmi/vr_get_supported_languages_request_test.cc @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2020, 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_get_supported_languages_request.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/commands/command_request_test.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/request_to_hmi.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vr_get_supported_languages_request { + +using ::testing::_; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; +using am::commands::RequestToHMI; +using sdl_rpc_plugin::commands::VRGetSupportedLanguagesRequest; + +typedef std::shared_ptr<RequestToHMI> RequestToHMIPtr; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kStrNumber = "123"; +} // namespace + +class VRGetSupportedLanguagesRequestTest + : public CommandsTest<CommandsTestMocks::kIsNice> { + public: + MessageSharedPtr CreateCommandMsg() { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::msg_params][strings::number] = kStrNumber; + (*command_msg)[strings::params][strings::connection_key] = kConnectionKey; + return command_msg; + } +}; + +TEST_F(VRGetSupportedLanguagesRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg = CreateCommandMsg(); + + RequestToHMIPtr command( + CreateCommand<VRGetSupportedLanguagesRequest>(command_msg)); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +TEST_F(VRGetSupportedLanguagesRequestTest, + onTimeOut_VRGetSupportedLanguagesUpdated) { + MessageSharedPtr command_msg = CreateCommandMsg(); + RequestToHMIPtr command( + CreateCommand<VRGetSupportedLanguagesRequest>(command_msg)); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VR_GetSupportedLanguages)); + ASSERT_TRUE(command->Init()); + + command->Run(); + command->onTimeOut(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + +} // namespace vr_get_supported_languages_request +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc new file mode 100644 index 0000000000..6bf379a4e2 --- /dev/null +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_get_vehicle_type_response_test.cc @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2020, 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/vi_get_vehicle_type_response.h" + +#include <memory> +#include <string> + +#include "gtest/gtest.h" + +#include "application_manager/application.h" +#include "application_manager/commands/commands_test.h" +#include "application_manager/commands/response_from_hmi.h" +#include "application_manager/mock_application_manager.h" +#include "application_manager/mock_hmi_capabilities.h" +#include "application_manager/mock_message_helper.h" +#include "application_manager/policies/mock_policy_handler_interface.h" +#include "application_manager/smart_object_keys.h" +#include "smart_objects/smart_object.h" +#include "vehicle_info_plugin/commands/vi_command_request_test.h" + +namespace test { +namespace components { +namespace commands_test { +namespace hmi_commands_test { +namespace vi_get_vehicle_type_response { + +using ::testing::_; +using ::testing::NiceMock; +using ::testing::Return; +namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +namespace hmi_response = am::hmi_response; +namespace hmi_interface = ::application_manager::hmi_interface; +using vehicle_info_plugin::commands::VIGetVehicleTypeResponse; + +typedef std::shared_ptr<VIGetVehicleTypeResponse> VIGetVehicleTypeResponsePtr; +typedef NiceMock< + ::test::components::application_manager_test::MockHMICapabilities> + MockHMICapabilities; + +namespace { +const uint32_t kConnectionKey = 2u; +const std::string kVehicleType = "vehicle_type"; +} // namespace + +class VIGetVehicleTypeResponseTest + : public VICommandRequestTest<CommandsTestMocks::kIsNice> { + public: + SmartObject capabilities_; +}; + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeSuccess_ChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::SUCCESS; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL( + mock_hmi_capabilities_, + set_vehicle_type( + (*command_msg)[strings::msg_params][hmi_response::vehicle_type])); + EXPECT_CALL(mock_hmi_capabilities_, + SaveCachedCapabilitiesToFile(hmi_interface::vehicle_info, _, _)); + ASSERT_TRUE(command->Init()); + + command->Run(); + EXPECT_TRUE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + RUN_ResultCodeNotSuccess_DontChangeHMICapabilities) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + (*command_msg)[strings::params][hmi_response::vehicle_type] = kVehicleType; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, set_vehicle_type(_)).Times(0); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_FALSE((*command_msg)[am::strings::msg_params].keyExists( + hmi_response::vehicle_type)); +} + +TEST_F(VIGetVehicleTypeResponseTest, + onTimeOut_Run_ResponseForInterface_ReceivedError) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[strings::params][hmi_response::code] = + hmi_apis::Common_Result::ABORTED; + + VIGetVehicleTypeResponsePtr command = + CreateCommandVI<VIGetVehicleTypeResponse>(command_msg); + + EXPECT_CALL(mock_hmi_capabilities_, + UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::VehicleInfo_GetVehicleType)); + ASSERT_TRUE(command->Init()); + + command->Run(); +} + +} // namespace vi_get_vehicle_type_response +} // namespace hmi_commands_test +} // namespace commands_test +} // namespace components +} // namespace test diff --git a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc index 01d33f456c..511484f2e2 100644 --- a/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc +++ b/src/components/application_manager/rpc_plugins/vehicle_info_plugin/test/commands/hmi/vi_is_ready_request_test.cc @@ -32,7 +32,9 @@ #include "hmi/vi_is_ready_request.h" +#include <memory> #include <set> + #include "gtest/gtest.h" #include "application_manager/event_engine/event.h" @@ -56,26 +58,32 @@ using ::testing::_; using ::testing::Return; using ::testing::ReturnRef; namespace am = ::application_manager; +namespace strings = ::application_manager::strings; +using am::commands::CommandImpl; using am::commands::MessageSharedPtr; +using am::commands::RequestToHMI; using am::event_engine::Event; using vehicle_info_plugin::commands::VIIsReadyRequest; -using MockHmiCapabilities = application_manager_test::MockHMICapabilities; typedef std::shared_ptr<VIIsReadyRequest> VIIsReadyRequestPtr; +namespace { +const uint32_t kConnectionKey = 2u; +} // namespace + class VIIsReadyRequestTest : public VICommandRequestTest<CommandsTestMocks::kIsNice> { public: VIIsReadyRequestTest() : command_(CreateCommandVI<VIIsReadyRequest>()) {} void SetUpExpectations(bool is_vi_cooperating_available, - bool is_send_message_to_hmi, - bool is_message_contain_param, + bool should_message_be_sent, + bool message_contains_param, am::HmiInterfaces::InterfaceState state) { EXPECT_CALL(mock_hmi_capabilities_, set_is_ivi_cooperating(is_vi_cooperating_available)); - if (is_message_contain_param) { + if (message_contains_param) { EXPECT_CALL(app_mngr_, hmi_interfaces()) .WillRepeatedly(ReturnRef(mock_hmi_interfaces_)); EXPECT_CALL(mock_hmi_interfaces_, @@ -92,7 +100,7 @@ class VIIsReadyRequestTest GetInterfaceState(am::HmiInterfaces::HMI_INTERFACE_VehicleInfo)) .WillOnce(Return(state)); - if (is_send_message_to_hmi) { + if (should_message_be_sent) { ExpectSendMessagesToHMI(); } } @@ -106,15 +114,15 @@ class VIIsReadyRequestTest EXPECT_CALL(mock_rpc_service_, ManageHMICommand(ivi_type, _)); } - void PrepareEvent(bool is_message_contain_param, - Event& event, - bool is_vi_cooperating_available = false) { + void PrepareEvent(bool message_contains_param, + bool is_vi_cooperating_available, + Event& out_event) { MessageSharedPtr msg = CreateMessage(smart_objects::SmartType_Map); - if (is_message_contain_param) { + if (message_contains_param) { (*msg)[am::strings::msg_params][am::strings::available] = is_vi_cooperating_available; } - event.set_smart_object(*msg); + out_event.set_smart_object(*msg); } void HMICapabilitiesExpectations() { @@ -128,44 +136,75 @@ class VIIsReadyRequestTest VIIsReadyRequestPtr command_; }; +TEST_F(VIIsReadyRequestTest, RUN_SendRequest_SUCCESS) { + MessageSharedPtr command_msg(CreateMessage(smart_objects::SmartType_Map)); + (*command_msg)[am::strings::params][am::strings::connection_key] = + kConnectionKey; + VIIsReadyRequestPtr command = CreateCommandVI<VIIsReadyRequest>(command_msg); + EXPECT_CALL(mock_rpc_service_, SendMessageToHMI(command_msg)); + ASSERT_TRUE(command->Init()); + + command->Run(); + + EXPECT_EQ(CommandImpl::hmi_protocol_type_, + (*command_msg)[strings::params][strings::protocol_type].asInt()); + EXPECT_EQ(CommandImpl::protocol_version_, + (*command_msg)[strings::params][strings::protocol_version].asInt()); +} + TEST_F(VIIsReadyRequestTest, Run_NoKeyAvailableInMessage_HmiInterfacesIgnored) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = false; + const bool should_message_be_sent = true; + const bool message_contains_param = false; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_NOT_RESPONSE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); HMICapabilitiesExpectations(); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_RESPONSE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToFalse_StateNotAvailable) { const bool is_vi_cooperating_available = false; - const bool is_send_message_to_hmi = false; - const bool is_message_contain_param = true; + const bool should_message_be_sent = false; + const bool message_contains_param = true; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_NOT_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); - PrepareEvent(is_message_contain_param, event); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_NOT_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } TEST_F(VIIsReadyRequestTest, Run_KeyAvailableEqualToTrue_StateAvailable) { const bool is_vi_cooperating_available = true; - const bool is_send_message_to_hmi = true; - const bool is_message_contain_param = true; + const bool should_message_be_sent = true; + const bool message_contains_param = true; + const am::HmiInterfaces::InterfaceState state = + am::HmiInterfaces::STATE_AVAILABLE; Event event(hmi_apis::FunctionID::VehicleInfo_IsReady); HMICapabilitiesExpectations(); - PrepareEvent(is_message_contain_param, event, is_vi_cooperating_available); + PrepareEvent(message_contains_param, is_vi_cooperating_available, event); SetUpExpectations(is_vi_cooperating_available, - is_send_message_to_hmi, - is_message_contain_param, - am::HmiInterfaces::STATE_AVAILABLE); + should_message_be_sent, + message_contains_param, + state); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->on_event(event); } @@ -175,6 +214,9 @@ TEST_F(VIIsReadyRequestTest, Run_HMIDoestRespond_SendMessageToHMIByTimeout) { EXPECT_CALL(mock_hmi_capabilities_, GetRequestsRequiredForCapabilities()) .WillOnce(Return(interfaces_to_update)); ExpectSendMessagesToHMI(); + ASSERT_TRUE(command_->Init()); + + command_->Run(); command_->onTimeOut(); } diff --git a/src/components/application_manager/test/hmi_capabilities_test.cc b/src/components/application_manager/test/hmi_capabilities_test.cc index 53217ea476..3c1a79b82a 100644 --- a/src/components/application_manager/test/hmi_capabilities_test.cc +++ b/src/components/application_manager/test/hmi_capabilities_test.cc @@ -33,8 +33,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "application_manager/hmi_capabilities_for_testing.h" + #include <algorithm> +#include <memory> #include <string> +#include <vector> #include "application_manager/hmi_capabilities.h" #include "application_manager/mock_message_helper.h" @@ -43,7 +47,6 @@ #include "smart_objects/enum_schema_item.h" #include "smart_objects/smart_object.h" -#include "application_manager/hmi_capabilities_for_testing.h" #include "application_manager/mock_application_manager.h" #include "application_manager/mock_application_manager_settings.h" #include "application_manager/mock_event_dispatcher.h" @@ -54,6 +57,7 @@ #include "resumption/last_state_impl.h" #include "resumption/last_state_wrapper_impl.h" #include "utils/file_system.h" +#include "utils/jsoncpp_reader_wrapper.h" namespace test { namespace components { @@ -304,16 +308,17 @@ class HMICapabilitiesTest : public ::testing::Test { ON_CALL(mock_application_manager_settings_, hmi_capabilities_cache_file_name()) .WillByDefault(ReturnRef(file_cache_name_)); - EXPECT_CALL(mock_event_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_event_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings_, launch_hmi()) - .WillOnce(Return(false)); + EXPECT_CALL(mock_event_dispatcher, add_observer(_, _, _)); + EXPECT_CALL(mock_event_dispatcher, remove_observer(_)); + ON_CALL(mock_application_manager_settings_, launch_hmi()) + .WillByDefault(Return(false)); hmi_capabilities_test = std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr_); hmi_capabilities_test->Init(last_state_wrapper_); } void TearDown() OVERRIDE { + DeleteFileIfExists(kHmiCapabilitiesCacheDefaultFile); hmi_capabilities_test.reset(); } static void TearDownTestCase() { @@ -888,19 +893,14 @@ TEST_F(HMICapabilitiesTest, const std::string hmi_capabilities_file = "hmi_capabilities_sc1.json"; - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_application_manager_settings, - hmi_capabilities_cache_file_name()) - .WillOnce(ReturnRef(file_cache_name_)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); DeleteFileIfExists(kAppInfoDataFile); @@ -929,19 +929,14 @@ TEST_F(HMICapabilitiesTest, const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_application_manager_settings, - hmi_capabilities_cache_file_name()) - .WillOnce(ReturnRef(file_cache_name_)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); DeleteFileIfExists(kAppInfoDataFile); @@ -973,19 +968,15 @@ TEST_F(HMICapabilitiesTest, const std::string hmi_capabilities_file = "hmi_capabilities_old_apt.json"; - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_file)); - EXPECT_CALL(mock_application_manager_settings, - hmi_capabilities_cache_file_name()) - .WillOnce(ReturnRef(file_cache_name_)); - EXPECT_CALL(mock_dispatcher, add_observer(_, _, _)).Times(1); - EXPECT_CALL(mock_dispatcher, remove_observer(_)).Times(1); - EXPECT_CALL(mock_application_manager_settings, launch_hmi()) - .WillOnce(Return(false)); + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); + EXPECT_CALL(*(MockMessageHelper::message_helper_mock()), CommonLanguageFromString(_)) .WillRepeatedly(Invoke(TestCommonLanguageFromString)); @@ -1071,15 +1062,14 @@ TEST_F( const std::string hmi_capabilities_invalid_file = "hmi_capabilities_invalid_file.json"; - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_invalid_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, - hmi_capabilities_cache_file_name()) - .WillOnce(ReturnRef(file_cache_name_)); + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); auto hmi_capabilities = std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); @@ -1109,15 +1099,14 @@ TEST_F(HMICapabilitiesTest, file_system::CreateFile(file_cache_name_); EXPECT_TRUE(file_system::FileExists(file_cache_name_)); - EXPECT_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) - .WillOnce(ReturnRef(hmi_capabilities_invalid_file)); - EXPECT_CALL(mock_app_mngr, event_dispatcher()) - .WillOnce(ReturnRef(mock_dispatcher)); - EXPECT_CALL(mock_app_mngr, get_settings()) - .WillRepeatedly(ReturnRef(mock_application_manager_settings)); - EXPECT_CALL(mock_application_manager_settings, - hmi_capabilities_cache_file_name()) - .WillOnce(ReturnRef(file_cache_name_)); + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_invalid_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); auto hmi_capabilities = std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); @@ -1129,6 +1118,196 @@ TEST_F(HMICapabilitiesTest, EXPECT_FALSE(file_system::FileExists(file_cache_name_)); } +TEST_F(HMICapabilitiesTest, + CacheFileNameNotSpecified_NoNeedToSave_ReturnSuccess) { + MockApplicationManager mock_app_mngr; + event_engine_test::MockEventDispatcher mock_dispatcher; + MockApplicationManagerSettings mock_application_manager_settings; + const smart_objects::CSmartSchema schema; + const std::string hmi_capabilities_empty_file_name = ""; + const std::vector<std::string> sections_to_update{hmi_response::language}; + + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_empty_file_name)); + + auto hmi_capabilities = + std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); + + EXPECT_TRUE(hmi_capabilities->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema)); +} + +TEST_F(HMICapabilitiesTest, SaveCachedCapabilitiesToFile_ParseFile_Failed) { + MockApplicationManager mock_app_mngr; + event_engine_test::MockEventDispatcher mock_dispatcher; + MockApplicationManagerSettings mock_application_manager_settings; + const smart_objects::CSmartSchema schema; + const std::vector<std::string> sections_to_update{hmi_response::language}; + + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); + + auto hmi_capabilities = + std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); + + file_system::CreateFile(file_cache_name_); + EXPECT_TRUE(file_system::FileExists(file_cache_name_)); + + EXPECT_FALSE(hmi_capabilities->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema)); +} + +TEST_F(HMICapabilitiesTest, + SaveCachedCapabilitiesToFile_ParsedFieldsSave_Success) { + MockApplicationManager mock_app_mngr; + event_engine_test::MockEventDispatcher mock_dispatcher; + MockApplicationManagerSettings mock_application_manager_settings; + const smart_objects::CSmartSchema schema; + const std::vector<std::string> sections_to_update{ + hmi_response::display_capabilities}; + const std::string content_to_save = "{\"field\" : \"value\" }"; + + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); + + auto hmi_capabilities = + std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); + + file_system::CreateFile(file_cache_name_); + EXPECT_TRUE(file_system::FileExists(file_cache_name_)); + + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + file_system::Write(file_cache_name_, binary_data_to_save); + + EXPECT_TRUE(hmi_capabilities->SaveCachedCapabilitiesToFile( + hmi_interface::tts, sections_to_update, schema)); + + std::string content_after_update; + EXPECT_TRUE(file_system::ReadFile(file_cache_name_, content_after_update)); + EXPECT_NE(content_to_save, content_after_update); +} + +TEST_F(HMICapabilitiesTest, PrepareJsonValueForSaving_Success) { + MockApplicationManager mock_app_mngr; + event_engine_test::MockEventDispatcher mock_dispatcher; + MockApplicationManagerSettings mock_application_manager_settings; + const smart_objects::CSmartSchema schema; + + const std::vector<std::string> sections_to_update{ + hmi_response::display_capabilities, + hmi_response::hmi_zone_capabilities, + hmi_response::soft_button_capabilities, + strings::audio_pass_thru_capabilities, + strings::hmi_capabilities, + strings::system_capabilities, + hmi_response::languages}; + + const std::vector<std::string> interfaces_name{ + hmi_interface::tts, + hmi_interface::vr, + hmi_interface::ui, + hmi_interface::buttons, + hmi_interface::vehicle_info, + hmi_interface::rc, + hmi_response::speech_capabilities, + hmi_response::prerecorded_speech_capabilities, + hmi_response::button_capabilities, + hmi_response::preset_bank_capabilities}; + + const std::string content_to_save = "{\"field\" : \"value\" }"; + const std::vector<uint8_t> binary_data_to_save(content_to_save.begin(), + content_to_save.end()); + + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); + + auto hmi_capabilities = + std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); + + file_system::CreateFile(file_cache_name_); + EXPECT_TRUE(file_system::FileExists(file_cache_name_)); + + file_system::Write(file_cache_name_, binary_data_to_save); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(hmi_capabilities->SaveCachedCapabilitiesToFile( + interfaces_name[i], sections_to_update, schema)); + } + + std::string content_after_update; + EXPECT_TRUE(file_system::ReadFile(file_cache_name_, content_after_update)); + + Json::Value root_node; + utils::JsonReader reader; + EXPECT_TRUE(reader.parse(content_after_update, &root_node)); + + for (size_t i = 0; i < interfaces_name.size(); ++i) { + EXPECT_TRUE(static_cast<bool>(root_node[interfaces_name[i]])); + } +} + +TEST_F(HMICapabilitiesTest, + OnCapabilityInitialized_RespondToAllPendingRAIRequestsIfTheyHold) { + MockApplicationManager mock_app_mngr; + NiceMock<event_engine_test::MockEventDispatcher> mock_dispatcher; + MockApplicationManagerSettings mock_application_manager_settings; + + const std::string hmi_capabilities_file = "hmi_capabilities_sc2.json"; + + ON_CALL(mock_app_mngr, event_dispatcher()) + .WillByDefault(ReturnRef(mock_dispatcher)); + ON_CALL(mock_app_mngr, get_settings()) + .WillByDefault(ReturnRef(mock_application_manager_settings)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_file_name()) + .WillByDefault(ReturnRef(hmi_capabilities_file)); + ON_CALL(mock_application_manager_settings, hmi_capabilities_cache_file_name()) + .WillByDefault(ReturnRef(file_cache_name_)); + + auto hmi_capabilities = + std::make_shared<HMICapabilitiesForTesting>(mock_app_mngr); + hmi_capabilities->Init(last_state_wrapper_); + + EXPECT_TRUE(hmi_capabilities->navigation_supported()); + + smart_objects::SmartObject navigation_capability_so = + *(hmi_capabilities->navigation_capability()); + EXPECT_TRUE(navigation_capability_so.keyExists("sendLocationEnabled")); + EXPECT_TRUE(navigation_capability_so.keyExists("getWayPointsEnabled")); + EXPECT_TRUE(navigation_capability_so["sendLocationEnabled"].asBool()); + EXPECT_FALSE(navigation_capability_so["getWayPointsEnabled"].asBool()); + EXPECT_FALSE(navigation_capability_so["getWayPointsEnabled"].asBool()); + + EXPECT_TRUE(hmi_capabilities->LoadCapabilitiesFromFile()); + EXPECT_CALL(mock_app_mngr, SetHMICooperating(true)); + + // All pending RAI requests are responded + EXPECT_CALL(mock_app_mngr, IsHMICooperating()).WillOnce(Return(true)); + hmi_capabilities->UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); + + // All pending RAI requests are hold, need respond them + EXPECT_CALL(mock_app_mngr, IsHMICooperating()).WillOnce(Return(false)); + hmi_capabilities->UpdateRequestsRequiredForCapabilities( + hmi_apis::FunctionID::UI_GetCapabilities); +} + } // namespace application_manager_test } // namespace components } // namespace test diff --git a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc index f6cc08c21d..1d8be1d8a0 100644 --- a/src/components/policy/policy_regular/test/policy_manager_impl_test.cc +++ b/src/components/policy/policy_regular/test/policy_manager_impl_test.cc @@ -1988,6 +1988,15 @@ TEST_F(PolicyManagerImplTest2, EXPECT_EQ(0u, ret.size()); } +TEST_F(PolicyManagerImplTest2, SetMetaInfo_SetCCPUVersion_SUCCESS) { + const std::string ccpu_version = "ccpu_version"; + const std::string wers_country_code = "wersCountryCode"; + const std::string language = "language"; + + manager->GetCache()->SetMetaInfo(ccpu_version, wers_country_code, language); + EXPECT_EQ(ccpu_version, (manager->GetCache())->GetCCPUVersionFromPT()); +} + } // namespace policy_test } // namespace components } // namespace test |