observer.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 abstract interface for test observer
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_TEST_OBSERVER_HPP_021005GER
  11. #define BOOST_TEST_TEST_OBSERVER_HPP_021005GER
  12. // Boost.Test
  13. #include <boost/test/detail/fwd_decl.hpp>
  14. #include <boost/test/detail/global_typedef.hpp>
  15. #include <boost/test/detail/config.hpp>
  16. #include <boost/test/detail/suppress_warnings.hpp>
  17. //____________________________________________________________________________//
  18. namespace boost {
  19. namespace unit_test {
  20. // ************************************************************************** //
  21. // ************** test_observer ************** //
  22. // ************************************************************************** //
  23. /// @brief Generic test observer interface
  24. ///
  25. /// This interface is used by observers in order to receive notifications from the
  26. /// Boost.Test framework on the current execution state.
  27. ///
  28. /// Several observers can be running at the same time, and it is not unusual to
  29. /// have interactions among them. The @ref test_observer::priority member function allows the specification
  30. /// of a particular order among them (lowest priority executed first, except specified otherwise).
  31. ///
  32. class BOOST_TEST_DECL test_observer {
  33. public:
  34. //! Called before the framework starts executing the test cases
  35. //!
  36. //! @param[in] number_of_test_cases indicates the number of test cases. Only active
  37. //! test cases are taken into account.
  38. //! @param[in] root_test_unit_id the ID root of the test tree currently being tested
  39. virtual void test_start( counter_t /* number_of_test_cases */, test_unit_id /* root_test_unit_id */ ) {}
  40. //! Called after the framework ends executing the test cases
  41. //!
  42. //! @note The call is made with a reversed priority order.
  43. virtual void test_finish() {}
  44. //! Called when a critical error is detected
  45. //!
  46. //! The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework.
  47. //! Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining
  48. //! tests are discarded.
  49. //!
  50. //! @note may be called before test_observer::test_unit_finish()
  51. virtual void test_aborted() {}
  52. //! Called before the framework starts executing a test unit
  53. //!
  54. //! @param[in] test_unit the test being executed
  55. virtual void test_unit_start( test_unit const& /* test */) {}
  56. //! Called at each end of a test unit.
  57. //!
  58. //! @param elapsed duration of the test unit in microseconds.
  59. virtual void test_unit_finish( test_unit const& /* test */, unsigned long /* elapsed */ ) {}
  60. virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); }
  61. virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility
  62. //! Called when the test timed out
  63. //!
  64. //! This function is called to signal that a test unit (case or suite) timed out.
  65. //! A valid test unit is available through boost::unit_test::framework::current_test_unit
  66. virtual void test_unit_timed_out( test_unit const& ) {}
  67. //! Called when a test unit indicates a fatal error.
  68. //!
  69. //! A fatal error happens when
  70. //! - a strong assertion (with @c REQUIRE) fails, which indicates that the test case cannot continue
  71. //! - an unexpected exception is caught by the Boost.Test framework
  72. virtual void test_unit_aborted( test_unit const& ) {}
  73. virtual void assertion_result( unit_test::assertion_result /* ar */ )
  74. {
  75. }
  76. //! Called when an exception is intercepted
  77. //!
  78. //! In case an exception is intercepted, this call happens before the call
  79. //! to @ref test_unit_aborted in order to log
  80. //! additional data about the exception.
  81. virtual void exception_caught( execution_exception const& ) {}
  82. //! The priority indicates the order at which this observer is initialized
  83. //! and tore down in the UTF framework. The order is lowest to highest priority.
  84. virtual int priority() { return 0; }
  85. protected:
  86. BOOST_TEST_PROTECTED_VIRTUAL ~test_observer() {}
  87. };
  88. } // namespace unit_test
  89. } // namespace boost
  90. #include <boost/test/detail/enable_warnings.hpp>
  91. #endif // BOOST_TEST_TEST_OBSERVER_HPP_021005GER