Back to home page

EIC code displayed by LXR

 
 

    


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

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 : implements OF_XML Log formatter
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
0016 #define BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
0017 
0018 // Boost.Test
0019 #include <boost/test/output/xml_log_formatter.hpp>
0020 #include <boost/test/execution_monitor.hpp>
0021 #include <boost/test/framework.hpp>
0022 #include <boost/test/tree/test_unit.hpp>
0023 #include <boost/test/utils/basic_cstring/io.hpp>
0024 #include <boost/test/utils/xml_printer.hpp>
0025 
0026 // Boost
0027 #include <boost/version.hpp>
0028 
0029 // STL
0030 #include <iostream>
0031 
0032 #include <boost/test/detail/suppress_warnings.hpp>
0033 
0034 //____________________________________________________________________________//
0035 
0036 namespace boost {
0037 namespace unit_test {
0038 namespace output {
0039 
0040 static const_string tu_type_name( test_unit const& tu )
0041 {
0042     return tu.p_type == TUT_CASE ? "TestCase" : "TestSuite";
0043 }
0044 
0045 // ************************************************************************** //
0046 // **************               xml_log_formatter              ************** //
0047 // ************************************************************************** //
0048 
0049 void
0050 xml_log_formatter::log_start( std::ostream& ostr, counter_t )
0051 {
0052     ostr  << "<TestLog>";
0053 }
0054 
0055 //____________________________________________________________________________//
0056 
0057 void
0058 xml_log_formatter::log_finish( std::ostream& ostr )
0059 {
0060     ostr  << "</TestLog>";
0061 }
0062 
0063 //____________________________________________________________________________//
0064 
0065 void
0066 xml_log_formatter::log_build_info( std::ostream& ostr, bool log_build_info )
0067 {
0068     if( log_build_info ) {
0069         ostr  << "<BuildInfo"
0070                 << " platform"  << utils::attr_value() << BOOST_PLATFORM
0071                 << " compiler"  << utils::attr_value() << BOOST_COMPILER
0072                 << " stl"       << utils::attr_value() << BOOST_STDLIB
0073                 << " boost=\""  << BOOST_VERSION/100000     << "."
0074                                 << BOOST_VERSION/100 % 1000 << "."
0075                                 << BOOST_VERSION % 100      << '\"'
0076                 << "/>";
0077     }
0078 }
0079 
0080 //____________________________________________________________________________//
0081 
0082 void
0083 xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
0084 {
0085     ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get();
0086 
0087     if( !tu.p_file_name.empty() )
0088         ostr << BOOST_TEST_L( " file" ) << utils::attr_value() << tu.p_file_name
0089              << BOOST_TEST_L( " line" ) << utils::attr_value() << tu.p_line_num;
0090 
0091     ostr << ">";
0092 }
0093 
0094 //____________________________________________________________________________//
0095 
0096 void
0097 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
0098 {
0099     if( tu.p_type == TUT_CASE )
0100         ostr << "<TestingTime>" << elapsed << "</TestingTime>";
0101 
0102     ostr << "</" << tu_type_name( tu ) << ">";
0103 }
0104 
0105 //____________________________________________________________________________//
0106 
0107 void
0108 xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason )
0109 {
0110     ostr << "<" << tu_type_name( tu )
0111          << " name"    << utils::attr_value() << tu.p_name.get()
0112          << " skipped" << utils::attr_value() << "yes"
0113          << " reason"  << utils::attr_value() << reason
0114          << "/>";
0115 }
0116 
0117 //____________________________________________________________________________//
0118 
0119 void
0120 xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
0121 {
0122     execution_exception::location const& loc = ex.where();
0123 
0124     ostr << "<Exception file" << utils::attr_value() << loc.m_file_name
0125          << " line"           << utils::attr_value() << loc.m_line_num;
0126 
0127     if( !loc.m_function.is_empty() )
0128         ostr << " function"   << utils::attr_value() << loc.m_function;
0129 
0130     ostr << ">" << utils::cdata() << ex.what();
0131 
0132     if( !checkpoint_data.m_file_name.is_empty() ) {
0133         ostr << "<LastCheckpoint file" << utils::attr_value() << checkpoint_data.m_file_name
0134              << " line"                << utils::attr_value() << checkpoint_data.m_line_num
0135              << ">"
0136              << utils::cdata() << checkpoint_data.m_message
0137              << "</LastCheckpoint>";
0138     }
0139 }
0140 
0141 //____________________________________________________________________________//
0142 
0143 void
0144 xml_log_formatter::log_exception_finish( std::ostream& ostr )
0145 {
0146     ostr << "</Exception>";
0147 }
0148 
0149 //____________________________________________________________________________//
0150 
0151 void
0152 xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
0153 {
0154     static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
0155 
0156     m_curr_tag = xml_tags[let];
0157     ostr << '<' << m_curr_tag
0158          << BOOST_TEST_L( " file" ) << utils::attr_value() << entry_data.m_file_name
0159          << BOOST_TEST_L( " line" ) << utils::attr_value() << entry_data.m_line_num
0160          << BOOST_TEST_L( "><![CDATA[" );
0161 
0162     m_value_closed = false;
0163 }
0164 
0165 //____________________________________________________________________________//
0166 
0167 void
0168 xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
0169 {
0170     utils::print_escaped_cdata( ostr, value );
0171 }
0172 
0173 //____________________________________________________________________________//
0174 
0175 void
0176 xml_log_formatter::log_entry_finish( std::ostream& ostr )
0177 {
0178     if( !m_value_closed ) {
0179         ostr << BOOST_TEST_L( "]]>" );
0180         m_value_closed = true;
0181     }
0182 
0183     ostr << BOOST_TEST_L( "</" ) << m_curr_tag << BOOST_TEST_L( ">" );
0184 
0185     m_curr_tag.clear();
0186 }
0187 
0188 //____________________________________________________________________________//
0189 
0190 void
0191 xml_log_formatter::entry_context_start( std::ostream& ostr, log_level )
0192 {
0193     if( !m_value_closed ) {
0194         ostr << BOOST_TEST_L( "]]>" );
0195         m_value_closed = true;
0196     }
0197 
0198     ostr << BOOST_TEST_L( "<Context>" );
0199 }
0200 
0201 //____________________________________________________________________________//
0202 
0203 void
0204 xml_log_formatter::entry_context_finish( std::ostream& ostr, log_level )
0205 {
0206     ostr << BOOST_TEST_L( "</Context>" );
0207 }
0208 
0209 //____________________________________________________________________________//
0210 
0211 void
0212 xml_log_formatter::log_entry_context( std::ostream& ostr, log_level, const_string context_descr )
0213 {
0214     ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" );
0215 }
0216 
0217 //____________________________________________________________________________//
0218 
0219 } // namespace output
0220 } // namespace unit_test
0221 } // namespace boost
0222 
0223 #include <boost/test/detail/enable_warnings.hpp>
0224 
0225 #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER