Commit | Line | Data |
---|---|---|
0e23f538 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
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. | |
13 | ||
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. | |
16 | ||
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. | |
19 | */ | |
b6fb82a2 RP |
20 | /** @file |
21 | * test cases for loggin module. | |
22 | * | |
23 | * (c) Copyright 2007 by Intra2net AG | |
b6fb82a2 RP |
24 | */ |
25 | ||
26 | //#define NOISEDEBUG | |
27 | ||
28 | #include <string> | |
29 | #include <iostream> | |
30 | #include <iomanip> | |
31 | #include <exception> | |
32 | ||
9fe0853b TJ |
33 | #define BOOST_TEST_DYN_LINK |
34 | #include <boost/test/unit_test.hpp> | |
b6fb82a2 RP |
35 | |
36 | #include <logfunc.hpp> | |
37 | #include <tracefunc.hpp> | |
c489769c | 38 | #include <filefunc.hxx> |
b6fb82a2 RP |
39 | |
40 | ||
41 | #ifdef NOISEDEBUG | |
42 | #define DOUT(msg) std::cout << msg << std::endl | |
43 | #else | |
44 | #define DOUT(msg) do {} while (0) | |
45 | #endif | |
46 | ||
b6fb82a2 RP |
47 | using namespace I2n; |
48 | ||
49 | namespace { | |
50 | ||
51 | Logger::PartLogger module_logger(HERE); | |
52 | ||
53 | } // eo namespace <anonymous> | |
54 | ||
9fe0853b TJ |
55 | class TestLoggingFixture |
56 | { | |
57 | public: | |
c489769c CH |
58 | std::string LogFile; |
59 | ||
9fe0853b TJ |
60 | TestLoggingFixture() |
61 | { | |
c489769c | 62 | LogFile = "zzUnitTest.log"; |
9fe0853b TJ |
63 | } |
64 | ||
65 | ~TestLoggingFixture() | |
66 | { | |
67 | Logger::set_log_level(0); | |
68 | Logger::enable_syslog(false); | |
69 | Logger::enable_stderr_log(false); | |
70 | Logger::enable_log_file(false); | |
c489769c CH |
71 | |
72 | if (file_exists(LogFile)) | |
73 | unlink(LogFile); | |
9fe0853b TJ |
74 | } |
75 | }; | |
76 | ||
77 | BOOST_FIXTURE_TEST_SUITE(TestLogging, TestLoggingFixture) | |
78 | ||
79 | BOOST_AUTO_TEST_CASE(Syslog1) | |
80 | { | |
81 | //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); | |
82 | Logger::enable_syslog( Logger::Facility::User ); | |
83 | Logger::PartLogger log(__func__); | |
84 | ||
85 | Logger::set_log_level( 7 ); | |
86 | Logger::enable_stderr_log(); | |
c489769c | 87 | Logger::enable_log_file(LogFile); |
9fe0853b TJ |
88 | |
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"; | |
95 | ||
96 | log.debug() | |
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"; | |
101 | ||
102 | module_logger.debug(HERE) << "module level debug message with source loc info"; | |
103 | } // eo Syslog1() | |
104 | ||
b6fb82a2 RP |
105 | |
106 | ||
9fe0853b | 107 | BOOST_AUTO_TEST_CASE(TestScopeTrace1) |
b6fb82a2 | 108 | { |
9fe0853b TJ |
109 | //Logger::enable_syslog("I2N Unittest", Logger::Facility::User ); |
110 | Logger::enable_syslog( Logger::Facility::User ); | |
111 | Logger::PartLogger log(__func__); | |
112 | ||
113 | Logger::set_log_level( 7 ); | |
114 | Logger::enable_stderr_log(); | |
c489769c | 115 | Logger::enable_log_file(LogFile); |
9fe0853b TJ |
116 | |
117 | SCOPETRACKER(); | |
118 | ||
119 | log.notice() << "Stream test notice msg"; | |
120 | { | |
121 | SCOPETRACKER(); // #2 | |
b6fb82a2 | 122 | { |
9fe0853b | 123 | SCOPETRACKER(); // #3 |
b6fb82a2 | 124 | { |
9fe0853b | 125 | SCOPETRACKER(); // #4 |
b6fb82a2 | 126 | } |
9fe0853b TJ |
127 | } |
128 | { | |
129 | SCOPETRACKER(); // #3 | |
130 | } | |
131 | } | |
132 | } // eo TestScopeTrace1() | |
b6fb82a2 | 133 | |
f4fcef65 TJ |
134 | void recursive_function(int level=0) |
135 | { | |
136 | SCOPETRACKER(); | |
137 | ||
138 | if (level < 10) | |
139 | recursive_function(++level); | |
140 | } | |
141 | ||
142 | BOOST_AUTO_TEST_CASE(TestRecursiveScopeTracker) | |
143 | { | |
144 | Logger::enable_syslog( Logger::Facility::User ); | |
145 | Logger::PartLogger log(__func__); | |
146 | ||
147 | Logger::set_log_level( 7 ); | |
148 | Logger::enable_stderr_log(); | |
c489769c | 149 | Logger::enable_log_file(LogFile); |
f4fcef65 TJ |
150 | |
151 | recursive_function(); | |
152 | } | |
153 | ||
9fe0853b | 154 | BOOST_AUTO_TEST_SUITE_END() |