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 : implements OF_XML Log formatter
13 // ***************************************************************************
15 #ifndef BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
16 #define BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER
19 #include <boost/test/output/xml_log_formatter.hpp>
20 #include <boost/test/execution_monitor.hpp>
21 #include <boost/test/framework.hpp>
22 #include <boost/test/tree/test_unit.hpp>
23 #include <boost/test/utils/basic_cstring/io.hpp>
24 #include <boost/test/utils/xml_printer.hpp>
27 #include <boost/version.hpp>
32 #include <boost/test/detail/suppress_warnings.hpp>
34 //____________________________________________________________________________//
40 static const_string tu_type_name( test_unit const& tu )
42 return tu.p_type == TUT_CASE ? "TestCase" : "TestSuite";
45 // ************************************************************************** //
46 // ************** xml_log_formatter ************** //
47 // ************************************************************************** //
50 xml_log_formatter::log_start( std::ostream& ostr, counter_t )
55 //____________________________________________________________________________//
58 xml_log_formatter::log_finish( std::ostream& ostr )
63 //____________________________________________________________________________//
66 xml_log_formatter::log_build_info( std::ostream& ostr )
69 << " platform" << utils::attr_value() << BOOST_PLATFORM
70 << " compiler" << utils::attr_value() << BOOST_COMPILER
71 << " stl" << utils::attr_value() << BOOST_STDLIB
72 << " boost=\"" << BOOST_VERSION/100000 << "."
73 << BOOST_VERSION/100 % 1000 << "."
74 << BOOST_VERSION % 100 << '\"'
78 //____________________________________________________________________________//
81 xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
83 ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get();
85 if( !tu.p_file_name.empty() )
86 ostr << BOOST_TEST_L( " file" ) << utils::attr_value() << tu.p_file_name
87 << BOOST_TEST_L( " line" ) << utils::attr_value() << tu.p_line_num;
92 //____________________________________________________________________________//
95 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
97 if( tu.p_type == TUT_CASE )
98 ostr << "<TestingTime>" << elapsed << "</TestingTime>";
100 ostr << "</" << tu_type_name( tu ) << ">";
103 //____________________________________________________________________________//
106 xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason )
108 ostr << "<" << tu_type_name( tu )
109 << " name" << utils::attr_value() << tu.p_name
110 << " skipped" << utils::attr_value() << "yes"
111 << " reason" << utils::attr_value() << reason
115 //____________________________________________________________________________//
118 xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
120 execution_exception::location const& loc = ex.where();
122 ostr << "<Exception file" << utils::attr_value() << loc.m_file_name
123 << " line" << utils::attr_value() << loc.m_line_num;
125 if( !loc.m_function.is_empty() )
126 ostr << " function" << utils::attr_value() << loc.m_function;
128 ostr << ">" << utils::cdata() << ex.what();
130 if( !checkpoint_data.m_file_name.is_empty() ) {
131 ostr << "<LastCheckpoint file" << utils::attr_value() << checkpoint_data.m_file_name
132 << " line" << utils::attr_value() << checkpoint_data.m_line_num
134 << utils::cdata() << checkpoint_data.m_message
135 << "</LastCheckpoint>";
139 //____________________________________________________________________________//
142 xml_log_formatter::log_exception_finish( std::ostream& ostr )
144 ostr << "</Exception>";
147 //____________________________________________________________________________//
150 xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
152 static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
154 m_curr_tag = xml_tags[let];
155 ostr << '<' << m_curr_tag
156 << BOOST_TEST_L( " file" ) << utils::attr_value() << entry_data.m_file_name
157 << BOOST_TEST_L( " line" ) << utils::attr_value() << entry_data.m_line_num
158 << BOOST_TEST_L( "><![CDATA[" );
160 m_value_closed = false;
163 //____________________________________________________________________________//
166 xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
168 utils::print_escaped_cdata( ostr, value );
171 //____________________________________________________________________________//
174 xml_log_formatter::log_entry_finish( std::ostream& ostr )
176 if( !m_value_closed ) {
177 ostr << BOOST_TEST_L( "]]>" );
178 m_value_closed = true;
181 ostr << BOOST_TEST_L( "</" ) << m_curr_tag << BOOST_TEST_L( ">" );
186 //____________________________________________________________________________//
189 xml_log_formatter::entry_context_start( std::ostream& ostr, log_level )
191 if( !m_value_closed ) {
192 ostr << BOOST_TEST_L( "]]>" );
193 m_value_closed = true;
196 ostr << BOOST_TEST_L( "<Context>" );
199 //____________________________________________________________________________//
202 xml_log_formatter::entry_context_finish( std::ostream& ostr )
204 ostr << BOOST_TEST_L( "</Context>" );
207 //____________________________________________________________________________//
210 xml_log_formatter::log_entry_context( std::ostream& ostr, const_string context_descr )
212 ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" );
215 //____________________________________________________________________________//
217 } // namespace output
218 } // namespace unit_test
221 #include <boost/test/detail/enable_warnings.hpp>
223 #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER