| 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 : implements OF_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/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> |
| 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 | |
| 36 | namespace boost { |
| 37 | namespace unit_test { |
| 38 | namespace output { |
| 39 | |
| 40 | static const_string tu_type_name( test_unit const& tu ) |
| 41 | { |
| 42 | return tu.p_type == TUT_CASE ? "TestCase" : "TestSuite" ; |
| 43 | } |
| 44 | |
| 45 | // ************************************************************************** // |
| 46 | // ************** xml_log_formatter ************** // |
| 47 | // ************************************************************************** // |
| 48 | |
| 49 | void |
| 50 | xml_log_formatter::log_start( std::ostream& ostr, counter_t ) |
| 51 | { |
| 52 | ostr << "<TestLog>" ; |
| 53 | } |
| 54 | |
| 55 | //____________________________________________________________________________// |
| 56 | |
| 57 | void |
| 58 | xml_log_formatter::log_finish( std::ostream& ostr ) |
| 59 | { |
| 60 | ostr << "</TestLog>" ; |
| 61 | } |
| 62 | |
| 63 | //____________________________________________________________________________// |
| 64 | |
| 65 | void |
| 66 | xml_log_formatter::log_build_info( std::ostream& ostr, bool log_build_info ) |
| 67 | { |
| 68 | if( log_build_info ) { |
| 69 | ostr << "<BuildInfo" |
| 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 << '\"' |
| 76 | << "/>" ; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | //____________________________________________________________________________// |
| 81 | |
| 82 | void |
| 83 | xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu ) |
| 84 | { |
| 85 | ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get(); |
| 86 | |
| 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; |
| 90 | |
| 91 | ostr << ">" ; |
| 92 | } |
| 93 | |
| 94 | //____________________________________________________________________________// |
| 95 | |
| 96 | void |
| 97 | xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed ) |
| 98 | { |
| 99 | if( tu.p_type == TUT_CASE ) |
| 100 | ostr << "<TestingTime>" << elapsed << "</TestingTime>" ; |
| 101 | |
| 102 | ostr << "</" << tu_type_name( tu ) << ">" ; |
| 103 | } |
| 104 | |
| 105 | //____________________________________________________________________________// |
| 106 | |
| 107 | void |
| 108 | xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason ) |
| 109 | { |
| 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 |
| 114 | << "/>" ; |
| 115 | } |
| 116 | |
| 117 | //____________________________________________________________________________// |
| 118 | |
| 119 | void |
| 120 | xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex ) |
| 121 | { |
| 122 | execution_exception::location const& loc = ex.where(); |
| 123 | |
| 124 | ostr << "<Exception file" << utils::attr_value() << loc.m_file_name |
| 125 | << " line" << utils::attr_value() << loc.m_line_num; |
| 126 | |
| 127 | if( !loc.m_function.is_empty() ) |
| 128 | ostr << " function" << utils::attr_value() << loc.m_function; |
| 129 | |
| 130 | ostr << ">" << utils::cdata() << ex.what(); |
| 131 | |
| 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 |
| 135 | << ">" |
| 136 | << utils::cdata() << checkpoint_data.m_message |
| 137 | << "</LastCheckpoint>" ; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | //____________________________________________________________________________// |
| 142 | |
| 143 | void |
| 144 | xml_log_formatter::log_exception_finish( std::ostream& ostr ) |
| 145 | { |
| 146 | ostr << "</Exception>" ; |
| 147 | } |
| 148 | |
| 149 | //____________________________________________________________________________// |
| 150 | |
| 151 | void |
| 152 | xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let ) |
| 153 | { |
| 154 | static literal_string xml_tags[] = { "Info" , "Message" , "Warning" , "Error" , "FatalError" }; |
| 155 | |
| 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[" ); |
| 161 | |
| 162 | m_value_closed = false; |
| 163 | } |
| 164 | |
| 165 | //____________________________________________________________________________// |
| 166 | |
| 167 | void |
| 168 | xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value ) |
| 169 | { |
| 170 | utils::print_escaped_cdata( where_to&: ostr, value ); |
| 171 | } |
| 172 | |
| 173 | //____________________________________________________________________________// |
| 174 | |
| 175 | void |
| 176 | xml_log_formatter::log_entry_finish( std::ostream& ostr ) |
| 177 | { |
| 178 | if( !m_value_closed ) { |
| 179 | ostr << BOOST_TEST_L( "]]>" ); |
| 180 | m_value_closed = true; |
| 181 | } |
| 182 | |
| 183 | ostr << BOOST_TEST_L( "</" ) << m_curr_tag << BOOST_TEST_L( ">" ); |
| 184 | |
| 185 | m_curr_tag.clear(); |
| 186 | } |
| 187 | |
| 188 | //____________________________________________________________________________// |
| 189 | |
| 190 | void |
| 191 | xml_log_formatter::entry_context_start( std::ostream& ostr, log_level ) |
| 192 | { |
| 193 | if( !m_value_closed ) { |
| 194 | ostr << BOOST_TEST_L( "]]>" ); |
| 195 | m_value_closed = true; |
| 196 | } |
| 197 | |
| 198 | ostr << BOOST_TEST_L( "<Context>" ); |
| 199 | } |
| 200 | |
| 201 | //____________________________________________________________________________// |
| 202 | |
| 203 | void |
| 204 | xml_log_formatter::entry_context_finish( std::ostream& ostr, log_level ) |
| 205 | { |
| 206 | ostr << BOOST_TEST_L( "</Context>" ); |
| 207 | } |
| 208 | |
| 209 | //____________________________________________________________________________// |
| 210 | |
| 211 | void |
| 212 | xml_log_formatter::log_entry_context( std::ostream& ostr, log_level, const_string context_descr ) |
| 213 | { |
| 214 | ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" ); |
| 215 | } |
| 216 | |
| 217 | //____________________________________________________________________________// |
| 218 | |
| 219 | } // namespace output |
| 220 | } // namespace unit_test |
| 221 | } // namespace boost |
| 222 | |
| 223 | #include <boost/test/detail/enable_warnings.hpp> |
| 224 | |
| 225 | #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER |
| 226 | |