results_collector.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 results_collector.hpp @brief defines testing result collector components
  8. ///
  9. /// Defines class results_collector_t that is responsible for
  10. /// gathering test results and class test_results for presenting this information to end-user
  11. // ***************************************************************************
  12. #ifndef BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
  13. #define BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER
  14. // Boost.Test
  15. #include <boost/test/tree/observer.hpp>
  16. #include <boost/test/detail/global_typedef.hpp>
  17. #include <boost/test/detail/fwd_decl.hpp>
  18. #include <boost/test/utils/trivial_singleton.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 testing results. The atributes presented as public properties on
  37. /// an instance of the class. In addition summary conclusion methods are presented to generate simple answer to pass/fail question
  38. // ************************************************************************** //
  39. class BOOST_TEST_DECL test_results {
  40. public:
  41. test_results();
  42. /// Type representing counter like public property
  43. typedef BOOST_READONLY_PROPERTY( counter_t, (results_collector_t)(test_results)(results_collect_helper) ) counter_prop;
  44. /// Type representing boolean like public property
  45. typedef BOOST_READONLY_PROPERTY( bool, (results_collector_t)(test_results)(results_collect_helper) ) bool_prop;
  46. /// @name Public properties
  47. counter_prop p_assertions_passed;
  48. counter_prop p_assertions_failed;
  49. counter_prop p_warnings_failed;
  50. counter_prop p_expected_failures;
  51. counter_prop p_test_cases_passed;
  52. counter_prop p_test_cases_warned;
  53. counter_prop p_test_cases_failed;
  54. counter_prop p_test_cases_skipped;
  55. counter_prop p_test_cases_aborted;
  56. bool_prop p_aborted;
  57. bool_prop p_skipped;
  58. /// @}
  59. /// @name Summary conclusion
  60. /// Returns true if test unit passed
  61. bool passed() const;
  62. /// Produces result code for the test unit execution
  63. /// This methhod return one of the result codes defined in boost/cstdlib.hpp
  64. /// @returns boost::exit_success on success, boost::exit_exception_failure in case test unit was aborted for any reason
  65. /// (incuding uncausght exception) and boost::exit_test_failure otherwise
  66. int result_code() const;
  67. /// @}
  68. // collection helper
  69. void operator+=( test_results const& );
  70. void clear();
  71. };
  72. // ************************************************************************** //
  73. /// This class implements test observer interface to collect the result of test unit execution
  74. // ************************************************************************** //
  75. class BOOST_TEST_DECL results_collector_t : public test_observer, public singleton<results_collector_t> {
  76. public:
  77. virtual void test_start( counter_t test_cases_amount );
  78. virtual void test_unit_start( test_unit const& );
  79. virtual void test_unit_finish( test_unit const&, unsigned long );
  80. virtual void test_unit_skipped( test_unit const&, const_string );
  81. virtual void test_unit_aborted( test_unit const& );
  82. virtual void assertion_result( unit_test::assertion_result );
  83. virtual void exception_caught( execution_exception const& );
  84. virtual int priority() { return 2; }
  85. /// Results access per test unit
  86. /// @param[in] tu_id id of a test unit
  87. test_results const& results( test_unit_id tu_id ) const;
  88. private:
  89. BOOST_TEST_SINGLETON_CONS( results_collector_t )
  90. };
  91. BOOST_TEST_SINGLETON_INST( results_collector )
  92. } // namespace unit_test
  93. } // namespace boost
  94. #include <boost/test/detail/enable_warnings.hpp>
  95. #endif // BOOST_TEST_RESULTS_COLLECTOR_HPP_071894GER