test_framework_init_observer.ipp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // (c) Copyright Raffi Enficiaud 2017.
  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. //! An observer for monitoring the success/failure of the other observers
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_FRAMEWORK_INIT_OBSERVER_IPP_021105GER
  11. #define BOOST_TEST_FRAMEWORK_INIT_OBSERVER_IPP_021105GER
  12. // Boost.Test
  13. #include <boost/test/test_framework_init_observer.hpp>
  14. #include <boost/test/framework.hpp>
  15. #include <boost/test/detail/suppress_warnings.hpp>
  16. //____________________________________________________________________________//
  17. namespace boost {
  18. namespace unit_test {
  19. //____________________________________________________________________________//
  20. // ************************************************************************** //
  21. // ************** framework_init_observer_t ************** //
  22. // ************************************************************************** //
  23. namespace {
  24. struct test_init_observer_check {
  25. bool has_failure;
  26. void clear()
  27. {
  28. has_failure = false;
  29. }
  30. };
  31. test_init_observer_check& s_tioc_impl() { static test_init_observer_check the_inst; return the_inst; }
  32. } // local namespace
  33. //____________________________________________________________________________//
  34. // singleton pattern
  35. BOOST_TEST_SINGLETON_CONS_IMPL(framework_init_observer_t)
  36. //____________________________________________________________________________//
  37. void
  38. framework_init_observer_t::clear()
  39. {
  40. if(!framework::test_in_progress())
  41. s_tioc_impl().clear();
  42. }
  43. //____________________________________________________________________________//
  44. void
  45. framework_init_observer_t::test_start( counter_t )
  46. {
  47. clear();
  48. }
  49. //____________________________________________________________________________//
  50. void
  51. framework_init_observer_t::assertion_result( unit_test::assertion_result ar )
  52. {
  53. test_init_observer_check& tr = s_tioc_impl();
  54. switch( ar ) {
  55. case AR_TRIGGERED: break;
  56. case AR_PASSED: break;
  57. case AR_FAILED: tr.has_failure = true; break;
  58. default:
  59. break;
  60. }
  61. }
  62. //____________________________________________________________________________//
  63. void
  64. framework_init_observer_t::exception_caught( execution_exception const& )
  65. {
  66. test_init_observer_check& tr = s_tioc_impl();
  67. tr.has_failure = true;
  68. }
  69. void
  70. framework_init_observer_t::test_aborted()
  71. {
  72. s_tioc_impl().has_failure = true;
  73. }
  74. //____________________________________________________________________________//
  75. bool
  76. framework_init_observer_t::has_failed() const
  77. {
  78. return s_tioc_impl().has_failure;
  79. }
  80. //____________________________________________________________________________//
  81. } // namespace unit_test
  82. } // namespace boost
  83. #include <boost/test/detail/enable_warnings.hpp>
  84. #endif // BOOST_TEST_FRAMEWORK_INIT_OBSERVER_IPP_021105GER