2 The software in this package is distributed under the GNU General
3 Public License version 2 (with a special exception described below).
5 A copy of GNU General Public License (GPL) is included in this distribution,
6 in the file COPYING.GPL.
8 As a special exception, if other files instantiate templates or use macros
9 or inline functions from this file, or you compile this file and link it
10 with other works to produce a work based on this file, this file
11 does not by itself cause the resulting work to be covered
12 by the GNU General Public License.
14 However the source code for this file must still be made available
15 in accordance with section (3) of the GNU General Public License.
17 This exception does not invalidate any other reasons why a work based
18 on this file might be covered by the GNU General Public License.
21 * test cases for loggin module.
23 * (c) Copyright 2007 by Intra2net AG
33 #define BOOST_TEST_DYN_LINK
34 #include <boost/test/unit_test.hpp>
36 #include <logfunc.hpp>
37 #include <tracefunc.hpp>
38 #include <filefunc.hxx>
42 #define DOUT(msg) std::cout << msg << std::endl
44 #define DOUT(msg) do {} while (0)
51 Logger::PartLogger module_logger(HERE);
53 } // eo namespace <anonymous>
55 class TestLoggingFixture
62 LogFile = "zzUnitTest.log";
67 Logger::set_log_level(0);
68 Logger::enable_syslog(false);
69 Logger::enable_stderr_log(false);
70 Logger::enable_log_file(false);
72 if (file_exists(LogFile))
77 BOOST_FIXTURE_TEST_SUITE(TestLogging, TestLoggingFixture)
79 BOOST_AUTO_TEST_CASE(Syslog1)
81 //Logger::enable_syslog("I2N Unittest", Logger::Facility::User );
82 Logger::enable_syslog( Logger::Facility::User );
83 Logger::PartLogger log(__func__);
85 Logger::set_log_level( 7 );
86 Logger::enable_stderr_log();
87 Logger::enable_log_file(LogFile);
89 log.error("Test error msg");
90 log.error() << "Stream test error msg #" << 2 << ".";
91 log.warning() << "Stream test warning msg";
92 log.notice() << "Stream test notice msg";
93 log.info() << "Stream test info msg";
94 log.debug() << "Stream test debug msg";
97 << "multiline log message" << std::endl
98 << "this (second) line should be indented" << std::endl
99 << "and this also!" << std::endl;
100 log.debug(HERE) << "This should have a source info";
102 module_logger.debug(HERE) << "module level debug message with source loc info";
107 BOOST_AUTO_TEST_CASE(TestScopeTrace1)
109 //Logger::enable_syslog("I2N Unittest", Logger::Facility::User );
110 Logger::enable_syslog( Logger::Facility::User );
111 Logger::PartLogger log(__func__);
113 Logger::set_log_level( 7 );
114 Logger::enable_stderr_log();
115 Logger::enable_log_file(LogFile);
119 log.notice() << "Stream test notice msg";
121 SCOPETRACKER(); // #2
123 SCOPETRACKER(); // #3
125 SCOPETRACKER(); // #4
129 SCOPETRACKER(); // #3
132 } // eo TestScopeTrace1()
134 void recursive_function(int level=0)
139 recursive_function(++level);
142 BOOST_AUTO_TEST_CASE(TestRecursiveScopeTracker)
144 Logger::enable_syslog( Logger::Facility::User );
145 Logger::PartLogger log(__func__);
147 Logger::set_log_level( 7 );
148 Logger::enable_stderr_log();
149 Logger::enable_log_file(LogFile);
151 recursive_function();
154 BOOST_AUTO_TEST_SUITE_END()