xml_log_formatter.ipp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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, bool log_build_info )
  52. {
  53. if( log_build_info ) {
  54. ostr << "<BuildInfo"
  55. << " platform" << utils::attr_value() << BOOST_PLATFORM
  56. << " compiler" << utils::attr_value() << BOOST_COMPILER
  57. << " stl" << utils::attr_value() << BOOST_STDLIB
  58. << " boost=\"" << BOOST_VERSION/100000 << "."
  59. << BOOST_VERSION/100 % 1000 << "."
  60. << BOOST_VERSION % 100 << '\"'
  61. << "/>";
  62. }
  63. }
  64. //____________________________________________________________________________//
  65. void
  66. xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
  67. {
  68. ostr << "<" << tu_type_name( tu ) << " name" << utils::attr_value() << tu.p_name.get();
  69. if( !tu.p_file_name.empty() )
  70. ostr << BOOST_TEST_L( " file" ) << utils::attr_value() << tu.p_file_name
  71. << BOOST_TEST_L( " line" ) << utils::attr_value() << tu.p_line_num;
  72. ostr << ">";
  73. }
  74. //____________________________________________________________________________//
  75. void
  76. xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
  77. {
  78. if( tu.p_type == TUT_CASE )
  79. ostr << "<TestingTime>" << elapsed << "</TestingTime>";
  80. ostr << "</" << tu_type_name( tu ) << ">";
  81. }
  82. //____________________________________________________________________________//
  83. void
  84. xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu, const_string reason )
  85. {
  86. ostr << "<" << tu_type_name( tu )
  87. << " name" << utils::attr_value() << tu.p_name
  88. << " skipped" << utils::attr_value() << "yes"
  89. << " reason" << utils::attr_value() << reason
  90. << "/>";
  91. }
  92. //____________________________________________________________________________//
  93. void
  94. xml_log_formatter::log_exception_start( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
  95. {
  96. execution_exception::location const& loc = ex.where();
  97. ostr << "<Exception file" << utils::attr_value() << loc.m_file_name
  98. << " line" << utils::attr_value() << loc.m_line_num;
  99. if( !loc.m_function.is_empty() )
  100. ostr << " function" << utils::attr_value() << loc.m_function;
  101. ostr << ">" << utils::cdata() << ex.what();
  102. if( !checkpoint_data.m_file_name.is_empty() ) {
  103. ostr << "<LastCheckpoint file" << utils::attr_value() << checkpoint_data.m_file_name
  104. << " line" << utils::attr_value() << checkpoint_data.m_line_num
  105. << ">"
  106. << utils::cdata() << checkpoint_data.m_message
  107. << "</LastCheckpoint>";
  108. }
  109. }
  110. //____________________________________________________________________________//
  111. void
  112. xml_log_formatter::log_exception_finish( std::ostream& ostr )
  113. {
  114. ostr << "</Exception>";
  115. }
  116. //____________________________________________________________________________//
  117. void
  118. xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
  119. {
  120. static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
  121. m_curr_tag = xml_tags[let];
  122. ostr << '<' << m_curr_tag
  123. << BOOST_TEST_L( " file" ) << utils::attr_value() << entry_data.m_file_name
  124. << BOOST_TEST_L( " line" ) << utils::attr_value() << entry_data.m_line_num
  125. << BOOST_TEST_L( "><![CDATA[" );
  126. m_value_closed = false;
  127. }
  128. //____________________________________________________________________________//
  129. void
  130. xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
  131. {
  132. utils::print_escaped_cdata( ostr, value );
  133. }
  134. //____________________________________________________________________________//
  135. void
  136. xml_log_formatter::log_entry_finish( std::ostream& ostr )
  137. {
  138. if( !m_value_closed ) {
  139. ostr << BOOST_TEST_L( "]]>" );
  140. m_value_closed = true;
  141. }
  142. ostr << BOOST_TEST_L( "</" ) << m_curr_tag << BOOST_TEST_L( ">" );
  143. m_curr_tag.clear();
  144. }
  145. //____________________________________________________________________________//
  146. void
  147. xml_log_formatter::entry_context_start( std::ostream& ostr, log_level )
  148. {
  149. if( !m_value_closed ) {
  150. ostr << BOOST_TEST_L( "]]>" );
  151. m_value_closed = true;
  152. }
  153. ostr << BOOST_TEST_L( "<Context>" );
  154. }
  155. //____________________________________________________________________________//
  156. void
  157. xml_log_formatter::entry_context_finish( std::ostream& ostr, log_level )
  158. {
  159. ostr << BOOST_TEST_L( "</Context>" );
  160. }
  161. //____________________________________________________________________________//
  162. void
  163. xml_log_formatter::log_entry_context( std::ostream& ostr, log_level, const_string context_descr )
  164. {
  165. ostr << BOOST_TEST_L( "<Frame>" ) << utils::cdata() << context_descr << BOOST_TEST_L( "</Frame>" );
  166. }
  167. //____________________________________________________________________________//
  168. } // namespace output
  169. } // namespace unit_test
  170. } // namespace boost
  171. #include <boost/test/detail/enable_warnings.hpp>
  172. #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER