test_case_counter.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. /// Defines @ref test_case_counter
  9. // ***************************************************************************
  10. #ifndef BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER
  11. #define BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER
  12. // Boost.Test
  13. #include <boost/test/detail/config.hpp>
  14. #include <boost/test/utils/class_properties.hpp>
  15. #include <boost/test/tree/test_unit.hpp>
  16. #include <boost/test/tree/visitor.hpp>
  17. #include <boost/test/detail/suppress_warnings.hpp>
  18. //____________________________________________________________________________//
  19. namespace boost {
  20. namespace unit_test {
  21. // ************************************************************************** //
  22. // ************** test_case_counter ************** //
  23. // ************************************************************************** //
  24. ///! Counts the number of enabled test cases
  25. class test_case_counter : public test_tree_visitor {
  26. public:
  27. // Constructor
  28. // @param ignore_disabled ignore the status when counting
  29. test_case_counter(bool ignore_status = false)
  30. : p_count( 0 )
  31. , m_ignore_status(ignore_status)
  32. {}
  33. BOOST_READONLY_PROPERTY( counter_t, (test_case_counter)) p_count;
  34. private:
  35. // test tree visitor interface
  36. virtual void visit( test_case const& tc ) { if( m_ignore_status || tc.is_enabled() ) ++p_count.value; }
  37. virtual bool test_suite_start( test_suite const& ts ) { return m_ignore_status || ts.is_enabled(); }
  38. bool m_ignore_status;
  39. };
  40. } // namespace unit_test
  41. } // namespace boost
  42. #include <boost/test/detail/enable_warnings.hpp>
  43. #endif // BOOST_TEST_TREE_TEST_CASE_COUNTER_HPP_100211GER