results_collector.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/trivial_singleton.hpp>
  20. #include <boost/test/utils/class_properties.hpp>
  21. #include <boost/test/detail/suppress_warnings.hpp>
  22. //____________________________________________________________________________//
  23. namespace boost {
  24. namespace unit_test {
  25. namespace {
  26. // ************************************************************************** //
  27. /// First failed assertion debugger hook
  28. ///
  29. /// This function is a placeholder where user can set a breakpoint in debugger to catch the
  30. /// very first assertion failure in each test case
  31. // ************************************************************************** //
  32. inline void first_failed_assertion() {}
  33. }
  34. // ************************************************************************** //
  35. /// @brief Collection of attributes constituting test unit results
  36. ///
  37. /// This class is a collection of attributes describing a test result.
  38. ///
  39. /// The attributes presented as public properties on
  40. /// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question
  41. class BOOST_TEST_DECL test_results {
  42. public:
  43. test_results();
  44. /// Type representing counter like public property
  45. typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t)
  46. (test_results)
  47. (results_collect_helper) ) counter_prop;
  48. /// Type representing boolean like public property
  49. typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t)
  50. (test_results)
  51. (results_collect_helper) ) bool_prop;
  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_duration_microseconds; //!< Duration of the test in microseconds
  62. bool_prop p_aborted; //!< Indicates that the test unit execution has been aborted
  63. bool_prop p_skipped; //!< Indicates that the test unit execution has been skipped
  64. /// Returns true if test unit passed
  65. bool passed() const;
  66. /// Returns true if test unit skipped
  67. ///
  68. /// For test suites, this indicates if the test suite itself has been marked as
  69. /// skipped, and not if the test suite contains any skipped test.
  70. bool skipped() const;
  71. /// Returns true if the test unit was aborted (hard failure)
  72. bool aborted() const;
  73. /// Produces result code for the test unit execution
  74. ///
  75. /// This methhod return one of the result codes defined in @c boost/cstdlib.hpp
  76. /// @returns
  77. /// - @c boost::exit_success on success,
  78. /// - @c boost::exit_exception_failure in case test unit
  79. /// was aborted for any reason (incuding uncaught exception)
  80. /// - and @c boost::exit_test_failure otherwise
  81. int result_code() const;
  82. //! Combines the results of the current instance with another
  83. //!
  84. //! Only the counters are updated and the @c p_aborted and @c p_skipped are left unchanged.
  85. void operator+=( test_results const& );
  86. //! Resets the current state of the result
  87. void clear();
  88. };
  89. // ************************************************************************** //
  90. /// @brief Collects and combines the test results
  91. ///
  92. /// This class collects and combines the results of the test unit during the execution of the
  93. /// test tree. The results_collector_t::results() function combines the test results on a subtree
  94. /// of the test tree.
  95. ///
  96. /// @see boost::unit_test::test_observer
  97. class BOOST_TEST_DECL results_collector_t : public test_observer, public singleton<results_collector_t> {
  98. public:
  99. virtual void test_start( counter_t );
  100. virtual void test_unit_start( test_unit const& );
  101. virtual void test_unit_finish( test_unit const&, unsigned long );
  102. virtual void test_unit_skipped( test_unit const&, const_string );
  103. virtual void test_unit_aborted( test_unit const& );
  104. virtual void assertion_result( unit_test::assertion_result );
  105. virtual void exception_caught( execution_exception const& );
  106. virtual int priority() { return 3; }
  107. /// Results access per test unit
  108. ///
  109. /// @param[in] tu_id id of a test unit
  110. test_results const& results( test_unit_id tu_id ) const;
  111. private:
  112. BOOST_TEST_SINGLETON_CONS( results_collector_t )
  113. };
  114. BOOST_TEST_SINGLETON_INST( results_collector )
  115. } // namespace unit_test
  116. } // namespace boost
  117. #include <boost/test/detail/enable_warnings.hpp>
  118. #endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER