results_reporter.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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
  8. /// @brief defines testing result reporter interfaces
  9. ///
  10. /// This file defines interfaces that are responsible for results reporting. Interface is presented in a form of
  11. /// free standing function implemented in namespace result_reporter
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_RESULTS_REPORTER_HPP_021205GER
  14. #define BOOST_TEST_RESULTS_REPORTER_HPP_021205GER
  15. // Boost.Test
  16. #include <boost/test/detail/global_typedef.hpp>
  17. #include <boost/test/detail/fwd_decl.hpp>
  18. // STL
  19. #include <iosfwd> // for std::ostream&
  20. #include <boost/test/detail/suppress_warnings.hpp>
  21. //____________________________________________________________________________//
  22. namespace boost {
  23. namespace unit_test {
  24. /// Namespace for results reporter interfaces
  25. namespace results_reporter {
  26. // ************************************************************************** //
  27. /// @brief Results report formatter interface
  28. ///
  29. /// This is abstract interface for the report formatter used by results reporter routines.
  30. /// You can define a custom formatter by implementing this interface and setting the formatter using set_format function.
  31. /// This is usually done during test module initialization
  32. // ************************************************************************** //
  33. class BOOST_TEST_DECL format {
  34. public:
  35. // Destructor
  36. virtual ~format() {}
  37. virtual void results_report_start( std::ostream& ostr ) = 0;
  38. virtual void results_report_finish( std::ostream& ostr ) = 0;
  39. virtual void test_unit_report_start( test_unit const&, std::ostream& ostr ) = 0;
  40. virtual void test_unit_report_finish( test_unit const&, std::ostream& ostr ) = 0;
  41. virtual void do_confirmation_report( test_unit const&, std::ostream& ostr ) = 0;
  42. };
  43. // ************************************************************************** //
  44. /// @name report configuration
  45. // ************************************************************************** //
  46. /// Sets reporting level
  47. /// There are only four possible levels for results report:
  48. /// - confirmation report (boost::unit_test::CONFIRMATION_REPORT). This report level only produces short confirmation
  49. /// message about test module pass/fail status
  50. /// - short report (boost::unit_test::SHORT_REPORT). This report level produces short summary report for failed/passed
  51. /// assertions and test units.
  52. /// - detailed report (boost::unit_test::DETAILED_REPORT). This report level produces detailed report per test unit for
  53. /// passed/failed assertions and uncaught exceptions
  54. /// - no report (boost::unit_test::NO_REPORT). This report level produces no results report. This is used for test modules
  55. /// running as part of some kind of continues integration framework
  56. /// @param[in] l report level
  57. BOOST_TEST_DECL void set_level( report_level l );
  58. /// Sets output stream for results reporting
  59. /// By default std::cerr is used. Use this function to set a different stream. The framework
  60. /// refers to the stream by reference, so you need to make sure the stream object lifetime exceeds the testing main scope.
  61. BOOST_TEST_DECL void set_stream( std::ostream& );
  62. /// Sets one of the predefined formats
  63. /// The framework implements two results report formats:
  64. /// - plain human readable format (boost::unit_test::OF_CLF)
  65. /// - XML format (boost::unit_test::OF_XML)
  66. /// @param[in] of one of the presefined enumeration values for output formats
  67. BOOST_TEST_DECL void set_format( output_format of );
  68. /// Sets custom report formatter
  69. /// The framework takes ownership of the pointer passed as an argument. So this should be a pointer to
  70. /// a heap allocated object
  71. /// @param[in] f pointer to heap allocated instance of custom report formatter class
  72. BOOST_TEST_DECL void set_format( results_reporter::format* f );
  73. /// @brief Access to configured results reporter stream
  74. ///
  75. /// Use this stream to report additional information abut test module execution
  76. BOOST_TEST_DECL std::ostream& get_stream();
  77. /// @}
  78. // ************************************************************************** //
  79. // ************** report initiation ************** //
  80. // ************************************************************************** //
  81. BOOST_TEST_DECL void make_report( report_level l = INV_REPORT_LEVEL, test_unit_id = INV_TEST_UNIT_ID );
  82. inline void confirmation_report( test_unit_id id = INV_TEST_UNIT_ID )
  83. { make_report( CONFIRMATION_REPORT, id ); }
  84. inline void short_report( test_unit_id id = INV_TEST_UNIT_ID )
  85. { make_report( SHORT_REPORT, id ); }
  86. inline void detailed_report( test_unit_id id = INV_TEST_UNIT_ID )
  87. { make_report( DETAILED_REPORT, id ); }
  88. } // namespace results_reporter
  89. } // namespace unit_test
  90. } // namespace boost
  91. #include <boost/test/detail/enable_warnings.hpp>
  92. #endif // BOOST_TEST_RESULTS_REPORTER_HPP_021205GER