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)
6 // See http://www.boost.org/libs/test for the library home page.
9 //!@brief defines abstract interface for test observer
10 // ***************************************************************************
12 #ifndef BOOST_TEST_TEST_OBSERVER_HPP_021005GER
13 #define BOOST_TEST_TEST_OBSERVER_HPP_021005GER
16 #include <boost/test/detail/fwd_decl.hpp>
17 #include <boost/test/detail/global_typedef.hpp>
18 #include <boost/test/detail/config.hpp>
20 #include <boost/test/detail/suppress_warnings.hpp>
22 //____________________________________________________________________________//
27 // ************************************************************************** //
28 // ************** test_observer ************** //
29 // ************************************************************************** //
31 /// @brief Generic test observer interface
33 /// This interface is used by observers in order to receive notifications from the
34 /// Boost.Test framework on the current execution state.
36 /// Several observers can be running at the same time, and it is not unusual to
37 /// have interactions among them. The test_observer#priority member function allows the specification
38 /// of a particular order among them (lowest priority executed first, except specified otherwise).
40 class BOOST_TEST_DECL test_observer {
43 //! Called before the framework starts executing the test cases
45 //! @param[in] number_of_test_cases indicates the number of test cases. Only active
46 //! test cases are taken into account.
48 virtual void test_start( counter_t /* number_of_test_cases */ ) {}
51 //! Called after the framework ends executing the test cases
53 //! @note The call is made with a reversed priority order.
54 virtual void test_finish() {}
56 //! Called when a critical error is detected
58 //! The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework.
59 //! Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining
60 //! tests are discarded.
62 //! @note may be called before test_observer::test_unit_finish()
63 virtual void test_aborted() {}
65 //! Called before the framework starts executing a test unit
67 //! @param[in] test_unit the test being executed
68 virtual void test_unit_start( test_unit const& /* test */) {}
70 //! Called at each end of a test unit.
72 //! @param elapsed duration of the test unit in microseconds.
73 virtual void test_unit_finish( test_unit const& /* test */, unsigned long /* elapsed */ ) {}
74 virtual void test_unit_skipped( test_unit const& tu, const_string ) { test_unit_skipped( tu ); }
75 virtual void test_unit_skipped( test_unit const& ) {} ///< backward compatibility
77 //! Called when a test unit indicates a fatal error.
79 //! A fatal error happens when
80 //! - a strong assertion (with @c REQUIRE) fails, which indicates that the test case cannot continue
81 //! - an unexpected exception is caught by the Boost.Test framework
82 virtual void test_unit_aborted( test_unit const& ) {}
84 virtual void assertion_result( unit_test::assertion_result ar )
87 case AR_PASSED: assertion_result( true ); break;
88 case AR_FAILED: assertion_result( false ); break;
89 case AR_TRIGGERED: break;
94 //! Called when an exception is intercepted
96 //! In case an exception is intercepted, this call happens before the call
97 //! to @ref test_unit_aborted in order to log
98 //! additional data about the exception.
99 virtual void exception_caught( execution_exception const& ) {}
101 virtual int priority() { return 0; }
105 virtual void assertion_result( bool /* passed */ ) {}
107 BOOST_TEST_PROTECTED_VIRTUAL ~test_observer() {}
110 } // namespace unit_test
113 #include <boost/test/detail/enable_warnings.hpp>
115 #endif // BOOST_TEST_TEST_OBSERVER_HPP_021005GER