/* 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. */ /** @file * test cases for loggin module. * * (c) Copyright 2007 by Intra2net AG */ //#define NOISEDEBUG #include #include #include #include #define BOOST_TEST_DYN_LINK #include #include #include #include #ifdef NOISEDEBUG #define DOUT(msg) std::cout << msg << std::endl #else #define DOUT(msg) do {} while (0) #endif using namespace I2n; namespace { Logger::PartLogger module_logger(HERE); } // eo namespace class TestLoggingFixture { public: std::string LogFile; TestLoggingFixture() { LogFile = "zzUnitTest.log"; } ~TestLoggingFixture() { Logger::set_log_level(0); Logger::enable_syslog(false); Logger::enable_stderr_log(false); Logger::enable_log_file(false); if (file_exists(LogFile)) unlink(LogFile); } }; BOOST_FIXTURE_TEST_SUITE(TestLogging, TestLoggingFixture) BOOST_AUTO_TEST_CASE(Syslog1) { //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); Logger::enable_syslog( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 ); Logger::enable_stderr_log(); Logger::enable_log_file(LogFile); log.error("Test error msg"); log.error() << "Stream test error msg #" << 2 << "."; log.warning() << "Stream test warning msg"; log.notice() << "Stream test notice msg"; log.info() << "Stream test info msg"; log.debug() << "Stream test debug msg"; log.debug() << "multiline log message" << std::endl << "this (second) line should be indented" << std::endl << "and this also!" << std::endl; log.debug(HERE) << "This should have a source info"; module_logger.debug(HERE) << "module level debug message with source loc info"; } // eo Syslog1() BOOST_AUTO_TEST_CASE(TestScopeTrace1) { //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); Logger::enable_syslog( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 ); Logger::enable_stderr_log(); Logger::enable_log_file(LogFile); SCOPETRACKER(); log.notice() << "Stream test notice msg"; { SCOPETRACKER(); // #2 { SCOPETRACKER(); // #3 { SCOPETRACKER(); // #4 } } { SCOPETRACKER(); // #3 } } } // eo TestScopeTrace1() void recursive_function(int level=0) { SCOPETRACKER(); if (level < 10) recursive_function(++level); } BOOST_AUTO_TEST_CASE(TestRecursiveScopeTracker) { Logger::enable_syslog( Logger::Facility::User ); Logger::PartLogger log(__func__); Logger::set_log_level( 7 ); Logger::enable_stderr_log(); Logger::enable_log_file(LogFile); recursive_function(); } BOOST_AUTO_TEST_SUITE_END()