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 results_collector.hpp @brief defines testing result collector components
9///
10/// Defines class results_collector_t that is responsible for
11/// gathering test results and class test_results for presenting this information to end-user
12// ***************************************************************************
13
14#ifndef BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
15#define BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
16
17// Boost.Test
18#include <boost/test/tree/observer.hpp>
19
20#include <boost/test/detail/global_typedef.hpp>
21#include <boost/test/detail/fwd_decl.hpp>
22
23#include <boost/test/utils/trivial_singleton.hpp>
24#include <boost/test/utils/class_properties.hpp>
25
26#include <boost/test/detail/suppress_warnings.hpp>
27
28//____________________________________________________________________________//
29
30namespace boost {
31namespace unit_test {
32
33namespace {
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// ************************************************************************** //
41inline 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 testing results. The atributes presented as public properties on
48/// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question
49// ************************************************************************** //
50
51class BOOST_TEST_DECL test_results {
52public:
53 test_results();
54
55 /// Type representing counter like public property
56 typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t)(test_results)(results_collect_helper) ) counter_prop;
57 /// Type representing boolean like public property
58 typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t)(test_results)(results_collect_helper) ) bool_prop;
59
60 /// @name Public properties
61 counter_prop p_assertions_passed;
62 counter_prop p_assertions_failed;
63 counter_prop p_warnings_failed;
64 counter_prop p_expected_failures;
65 counter_prop p_test_cases_passed;
66 counter_prop p_test_cases_warned;
67 counter_prop p_test_cases_failed;
68 counter_prop p_test_cases_skipped;
69 counter_prop p_test_cases_aborted;
70 bool_prop p_aborted;
71 bool_prop p_skipped;
72 /// @}
73
74 /// @name Summary conclusion
75
76 /// Returns true if test unit passed
77 bool passed() const;
78 /// Produces result code for the test unit execution
79
80 /// This methhod return one of the result codes defined in boost/cstdlib.hpp
81 /// @returns boost::exit_success on success, boost::exit_exception_failure in case test unit was aborted for any reason
82 /// (incuding uncausght exception) and boost::exit_test_failure otherwise
83 int result_code() const;
84 /// @}
85
86 // collection helper
87 void operator+=( test_results const& );
88
89 void clear();
90};
91
92// ************************************************************************** //
93/// This class implements test observer interface to collect the result of test unit execution
94// ************************************************************************** //
95
96class BOOST_TEST_DECL results_collector_t : public test_observer, public singleton<results_collector_t> {
97public:
98
99 virtual void test_start( counter_t test_cases_amount );
100
101 virtual void test_unit_start( test_unit const& );
102 virtual void test_unit_finish( test_unit const&, unsigned long );
103 virtual void test_unit_skipped( test_unit const&, const_string );
104 virtual void test_unit_aborted( test_unit const& );
105
106 virtual void assertion_result( unit_test::assertion_result );
107 virtual void exception_caught( execution_exception const& );
108
109 virtual int priority() { return 2; }
110
111 /// Results access per test unit
112
113 /// @param[in] tu_id id of a test unit
114 test_results const& results( test_unit_id tu_id ) const;
115
116private:
117 BOOST_TEST_SINGLETON_CONS( results_collector_t )
118};
119
120BOOST_TEST_SINGLETON_INST( results_collector )
121
122} // namespace unit_test
123} // namespace boost
124
125#include <boost/test/detail/enable_warnings.hpp>
126
127#endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
128
129

source code of boost/boost/test/results_collector.hpp