| 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 | |
| 6 | // See http://www.boost.org/libs/test for the library home page. |
| 7 | // |
| 8 | /// @file |
| 9 | /// @brief Defines testing result collector components |
| 10 | /// |
| 11 | /// Defines classes for keeping track (@ref test_results) and collecting |
| 12 | /// (@ref results_collector_t) the states of the test units. |
| 13 | // *************************************************************************** |
| 14 | |
| 15 | #ifndef BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER |
| 16 | #define BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER |
| 17 | |
| 18 | // Boost.Test |
| 19 | #include <boost/test/tree/observer.hpp> |
| 20 | |
| 21 | #include <boost/test/detail/global_typedef.hpp> |
| 22 | #include <boost/test/detail/fwd_decl.hpp> |
| 23 | |
| 24 | #include <boost/test/utils/class_properties.hpp> |
| 25 | |
| 26 | #include <boost/test/detail/suppress_warnings.hpp> |
| 27 | |
| 28 | //____________________________________________________________________________// |
| 29 | |
| 30 | namespace boost { |
| 31 | namespace unit_test { |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | // ************************************************************************** // |
| 36 | /// First failed assertion debugger hook |
| 37 | /// |
| 38 | /// This function is a placeholder where user can set a breakpoint in debugger to catch the |
| 39 | /// very first assertion failure in each test case |
| 40 | // ************************************************************************** // |
| 41 | inline void first_failed_assertion() {} |
| 42 | } |
| 43 | |
| 44 | // ************************************************************************** // |
| 45 | /// @brief Collection of attributes constituting test unit results |
| 46 | /// |
| 47 | /// This class is a collection of attributes describing a test result. |
| 48 | /// |
| 49 | /// The attributes presented as public properties on |
| 50 | /// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question |
| 51 | |
| 52 | class BOOST_TEST_DECL test_results { |
| 53 | public: |
| 54 | test_results(); |
| 55 | |
| 56 | /// Type representing counter like public property |
| 57 | typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t) |
| 58 | (test_results) |
| 59 | (results_collect_helper) ) counter_prop; |
| 60 | /// Type representing boolean like public property |
| 61 | typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t) |
| 62 | (test_results) |
| 63 | (results_collect_helper) ) bool_prop; |
| 64 | |
| 65 | counter_prop p_test_suites; //!< Number of test suites |
| 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_test_cases_timed_out; //!< Number of timed out test cases |
| 76 | counter_prop p_test_suites_timed_out; //!< Number of timed out test suites |
| 77 | counter_prop p_duration_microseconds; //!< Duration of the test in microseconds |
| 78 | bool_prop p_aborted; //!< Indicates that the test unit execution has been aborted |
| 79 | bool_prop p_skipped; //!< Indicates that the test unit execution has been skipped |
| 80 | bool_prop p_timed_out; //!< Indicates that the test unit has timed out |
| 81 | |
| 82 | /// Returns true if test unit passed |
| 83 | bool passed() const; |
| 84 | |
| 85 | /// Returns true if test unit skipped |
| 86 | /// |
| 87 | /// For test suites, this indicates if the test suite itself has been marked as |
| 88 | /// skipped, and not if the test suite contains any skipped test. |
| 89 | bool skipped() const; |
| 90 | |
| 91 | /// Returns true if the test unit was aborted (hard failure) |
| 92 | bool aborted() const; |
| 93 | |
| 94 | /// Produces result code for the test unit execution |
| 95 | /// |
| 96 | /// This methhod return one of the result codes defined in @c boost/cstdlib.hpp |
| 97 | /// @returns |
| 98 | /// - @c boost::exit_success on success, |
| 99 | /// - @c boost::exit_exception_failure in case test unit |
| 100 | /// was aborted for any reason (including uncaught exception) |
| 101 | /// - and @c boost::exit_test_failure otherwise |
| 102 | int result_code() const; |
| 103 | |
| 104 | //! Combines the results of the current instance with another |
| 105 | //! |
| 106 | //! Only the counters are updated and the @c p_aborted and @c p_skipped are left unchanged. |
| 107 | void operator+=( test_results const& ); |
| 108 | |
| 109 | //! Resets the current state of the result |
| 110 | void clear(); |
| 111 | }; |
| 112 | |
| 113 | // ************************************************************************** // |
| 114 | /// @brief Collects and combines the test results |
| 115 | /// |
| 116 | /// This class collects and combines the results of the test unit during the execution of the |
| 117 | /// test tree. The results_collector_t::results() function combines the test results on a subtree |
| 118 | /// of the test tree. |
| 119 | /// |
| 120 | /// @see boost::unit_test::test_observer |
| 121 | class BOOST_TEST_DECL results_collector_t : public test_observer { |
| 122 | public: |
| 123 | |
| 124 | void test_start( counter_t, test_unit_id ) BOOST_OVERRIDE; |
| 125 | |
| 126 | void test_unit_start( test_unit const& ) BOOST_OVERRIDE; |
| 127 | void test_unit_finish( test_unit const&, unsigned long ) BOOST_OVERRIDE; |
| 128 | void test_unit_skipped( test_unit const&, const_string ) BOOST_OVERRIDE; |
| 129 | void test_unit_aborted( test_unit const& ) BOOST_OVERRIDE; |
| 130 | void test_unit_timed_out( test_unit const& ) BOOST_OVERRIDE; |
| 131 | |
| 132 | void assertion_result( unit_test::assertion_result ) BOOST_OVERRIDE; |
| 133 | void exception_caught( execution_exception const& ) BOOST_OVERRIDE; |
| 134 | |
| 135 | int priority() BOOST_OVERRIDE { return 3; } |
| 136 | |
| 137 | /// Results access per test unit |
| 138 | /// |
| 139 | /// @param[in] tu_id id of a test unit |
| 140 | test_results const& results( test_unit_id tu_id ) const; |
| 141 | |
| 142 | /// Singleton pattern |
| 143 | BOOST_TEST_SINGLETON_CONS( results_collector_t ) |
| 144 | }; |
| 145 | |
| 146 | BOOST_TEST_SINGLETON_INST( results_collector ) |
| 147 | |
| 148 | } // namespace unit_test |
| 149 | } // namespace boost |
| 150 | |
| 151 | #include <boost/test/detail/enable_warnings.hpp> |
| 152 | |
| 153 | #endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER |
| 154 | |