progress_monitor.ipp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // (C) Copyright Gennadiy Rozental 2005-2008.
  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 : $RCSfile$
  8. //
  9. // Version : $Revision: 57992 $
  10. //
  11. // Description : implements simple text based progress monitor
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_PROGRESS_MONITOR_IPP_020105GER
  14. #define BOOST_TEST_PROGRESS_MONITOR_IPP_020105GER
  15. // Boost.Test
  16. #include <boost/test/progress_monitor.hpp>
  17. #include <boost/test/unit_test_suite_impl.hpp>
  18. #include <boost/test/detail/unit_test_parameters.hpp>
  19. // Boost
  20. #include <boost/progress.hpp>
  21. #include <boost/scoped_ptr.hpp>
  22. #include <boost/test/detail/suppress_warnings.hpp>
  23. //____________________________________________________________________________//
  24. namespace boost {
  25. namespace unit_test {
  26. // ************************************************************************** //
  27. // ************** progress_monitor ************** //
  28. // ************************************************************************** //
  29. namespace {
  30. struct progress_monitor_impl {
  31. // Constructor
  32. progress_monitor_impl()
  33. : m_stream( runtime_config::log_sink() )
  34. {}
  35. std::ostream* m_stream;
  36. scoped_ptr<progress_display> m_progress_display;
  37. };
  38. progress_monitor_impl& s_pm_impl() { static progress_monitor_impl the_inst; return the_inst; }
  39. } // local namespace
  40. //____________________________________________________________________________//
  41. void
  42. progress_monitor_t::test_start( counter_t test_cases_amount )
  43. {
  44. s_pm_impl().m_progress_display.reset( new progress_display( test_cases_amount, *s_pm_impl().m_stream ) );
  45. }
  46. //____________________________________________________________________________//
  47. void
  48. progress_monitor_t::test_aborted()
  49. {
  50. (*s_pm_impl().m_progress_display) += s_pm_impl().m_progress_display->count();
  51. }
  52. //____________________________________________________________________________//
  53. void
  54. progress_monitor_t::test_unit_finish( test_unit const& tu, unsigned long )
  55. {
  56. if( tu.p_type == tut_case )
  57. ++(*s_pm_impl().m_progress_display);
  58. }
  59. //____________________________________________________________________________//
  60. void
  61. progress_monitor_t::test_unit_skipped( test_unit const& tu )
  62. {
  63. test_case_counter tcc;
  64. traverse_test_tree( tu, tcc );
  65. (*s_pm_impl().m_progress_display) += tcc.p_count;
  66. }
  67. //____________________________________________________________________________//
  68. void
  69. progress_monitor_t::set_stream( std::ostream& ostr )
  70. {
  71. s_pm_impl().m_stream = &ostr;
  72. }
  73. //____________________________________________________________________________//
  74. } // namespace unit_test
  75. } // namespace boost
  76. //____________________________________________________________________________//
  77. #include <boost/test/detail/enable_warnings.hpp>
  78. #endif // BOOST_TEST_PROGRESS_MONITOR_IPP_020105GER