1// (C) Copyright Gennadiy Rozental 2005-2008. 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: 57992 $ 11// 12// Description : implements XML Log formatter 13// *************************************************************************** 14 15#ifndef BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER 16#define BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER 17 18// Boost.Test 19#include <boost/test/output/xml_log_formatter.hpp> 20#include <boost/test/unit_test_suite_impl.hpp> 21#include <boost/test/framework.hpp> 22#include <boost/test/utils/basic_cstring/io.hpp> 23 24#include <boost/test/utils/xml_printer.hpp> 25 26// Boost 27#include <boost/version.hpp> 28 29// STL 30#include <iostream> 31 32#include <boost/test/detail/suppress_warnings.hpp> 33 34//____________________________________________________________________________// 35 36namespace boost { 37 38namespace unit_test { 39 40namespace output { 41 42static const_string tu_type_name( test_unit const& tu ) 43{ 44 return tu.p_type == tut_case ? "TestCase" : "TestSuite"; 45} 46 47// ************************************************************************** // 48// ************** xml_log_formatter ************** // 49// ************************************************************************** // 50 51void 52xml_log_formatter::log_start( std::ostream& ostr, counter_t ) 53{ 54 ostr << "<TestLog>"; 55} 56 57//____________________________________________________________________________// 58 59void 60xml_log_formatter::log_finish( std::ostream& ostr ) 61{ 62 ostr << "</TestLog>"; 63} 64 65//____________________________________________________________________________// 66 67void 68xml_log_formatter::log_build_info( std::ostream& ostr ) 69{ 70 ostr << "<BuildInfo" 71 << " platform" << attr_value() << BOOST_PLATFORM 72 << " compiler" << attr_value() << BOOST_COMPILER 73 << " stl" << attr_value() << BOOST_STDLIB 74 << " boost=\"" << BOOST_VERSION/100000 << "." 75 << BOOST_VERSION/100 % 1000 << "." 76 << BOOST_VERSION % 100 << '\"' 77 << "/>"; 78} 79 80//____________________________________________________________________________// 81 82void 83xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu ) 84{ 85 ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get() << ">"; 86} 87 88//____________________________________________________________________________// 89 90void 91xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed ) 92{ 93 if( tu.p_type == tut_case ) 94 ostr << "<TestingTime>" << elapsed << "</TestingTime>"; 95 96 ostr << "</" << tu_type_name( tu ) << ">"; 97} 98 99//____________________________________________________________________________// 100 101void 102xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu ) 103{ 104 ostr << "<" << tu_type_name( tu ) 105 << " name" << attr_value() << tu.p_name.get() 106 << " skipped" << attr_value() << "yes" 107 << "/>"; 108} 109 110//____________________________________________________________________________// 111 112void 113xml_log_formatter::log_exception( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex ) 114{ 115 execution_exception::location const& loc = ex.where(); 116 117 ostr << "<Exception file" << attr_value() << loc.m_file_name 118 << " line" << attr_value() << loc.m_line_num; 119 120 if( !loc.m_function.is_empty() ) 121 ostr << " function" << attr_value() << loc.m_function; 122 123 ostr << ">" << cdata() << ex.what(); 124 125 if( !checkpoint_data.m_file_name.is_empty() ) { 126 ostr << "<LastCheckpoint file" << attr_value() << checkpoint_data.m_file_name 127 << " line" << attr_value() << checkpoint_data.m_line_num 128 << ">" 129 << cdata() << checkpoint_data.m_message 130 << "</LastCheckpoint>"; 131 } 132 133 ostr << "</Exception>"; 134} 135 136//____________________________________________________________________________// 137 138void 139xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let ) 140{ 141 static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" }; 142 143 m_curr_tag = xml_tags[let]; 144 ostr << '<' << m_curr_tag 145 << BOOST_TEST_L( " file" ) << attr_value() << entry_data.m_file_name 146 << BOOST_TEST_L( " line" ) << attr_value() << entry_data.m_line_num 147 << BOOST_TEST_L( "><![CDATA[" ); 148} 149 150//____________________________________________________________________________// 151 152void 153xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value ) 154{ 155 ostr << value; 156} 157 158//____________________________________________________________________________// 159 160void 161xml_log_formatter::log_entry_finish( std::ostream& ostr ) 162{ 163 ostr << BOOST_TEST_L( "]]></" ) << m_curr_tag << BOOST_TEST_L( ">" ); 164 165 m_curr_tag.clear(); 166} 167 168//____________________________________________________________________________// 169 170} // namespace output 171 172} // namespace unit_test 173 174} // namespace boost 175 176//____________________________________________________________________________// 177 178#include <boost/test/detail/enable_warnings.hpp> 179 180#endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER 181