1 | // (C) Copyright Gennadiy Rozental 2001-2005. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. |
---|
3 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | |
---|
6 | // See http://www.boost.org/libs/test for the library home page. |
---|
7 | // |
---|
8 | // File : $RCSfile: unit_test_log.hpp,v $ |
---|
9 | // |
---|
10 | // Version : $Revision: 1.32 $ |
---|
11 | // |
---|
12 | // Description : defines singleton class unit_test_log and all manipulators. |
---|
13 | // unit_test_log has output stream like interface. It's implementation is |
---|
14 | // completely hidden with pimple idiom |
---|
15 | // *************************************************************************** |
---|
16 | |
---|
17 | #ifndef BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER |
---|
18 | #define BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER |
---|
19 | |
---|
20 | // Boost.Test |
---|
21 | #include <boost/test/test_observer.hpp> |
---|
22 | |
---|
23 | #include <boost/test/detail/global_typedef.hpp> |
---|
24 | #include <boost/test/detail/log_level.hpp> |
---|
25 | #include <boost/test/detail/fwd_decl.hpp> |
---|
26 | |
---|
27 | #include <boost/test/utils/wrap_stringstream.hpp> |
---|
28 | #include <boost/test/utils/trivial_singleton.hpp> |
---|
29 | |
---|
30 | // Boost |
---|
31 | #include <boost/utility.hpp> |
---|
32 | |
---|
33 | // STL |
---|
34 | #include <iosfwd> // for std::ostream& |
---|
35 | |
---|
36 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
37 | |
---|
38 | //____________________________________________________________________________// |
---|
39 | |
---|
40 | namespace boost { |
---|
41 | |
---|
42 | namespace unit_test { |
---|
43 | |
---|
44 | // ************************************************************************** // |
---|
45 | // ************** log manipulators ************** // |
---|
46 | // ************************************************************************** // |
---|
47 | |
---|
48 | namespace log { |
---|
49 | |
---|
50 | struct BOOST_TEST_DECL begin { |
---|
51 | begin( const_string fn, std::size_t ln ) |
---|
52 | : m_file_name( fn ) |
---|
53 | , m_line_num( ln ) |
---|
54 | {} |
---|
55 | |
---|
56 | const_string m_file_name; |
---|
57 | std::size_t m_line_num; |
---|
58 | }; |
---|
59 | |
---|
60 | struct end {}; |
---|
61 | |
---|
62 | } // namespace log |
---|
63 | |
---|
64 | // ************************************************************************** // |
---|
65 | // ************** entry_value_collector ************** // |
---|
66 | // ************************************************************************** // |
---|
67 | |
---|
68 | namespace ut_detail { |
---|
69 | |
---|
70 | class BOOST_TEST_DECL entry_value_collector { |
---|
71 | public: |
---|
72 | // Constructors |
---|
73 | entry_value_collector() : m_last( true ) {} |
---|
74 | entry_value_collector( entry_value_collector& rhs ) : m_last( true ) { rhs.m_last = false; } |
---|
75 | ~entry_value_collector(); |
---|
76 | |
---|
77 | // collection interface |
---|
78 | entry_value_collector operator<<( const_string ); |
---|
79 | |
---|
80 | private: |
---|
81 | // Data members |
---|
82 | bool m_last; |
---|
83 | }; |
---|
84 | |
---|
85 | } // namespace ut_detail |
---|
86 | |
---|
87 | // ************************************************************************** // |
---|
88 | // ************** unit_test_log ************** // |
---|
89 | // ************************************************************************** // |
---|
90 | |
---|
91 | class BOOST_TEST_DECL unit_test_log_t : public test_observer, public singleton<unit_test_log_t> { |
---|
92 | public: |
---|
93 | // test_observer interface implementation |
---|
94 | void test_start( counter_t test_cases_amount ); |
---|
95 | void test_finish(); |
---|
96 | void test_aborted(); |
---|
97 | |
---|
98 | void test_unit_start( test_unit const& ); |
---|
99 | void test_unit_finish( test_unit const&, unsigned long elapsed ); |
---|
100 | void test_unit_skipped( test_unit const& ); |
---|
101 | void test_unit_aborted( test_unit const& ); |
---|
102 | |
---|
103 | void assertion_result( bool passed ); |
---|
104 | void exception_caught( execution_exception const& ); |
---|
105 | |
---|
106 | virtual int priority() { return 1; } |
---|
107 | |
---|
108 | // log configuration methods |
---|
109 | void set_stream( std::ostream& ); |
---|
110 | void set_threshold_level( log_level ); |
---|
111 | void set_format( output_format ); |
---|
112 | void set_formatter( unit_test_log_formatter* ); |
---|
113 | |
---|
114 | // test progress logging |
---|
115 | void set_checkpoint( const_string file, std::size_t line_num, const_string msg = const_string() ); |
---|
116 | |
---|
117 | // entry logging |
---|
118 | unit_test_log_t& operator<<( log::begin const& ); // begin entry |
---|
119 | unit_test_log_t& operator<<( log::end const& ); // end entry |
---|
120 | unit_test_log_t& operator<<( log_level ); // set entry level |
---|
121 | unit_test_log_t& operator<<( const_string ); // log entry value |
---|
122 | |
---|
123 | ut_detail::entry_value_collector operator()( log_level ); // initiate entry collection |
---|
124 | |
---|
125 | private: |
---|
126 | BOOST_TEST_SINGLETON_CONS( unit_test_log_t ); |
---|
127 | }; // unit_test_log_t |
---|
128 | |
---|
129 | BOOST_TEST_SINGLETON_INST( unit_test_log ) |
---|
130 | |
---|
131 | // helper macros |
---|
132 | #define BOOST_TEST_LOG_ENTRY( ll ) \ |
---|
133 | (::boost::unit_test::unit_test_log \ |
---|
134 | << ::boost::unit_test::log::begin( BOOST_TEST_L(__FILE__), __LINE__ ))(ll) \ |
---|
135 | /**/ |
---|
136 | |
---|
137 | } // namespace unit_test |
---|
138 | |
---|
139 | } // namespace boost |
---|
140 | |
---|
141 | // ************************************************************************** // |
---|
142 | // ************** Unit test log interface helpers ************** // |
---|
143 | // ************************************************************************** // |
---|
144 | |
---|
145 | #define BOOST_TEST_MESSAGE( M ) \ |
---|
146 | BOOST_TEST_LOG_ENTRY( ::boost::unit_test::log_messages ) \ |
---|
147 | << (boost::wrap_stringstream().ref() << M).str() \ |
---|
148 | /**/ |
---|
149 | |
---|
150 | //____________________________________________________________________________// |
---|
151 | |
---|
152 | #define BOOST_TEST_PASSPOINT() \ |
---|
153 | ::boost::unit_test::unit_test_log.set_checkpoint( \ |
---|
154 | BOOST_TEST_L(__FILE__), \ |
---|
155 | (std::size_t)__LINE__ ) \ |
---|
156 | /**/ |
---|
157 | |
---|
158 | //____________________________________________________________________________// |
---|
159 | |
---|
160 | #define BOOST_TEST_CHECKPOINT( M ) \ |
---|
161 | ::boost::unit_test::unit_test_log.set_checkpoint( \ |
---|
162 | BOOST_TEST_L(__FILE__), \ |
---|
163 | (std::size_t)__LINE__, \ |
---|
164 | (boost::wrap_stringstream().ref() << M).str() ) \ |
---|
165 | /**/ |
---|
166 | |
---|
167 | //____________________________________________________________________________// |
---|
168 | |
---|
169 | #include <boost/test/detail/enable_warnings.hpp> |
---|
170 | |
---|
171 | // *************************************************************************** |
---|
172 | // Revision History : |
---|
173 | // |
---|
174 | // $Log: unit_test_log.hpp,v $ |
---|
175 | // Revision 1.32 2006/01/28 08:57:02 rogeeff |
---|
176 | // VC6.0 workaround removed |
---|
177 | // |
---|
178 | // Revision 1.31 2005/12/14 05:23:21 rogeeff |
---|
179 | // dll support introduced |
---|
180 | // Minor interface simplifications |
---|
181 | // BOOST_TEST_MESSAGE and BOOST_TEST_CHECKPOINT moved into log realm |
---|
182 | // BOOST_TEST_PASSPOINT is introduced |
---|
183 | // |
---|
184 | // Revision 1.30 2005/02/20 08:27:06 rogeeff |
---|
185 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates |
---|
186 | // |
---|
187 | // Revision 1.29 2005/02/02 12:08:14 rogeeff |
---|
188 | // namespace log added for log manipulators |
---|
189 | // |
---|
190 | // Revision 1.28 2005/02/01 06:40:06 rogeeff |
---|
191 | // copyright update |
---|
192 | // old log entries removed |
---|
193 | // minor stilistic changes |
---|
194 | // depricated tools removed |
---|
195 | // |
---|
196 | // Revision 1.27 2005/01/30 03:26:29 rogeeff |
---|
197 | // return an ability for explicit end() |
---|
198 | // |
---|
199 | // Revision 1.26 2005/01/21 07:30:24 rogeeff |
---|
200 | // to log testing time log formatter interfaces changed |
---|
201 | // |
---|
202 | // Revision 1.25 2005/01/18 08:26:12 rogeeff |
---|
203 | // unit_test_log rework: |
---|
204 | // eliminated need for ::instance() |
---|
205 | // eliminated need for << end and ...END macro |
---|
206 | // straitend interface between log and formatters |
---|
207 | // change compiler like formatter name |
---|
208 | // minimized unit_test_log interface and reworked to use explicit calls |
---|
209 | // |
---|
210 | // *************************************************************************** |
---|
211 | |
---|
212 | #endif // BOOST_TEST_UNIT_TEST_LOG_HPP_071894GER |
---|
213 | |
---|