observer.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. virtual void test_start( counter_t /* number_of_test_cases */ ) {}
  39. //! Called after the framework ends executing the test cases
  40. //!
  41. //! @note The call is made with a reversed priority order.
  42. virtual void test_finish() {}
  43. //! Called when a critical error is detected
  44. //!
  45. //! The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework.
  46. //! Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining
  47. //! tests are discarded.
  48. //!
  49. //! @note may be called before test_observer::test_unit_finish()
  50. virtual void test_aborted() {}
  51. //! Called before the framework starts executing a test unit
  52. //!
  53. //! @param[in] test_unit the test being executed
  54. virtual void test_unit_start( test_unit const& /* test */) {}
  55. //! Called at each end of a test unit.
  56. //!
  57. //! @param elapsed duration of the test unit in microseconds.
  58. virtual void test_unit_finish( test_unit const& /* test */, unsigned long /* elapsed */ ) {}
  59. virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); }
  60. virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility
  61. //! Called when the test timed out
  62. //!
  63. //! This function is called to signal that a test unit (case or suite) timed out.
  64. //! A valid test unit is available through boost::unit_test::framework::current_test_unit
  65. virtual void test_unit_timed_out( test_unit const& ) {}
  66. //! Called when a test unit indicates a fatal error.
  67. //!
  68. //! A fatal error happens when
  69. //! - a strong assertion (with @c REQUIRE) fails, which indicates that the test case cannot continue
  70. //! - an unexpected exception is caught by the Boost.Test framework
  71. virtual void test_unit_aborted( test_unit const& ) {}
  72. virtual void assertion_result( unit_test::assertion_result /* ar */ )
  73. {
  74. }
  75. //! Called when an exception is intercepted
  76. //!
  77. //! In case an exception is intercepted, this call happens before the call
  78. //! to @ref test_unit_aborted in order to log
  79. //! additional data about the exception.
  80. virtual void exception_caught( execution_exception const& ) {}
  81. //! The priority indicates the order at which this observer is initialized
  82. //! and tore down in the UTF framework. The order is lowest to highest priority.
  83. virtual int priority() { return 0; }
  84. protected:
  85. BOOST_TEST_PROTECTED_VIRTUAL ~test_observer() {}
  86. };
  87. } // namespace unit_test
  88. } // namespace boost
  89. #include <boost/test/detail/enable_warnings.hpp>
  90. #endif // BOOST_TEST_TEST_OBSERVER_HPP_021005GER