1 // (C) Copyright Gennadiy Rozental 2001.
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)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : result reporting facilties
13 // ***************************************************************************
15 #ifndef BOOST_TEST_RESULTS_REPORTER_IPP_020105GER
16 #define BOOST_TEST_RESULTS_REPORTER_IPP_020105GER
19 #include <boost/test/results_reporter.hpp>
20 #include <boost/test/results_collector.hpp>
21 #include <boost/test/framework.hpp>
23 #include <boost/test/output/plain_report_formatter.hpp>
24 #include <boost/test/output/xml_report_formatter.hpp>
26 #include <boost/test/tree/visitor.hpp>
27 #include <boost/test/tree/test_unit.hpp>
28 #include <boost/test/tree/traverse.hpp>
31 #include <boost/scoped_ptr.hpp>
32 #include <boost/io/ios_state.hpp>
33 typedef ::boost::io::ios_base_all_saver io_saver_type;
38 #include <boost/test/detail/suppress_warnings.hpp>
40 //____________________________________________________________________________//
44 namespace results_reporter {
46 // ************************************************************************** //
47 // ************** result reporter implementation ************** //
48 // ************************************************************************** //
52 struct results_reporter_impl : test_tree_visitor {
54 results_reporter_impl()
55 : m_stream( &std::cerr )
56 , m_stream_state_saver( new io_saver_type( std::cerr ) )
57 , m_report_level( CONFIRMATION_REPORT )
58 , m_formatter( new output::plain_report_formatter )
61 // test tree visitor interface implementation
62 void visit( test_case const& tc )
64 m_formatter->test_unit_report_start( tc, *m_stream );
65 m_formatter->test_unit_report_finish( tc, *m_stream );
67 bool test_suite_start( test_suite const& ts )
69 m_formatter->test_unit_report_start( ts, *m_stream );
71 if( m_report_level == DETAILED_REPORT && !results_collector.results( ts.p_id ).p_skipped )
74 m_formatter->test_unit_report_finish( ts, *m_stream );
77 void test_suite_finish( test_suite const& ts )
79 m_formatter->test_unit_report_finish( ts, *m_stream );
82 typedef scoped_ptr<io_saver_type> saver_ptr;
85 std::ostream* m_stream;
86 saver_ptr m_stream_state_saver;
87 report_level m_report_level;
88 scoped_ptr<format> m_formatter;
91 results_reporter_impl& s_rr_impl() { static results_reporter_impl the_inst; return the_inst; }
95 // ************************************************************************** //
96 // ************** report configuration ************** //
97 // ************************************************************************** //
100 set_level( report_level l )
102 if( l != INV_REPORT_LEVEL )
103 s_rr_impl().m_report_level = l;
106 //____________________________________________________________________________//
109 set_stream( std::ostream& ostr )
111 s_rr_impl().m_stream = &ostr;
112 s_rr_impl().m_stream_state_saver.reset( new io_saver_type( ostr ) );
115 //____________________________________________________________________________//
120 return *s_rr_impl().m_stream;
123 //____________________________________________________________________________//
126 set_format( output_format rf )
131 set_format( new output::plain_report_formatter );
134 set_format( new output::xml_report_formatter );
139 //____________________________________________________________________________//
142 set_format( results_reporter::format* f )
145 s_rr_impl().m_formatter.reset( f );
148 //____________________________________________________________________________//
150 // ************************************************************************** //
151 // ************** report initiation ************** //
152 // ************************************************************************** //
155 make_report( report_level l, test_unit_id id )
157 if( l == INV_REPORT_LEVEL )
158 l = s_rr_impl().m_report_level;
163 if( id == INV_TEST_UNIT_ID )
164 id = framework::master_test_suite().p_id;
166 s_rr_impl().m_stream_state_saver->restore();
168 report_level bkup = s_rr_impl().m_report_level;
169 s_rr_impl().m_report_level = l;
171 s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_stream );
174 case CONFIRMATION_REPORT:
175 s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_stream );
178 case DETAILED_REPORT:
179 traverse_test_tree( id, s_rr_impl() );
185 s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_stream );
186 s_rr_impl().m_report_level = bkup;
189 //____________________________________________________________________________//
191 } // namespace results_reporter
192 } // namespace unit_test
195 #include <boost/test/detail/enable_warnings.hpp>
197 #endif // BOOST_TEST_RESULTS_REPORTER_IPP_020105GER