xml_log_formatter.ipp 6.8 KB

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