unit_test_monitor.ipp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : implements specific subclass of Executon Monitor used by Unit
  12. // Test Framework to monitor test cases run.
  13. // ***************************************************************************
  14. #ifndef BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER
  15. #define BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER
  16. // Boost.Test
  17. #include <boost/test/unit_test_monitor.hpp>
  18. #include <boost/test/framework.hpp>
  19. #include <boost/test/tree/test_unit.hpp>
  20. #include <boost/test/unit_test_parameters.hpp>
  21. #include <boost/test/detail/suppress_warnings.hpp>
  22. //____________________________________________________________________________//
  23. namespace boost {
  24. namespace unit_test {
  25. // singleton pattern
  26. BOOST_TEST_SINGLETON_CONS_IMPL(unit_test_monitor_t)
  27. // ************************************************************************** //
  28. // ************** unit_test_monitor ************** //
  29. // ************************************************************************** //
  30. unit_test_monitor_t::error_level
  31. unit_test_monitor_t::execute_and_translate( boost::function<void ()> const& func, unsigned long int timeout_microseconds )
  32. {
  33. BOOST_TEST_I_TRY {
  34. p_catch_system_errors.value = runtime_config::get<bool>( runtime_config::btrt_catch_sys_errors );
  35. p_timeout.value = timeout_microseconds;
  36. p_auto_start_dbg.value = runtime_config::get<bool>( runtime_config::btrt_auto_start_dbg );
  37. p_use_alt_stack.value = runtime_config::get<bool>( runtime_config::btrt_use_alt_stack );
  38. p_detect_fp_exceptions.value = runtime_config::get<bool>( runtime_config::btrt_detect_fp_except );
  39. vexecute( func );
  40. }
  41. BOOST_TEST_I_CATCH( execution_exception, ex ) {
  42. framework::exception_caught( ex );
  43. framework::test_unit_aborted( framework::current_test_unit() );
  44. // translate execution_exception::error_code to error_level
  45. switch( ex.code() ) {
  46. case execution_exception::no_error: return test_ok;
  47. case execution_exception::user_error: return unexpected_exception;
  48. case execution_exception::cpp_exception_error: return unexpected_exception;
  49. case execution_exception::system_error: return os_exception;
  50. case execution_exception::timeout_error: return os_timeout;
  51. case execution_exception::user_fatal_error:
  52. case execution_exception::system_fatal_error: return fatal_error;
  53. default: return unexpected_exception;
  54. }
  55. }
  56. return test_ok;
  57. }
  58. //____________________________________________________________________________//
  59. } // namespace unit_test
  60. } // namespace boost
  61. #include <boost/test/detail/enable_warnings.hpp>
  62. #endif // BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER