xml_log_formatter.ipp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision: 57992 $
  10. //
  11. // Description : implements 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/unit_test_suite_impl.hpp>
  18. #include <boost/test/framework.hpp>
  19. #include <boost/test/utils/basic_cstring/io.hpp>
  20. #include <boost/test/utils/xml_printer.hpp>
  21. // Boost
  22. #include <boost/version.hpp>
  23. // STL
  24. #include <iostream>
  25. #include <boost/test/detail/suppress_warnings.hpp>
  26. //____________________________________________________________________________//
  27. namespace boost {
  28. namespace unit_test {
  29. namespace output {
  30. static const_string tu_type_name( test_unit const& tu )
  31. {
  32. return tu.p_type == tut_case ? "TestCase" : "TestSuite";
  33. }
  34. // ************************************************************************** //
  35. // ************** xml_log_formatter ************** //
  36. // ************************************************************************** //
  37. void
  38. xml_log_formatter::log_start( std::ostream& ostr, counter_t )
  39. {
  40. ostr << "<TestLog>";
  41. }
  42. //____________________________________________________________________________//
  43. void
  44. xml_log_formatter::log_finish( std::ostream& ostr )
  45. {
  46. ostr << "</TestLog>";
  47. }
  48. //____________________________________________________________________________//
  49. void
  50. xml_log_formatter::log_build_info( std::ostream& ostr )
  51. {
  52. ostr << "<BuildInfo"
  53. << " platform" << attr_value() << BOOST_PLATFORM
  54. << " compiler" << attr_value() << BOOST_COMPILER
  55. << " stl" << attr_value() << BOOST_STDLIB
  56. << " boost=\"" << BOOST_VERSION/100000 << "."
  57. << BOOST_VERSION/100 % 1000 << "."
  58. << BOOST_VERSION % 100 << '\"'
  59. << "/>";
  60. }
  61. //____________________________________________________________________________//
  62. void
  63. xml_log_formatter::test_unit_start( std::ostream& ostr, test_unit const& tu )
  64. {
  65. ostr << "<" << tu_type_name( tu ) << " name" << attr_value() << tu.p_name.get() << ">";
  66. }
  67. //____________________________________________________________________________//
  68. void
  69. xml_log_formatter::test_unit_finish( std::ostream& ostr, test_unit const& tu, unsigned long elapsed )
  70. {
  71. if( tu.p_type == tut_case )
  72. ostr << "<TestingTime>" << elapsed << "</TestingTime>";
  73. ostr << "</" << tu_type_name( tu ) << ">";
  74. }
  75. //____________________________________________________________________________//
  76. void
  77. xml_log_formatter::test_unit_skipped( std::ostream& ostr, test_unit const& tu )
  78. {
  79. ostr << "<" << tu_type_name( tu )
  80. << " name" << attr_value() << tu.p_name.get()
  81. << " skipped" << attr_value() << "yes"
  82. << "/>";
  83. }
  84. //____________________________________________________________________________//
  85. void
  86. xml_log_formatter::log_exception( std::ostream& ostr, log_checkpoint_data const& checkpoint_data, execution_exception const& ex )
  87. {
  88. execution_exception::location const& loc = ex.where();
  89. ostr << "<Exception file" << attr_value() << loc.m_file_name
  90. << " line" << attr_value() << loc.m_line_num;
  91. if( !loc.m_function.is_empty() )
  92. ostr << " function" << attr_value() << loc.m_function;
  93. ostr << ">" << cdata() << ex.what();
  94. if( !checkpoint_data.m_file_name.is_empty() ) {
  95. ostr << "<LastCheckpoint file" << attr_value() << checkpoint_data.m_file_name
  96. << " line" << attr_value() << checkpoint_data.m_line_num
  97. << ">"
  98. << cdata() << checkpoint_data.m_message
  99. << "</LastCheckpoint>";
  100. }
  101. ostr << "</Exception>";
  102. }
  103. //____________________________________________________________________________//
  104. void
  105. xml_log_formatter::log_entry_start( std::ostream& ostr, log_entry_data const& entry_data, log_entry_types let )
  106. {
  107. static literal_string xml_tags[] = { "Info", "Message", "Warning", "Error", "FatalError" };
  108. m_curr_tag = xml_tags[let];
  109. ostr << '<' << m_curr_tag
  110. << BOOST_TEST_L( " file" ) << attr_value() << entry_data.m_file_name
  111. << BOOST_TEST_L( " line" ) << attr_value() << entry_data.m_line_num
  112. << BOOST_TEST_L( "><![CDATA[" );
  113. }
  114. //____________________________________________________________________________//
  115. void
  116. xml_log_formatter::log_entry_value( std::ostream& ostr, const_string value )
  117. {
  118. ostr << value;
  119. }
  120. //____________________________________________________________________________//
  121. void
  122. xml_log_formatter::log_entry_finish( std::ostream& ostr )
  123. {
  124. ostr << BOOST_TEST_L( "]]></" ) << m_curr_tag << BOOST_TEST_L( ">" );
  125. m_curr_tag.clear();
  126. }
  127. //____________________________________________________________________________//
  128. } // namespace output
  129. } // namespace unit_test
  130. } // namespace boost
  131. //____________________________________________________________________________//
  132. #include <boost/test/detail/enable_warnings.hpp>
  133. #endif // BOOST_TEST_XML_LOG_FORMATTER_IPP_020105GER