unit_test_monitor.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 specific version of execution monitor used to managed run unit of test cases
  9. ///
  10. /// Translates execution exception into error level
  11. // ***************************************************************************
  12. #ifndef BOOST_TEST_UNIT_TEST_MONITOR_HPP_020905GER
  13. #define BOOST_TEST_UNIT_TEST_MONITOR_HPP_020905GER
  14. // Boost.Test
  15. #include <boost/test/execution_monitor.hpp>
  16. #include <boost/test/detail/fwd_decl.hpp>
  17. #include <boost/test/utils/trivial_singleton.hpp>
  18. #include <boost/test/detail/suppress_warnings.hpp>
  19. //____________________________________________________________________________//
  20. namespace boost {
  21. namespace unit_test {
  22. // ************************************************************************** //
  23. // ************** unit_test_monitor ************** //
  24. // ************************************************************************** //
  25. class BOOST_TEST_DECL unit_test_monitor_t : public singleton<unit_test_monitor_t>, public execution_monitor {
  26. public:
  27. enum error_level {
  28. test_ok = 0,
  29. /// Indicates a failure to prepare the unit test (eg. fixture). Does not
  30. /// account for tests skipped because of parent tests failed/skipped.
  31. test_setup_failure = -1,
  32. unexpected_exception = -2,
  33. os_exception = -3,
  34. os_timeout = -4,
  35. fatal_error = -5 // includes both system and user
  36. };
  37. static bool is_critical_error( error_level e ) { return e <= fatal_error; }
  38. // monitor method
  39. error_level execute_and_translate( boost::function<void ()> const& func, unsigned timeout = 0 );
  40. private:
  41. BOOST_TEST_SINGLETON_CONS( unit_test_monitor_t )
  42. };
  43. BOOST_TEST_SINGLETON_INST( unit_test_monitor )
  44. } // namespace unit_test
  45. } // namespace boost
  46. #include <boost/test/detail/enable_warnings.hpp>
  47. #endif // BOOST_TEST_UNIT_TEST_MONITOR_HPP_020905GER