Test: added testcase for log-output configuration option.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 3 Jul 2012 01:57:48 +0000 (22:57 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Tue, 3 Jul 2012 02:11:45 +0000 (23:11 -0300)
test/CMakeLists.test_configurationcommandline.txt
test/CMakeLists.test_configurationfile.txt
test/CMakeLists.test_configurationoptions.txt
test/CMakeLists.test_logoutput.txt [new file with mode: 0644]
test/CMakeLists.txt
test/test_configurationoptions.cpp
test/test_logoutput.cpp [new file with mode: 0644]

index 2ff5f79..4c9460d 100644 (file)
@@ -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
 )
 
index 721bc93..bba0354 100644 (file)
@@ -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
 )
 
index 3d4b66b..0570cbf 100644 (file)
@@ -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 (file)
index 0000000..97f76d7
--- /dev/null
@@ -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)
index 1fdeb02..bf5eee0 100644 (file)
@@ -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)
index f26d86d..441927e 100644 (file)
@@ -28,6 +28,7 @@ on this file might be covered by the GNU General Public License.
 #include <boost/test/unit_test.hpp>
 
 #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<int>(configuration.get_log_level()), static_cast<int>(I2n::Logger::LogLevel::Emergency) );
+    BOOST_CHECK_EQUAL( static_cast<int>(configuration.get_log_output()), static_cast<int>(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 (file)
index 0000000..6f90f04
--- /dev/null
@@ -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 <boost/test/unit_test.hpp>
+
+#include <logfunc.hpp>
+
+#include "host/logoutput.h"
+
+BOOST_AUTO_TEST_SUITE( TestLogOutput )
+
+BOOST_AUTO_TEST_CASE( lowercase )
+{
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "syslog" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "terminal" )), static_cast<int>(LogOutput_TERMINAL) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "console" )), static_cast<int>(LogOutput_TERMINAL) );
+}
+
+BOOST_AUTO_TEST_CASE( uppercase )
+{
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SYSLOG" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "TERMINAL" )), static_cast<int>(LogOutput_TERMINAL) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "CONSOLE" )), static_cast<int>(LogOutput_TERMINAL) );
+}
+
+BOOST_AUTO_TEST_CASE( mixed_case )
+{
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SysLoG" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "teRmINAl" )), static_cast<int>(LogOutput_TERMINAL) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "ConSOlE" )), static_cast<int>(LogOutput_TERMINAL) );
+}
+
+BOOST_AUTO_TEST_CASE( misspelled )
+{
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "when" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "the" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "word" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "is" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "wrong" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "stick" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "to" )), static_cast<int>(LogOutput_SYSLOG) );
+    BOOST_CHECK_EQUAL( static_cast<int>(get_log_output_from_string( "SYSLOG" )), static_cast<int>(LogOutput_SYSLOG) );
+}
+
+BOOST_AUTO_TEST_SUITE_END()