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, bool log_build_info )
68 if( log_build_info ) {
70 << " platform" << utils::attr_value() << BOOST_PLATFORM
71 << " compiler" << utils::attr_value() << BOOST_COMPILER
72 << " stl" << utils::attr_value() << BOOST_STDLIB
73 << " boost=\"" << BOOST_VERSION/100000 << "."
74 << BOOST_VERSION/100 % 1000 << "."
75 << BOOST_VERSION % 100 << '\"'
80 //____________________________________________________________________________//
83 xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
85 ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get();
87 if( !tu.p_file_name.empty() )
88 ostr << BOOST_TEST_L( " file" ) << utils::attr_value() << tu.p_file_name
89 << BOOST_TEST_L( " line" ) << utils::attr_value() << tu.p_line_num;
94 //____________________________________________________________________________//
97 xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
99 if( tu.p_type == TUT_CASE )
100 ostr << "<TestingTime>" << elapsed << "</TestingTime>";
102 ostr << "</" << tu_type_name( tu ) << ">";
105 //____________________________________________________________________________//
108 xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason )
110 ostr << "<" << tu_type_name( tu )
111 << " name" << utils::attr_value() << tu.p_name.get()
112 << " skipped" << utils::attr_value() << "yes"
113 << " reason" << utils::attr_value() << reason
117 //____________________________________________________________________________//
120 xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
122 execution_exception::location const& loc = ex.where();
124 ostr << "<Exception file" << utils::attr_value() << loc.m_file_name
125 << " line" << utils::attr_value() << loc.m_line_num;
127 if( !loc.m_function.is_empty() )
128 ostr << " function" << utils::attr_value() << loc.m_function;
130 ostr << ">" << utils::cdata() << ex.what();
132 if( !checkpoint_data.m_file_name.is_empty() ) {
133 ostr << "<LastCheckpoint file" << utils::attr_value() << checkpoint_data.m_file_name
134 << " line" << utils::attr_value() << checkpoint_data.m_line_num
136 << utils::cdata() << checkpoint_data.m_message
137 << "</LastCheckpoint>";
141 //____________________________________________________________________________//
144 xml_log_formatter::log_exception_finish( std::ostream& ostr )
146 ostr << "</Exception>";
149 //____________________________________________________________________________//
152 xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
154 static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
156 m_curr_tag = xml_tags[let];
157 ostr << '<' << m_curr_tag
158 << BOOST_TEST_L( " file" ) << utils::attr_value() << entry_data.m_file_name
159 << BOOST_TEST_L( " line" ) << utils::attr_value() << entry_data.m_line_num
160 << BOOST_TEST_L( "><![CDATA[" );
162 m_value_closed = false;
165 //____________________________________________________________________________//
168 xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
170 utils::print_escaped_cdata( ostr, value );
173 //____________________________________________________________________________//
176 xml_log_formatter::log_entry_finish( std::ostream& ostr )
178 if( !m_value_closed ) {
179 ostr << BOOST_TEST_L( "]]>" );
180 m_value_closed = true;
183 ostr << BOOST_TEST_L( "</" ) << m_curr_tag << BOOST_TEST_L( ">" );
188 //____________________________________________________________________________//
191 xml_log_formatter::entry_context_start( std::ostream& ostr, log_level )
193 if( !m_value_closed ) {
194 ostr << BOOST_TEST_L( "]]>" );
195 m_value_closed = true;
198 ostr << BOOST_TEST_L( "<Context>" );
201 //____________________________________________________________________________//
204 xml_log_formatter::entry_context_finish( std::ostream& ostr, log_level )
206 ostr << BOOST_TEST_L( "</Context>" );
209 //____________________________________________________________________________//
212 xml_log_formatter::log_entry_context( std::ostream& ostr, log_level, const_string context_descr )
214 ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" );
217 //____________________________________________________________________________//
219 } // namespace output
220 } // namespace unit_test
223 #include <boost/test/detail/enable_warnings.hpp>
225 #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER