unit_test_monitor.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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/detail/suppress_warnings.hpp>
  18. //____________________________________________________________________________//
  19. namespace boost {
  20. namespace unit_test {
  21. // ************************************************************************** //
  22. // ************** unit_test_monitor ************** //
  23. // ************************************************************************** //
  24. class BOOST_TEST_DECL unit_test_monitor_t :public execution_monitor {
  25. public:
  26. enum error_level {
  27. test_ok = 0,
  28. /// Indicates a failure to prepare the unit test (eg. fixture). Does not
  29. /// account for tests skipped because of parent tests failed/skipped.
  30. test_setup_failure = -1,
  31. unexpected_exception = -2,
  32. os_exception = -3,
  33. os_timeout = -4,
  34. fatal_error = -5 // includes both system and user
  35. };
  36. static bool is_critical_error( error_level e ) { return e <= fatal_error; }
  37. // monitor method
  38. // timeout is expressed in seconds
  39. error_level execute_and_translate( boost::function<void ()> const& func, unsigned long int timeout_microseconds = 0 );
  40. // singleton pattern
  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