results_collector.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 testing result collector components
  9. ///
  10. /// Defines classes for keeping track (@ref test_results) and collecting
  11. /// (@ref results_collector_t) the states of the test units.
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
  14. #define BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
  15. // Boost.Test
  16. #include <boost/test/tree/observer.hpp>
  17. #include <boost/test/detail/global_typedef.hpp>
  18. #include <boost/test/detail/fwd_decl.hpp>
  19. #include <boost/test/utils/class_properties.hpp>
  20. #include <boost/test/detail/suppress_warnings.hpp>
  21. //____________________________________________________________________________//
  22. namespace boost {
  23. namespace unit_test {
  24. namespace {
  25. // ************************************************************************** //
  26. /// First failed assertion debugger hook
  27. ///
  28. /// This function is a placeholder where user can set a breakpoint in debugger to catch the
  29. /// very first assertion failure in each test case
  30. // ************************************************************************** //
  31. inline void first_failed_assertion() {}
  32. }
  33. // ************************************************************************** //
  34. /// @brief Collection of attributes constituting test unit results
  35. ///
  36. /// This class is a collection of attributes describing a test result.
  37. ///
  38. /// The attributes presented as public properties on
  39. /// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question
  40. class BOOST_TEST_DECL test_results {
  41. public:
  42. test_results();
  43. /// Type representing counter like public property
  44. typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t)
  45. (test_results)
  46. (results_collect_helper) ) counter_prop;
  47. /// Type representing boolean like public property
  48. typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t)
  49. (test_results)
  50. (results_collect_helper) ) bool_prop;
  51. counter_prop p_test_suites; //!< Number of test suites
  52. counter_prop p_assertions_passed; //!< Number of successful assertions
  53. counter_prop p_assertions_failed; //!< Number of failing assertions
  54. counter_prop p_warnings_failed; //!< Number of warnings
  55. counter_prop p_expected_failures;
  56. counter_prop p_test_cases_passed; //!< Number of successfull test cases
  57. counter_prop p_test_cases_warned; //!< Number of warnings in test cases
  58. counter_prop p_test_cases_failed; //!< Number of failing test cases
  59. counter_prop p_test_cases_skipped; //!< Number of skipped test cases
  60. counter_prop p_test_cases_aborted; //!< Number of aborted test cases
  61. counter_prop p_test_cases_timed_out; //!< Number of timed out test cases
  62. counter_prop p_test_suites_timed_out; //!< Number of timed out test suites
  63. counter_prop p_duration_microseconds; //!< Duration of the test in microseconds
  64. bool_prop p_aborted; //!< Indicates that the test unit execution has been aborted
  65. bool_prop p_skipped; //!< Indicates that the test unit execution has been skipped
  66. bool_prop p_timed_out; //!< Indicates that the test unit has timed out
  67. /// Returns true if test unit passed
  68. bool passed() const;
  69. /// Returns true if test unit skipped
  70. ///
  71. /// For test suites, this indicates if the test suite itself has been marked as
  72. /// skipped, and not if the test suite contains any skipped test.
  73. bool skipped() const;
  74. /// Returns true if the test unit was aborted (hard failure)
  75. bool aborted() const;
  76. /// Produces result code for the test unit execution
  77. ///
  78. /// This methhod return one of the result codes defined in @c boost/cstdlib.hpp
  79. /// @returns
  80. /// - @c boost::exit_success on success,
  81. /// - @c boost::exit_exception_failure in case test unit
  82. /// was aborted for any reason (incuding uncaught exception)
  83. /// - and @c boost::exit_test_failure otherwise
  84. int result_code() const;
  85. //! Combines the results of the current instance with another
  86. //!
  87. //! Only the counters are updated and the @c p_aborted and @c p_skipped are left unchanged.
  88. void operator+=( test_results const& );
  89. //! Resets the current state of the result
  90. void clear();
  91. };
  92. // ************************************************************************** //
  93. /// @brief Collects and combines the test results
  94. ///
  95. /// This class collects and combines the results of the test unit during the execution of the
  96. /// test tree. The results_collector_t::results() function combines the test results on a subtree
  97. /// of the test tree.
  98. ///
  99. /// @see boost::unit_test::test_observer
  100. class BOOST_TEST_DECL results_collector_t : public test_observer {
  101. public:
  102. virtual void test_start( counter_t );
  103. virtual void test_unit_start( test_unit const& );
  104. virtual void test_unit_finish( test_unit const&, unsigned long );
  105. virtual void test_unit_skipped( test_unit const&, const_string );
  106. virtual void test_unit_aborted( test_unit const& );
  107. virtual void test_unit_timed_out( test_unit const& );
  108. virtual void assertion_result( unit_test::assertion_result );
  109. virtual void exception_caught( execution_exception const& );
  110. virtual int priority() { return 3; }
  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. /// Singleton pattern
  116. BOOST_TEST_SINGLETON_CONS( results_collector_t )
  117. };
  118. BOOST_TEST_SINGLETON_INST( results_collector )
  119. } // namespace unit_test
  120. } // namespace boost
  121. #include <boost/test/detail/enable_warnings.hpp>
  122. #endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER