diff options
author | Andriy Byzhynar <abyzhynar@luxoft.com> | 2018-06-27 15:22:19 +0300 |
---|---|---|
committer | Alexander <akutsan@luxoft.com> | 2018-08-21 12:30:03 +0300 |
commit | b003a5f4bf1859190bc00c138a8e97f9f83f19e5 (patch) | |
tree | 2dfd81fa8697d1d53c6e80bf1d7eedbf18f046c2 | |
parent | d1308d1c87ff7176258fe43d14e70f04894e0494 (diff) | |
download | sdl_core-b003a5f4bf1859190bc00c138a8e97f9f83f19e5.tar.gz |
Implement unit tests for Low Voltage Signals handler
-rw-r--r-- | src/appMain/CMakeLists.txt | 3 | ||||
-rw-r--r-- | src/appMain/test/CMakeLists.txt | 44 | ||||
-rw-r--r-- | src/appMain/test/low_voltage_signals_handler_test.cc | 125 | ||||
-rw-r--r-- | src/appMain/test/mock_life_cycle.h | 54 | ||||
-rw-r--r-- | src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt | 1 |
5 files changed, 227 insertions, 0 deletions
diff --git a/src/appMain/CMakeLists.txt b/src/appMain/CMakeLists.txt index 41d3d4202e..fe9a6af3f7 100644 --- a/src/appMain/CMakeLists.txt +++ b/src/appMain/CMakeLists.txt @@ -253,3 +253,6 @@ else() GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) endif() +if(BUILD_TESTS) + add_subdirectory(test) +endif() diff --git a/src/appMain/test/CMakeLists.txt b/src/appMain/test/CMakeLists.txt new file mode 100644 index 0000000000..c90cad203b --- /dev/null +++ b/src/appMain/test/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (c) 2018, Ford Motor Company +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following +# disclaimer in the documentation and/or other materials provided with the +# distribution. +# +# Neither the name of the Ford Motor Company nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +include_directories ( + ${GMOCK_INCLUDE_DIRECTORY} +) + +set(testSources + $<TARGET_OBJECTS:LowVoltageHandlerObjLibrary> + ${CMAKE_SOURCE_DIR}/src/appMain/test/low_voltage_signals_handler_test.cc +) + +set(LIBRARIES + gmock +) + +create_test(low_voltage_signals_handler_test "${testSources}" "${LIBRARIES}") diff --git a/src/appMain/test/low_voltage_signals_handler_test.cc b/src/appMain/test/low_voltage_signals_handler_test.cc new file mode 100644 index 0000000000..c6be92e558 --- /dev/null +++ b/src/appMain/test/low_voltage_signals_handler_test.cc @@ -0,0 +1,125 @@ +/* +* Copyright (c) 2018, Ford Motor Company +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright notice, this +* list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* Neither the name of the Ford Motor Company nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "appMain/low_voltage_signals_handler.h" + +#include <memory> +#include "gtest/gtest.h" +#include "appMain/test/mock_life_cycle.h" +#include "config_profile/profile.h" +#include "utils/macro.h" + +namespace test { + +class LowVoltageSignalsHandlerTest : public ::testing::Test { + protected: + void SetUp() OVERRIDE { + profile_.set_config_file_name("smartDeviceLink.ini"); + signals_offset_ = {profile_.low_voltage_signal_offset(), + profile_.wake_up_signal_offset(), + profile_.ignition_off_signal_offset()}; + + low_voltage_signals_handler_ = + std::unique_ptr<main_namespace::LowVoltageSignalsHandler>( + new main_namespace::LowVoltageSignalsHandler(mock_life_cycle_, + signals_offset_)); + } + + profile::Profile profile_; + main_namespace::LowVoltageSignalsOffset signals_offset_; + std::unique_ptr<main_namespace::LowVoltageSignalsHandler> + low_voltage_signals_handler_; + main_namespace::MockLifeCycle mock_life_cycle_; +}; + +TEST_F(LowVoltageSignalsHandlerTest, + LowVoltageSignalReceived_ExpectLifeCycleLowVoltageCall) { + // Check that initial SDL state is running + EXPECT_EQ(main_namespace::SDLState::kRun, + low_voltage_signals_handler_->get_current_sdl_state()); + // Set expectation after LOW VOLTAGE signal + EXPECT_CALL(mock_life_cycle_, LowVoltage()); + const int low_voltage_signo = + low_voltage_signals_handler_->low_voltage_signo(); + // Emulate LOW VOLTAGE signal receipt and handling + low_voltage_signals_handler_->HandleSignal(low_voltage_signo); + // Check that SDL is in sleep state after LOW VOLTAGE + EXPECT_EQ(main_namespace::SDLState::kSleep, + low_voltage_signals_handler_->get_current_sdl_state()); +} + +TEST_F(LowVoltageSignalsHandlerTest, + WakeUpSignalReceived_ExpectLifeCycleWakeUpCall) { + // Check that initial SDL state is running + EXPECT_EQ(main_namespace::SDLState::kRun, + low_voltage_signals_handler_->get_current_sdl_state()); + EXPECT_CALL(mock_life_cycle_, LowVoltage()); + const int low_voltage_signo = + low_voltage_signals_handler_->low_voltage_signo(); + // Emulate LOW VOLTAGE signals receipt and handling + low_voltage_signals_handler_->HandleSignal(low_voltage_signo); + // Check that SDL is in sleep state after LOW VOLTAGE + EXPECT_EQ(main_namespace::SDLState::kSleep, + low_voltage_signals_handler_->get_current_sdl_state()); + EXPECT_CALL(mock_life_cycle_, WakeUp()); + const int wake_up_signo = low_voltage_signals_handler_->wake_up_signo(); + // Emulate WAKE UP signal receipt and handling + low_voltage_signals_handler_->HandleSignal(wake_up_signo); + // Check that SDL is in running state after WAKE UP + EXPECT_EQ(main_namespace::SDLState::kRun, + low_voltage_signals_handler_->get_current_sdl_state()); +} + +TEST_F(LowVoltageSignalsHandlerTest, + IgnitionOffSignalReceived_ExpectLifeCycleIgnitionOffCall) { + // Check that initial SDL state is running + EXPECT_EQ(main_namespace::SDLState::kRun, + low_voltage_signals_handler_->get_current_sdl_state()); + EXPECT_CALL(mock_life_cycle_, LowVoltage()); + const int low_voltage_signo = + low_voltage_signals_handler_->low_voltage_signo(); + // Emulate LOW VOLTAGE signals receipt and handling + low_voltage_signals_handler_->HandleSignal(low_voltage_signo); + // Check that SDL is in sleep state after LOW VOLTAGE + EXPECT_EQ(main_namespace::SDLState::kSleep, + low_voltage_signals_handler_->get_current_sdl_state()); + EXPECT_CALL(mock_life_cycle_, IgnitionOff()); + const int ignition_off_signo = + low_voltage_signals_handler_->ignition_off_signo(); + + // Emulate IGNITION OFF signal receipt and handling + low_voltage_signals_handler_->HandleSignal(ignition_off_signo); + // Check that SDL is in stopped state after IGNITION OFF + EXPECT_EQ(main_namespace::SDLState::kStop, + low_voltage_signals_handler_->get_current_sdl_state()); +} +} // namespace test diff --git a/src/appMain/test/mock_life_cycle.h b/src/appMain/test/mock_life_cycle.h new file mode 100644 index 0000000000..fc24b26080 --- /dev/null +++ b/src/appMain/test/mock_life_cycle.h @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2018, Ford Motor Company +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright notice, this +* list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following +* disclaimer in the documentation and/or other materials provided with the +* distribution. +* +* Neither the name of the Ford Motor Company nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef SRC_APPMAIN_TEST_MOCK_LIFE_CYCLE_H_ +#define SRC_APPMAIN_TEST_MOCK_LIFE_CYCLE_H_ + +#include "appMain/life_cycle.h" +#include "gmock/gmock.h" + +namespace main_namespace { + +class MockLifeCycle : public LifeCycle { + public: + MOCK_METHOD0(StartComponents, bool()); + MOCK_METHOD0(InitMessageSystem, bool()); + MOCK_METHOD0(Run, void()); + MOCK_METHOD0(StopComponents, void()); + MOCK_METHOD0(LowVoltage, void()); + MOCK_METHOD0(WakeUp, void()); + MOCK_METHOD0(IgnitionOff, void()); +}; + +} // namespace main_namespace + +#endif // SRC_APPMAIN_TEST_MOCK_LIFE_CYCLE_H_ diff --git a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt index da51c3e4e4..1a206c2cce 100644 --- a/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt +++ b/src/components/application_manager/rpc_plugins/sdl_rpc_plugin/test/CMakeLists.txt @@ -6,6 +6,7 @@ include_directories( ${COMPONENTS_DIR}/application_manager/rpc_plugins/sdl_rpc_plugin/include/sdl_rpc_plugin/commands/ ${COMPONENTS_DIR}/application_manager/test/include/ ${POLICY_MOCK_INCLUDE_PATH}/ + ${CMAKE_SOURCE_DIR}/src ) |