From e3c7d9ac4a22080c1b0a000a64292d6065b676dc Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 2 Jul 2012 22:57:48 -0300 Subject: [PATCH] Test: added testcase for log-output configuration option. --- test/CMakeLists.test_configurationcommandline.txt | 2 + test/CMakeLists.test_configurationfile.txt | 2 + test/CMakeLists.test_configurationoptions.txt | 2 + test/CMakeLists.test_logoutput.txt | 15 +++++ test/CMakeLists.txt | 1 + test/test_configurationoptions.cpp | 9 +++- test/test_logoutput.cpp | 65 +++++++++++++++++++++ 7 files changed, 95 insertions(+), 1 deletions(-) create mode 100644 test/CMakeLists.test_logoutput.txt create mode 100644 test/test_logoutput.cpp diff --git a/test/CMakeLists.test_configurationcommandline.txt b/test/CMakeLists.test_configurationcommandline.txt index 2ff5f79..4c9460d 100644 --- a/test/CMakeLists.test_configurationcommandline.txt +++ b/test/CMakeLists.test_configurationcommandline.txt @@ -19,12 +19,14 @@ add_executable(test_configurationcommandline ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp + ${CMAKE_SOURCE_DIR}/src/config/option/logoutputoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp + ${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp ${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp ) diff --git a/test/CMakeLists.test_configurationfile.txt b/test/CMakeLists.test_configurationfile.txt index 721bc93..bba0354 100644 --- a/test/CMakeLists.test_configurationfile.txt +++ b/test/CMakeLists.test_configurationfile.txt @@ -19,12 +19,14 @@ add_executable(test_configurationfile ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp + ${CMAKE_SOURCE_DIR}/src/config/option/logoutputoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp + ${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp ${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp ) diff --git a/test/CMakeLists.test_configurationoptions.txt b/test/CMakeLists.test_configurationoptions.txt index 3d4b66b..0570cbf 100644 --- a/test/CMakeLists.test_configurationoptions.txt +++ b/test/CMakeLists.test_configurationoptions.txt @@ -17,12 +17,14 @@ add_executable(test_configurationoptions ${CMAKE_SOURCE_DIR}/src/config/option/linkdownintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/linkupintervaloption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/logleveloption.cpp + ${CMAKE_SOURCE_DIR}/src/config/option/logoutputoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/nameserveroption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/pingfaillimitoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/sourcenetworkinterfaceoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/statusnotifiercmdoption.cpp ${CMAKE_SOURCE_DIR}/src/config/option/versionoption.cpp ${CMAKE_SOURCE_DIR}/src/host/loglevel.cpp + ${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp ${CMAKE_SOURCE_DIR}/src/host/pingprotocol.cpp ) diff --git a/test/CMakeLists.test_logoutput.txt b/test/CMakeLists.test_logoutput.txt new file mode 100644 index 0000000..97f76d7 --- /dev/null +++ b/test/CMakeLists.test_logoutput.txt @@ -0,0 +1,15 @@ +# compiler: creates the binaries +add_executable(test_logoutput + test_logoutput.cpp + ${CMAKE_SOURCE_DIR}/src/host/logoutput.cpp +) + +# linker: link the program against the libraries +target_link_libraries( + test_logoutput + ${I2NCOMMON_LIBRARIES} + ${Boost_LIBRARIES} +) + +# cmake: invocation via "make test" +add_test(test_logoutput test_logoutput) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1fdeb02..bf5eee0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,6 +32,7 @@ include(CMakeLists.test_pingprotocol.txt) include(CMakeLists.test_hoststatus.txt) include(CMakeLists.test_linkstatus.txt) include(CMakeLists.test_loglevel.txt) +include(CMakeLists.test_logoutput.txt) include(CMakeLists.test_ipv4header.txt) include(CMakeLists.test_ipv6header.txt) include(CMakeLists.test_icmpv4header.txt) diff --git a/test/test_configurationoptions.cpp b/test/test_configurationoptions.cpp index f26d86d..441927e 100644 --- a/test/test_configurationoptions.cpp +++ b/test/test_configurationoptions.cpp @@ -28,6 +28,7 @@ on this file might be covered by the GNU General Public License. #include #include "host/loglevel.h" +#include "host/logoutput.h" #include "host/pingprotocol.h" #include "config/configurationoptions.h" @@ -103,13 +104,14 @@ BOOST_AUTO_TEST_CASE( get_generic_options ) // if this assert fails, you must add or remove one of the options in the // test bellow - BOOST_CHECK_EQUAL( options.size(), 5 ); // help, version, daemon, config-file and log-level + BOOST_CHECK_EQUAL( options.size(), 6 ); // help, version, daemon, config-file, log-level and log-output BOOST_CHECK_EQUAL( option_present( options, "help" ), true ); BOOST_CHECK_EQUAL( option_present( options, "config-file" ), true ); BOOST_CHECK_EQUAL( option_present( options, "daemon" ), true ); BOOST_CHECK_EQUAL( option_present( options, "version" ), true ); BOOST_CHECK_EQUAL( option_present( options, "log-level" ), true ); + BOOST_CHECK_EQUAL( option_present( options, "log-output" ), true ); } BOOST_AUTO_TEST_CASE( get_configuration_options ) @@ -142,6 +144,7 @@ BOOST_AUTO_TEST_CASE( parse_generic_options ) option_insert( "config-file", boost::any( std::string("pingcheck.conf") ), vm ); option_insert( "daemon", boost::any(), vm ); option_insert( "log-level", boost::any( std::string("EMERGENCY") ), vm ); + option_insert( "log-output", boost::any( std::string("TERMINAL") ), vm ); ConfigurationOptions config_options; Configuration configuration; @@ -150,6 +153,7 @@ BOOST_AUTO_TEST_CASE( parse_generic_options ) BOOST_CHECK_EQUAL( configuration.get_config_file_name(), "pingcheck.conf" ); BOOST_CHECK_EQUAL( configuration.get_daemon(), true ); BOOST_CHECK_EQUAL( static_cast(configuration.get_log_level()), static_cast(I2n::Logger::LogLevel::Emergency) ); + BOOST_CHECK_EQUAL( static_cast(configuration.get_log_output()), static_cast(LogOutput_TERMINAL) ); } BOOST_AUTO_TEST_CASE( parse_configuration_options ) @@ -301,6 +305,9 @@ BOOST_AUTO_TEST_CASE( halt_on_generic_options ) option_clear_and_insert( "log-level", value, vm ); BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false ); + option_clear_and_insert( "log-output", value, vm ); + BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false ); + option_clear_and_insert( "hosts-down-limit", value, vm ); BOOST_CHECK_EQUAL( config_options.halt_on_generic_options( vm ), false ); diff --git a/test/test_logoutput.cpp b/test/test_logoutput.cpp new file mode 100644 index 0000000..6f90f04 --- /dev/null +++ b/test/test_logoutput.cpp @@ -0,0 +1,65 @@ +/* +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ + +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK + +#include + +#include + +#include "host/logoutput.h" + +BOOST_AUTO_TEST_SUITE( TestLogOutput ) + +BOOST_AUTO_TEST_CASE( lowercase ) +{ + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "syslog" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "terminal" )), static_cast(LogOutput_TERMINAL) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "console" )), static_cast(LogOutput_TERMINAL) ); +} + +BOOST_AUTO_TEST_CASE( uppercase ) +{ + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "SYSLOG" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "TERMINAL" )), static_cast(LogOutput_TERMINAL) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "CONSOLE" )), static_cast(LogOutput_TERMINAL) ); +} + +BOOST_AUTO_TEST_CASE( mixed_case ) +{ + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "SysLoG" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "teRmINAl" )), static_cast(LogOutput_TERMINAL) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "ConSOlE" )), static_cast(LogOutput_TERMINAL) ); +} + +BOOST_AUTO_TEST_CASE( misspelled ) +{ + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "when" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "the" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "word" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "is" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "wrong" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "stick" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "to" )), static_cast(LogOutput_SYSLOG) ); + BOOST_CHECK_EQUAL( static_cast(get_log_output_from_string( "SYSLOG" )), static_cast(LogOutput_SYSLOG) ); +} + +BOOST_AUTO_TEST_SUITE_END() -- 1.7.1