LCOV - code coverage report
Current view: top level - opt/homebrew/include/boost/test/impl - results_reporter.ipp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 39 62 62.9 %
Date: 2026-06-25 07:23:43 Functions: 10 15 66.7 %

          Line data    Source code
       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)
       5             : 
       6             : //  See http://www.boost.org/libs/test for the library home page.
       7             : //
       8             : //  File        : $RCSfile$
       9             : //
      10             : //  Version     : $Revision$
      11             : //
      12             : //  Description : result reporting facilities
      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/results_collector.hpp>
      21             : #include <boost/test/framework.hpp>
      22             : 
      23             : #include <boost/test/output/plain_report_formatter.hpp>
      24             : #include <boost/test/output/xml_report_formatter.hpp>
      25             : 
      26             : #include <boost/test/tree/visitor.hpp>
      27             : #include <boost/test/tree/test_unit.hpp>
      28             : #include <boost/test/tree/traverse.hpp>
      29             : 
      30             : // Boost
      31             : #include <boost/scoped_ptr.hpp>
      32             : #include <boost/io/ios_state.hpp>
      33             : typedef ::boost::io::ios_base_all_saver io_saver_type;
      34             : 
      35             : // STL
      36             : #include <iostream>
      37             : 
      38             : #include <boost/test/detail/suppress_warnings.hpp>
      39             : 
      40             : //____________________________________________________________________________//
      41             : 
      42             : namespace boost {
      43             : namespace unit_test {
      44             : namespace results_reporter {
      45             : 
      46             : // ************************************************************************** //
      47             : // **************        result reporter implementation        ************** //
      48             : // ************************************************************************** //
      49             : 
      50             : namespace {
      51             : 
      52             : struct results_reporter_impl : test_tree_visitor {
      53             :     // Constructor
      54         292 :     results_reporter_impl()
      55         146 :     : m_stream( &std::cerr )
      56         146 :     , m_stream_state_saver( new io_saver_type( std::cerr ) )
      57         146 :     , m_report_level( CONFIRMATION_REPORT )
      58         146 :     , m_formatter( new output::plain_report_formatter )
      59         438 :     {}
      60             : 
      61             :     // test tree visitor interface implementation
      62           0 :     void    visit( test_case const& tc ) BOOST_OVERRIDE
      63             :     {
      64           0 :         m_formatter->test_unit_report_start( tc, *m_stream );
      65           0 :         m_formatter->test_unit_report_finish( tc, *m_stream );
      66           0 :     }
      67           0 :     bool    test_suite_start( test_suite const& ts ) BOOST_OVERRIDE
      68             :     {
      69           0 :         m_formatter->test_unit_report_start( ts, *m_stream );
      70             : 
      71           0 :         if( m_report_level == DETAILED_REPORT && !results_collector.results( ts.p_id ).p_skipped )
      72           0 :             return true;
      73             : 
      74           0 :         m_formatter->test_unit_report_finish( ts, *m_stream );
      75           0 :         return false;
      76           0 :     }
      77           0 :     void    test_suite_finish( test_suite const& ts ) BOOST_OVERRIDE
      78             :     {
      79           0 :         m_formatter->test_unit_report_finish( ts, *m_stream );
      80           0 :     }
      81             : 
      82             :     typedef scoped_ptr<io_saver_type> saver_ptr;
      83             : 
      84             :     // Data members
      85             :     std::ostream*       m_stream;
      86             :     saver_ptr           m_stream_state_saver;
      87             :     report_level        m_report_level;
      88             :     scoped_ptr<format>  m_formatter;
      89             : };
      90             : 
      91        2179 : results_reporter_impl& s_rr_impl() { static results_reporter_impl the_inst; return the_inst; }
      92             : 
      93             : } // local namespace
      94             : 
      95             : // ************************************************************************** //
      96             : // **************              report configuration            ************** //
      97             : // ************************************************************************** //
      98             : 
      99             : void
     100         146 : set_level( report_level l )
     101             : {
     102         146 :     if( l != INV_REPORT_LEVEL )
     103         146 :         s_rr_impl().m_report_level = l;
     104         146 : }
     105             : 
     106             : //____________________________________________________________________________//
     107             : 
     108             : void
     109         146 : set_stream( std::ostream& ostr )
     110             : {
     111         146 :     s_rr_impl().m_stream = &ostr;
     112         146 :     s_rr_impl().m_stream_state_saver.reset( new io_saver_type( ostr ) );
     113         146 : }
     114             : 
     115             : //____________________________________________________________________________//
     116             : 
     117             : std::ostream&
     118           0 : get_stream()
     119             : {
     120           0 :     return *s_rr_impl().m_stream;
     121             : }
     122             : 
     123             : //____________________________________________________________________________//
     124             : 
     125             : void
     126         146 : set_format( output_format rf )
     127             : {
     128         146 :     switch( rf ) {
     129             :     default:
     130             :     case OF_CLF:
     131         146 :         set_format( new output::plain_report_formatter );
     132         146 :         break;
     133             :     case OF_XML:
     134           0 :         set_format( new output::xml_report_formatter );
     135           0 :         break;
     136             :     }
     137         146 : }
     138             : 
     139             : //____________________________________________________________________________//
     140             : 
     141             : void
     142         146 : set_format( results_reporter::format* f )
     143             : {
     144         146 :     if( f )
     145         146 :         s_rr_impl().m_formatter.reset( f );
     146         146 : }
     147             : 
     148             : //____________________________________________________________________________//
     149             : 
     150             : // ************************************************************************** //
     151             : // **************               report initiation              ************** //
     152             : // ************************************************************************** //
     153             : 
     154             : void
     155         145 : make_report( report_level l, test_unit_id id )
     156             : {
     157         145 :     if( l == INV_REPORT_LEVEL )
     158         145 :         l = s_rr_impl().m_report_level;
     159             : 
     160         145 :     if( l == NO_REPORT )
     161           0 :         return;
     162             : 
     163         145 :     if( id == INV_TEST_UNIT_ID )
     164           0 :         id = framework::master_test_suite().p_id;
     165             : 
     166         145 :     s_rr_impl().m_stream_state_saver->restore();
     167             : 
     168         145 :     report_level bkup = s_rr_impl().m_report_level;
     169         145 :     s_rr_impl().m_report_level = l;
     170             : 
     171         145 :     s_rr_impl().m_formatter->results_report_start( *s_rr_impl().m_stream );
     172             : 
     173         145 :     switch( l ) {
     174             :     case CONFIRMATION_REPORT:
     175         145 :         s_rr_impl().m_formatter->do_confirmation_report( framework::get<test_unit>( id ), *s_rr_impl().m_stream );
     176         145 :         break;
     177             :     case SHORT_REPORT:
     178             :     case DETAILED_REPORT:
     179           0 :         traverse_test_tree( id, s_rr_impl() );
     180           0 :         break;
     181             :     default:
     182           0 :         break;
     183             :     }
     184             : 
     185         145 :     s_rr_impl().m_formatter->results_report_finish( *s_rr_impl().m_stream );
     186         145 :     s_rr_impl().m_report_level = bkup;
     187         145 : }
     188             : 
     189             : //____________________________________________________________________________//
     190             : 
     191             : } // namespace results_reporter
     192             : } // namespace unit_test
     193             : } // namespace boost
     194             : 
     195             : #include <boost/test/detail/enable_warnings.hpp>
     196             : 
     197             : #endif // BOOST_TEST_RESULTS_REPORTER_IPP_020105GER

Generated by: LCOV version 1.16