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>
41 #define DOUT(msg) std::cout << msg << std::endl
43 #define DOUT(msg) do {} while (0)
50 Logger::PartLogger module_logger(HERE);
52 } // eo namespace <anonymous>
54 class TestLoggingFixture
63 Logger::set_log_level(0);
64 Logger::enable_syslog(false);
65 Logger::enable_stderr_log(false);
66 Logger::enable_log_file(false);
70 BOOST_FIXTURE_TEST_SUITE(TestLogging, TestLoggingFixture)
72 BOOST_AUTO_TEST_CASE(Syslog1)
74 //Logger::enable_syslog("I2N Unittest", Logger::Facility::User );
75 Logger::enable_syslog( Logger::Facility::User );
76 Logger::PartLogger log(__func__);
78 Logger::set_log_level( 7 );
79 Logger::enable_stderr_log();
80 Logger::enable_log_file("zzUnitTest.log");
82 log.error("Test error msg");
83 log.error() << "Stream test error msg #" << 2 << ".";
84 log.warning() << "Stream test warning msg";
85 log.notice() << "Stream test notice msg";
86 log.info() << "Stream test info msg";
87 log.debug() << "Stream test debug msg";
90 << "multiline log message" << std::endl
91 << "this (second) line should be indented" << std::endl
92 << "and this also!" << std::endl;
93 log.debug(HERE) << "This should have a source info";
95 module_logger.debug(HERE) << "module level debug message with source loc info";
100 BOOST_AUTO_TEST_CASE(TestScopeTrace1)
102 //Logger::enable_syslog("I2N Unittest", Logger::Facility::User );
103 Logger::enable_syslog( Logger::Facility::User );
104 Logger::PartLogger log(__func__);
106 Logger::set_log_level( 7 );
107 Logger::enable_stderr_log();
108 Logger::enable_log_file("zzUnitTest.log");
112 log.notice() << "Stream test notice msg";
114 SCOPETRACKER(); // #2
116 SCOPETRACKER(); // #3
118 SCOPETRACKER(); // #4
122 SCOPETRACKER(); // #3
125 } // eo TestScopeTrace1()
127 void recursive_function(int level=0)
132 recursive_function(++level);
135 BOOST_AUTO_TEST_CASE(TestRecursiveScopeTracker)
137 Logger::enable_syslog( Logger::Facility::User );
138 Logger::PartLogger log(__func__);
140 Logger::set_log_level( 7 );
141 Logger::enable_stderr_log();
142 Logger::enable_log_file("zzUnitTest.log");
144 recursive_function();
147 BOOST_AUTO_TEST_SUITE_END()