LCOV - code coverage report
Current view: top level - opt/homebrew/include/boost/test/impl - unit_test_log.ipp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 218 386 56.5 %
Date: 2026-06-25 07:23:43 Functions: 41 55 74.5 %

          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 : implemets Unit Test Log
      13             : // ***************************************************************************
      14             : 
      15             : #ifndef BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER
      16             : #define BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER
      17             : 
      18             : // Boost.Test
      19             : #include <boost/test/unit_test_log.hpp>
      20             : #include <boost/test/unit_test_log_formatter.hpp>
      21             : #include <boost/test/execution_monitor.hpp>
      22             : #include <boost/test/framework.hpp>
      23             : #include <boost/test/unit_test_parameters.hpp>
      24             : 
      25             : #include <boost/test/utils/basic_cstring/compare.hpp>
      26             : #include <boost/test/utils/foreach.hpp>
      27             : 
      28             : #include <boost/test/output/compiler_log_formatter.hpp>
      29             : #include <boost/test/output/xml_log_formatter.hpp>
      30             : #include <boost/test/output/junit_log_formatter.hpp>
      31             : 
      32             : // Boost
      33             : #include <boost/shared_ptr.hpp>
      34             : #include <boost/io/ios_state.hpp>
      35             : typedef ::boost::io::ios_base_all_saver io_saver_type;
      36             : 
      37             : #include <boost/test/detail/suppress_warnings.hpp>
      38             : 
      39             : //____________________________________________________________________________//
      40             : 
      41             : namespace boost {
      42             : namespace unit_test {
      43             : 
      44             : // ************************************************************************** //
      45             : // **************             entry_value_collector            ************** //
      46             : // ************************************************************************** //
      47             : 
      48             : namespace ut_detail {
      49             : 
      50             : entry_value_collector const&
      51         128 : entry_value_collector::operator<<( lazy_ostream const& v ) const
      52             : {
      53         128 :     unit_test_log << v;
      54             : 
      55         128 :     return *this;
      56             : }
      57             : 
      58             : //____________________________________________________________________________//
      59             : 
      60             : entry_value_collector const&
      61           0 : entry_value_collector::operator<<( const_string v ) const
      62             : {
      63           0 :     unit_test_log << v;
      64             : 
      65           0 :     return *this;
      66             : }
      67             : 
      68             : //____________________________________________________________________________//
      69             : 
      70         256 : entry_value_collector::~entry_value_collector()
      71         128 : {
      72         128 :     if( m_last )
      73         128 :         unit_test_log << log::end();
      74         256 : }
      75             : 
      76             : //____________________________________________________________________________//
      77             : 
      78             : } // namespace ut_detail
      79             : 
      80             : // ************************************************************************** //
      81             : // **************                 unit_test_log                ************** //
      82             : // ************************************************************************** //
      83             : 
      84             : namespace {
      85             : 
      86             : // log data
      87             : struct unit_test_log_data_helper_impl {
      88             :   typedef boost::shared_ptr<unit_test_log_formatter> formatter_ptr;
      89             :   typedef boost::shared_ptr<io_saver_type>           saver_ptr;
      90             : 
      91             :   bool                m_enabled;
      92             :   output_format       m_format;
      93             :   std::ostream*       m_stream;
      94             :   saver_ptr           m_stream_state_saver;
      95             :   formatter_ptr       m_log_formatter;
      96             :   bool                m_entry_in_progress;
      97             : 
      98         876 :   unit_test_log_data_helper_impl(unit_test_log_formatter* p_log_formatter, output_format format, bool enabled = false)
      99         438 :     : m_enabled( enabled )
     100         438 :     , m_format( format )
     101         438 :     , m_stream( &std::cout )
     102         438 :     , m_stream_state_saver( new io_saver_type( std::cout ) )
     103         438 :     , m_log_formatter()
     104         438 :     , m_entry_in_progress( false )
     105         438 :   {
     106         438 :     m_log_formatter.reset(p_log_formatter);
     107         438 :     m_log_formatter->set_log_level(log_all_errors);
     108         876 :   }
     109             : 
     110             :   // helper functions
     111       24011 :   std::ostream&       stream()
     112             :   {
     113       24011 :       return *m_stream;
     114             :   }
     115             : 
     116    31665042 :   log_level get_log_level() const
     117             :   {
     118    31665042 :       return m_log_formatter->get_log_level();
     119             :   }
     120             : };
     121             : 
     122             : struct unit_test_log_impl {
     123             :     // Constructor
     124         292 :     unit_test_log_impl()
     125         146 :     {
     126         146 :       m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::compiler_log_formatter, OF_CLF, true) ); // only this one is active by default,
     127         146 :       m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::xml_log_formatter, OF_XML, false) );
     128         146 :       m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::junit_log_formatter, OF_JUNIT, false) );
     129         292 :     }
     130             : 
     131             :     typedef std::vector<unit_test_log_data_helper_impl> v_formatter_data_t;
     132             :     v_formatter_data_t m_log_formatter_data;
     133             : 
     134             :     typedef std::vector<unit_test_log_data_helper_impl*> vp_formatter_data_t;
     135             :     vp_formatter_data_t m_active_log_formatter_data;
     136             : 
     137             :     // entry data
     138             :     log_entry_data      m_entry_data;
     139             : 
     140    17657057 :     bool has_entry_in_progress() const {
     141    35313548 :         for( vp_formatter_data_t::const_iterator it(m_active_log_formatter_data.begin()), ite(m_active_log_formatter_data.end()); 
     142    35313548 :              it < ite; 
     143    17656491 :              ++it)
     144             :         {
     145    17656619 :             unit_test_log_data_helper_impl& current_logger_data = **it;
     146    17656619 :             if( current_logger_data.m_entry_in_progress )
     147         128 :                 return true;
     148    17656491 :         }
     149    17656929 :         return false;
     150    17657057 :     }
     151             : 
     152             :     // check point data
     153             :     log_checkpoint_data m_checkpoint_data;
     154             : 
     155     8820492 :     void                set_checkpoint( const_string file, std::size_t line_num, const_string msg )
     156             :     {
     157     8820492 :         assign_op( m_checkpoint_data.m_message, msg, 0 );
     158     8820492 :         m_checkpoint_data.m_file_name   = file;
     159     8820492 :         m_checkpoint_data.m_line_num    = line_num;
     160     8820492 :     }
     161             : };
     162             : 
     163   160321473 : unit_test_log_impl& s_log_impl() { static unit_test_log_impl the_inst; return the_inst; }
     164             : 
     165             : 
     166             : //____________________________________________________________________________//
     167             : 
     168             : void
     169         128 : log_entry_context( log_level l, unit_test_log_data_helper_impl& current_logger_data)
     170             : {
     171         128 :     framework::context_generator const& context = framework::get_context();
     172         128 :     if( context.is_empty() )
     173         128 :         return;
     174             : 
     175           0 :     const_string frame;
     176           0 :     current_logger_data.m_log_formatter->entry_context_start( current_logger_data.stream(), l );
     177           0 :     while( !(frame=context.next()).is_empty() )
     178             :     {
     179           0 :         current_logger_data.m_log_formatter->log_entry_context( current_logger_data.stream(), l, frame );
     180             :     }
     181           0 :     current_logger_data.m_log_formatter->entry_context_finish( current_logger_data.stream(), l );
     182         128 : }
     183             : 
     184             : //____________________________________________________________________________//
     185             : 
     186             : void
     187     8816787 : clear_entry_context()
     188             : {
     189     8816787 :     framework::clear_context();
     190     8816787 : }
     191             : 
     192             : // convenience
     193             : typedef unit_test_log_impl::vp_formatter_data_t vp_logger_t;
     194             : typedef unit_test_log_impl::v_formatter_data_t v_logger_t;
     195             : 
     196             : } // local namespace
     197             : 
     198             : //____________________________________________________________________________//
     199             : 
     200       21462 : BOOST_TEST_SINGLETON_CONS_IMPL( unit_test_log_t )
     201             : 
     202             : void
     203         292 : unit_test_log_t::configure( )
     204             : {
     205             :     // configure is not test_start:
     206             :     // test_start pushes the necessary log information when the test module is starting, and implies configure.
     207             :     // configure: should be called each time the set of loggers, stream or configuration is changed.
     208         292 :     s_log_impl().m_active_log_formatter_data.clear();
     209        1460 :     for( unit_test_log_impl::v_formatter_data_t::iterator it(s_log_impl().m_log_formatter_data.begin()), 
     210         292 :                                                           ite(s_log_impl().m_log_formatter_data.end());
     211        1168 :         it < ite;
     212         876 :         ++it)
     213             :     {
     214         876 :       if( !it->m_enabled || it->get_log_level() == log_nothing )
     215         584 :           continue;
     216             : 
     217         292 :       s_log_impl().m_active_log_formatter_data.push_back(&*it);
     218         292 :       it->m_entry_in_progress = false;
     219         292 :     }
     220         292 : }
     221             : 
     222             : //____________________________________________________________________________//
     223             : 
     224             : void
     225         146 : unit_test_log_t::test_start( counter_t test_cases_amount, test_unit_id )
     226             : {
     227         146 :     configure();
     228         146 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     229         292 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     230             :     {
     231         146 :       unit_test_log_data_helper_impl& current_logger_data = **it;
     232             : 
     233         146 :       current_logger_data.m_log_formatter->log_start( current_logger_data.stream(), test_cases_amount );
     234         292 :       current_logger_data.m_log_formatter->log_build_info(
     235         146 :           current_logger_data.stream(),
     236         146 :           runtime_config::get<bool>( runtime_config::btrt_build_info ));
     237             : 
     238             :       //current_logger_data.stream().flush();
     239         146 :     }
     240         146 : }
     241             : 
     242             : //____________________________________________________________________________//
     243             : 
     244             : void
     245         145 : unit_test_log_t::test_finish()
     246             : {
     247         145 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     248         290 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     249             :     {
     250         145 :       unit_test_log_data_helper_impl& current_logger_data = **it;
     251         145 :       current_logger_data.m_log_formatter->log_finish( current_logger_data.stream() );
     252         145 :       current_logger_data.stream().flush();
     253         145 :     }
     254         145 : }
     255             : 
     256             : //____________________________________________________________________________//
     257             : 
     258             : void
     259           0 : unit_test_log_t::test_aborted()
     260             : {
     261           0 :     BOOST_TEST_LOG_ENTRY( log_messages ) << "Test is aborted";
     262           0 : }
     263             : 
     264             : //____________________________________________________________________________//
     265             : 
     266             : void
     267        1023 : unit_test_log_t::test_unit_start( test_unit const& tu )
     268             : {
     269        1023 :     if( s_log_impl().has_entry_in_progress() )
     270           0 :         *this << log::end();
     271             : 
     272        1023 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     273        2046 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     274             :     {
     275        1023 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     276        1023 :         if( current_logger_data.get_log_level() > log_test_units )
     277           0 :             continue;
     278        1023 :         current_logger_data.m_log_formatter->test_unit_start( current_logger_data.stream(), tu );
     279        1023 :     }
     280        1023 : }
     281             : 
     282             : //____________________________________________________________________________//
     283             : 
     284             : void
     285        1020 : unit_test_log_t::test_unit_finish( test_unit const& tu, unsigned long elapsed )
     286             : {
     287        1020 :     s_log_impl().m_checkpoint_data.clear();
     288             : 
     289        1020 :     if( s_log_impl().has_entry_in_progress() )
     290           0 :         *this << log::end();
     291             : 
     292        1020 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     293        2040 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     294             :     {
     295        1020 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     296        1020 :         if( current_logger_data.get_log_level() > log_test_units )
     297           0 :             continue;
     298             : 
     299        1020 :         current_logger_data.m_log_formatter->test_unit_finish( current_logger_data.stream(), tu, elapsed );
     300        1020 :     }
     301        1020 : }
     302             : 
     303             : //____________________________________________________________________________//
     304             : 
     305             : void
     306       21002 : unit_test_log_t::test_unit_skipped( test_unit const& tu, const_string reason )
     307             : {
     308       21002 :     if( s_log_impl().has_entry_in_progress() )
     309           0 :         *this << log::end();
     310             : 
     311       21002 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     312       42004 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     313             :     {
     314       21002 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     315       21002 :         if( current_logger_data.get_log_level() > log_test_units )
     316           0 :             continue;
     317             : 
     318       21002 :         current_logger_data.m_log_formatter->test_unit_skipped( current_logger_data.stream(), tu, reason );
     319       21002 :     }
     320       21002 : }
     321             : 
     322             : void
     323           0 : unit_test_log_t::test_unit_aborted( test_unit const& tu )
     324             : {
     325           0 :     if( s_log_impl().has_entry_in_progress() )
     326           0 :         *this << log::end();
     327             : 
     328           0 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     329           0 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     330             :     {
     331           0 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     332           0 :         if( current_logger_data.get_log_level() > log_test_units )
     333           0 :             continue;
     334             : 
     335           0 :         current_logger_data.m_log_formatter->test_unit_aborted(current_logger_data.stream(), tu );
     336           0 :     }
     337           0 : }
     338             : 
     339             : void
     340           0 : unit_test_log_t::test_unit_timed_out( test_unit const& tu )
     341             : {
     342           0 :     if( s_log_impl().has_entry_in_progress() )
     343           0 :         *this << log::end();
     344             : 
     345           0 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     346           0 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     347             :     {
     348           0 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     349           0 :         if( current_logger_data.get_log_level() > log_test_units )
     350           0 :             continue;
     351             : 
     352           0 :         current_logger_data.m_log_formatter->test_unit_timed_out(current_logger_data.stream(), tu );
     353           0 :     }
     354           0 : }
     355             : 
     356             : //____________________________________________________________________________//
     357             : 
     358             : void
     359           0 : unit_test_log_t::exception_caught( execution_exception const& ex )
     360             : {
     361           0 :     log_level l =
     362           0 :         ex.code() <= execution_exception::cpp_exception_error   ? log_cpp_exception_errors :
     363           0 :         (ex.code() <= execution_exception::timeout_error        ? log_system_errors
     364             :                                                                 : log_fatal_errors );
     365             : 
     366           0 :     if( s_log_impl().has_entry_in_progress() )
     367           0 :         *this << log::end();
     368             : 
     369           0 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     370           0 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     371             :     {
     372           0 :       unit_test_log_data_helper_impl& current_logger_data = **it;
     373             : 
     374           0 :       if( l >= current_logger_data.get_log_level() ) {
     375             : 
     376           0 :           current_logger_data.m_log_formatter->log_exception_start( current_logger_data.stream(), s_log_impl().m_checkpoint_data, ex );
     377             : 
     378           0 :           log_entry_context( l, current_logger_data );
     379             : 
     380           0 :           current_logger_data.m_log_formatter->log_exception_finish( current_logger_data.stream() );
     381           0 :       }
     382           0 :     }
     383           0 :     clear_entry_context();
     384           0 : }
     385             : 
     386             : //____________________________________________________________________________//
     387             : 
     388             : void
     389     8820492 : unit_test_log_t::set_checkpoint( const_string file, std::size_t line_num, const_string msg )
     390             : {
     391     8820492 :     s_log_impl().set_checkpoint( file, line_num, msg );
     392     8820492 : }
     393             : 
     394             : //____________________________________________________________________________//
     395             : 
     396             : char
     397   191996918 : set_unix_slash( char in )
     398             : {
     399   191996918 :     return in == '\\' ? '/' : in;
     400             : }
     401             : 
     402             : unit_test_log_t&
     403     8816787 : unit_test_log_t::operator<<( log::begin const& b )
     404             : {
     405     8816787 :     if( s_log_impl().has_entry_in_progress() )
     406           0 :         *this << log::end();
     407             : 
     408     8816787 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     409    17633574 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     410             :     {
     411     8816787 :       unit_test_log_data_helper_impl& current_logger_data = **it;
     412     8816787 :       current_logger_data.m_stream_state_saver->restore();
     413     8816787 :     }
     414             : 
     415     8816787 :     s_log_impl().m_entry_data.clear();
     416             : 
     417     8816787 :     assign_op( s_log_impl().m_entry_data.m_file_name, b.m_file_name, 0 );
     418             : 
     419             :     // normalize file name
     420    17633574 :     std::transform( s_log_impl().m_entry_data.m_file_name.begin(), s_log_impl().m_entry_data.m_file_name.end(),
     421     8816787 :                     s_log_impl().m_entry_data.m_file_name.begin(),
     422             :                     &set_unix_slash );
     423             : 
     424     8816787 :     s_log_impl().m_entry_data.m_line_num = b.m_line_num;
     425             : 
     426     8816787 :     return *this;
     427             : }
     428             : 
     429             : //____________________________________________________________________________//
     430             : 
     431             : unit_test_log_t&
     432     8816787 : unit_test_log_t::operator<<( log::end const& )
     433             : {
     434     8816787 :     if( s_log_impl().has_entry_in_progress() ) {
     435         128 :         vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     436         128 :         log_level l = s_log_impl().m_entry_data.m_level;
     437         256 :         for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     438             :         {
     439         128 :             unit_test_log_data_helper_impl& current_logger_data = **it;
     440         128 :             if( current_logger_data.m_entry_in_progress ) {
     441         128 :                 if( l >= current_logger_data.get_log_level() ) {
     442         128 :                     log_entry_context( l, current_logger_data );
     443         128 :                 }
     444         128 :                 current_logger_data.m_log_formatter->log_entry_finish( current_logger_data.stream() );
     445         128 :             }
     446         128 :             current_logger_data.m_entry_in_progress = false;
     447         128 :         }
     448         128 :     }
     449             : 
     450     8816787 :     clear_entry_context();
     451             : 
     452     8816787 :     return *this;
     453             : }
     454             : 
     455             : //____________________________________________________________________________//
     456             : 
     457             : unit_test_log_t&
     458     8816787 : unit_test_log_t::operator<<( log_level l )
     459             : {
     460     8816787 :     s_log_impl().m_entry_data.m_level = l;
     461             : 
     462     8816787 :     return *this;
     463             : }
     464             : 
     465             : //____________________________________________________________________________//
     466             : 
     467             : ut_detail::entry_value_collector
     468         128 : unit_test_log_t::operator()( log_level l )
     469             : {
     470         128 :     *this << l;
     471             : 
     472         128 :     return ut_detail::entry_value_collector();
     473             : }
     474             : 
     475             : //____________________________________________________________________________//
     476             : 
     477             : bool
     478         128 : log_entry_start(unit_test_log_data_helper_impl &current_logger_data)
     479             : {
     480         128 :     if( current_logger_data.m_entry_in_progress )
     481           0 :         return true;
     482             : 
     483         128 :     switch( s_log_impl().m_entry_data.m_level ) {
     484             :     case log_successful_tests:
     485           0 :         current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
     486             :                                               unit_test_log_formatter::BOOST_UTL_ET_INFO );
     487           0 :         break;
     488             :     case log_messages:
     489         128 :         current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
     490             :                                               unit_test_log_formatter::BOOST_UTL_ET_MESSAGE );
     491         128 :         break;
     492             :     case log_warnings:
     493           0 :         current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
     494             :                                               unit_test_log_formatter::BOOST_UTL_ET_WARNING );
     495           0 :         break;
     496             :     case log_all_errors:
     497             :     case log_cpp_exception_errors:
     498             :     case log_system_errors:
     499           0 :         current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
     500             :                                               unit_test_log_formatter::BOOST_UTL_ET_ERROR );
     501           0 :         break;
     502             :     case log_fatal_errors:
     503           0 :         current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
     504             :                                               unit_test_log_formatter::BOOST_UTL_ET_FATAL_ERROR );
     505           0 :         break;
     506             :     case log_nothing:
     507             :     case log_test_units:
     508             :     case invalid_log_level:
     509           0 :         return false;
     510             :     }
     511             : 
     512         128 :     current_logger_data.m_entry_in_progress = true;
     513         128 :     return true;
     514         128 : }
     515             : 
     516             : //____________________________________________________________________________//
     517             : 
     518             : unit_test_log_t&
     519    25012850 : unit_test_log_t::operator<<( const_string value )
     520             : {
     521    25012850 :     if(value.empty()) {
     522           4 :         return *this;
     523             :     }
     524             : 
     525    25012846 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     526    50025692 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     527             :     {
     528    25012846 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     529    25012846 :         if( s_log_impl().m_entry_data.m_level >= current_logger_data.get_log_level() )
     530           0 :             if( log_entry_start(current_logger_data) ) {
     531           0 :                 current_logger_data.m_log_formatter->log_entry_value( current_logger_data.stream(), value );
     532           0 :             }
     533    25012846 :     }
     534    25012846 :     return *this;
     535    25012850 : }
     536             : 
     537             : //____________________________________________________________________________//
     538             : 
     539             : unit_test_log_t&
     540     6628731 : unit_test_log_t::operator<<( lazy_ostream const& value )
     541             : {
     542     6628731 :     if(value.empty()) {
     543           0 :         return *this;
     544             :     }
     545             : 
     546     6628731 :     vp_logger_t& vloggers = s_log_impl().m_active_log_formatter_data;
     547    13257462 :     for( vp_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     548             :     {
     549     6628731 :         unit_test_log_data_helper_impl& current_logger_data = **it;
     550     6628731 :         if( s_log_impl().m_entry_data.m_level >= current_logger_data.get_log_level() ) {
     551         128 :             if( log_entry_start(current_logger_data) ) {
     552         128 :                 current_logger_data.m_log_formatter->log_entry_value( current_logger_data.stream(), value );
     553         128 :             }
     554         128 :         }
     555     6628731 :     }
     556     6628731 :     return *this;
     557     6628731 : }
     558             : 
     559             : //____________________________________________________________________________//
     560             : 
     561             : void
     562         146 : unit_test_log_t::set_stream( std::ostream& str )
     563             : {
     564         146 :     if( s_log_impl().has_entry_in_progress() )
     565           0 :         return;
     566             : 
     567         146 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     568         584 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     569             :     {
     570         438 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     571             : 
     572         438 :         current_logger_data.m_stream = &str;
     573         438 :         current_logger_data.m_stream_state_saver.reset( new io_saver_type( str ) );
     574         438 :     }
     575         146 : }
     576             : 
     577             : //____________________________________________________________________________//
     578             : 
     579             : void
     580           0 : unit_test_log_t::set_stream( output_format log_format, std::ostream& str )
     581             : {
     582           0 :     if( s_log_impl().has_entry_in_progress() )
     583           0 :         return;
     584             : 
     585           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     586           0 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     587             :     {
     588           0 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     589           0 :         if( current_logger_data.m_format == log_format) {
     590           0 :             current_logger_data.m_stream = &str;
     591           0 :             current_logger_data.m_stream_state_saver.reset( new io_saver_type( str ) );
     592           0 :             break;
     593             :         }
     594           0 :     }
     595           0 : }
     596             : 
     597             : std::ostream*
     598           0 : unit_test_log_t::get_stream( output_format log_format ) const
     599             : {
     600           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     601           0 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     602             :     {
     603           0 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     604           0 :         if( current_logger_data.m_format == log_format) {
     605           0 :             return current_logger_data.m_stream;
     606             :         }
     607           0 :     }
     608           0 :     return 0;
     609           0 : }
     610             : 
     611             : //____________________________________________________________________________//
     612             : 
     613             : log_level
     614         146 : unit_test_log_t::set_threshold_level( log_level lev )
     615             : {
     616         146 :     if( s_log_impl().has_entry_in_progress() || lev == invalid_log_level )
     617           0 :         return invalid_log_level;
     618             : 
     619         146 :     log_level ret = log_nothing;
     620         146 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     621         584 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     622             :     {
     623         438 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     624         438 :         ret = (std::min)(ret, current_logger_data.m_log_formatter->get_log_level());
     625         438 :         current_logger_data.m_log_formatter->set_log_level( lev );
     626         438 :     }
     627         146 :     return ret;
     628         146 : }
     629             : 
     630             : //____________________________________________________________________________//
     631             : 
     632             : log_level
     633           0 : unit_test_log_t::set_threshold_level( output_format log_format, log_level lev )
     634             : {
     635           0 :     if( s_log_impl().has_entry_in_progress() || lev == invalid_log_level )
     636           0 :         return invalid_log_level;
     637             : 
     638           0 :     log_level ret = log_nothing;
     639           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     640           0 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     641             :     {
     642           0 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     643           0 :         if( current_logger_data.m_format == log_format) {
     644           0 :             ret = current_logger_data.m_log_formatter->get_log_level(); 
     645           0 :             current_logger_data.m_log_formatter->set_log_level( lev );
     646           0 :             break;
     647             :         }
     648           0 :     }
     649           0 :     return ret;
     650           0 : }
     651             : 
     652             : //____________________________________________________________________________//
     653             : 
     654             : void
     655         146 : unit_test_log_t::set_format( output_format log_format )
     656             : {
     657         146 :     if( s_log_impl().has_entry_in_progress() )
     658           0 :         return;
     659             : 
     660         146 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     661         584 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     662             :     {
     663         438 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     664         438 :         current_logger_data.m_enabled = current_logger_data.m_format == log_format;
     665         438 :     }
     666         146 : }
     667             : 
     668             : //____________________________________________________________________________//
     669             : 
     670             : void
     671           0 : unit_test_log_t::add_format( output_format log_format )
     672             : {
     673           0 :     if( s_log_impl().has_entry_in_progress() )
     674           0 :         return;
     675             : 
     676           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     677           0 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     678             :     {
     679           0 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     680           0 :         if( current_logger_data.m_format == log_format) {
     681           0 :             current_logger_data.m_enabled = true;
     682           0 :             break;
     683             :         }
     684           0 :     }
     685           0 : }
     686             : 
     687             : //____________________________________________________________________________//
     688             : 
     689             : unit_test_log_formatter*
     690           0 : unit_test_log_t::get_formatter( output_format log_format ) {
     691             :     
     692           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     693           0 :     for( v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     694             :     {
     695           0 :         unit_test_log_data_helper_impl& current_logger_data = *it;
     696           0 :         if( current_logger_data.m_format == log_format) {
     697           0 :             return current_logger_data.m_log_formatter.get();
     698             :         }
     699           0 :     }
     700           0 :     return 0;
     701           0 : }
     702             : 
     703             : 
     704             : void
     705           0 : unit_test_log_t::add_formatter( unit_test_log_formatter* the_formatter )
     706             : {
     707             :     // remove only user defined logger
     708           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     709           0 :     for(v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     710             :     {
     711           0 :         if( it->m_format == OF_CUSTOM_LOGGER) {
     712           0 :             s_log_impl().m_log_formatter_data.erase(it);
     713           0 :             break;
     714             :         }
     715           0 :     }
     716             : 
     717           0 :     if( the_formatter ) {
     718           0 :         s_log_impl().m_active_log_formatter_data.clear(); // otherwise dandling references
     719           0 :         vloggers.push_back( unit_test_log_data_helper_impl(the_formatter, OF_CUSTOM_LOGGER, true) );
     720           0 :     }
     721           0 : }
     722             : 
     723             : void
     724           0 : unit_test_log_t::set_formatter( unit_test_log_formatter* the_formatter )
     725             : {
     726           0 :     if( s_log_impl().has_entry_in_progress() )
     727           0 :         return;
     728             : 
     729             :     // remove only user defined logger
     730           0 :     log_level current_level = invalid_log_level;
     731           0 :     std::ostream *current_stream = 0;
     732           0 :     output_format previous_format = OF_INVALID;
     733           0 :     v_logger_t& vloggers = s_log_impl().m_log_formatter_data;
     734           0 :     for(v_logger_t::iterator it(vloggers.begin()), ite(vloggers.end()); it < ite; ++it)
     735             :     {
     736           0 :         if( it->m_enabled ) {
     737           0 :             if( current_level == invalid_log_level || it->m_format < previous_format || it->m_format == OF_CUSTOM_LOGGER) {
     738           0 :                 current_level = it->get_log_level();
     739           0 :                 current_stream = &(it->stream());
     740           0 :                 previous_format = it->m_format;
     741           0 :             }
     742           0 :         }
     743           0 :     }
     744             : 
     745           0 :     if( the_formatter ) {
     746           0 :         add_formatter(the_formatter);
     747           0 :         set_format(OF_CUSTOM_LOGGER);
     748           0 :         set_threshold_level(OF_CUSTOM_LOGGER, current_level);
     749           0 :         set_stream(OF_CUSTOM_LOGGER, *current_stream);
     750           0 :     }
     751             : 
     752           0 :     configure();
     753           0 : }
     754             : 
     755             : //____________________________________________________________________________//
     756             : 
     757             : // ************************************************************************** //
     758             : // **************            unit_test_log_formatter           ************** //
     759             : // ************************************************************************** //
     760             : 
     761             : void
     762           0 : unit_test_log_formatter::log_entry_value( std::ostream& ostr, lazy_ostream const& value )
     763             : {
     764           0 :     log_entry_value( ostr, (wrap_stringstream().ref() << value).str() );
     765           0 : }
     766             : 
     767             : void
     768         584 : unit_test_log_formatter::set_log_level(log_level new_log_level)
     769             : {
     770         584 :     m_log_level = new_log_level;
     771         584 : }
     772             : 
     773             : log_level
     774    31665480 : unit_test_log_formatter::get_log_level() const
     775             : {
     776    31665480 :     return m_log_level;
     777             : }
     778             : 
     779             : //____________________________________________________________________________//
     780             : 
     781             : } // namespace unit_test
     782             : } // namespace boost
     783             : 
     784             : #include <boost/test/detail/enable_warnings.hpp>
     785             : 
     786             : #endif // BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER
     787             : 

Generated by: LCOV version 1.16