unit_test_log_formatter.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // (C) Copyright Gennadiy Rozental 2003-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 :
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER
  14. #define BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER
  15. // Boost.Test
  16. #include <boost/test/detail/global_typedef.hpp>
  17. #include <boost/test/detail/log_level.hpp>
  18. #include <boost/test/detail/fwd_decl.hpp>
  19. #include <boost/test/execution_monitor.hpp>
  20. // STL
  21. #include <iosfwd>
  22. #include <string> // for std::string
  23. #include <boost/test/detail/suppress_warnings.hpp>
  24. //____________________________________________________________________________//
  25. namespace boost {
  26. namespace unit_test {
  27. // ************************************************************************** //
  28. // ************** log_entry_data ************** //
  29. // ************************************************************************** //
  30. struct BOOST_TEST_DECL log_entry_data {
  31. log_entry_data()
  32. {
  33. m_file_name.reserve( 200 );
  34. }
  35. std::string m_file_name;
  36. std::size_t m_line_num;
  37. log_level m_level;
  38. void clear()
  39. {
  40. m_file_name.erase();
  41. m_line_num = 0;
  42. m_level = log_nothing;
  43. }
  44. };
  45. // ************************************************************************** //
  46. // ************** checkpoint_data ************** //
  47. // ************************************************************************** //
  48. struct BOOST_TEST_DECL log_checkpoint_data
  49. {
  50. const_string m_file_name;
  51. std::size_t m_line_num;
  52. std::string m_message;
  53. void clear()
  54. {
  55. m_file_name.clear();
  56. m_line_num = 0;
  57. m_message = std::string();
  58. }
  59. };
  60. // ************************************************************************** //
  61. // ************** unit_test_log_formatter ************** //
  62. // ************************************************************************** //
  63. class BOOST_TEST_DECL unit_test_log_formatter {
  64. public:
  65. enum log_entry_types { BOOST_UTL_ET_INFO,
  66. BOOST_UTL_ET_MESSAGE,
  67. BOOST_UTL_ET_WARNING,
  68. BOOST_UTL_ET_ERROR,
  69. BOOST_UTL_ET_FATAL_ERROR };
  70. // Destructor
  71. virtual ~unit_test_log_formatter() {}
  72. // Formatter interface
  73. virtual void log_start( std::ostream&, counter_t test_cases_amount ) = 0;
  74. virtual void log_finish( std::ostream& ) = 0;
  75. virtual void log_build_info( std::ostream& ) = 0;
  76. virtual void test_unit_start( std::ostream&, test_unit const& tu ) = 0;
  77. virtual void test_unit_finish( std::ostream&, test_unit const& tu, unsigned long elapsed ) = 0;
  78. virtual void test_unit_skipped( std::ostream&, test_unit const& ) = 0;
  79. virtual void log_exception( std::ostream& os, log_checkpoint_data const& cd, execution_exception const& ex )
  80. {
  81. // for backward compatibility
  82. log_exception( os, cd, ex.what() );
  83. }
  84. virtual void log_exception( std::ostream&, log_checkpoint_data const&, const_string /* explanation */ ) {}
  85. virtual void log_entry_start( std::ostream&, log_entry_data const&, log_entry_types let ) = 0;
  86. virtual void log_entry_value( std::ostream&, const_string value ) = 0;
  87. virtual void log_entry_value( std::ostream&, lazy_ostream const& value ); // there is a default impl
  88. virtual void log_entry_finish( std::ostream& ) = 0;
  89. };
  90. } // namespace unit_test
  91. } // namespace boost
  92. //____________________________________________________________________________//
  93. #include <boost/test/detail/enable_warnings.hpp>
  94. #endif // BOOST_TEST_UNIT_TEST_LOG_FORMATTER_HPP_071894GER