1 | // (C) Copyright Gennadiy Rozental 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: results_reporter.ipp,v $ |
---|
9 | // |
---|
10 | // Version : $Revision: 1.5 $ |
---|
11 | // |
---|
12 | // Description : result reporting facilties |
---|
13 | // *************************************************************************** |
---|
14 | |
---|
15 | #ifndef BOOST_TEST_RESULTS_REPORTER_IPP_020105GER |
---|
16 | #define BOOST_TEST_RESULTS_REPORTER_IPP_020105GER |
---|
17 | |
---|
18 | // Boost.Test |
---|
19 | #include <boost/test/results_reporter.hpp> |
---|
20 | #include <boost/test/unit_test_suite_impl.hpp> |
---|
21 | #include <boost/test/results_collector.hpp> |
---|
22 | #include <boost/test/framework.hpp> |
---|
23 | #include <boost/test/output/plain_report_formatter.hpp> |
---|
24 | #include <boost/test/output/xml_report_formatter.hpp> |
---|
25 | |
---|
26 | #include <boost/test/detail/wrap_io_saver.hpp> |
---|
27 | |
---|
28 | // Boost |
---|
29 | #include <boost/scoped_ptr.hpp> |
---|
30 | |
---|
31 | // STL |
---|
32 | #include <iostream> |
---|
33 | |
---|
34 | #include <boost/test/detail/suppress_warnings.hpp> |
---|
35 | |
---|
36 | //____________________________________________________________________________// |
---|
37 | |
---|
38 | namespace boost { |
---|
39 | |
---|
40 | namespace unit_test { |
---|
41 | |
---|
42 | namespace results_reporter { |
---|
43 | |
---|
44 | // ************************************************************************** // |
---|
45 | // ************** result reporter implementation ************** // |
---|
46 | // ************************************************************************** // |
---|
47 | |
---|
48 | namespace { |
---|
49 | |
---|
50 | struct results_reporter_impl : test_tree_visitor { |
---|
51 | // Constructor |
---|
52 | results_reporter_impl() |
---|
53 | : m_output( &std::cerr ) |
---|
54 | , m_stream_state_saver( new io_saver_type( std::cerr ) ) |
---|
55 | , m_report_level( CONFIRMATION_REPORT ) |
---|
56 | , m_formatter( new output::plain_report_formatter ) |
---|
57 | {} |
---|
58 | |
---|
59 | // test tree visitor interface implementation |
---|
60 | void visit( test_case const& tc ) |
---|
61 | { |
---|
62 | m_formatter->test_unit_report_start( tc, *m_output ); |
---|
63 | m_formatter->test_unit_report_finish( tc, *m_output ); |
---|
64 | } |
---|
65 | bool test_suite_start( test_suite const& ts ) |
---|
66 | { |
---|
67 | m_formatter->test_unit_report_start( ts, *m_output ); |
---|
68 | |
---|
69 | if( m_report_level == DETAILED_REPORT && !results_collector.results( ts.p_id ).p_skipped ) |
---|
70 | return true; |
---|
71 | |
---|
72 | m_formatter->test_unit_report_finish( ts, *m_output ); |
---|
73 | return false; |
---|
74 | } |
---|
75 | void test_suite_finish( test_suite const& ts ) |
---|
76 | { |
---|
77 | m_formatter->test_unit_report_finish( ts, *m_output ); |
---|
78 | } |
---|
79 | |
---|
80 | typedef scoped_ptr<io_saver_type> saver_ptr; |
---|
81 | |
---|
82 | // Data members |
---|
83 | std::ostream* m_output; |
---|
84 | saver_ptr m_stream_state_saver; |
---|
85 | report_level m_report_level; |
---|
86 | scoped_ptr<format> m_formatter; |
---|
87 | }; |
---|
88 | |
---|
89 | results_reporter_impl& s_rr_impl() { static results_reporter_impl the_inst; return the_inst; } |
---|
90 | |
---|
91 | } // local namespace |
---|
92 | |
---|
93 | // ************************************************************************** // |
---|
94 | // ************** report configuration ************** // |
---|
95 | // ************************************************************************** // |
---|
96 | |
---|
97 | void |
---|
98 | set_level( report_level l ) |
---|
99 | { |
---|
100 | if( l != INV_REPORT_LEVEL ) |
---|
101 | s_rr_impl().m_report_level = l; |
---|
102 | } |
---|
103 | |
---|
104 | //____________________________________________________________________________// |
---|
105 | |
---|
106 | void |
---|
107 | set_stream( std::ostream& ostr ) |
---|
108 | { |
---|
109 | s_rr_impl().m_output = &ostr; |
---|
110 | s_rr_impl().m_stream_state_saver.reset( new io_saver_type( ostr ) ); |
---|
111 | } |
---|
112 | |
---|
113 | //____________________________________________________________________________// |
---|
114 | |
---|
115 | void |
---|
116 | set_format( output_format rf ) |
---|
117 | { |
---|
118 | switch( rf ) { |
---|
119 | case CLF: |
---|
120 | set_format( new output::plain_report_formatter ); |
---|
121 | break; |
---|
122 | case XML: |
---|
123 | set_format( new output::xml_report_formatter ); |
---|
124 | break; |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | //____________________________________________________________________________// |
---|
129 | |
---|
130 | void |
---|
131 | set_format( results_reporter::format* f ) |
---|
132 | { |
---|
133 | if( f ) |
---|
134 | s_rr_impl().m_formatter.reset( f ); |
---|
135 | } |
---|
136 | |
---|
137 | //____________________________________________________________________________// |
---|
138 | |
---|
139 | // ************************************************************************** // |
---|
140 | // ************** report initiation ************** // |
---|
141 | // ************************************************************************** // |
---|
142 | |
---|
143 | void |
---|
144 | make_report( report_level l, test_unit_id id ) |
---|
145 | { |
---|
146 | if( l == INV_REPORT_LEVEL ) |
---|
147 | l = s_rr_impl().m_report_level; |
---|
148 | |
---|
149 | if( l == NO_REPORT ) |
---|
150 | return; |
---|
151 | |
---|
152 | if( id == INV_TEST_UNIT_ID ) |
---|
153 | id = framework::master_test_suite().p_id; |
---|
154 | |
---|
155 | s_rr_impl().m_stream_state_saver->restore(); |
---|
156 | |
---|
157 | report_level bkup = s_rr_impl().m_report_level; |
---|
158 | s_rr_impl().m_report_level = l; |
---|
159 | |
---|
160 | s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_output ); |
---|
161 | |
---|
162 | switch( l ) { |
---|
163 | case CONFIRMATION_REPORT: |
---|
164 | s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_output ); |
---|
165 | break; |
---|
166 | case SHORT_REPORT: |
---|
167 | case DETAILED_REPORT: |
---|
168 | traverse_test_tree( id, s_rr_impl() ); |
---|
169 | break; |
---|
170 | default: |
---|
171 | break; |
---|
172 | } |
---|
173 | |
---|
174 | s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_output ); |
---|
175 | s_rr_impl().m_report_level = bkup; |
---|
176 | } |
---|
177 | |
---|
178 | //____________________________________________________________________________// |
---|
179 | |
---|
180 | } // namespace results_reporter |
---|
181 | |
---|
182 | } // namespace unit_test |
---|
183 | |
---|
184 | } // namespace boost |
---|
185 | |
---|
186 | //____________________________________________________________________________// |
---|
187 | |
---|
188 | #include <boost/test/detail/enable_warnings.hpp> |
---|
189 | |
---|
190 | // *************************************************************************** |
---|
191 | // Revision History : |
---|
192 | // |
---|
193 | // $Log: results_reporter.ipp,v $ |
---|
194 | // Revision 1.5 2005/12/14 05:57:32 rogeeff |
---|
195 | // *** empty log message *** |
---|
196 | // |
---|
197 | // Revision 1.4 2005/04/30 16:48:51 rogeeff |
---|
198 | // io saver warkaround for classic io is shared |
---|
199 | // |
---|
200 | // Revision 1.3 2005/04/29 06:27:45 rogeeff |
---|
201 | // bug fix for manipulator nandling |
---|
202 | // bug fix for invalid output stream |
---|
203 | // bug fix for set_format function implementation |
---|
204 | // |
---|
205 | // Revision 1.2 2005/02/21 10:12:20 rogeeff |
---|
206 | // Support for random order of test cases implemented |
---|
207 | // |
---|
208 | // Revision 1.1 2005/02/20 08:27:07 rogeeff |
---|
209 | // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates |
---|
210 | // |
---|
211 | // *************************************************************************** |
---|
212 | |
---|
213 | #endif // BOOST_TEST_RESULTS_REPORTER_IPP_020105GER |
---|