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 testing result collector components
11 /// Defines classes for keeping track (@ref test_results) and collecting
12 /// (@ref results_collector_t) the states of the test units.
13 // ***************************************************************************
15 #ifndef BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
16 #define BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
19 #include <boost/test/tree/observer.hpp>
21 #include <boost/test/detail/global_typedef.hpp>
22 #include <boost/test/detail/fwd_decl.hpp>
24 #include <boost/test/utils/trivial_singleton.hpp>
25 #include <boost/test/utils/class_properties.hpp>
27 #include <boost/test/detail/suppress_warnings.hpp>
29 //____________________________________________________________________________//
36 // ************************************************************************** //
37 /// First failed assertion debugger hook
39 /// This function is a placeholder where user can set a breakpoint in debugger to catch the
40 /// very first assertion failure in each test case
41 // ************************************************************************** //
42 inline void first_failed_assertion() {}
45 // ************************************************************************** //
46 /// @brief Collection of attributes constituting test unit results
48 /// This class is a collection of attributes describing a test result.
50 /// The attributes presented as public properties on
51 /// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question
53 class BOOST_TEST_DECL test_results {
57 /// Type representing counter like public property
58 typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t)
60 (results_collect_helper) ) counter_prop;
61 /// Type representing boolean like public property
62 typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t)
64 (results_collect_helper) ) bool_prop;
66 counter_prop p_assertions_passed; //!< Number of successful assertions
67 counter_prop p_assertions_failed; //!< Number of failing assertions
68 counter_prop p_warnings_failed; //!< Number of warnings
69 counter_prop p_expected_failures;
70 counter_prop p_test_cases_passed; //!< Number of successfull test cases
71 counter_prop p_test_cases_warned; //!< Number of warnings in test cases
72 counter_prop p_test_cases_failed; //!< Number of failing test cases
73 counter_prop p_test_cases_skipped; //!< Number of skipped test cases
74 counter_prop p_test_cases_aborted; //!< Number of aborted test cases
75 counter_prop p_duration_microseconds; //!< Duration of the test in microseconds
76 bool_prop p_aborted; //!< Indicates that the test unit execution has been aborted
77 bool_prop p_skipped; //!< Indicates that the test unit execution has been skipped
79 /// Returns true if test unit passed
82 /// Produces result code for the test unit execution
84 /// This methhod return one of the result codes defined in @c boost/cstdlib.hpp
86 /// - @c boost::exit_success on success,
87 /// - @c boost::exit_exception_failure in case test unit
88 /// was aborted for any reason (incuding uncaught exception)
89 /// - and @c boost::exit_test_failure otherwise
90 int result_code() const;
92 //! Combines the results of the current instance with another
94 //! Only the counters are updated and the @c p_aborted and @c p_skipped are left unchanged.
95 void operator+=( test_results const& );
97 //! Resets the current state of the result
101 // ************************************************************************** //
102 /// @brief Collects and combines the test results
104 /// This class collects and combines the results of the test unit during the execution of the
105 /// test tree. The results_collector_t::results() function combines the test results on a subtree
106 /// of the test tree.
108 /// @see boost::unit_test::test_observer
109 class BOOST_TEST_DECL results_collector_t : public test_observer, public singleton<results_collector_t> {
112 virtual void test_start( counter_t );
114 virtual void test_unit_start( test_unit const& );
115 virtual void test_unit_finish( test_unit const&, unsigned long );
116 virtual void test_unit_skipped( test_unit const&, const_string );
117 virtual void test_unit_aborted( test_unit const& );
119 virtual void assertion_result( unit_test::assertion_result );
120 virtual void exception_caught( execution_exception const& );
122 virtual int priority() { return 2; }
124 /// Results access per test unit
126 /// @param[in] tu_id id of a test unit
127 test_results const& results( test_unit_id tu_id ) const;
130 BOOST_TEST_SINGLETON_CONS( results_collector_t )
133 BOOST_TEST_SINGLETON_INST( results_collector )
135 } // namespace unit_test
138 #include <boost/test/detail/enable_warnings.hpp>
140 #endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER