Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:01:00

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : result reporting facilities
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_RESULTS_REPORTER_IPP_020105GER
0016 #define BOOST_TEST_RESULTS_REPORTER_IPP_020105GER
0017 
0018 // Boost.Test
0019 #include <boost/test/results_reporter.hpp>
0020 #include <boost/test/results_collector.hpp>
0021 #include <boost/test/framework.hpp>
0022 
0023 #include <boost/test/output/plain_report_formatter.hpp>
0024 #include <boost/test/output/xml_report_formatter.hpp>
0025 
0026 #include <boost/test/tree/visitor.hpp>
0027 #include <boost/test/tree/test_unit.hpp>
0028 #include <boost/test/tree/traverse.hpp>
0029 
0030 // Boost
0031 #include <boost/scoped_ptr.hpp>
0032 #include <boost/io/ios_state.hpp>
0033 typedef ::boost::io::ios_base_all_saver io_saver_type;
0034 
0035 // STL
0036 #include <iostream>
0037 
0038 #include <boost/test/detail/suppress_warnings.hpp>
0039 
0040 //____________________________________________________________________________//
0041 
0042 namespace boost {
0043 namespace unit_test {
0044 namespace results_reporter {
0045 
0046 // ************************************************************************** //
0047 // **************        result reporter implementation        ************** //
0048 // ************************************************************************** //
0049 
0050 namespace {
0051 
0052 struct results_reporter_impl : test_tree_visitor {
0053     // Constructor
0054     results_reporter_impl()
0055     : m_stream( &std::cerr )
0056     , m_stream_state_saver( new io_saver_type( std::cerr ) )
0057     , m_report_level( CONFIRMATION_REPORT )
0058     , m_formatter( new output::plain_report_formatter )
0059     {}
0060 
0061     // test tree visitor interface implementation
0062     void    visit( test_case const& tc ) BOOST_OVERRIDE
0063     {
0064         m_formatter->test_unit_report_start( tc, *m_stream );
0065         m_formatter->test_unit_report_finish( tc, *m_stream );
0066     }
0067     bool    test_suite_start( test_suite const& ts ) BOOST_OVERRIDE
0068     {
0069         m_formatter->test_unit_report_start( ts, *m_stream );
0070 
0071         if( m_report_level == DETAILED_REPORT && !results_collector.results( ts.p_id ).p_skipped )
0072             return true;
0073 
0074         m_formatter->test_unit_report_finish( ts, *m_stream );
0075         return false;
0076     }
0077     void    test_suite_finish( test_suite const& ts ) BOOST_OVERRIDE
0078     {
0079         m_formatter->test_unit_report_finish( ts, *m_stream );
0080     }
0081 
0082     typedef scoped_ptr<io_saver_type> saver_ptr;
0083 
0084     // Data members
0085     std::ostream*       m_stream;
0086     saver_ptr           m_stream_state_saver;
0087     report_level        m_report_level;
0088     scoped_ptr<format>  m_formatter;
0089 };
0090 
0091 results_reporter_impl& s_rr_impl() { static results_reporter_impl the_inst; return the_inst; }
0092 
0093 } // local namespace
0094 
0095 // ************************************************************************** //
0096 // **************              report configuration            ************** //
0097 // ************************************************************************** //
0098 
0099 void
0100 set_level( report_level l )
0101 {
0102     if( l != INV_REPORT_LEVEL )
0103         s_rr_impl().m_report_level = l;
0104 }
0105 
0106 //____________________________________________________________________________//
0107 
0108 void
0109 set_stream( std::ostream& ostr )
0110 {
0111     s_rr_impl().m_stream = &ostr;
0112     s_rr_impl().m_stream_state_saver.reset( new io_saver_type( ostr ) );
0113 }
0114 
0115 //____________________________________________________________________________//
0116 
0117 std::ostream&
0118 get_stream()
0119 {
0120     return *s_rr_impl().m_stream;
0121 }
0122 
0123 //____________________________________________________________________________//
0124 
0125 void
0126 set_format( output_format rf )
0127 {
0128     switch( rf ) {
0129     default:
0130     case OF_CLF:
0131         set_format( new output::plain_report_formatter );
0132         break;
0133     case OF_XML:
0134         set_format( new output::xml_report_formatter );
0135         break;
0136     }
0137 }
0138 
0139 //____________________________________________________________________________//
0140 
0141 void
0142 set_format( results_reporter::format* f )
0143 {
0144     if( f )
0145         s_rr_impl().m_formatter.reset( f );
0146 }
0147 
0148 //____________________________________________________________________________//
0149 
0150 // ************************************************************************** //
0151 // **************               report initiation              ************** //
0152 // ************************************************************************** //
0153 
0154 void
0155 make_report( report_level l, test_unit_id id )
0156 {
0157     if( l == INV_REPORT_LEVEL )
0158         l = s_rr_impl().m_report_level;
0159 
0160     if( l == NO_REPORT )
0161         return;
0162 
0163     if( id == INV_TEST_UNIT_ID )
0164         id = framework::master_test_suite().p_id;
0165 
0166     s_rr_impl().m_stream_state_saver->restore();
0167 
0168     report_level bkup = s_rr_impl().m_report_level;
0169     s_rr_impl().m_report_level = l;
0170 
0171     s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_stream );
0172 
0173     switch( l ) {
0174     case CONFIRMATION_REPORT:
0175         s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_stream );
0176         break;
0177     case SHORT_REPORT:
0178     case DETAILED_REPORT:
0179         traverse_test_tree( id, s_rr_impl() );
0180         break;
0181     default:
0182         break;
0183     }
0184 
0185     s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_stream );
0186     s_rr_impl().m_report_level = bkup;
0187 }
0188 
0189 //____________________________________________________________________________//
0190 
0191 } // namespace results_reporter
0192 } // namespace unit_test
0193 } // namespace boost
0194 
0195 #include <boost/test/detail/enable_warnings.hpp>
0196 
0197 #endif // BOOST_TEST_RESULTS_REPORTER_IPP_020105GER