diff options
author | Yaroslav Mamykin (GitHub) <ymamykin@luxoft.com> | 2019-09-05 14:03:57 +0300 |
---|---|---|
committer | Yarik <ymamykin@gmail.com> | 2019-11-15 15:16:38 +0200 |
commit | aae04d0f3b53ba950688a9db0f768c38926b88cc (patch) | |
tree | 88d02148ea8eeb820999b61cc7891e0d4d0cfbb0 | |
parent | 6e01ff7ca921fd1d1af9a01cdb0cadfca14ea519 (diff) | |
download | sdl_core-aae04d0f3b53ba950688a9db0f768c38926b88cc.tar.gz |
Add unit test
-rwxr-xr-x | src/components/application_manager/test/CMakeLists.txt | 5 | ||||
-rw-r--r-- | src/components/application_manager/test/rpc_handler_impl_test.cc | 117 |
2 files changed, 122 insertions, 0 deletions
diff --git a/src/components/application_manager/test/CMakeLists.txt b/src/components/application_manager/test/CMakeLists.txt index f6146f96f9..230be524c8 100755 --- a/src/components/application_manager/test/CMakeLists.txt +++ b/src/components/application_manager/test/CMakeLists.txt @@ -86,6 +86,9 @@ set (RequestController_SOURCES ${AM_TEST_DIR}/mock_message_helper.cc ) +set (RPCHandlerImplTest_SOURCES ${AM_TEST_DIR}/rpc_handler_impl_test.cc + ${AM_TEST_DIR}/mock_message_helper.cc) + set(LIBRARIES Utils ApplicationManager @@ -144,6 +147,8 @@ create_test("help_prompt_manager_test" "${testSourcesHelpPromptManager}" "${LIBR create_test("request_controller_test" "${RequestController_SOURCES}" "${LIBRARIES}") +create_test("rpc_handler_impl_test" "${RPCHandlerImplTest_SOURCES}" "${LIBRARIES}") + set(ResumptionData_SOURCES ${AM_TEST_DIR}/resumption/resumption_data_test.cc ${AM_TEST_DIR}/resumption/resumption_data_db_test.cc diff --git a/src/components/application_manager/test/rpc_handler_impl_test.cc b/src/components/application_manager/test/rpc_handler_impl_test.cc new file mode 100644 index 0000000000..9db8e7c0d8 --- /dev/null +++ b/src/components/application_manager/test/rpc_handler_impl_test.cc @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2019, Ford Motor Company + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following + * disclaimer in the documentation and/or other materials provided with the + * distribution. + * + * Neither the name of the Ford Motor Company nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "application_manager/rpc_handler_impl.h" +#include <memory> +#include "application_manager/mock_application_manager.h" +#include "application_manager/smart_object_keys.h" +#include "interfaces/HMI_API.h" +#include "interfaces/MOBILE_API.h" + +namespace test { +namespace components { +namespace application_manager_test { + +using ::test::components::application_manager_test::MockApplicationManager; +using ::testing::_; +using ::testing::Mock; +using ::testing::NiceMock; +using namespace ::smart_objects; +using namespace application_manager::rpc_handler; + +class RPCHandlerImplTest : public ::testing::Test { + public: + RPCHandlerImplTest() + : rpc_handler_(new RPCHandlerImpl( + mock_app_mngr_, hmi_so_factory_, mobile_so_factory_)) {} + + protected: + std::unique_ptr<RPCHandlerImpl> rpc_handler_; + hmi_apis::HMI_API hmi_so_factory_; + mobile_apis::MOBILE_API mobile_so_factory_; + NiceMock<MockApplicationManager> mock_app_mngr_; +}; + +TEST_F(RPCHandlerImplTest, GetMessageVersion_SUCCESS) { + namespace json_str = ns_smart_device_link::ns_json_handler::strings; + namespace app_str = application_manager::strings; + + std::vector<utils::SemanticVersion> test_versions = { + utils::SemanticVersion("2.5.0"), + utils::SemanticVersion("3.0.0"), + utils::SemanticVersion("5.0.0"), + utils::SemanticVersion("6.1.0")}; + + SmartObject message; + message[json_str::S_MSG_PARAMS] = SmartObject(SmartType_Map); + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] = + SmartObject(SmartType_Map); + + for (const auto& expected_version : test_versions) { + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::major_version] = expected_version.major_version_; + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::minor_version] = expected_version.minor_version_; + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::patch_version] = expected_version.patch_version_; + + utils::SemanticVersion result_message_version; + rpc_handler_->GetMessageVersion(message, result_message_version); + EXPECT_EQ(expected_version, result_message_version); + } +} + +TEST_F(RPCHandlerImplTest, GetMessageVersion_InvalidVersion) { + namespace json_str = ns_smart_device_link::ns_json_handler::strings; + namespace app_str = application_manager::strings; + + SmartObject message; + message[json_str::S_MSG_PARAMS] = SmartObject(SmartType_Map); + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] = + SmartObject(SmartType_Map); + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::major_version] = 0; + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::minor_version] = 0; + message[json_str::S_MSG_PARAMS][app_str::sync_msg_version] + [app_str::patch_version] = 0; + + utils::SemanticVersion expected_version(utils::base_rpc_version); + + utils::SemanticVersion result_message_version; + rpc_handler_->GetMessageVersion(message, result_message_version); + EXPECT_EQ(expected_version, result_message_version); +} + +} // namespace application_manager_test +} // namespace components +} // namespace test |