unit_test_monitor.ipp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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: 49312 $
  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/unit_test_suite_impl.hpp>
  19. #include <boost/test/test_tools.hpp>
  20. #include <boost/test/framework.hpp>
  21. #include <boost/test/detail/unit_test_parameters.hpp>
  22. #include <boost/test/detail/suppress_warnings.hpp>
  23. //____________________________________________________________________________//
  24. namespace boost {
  25. namespace unit_test {
  26. namespace {
  27. template<typename F>
  28. struct zero_return_wrapper_t {
  29. explicit zero_return_wrapper_t( F const& f ) : m_f( f ) {}
  30. int operator()() { m_f(); return 0; }
  31. F const& m_f;
  32. };
  33. template<typename F>
  34. zero_return_wrapper_t<F>
  35. zero_return_wrapper( F const& f )
  36. {
  37. return zero_return_wrapper_t<F>( f );
  38. }
  39. }
  40. // ************************************************************************** //
  41. // ************** unit_test_monitor ************** //
  42. // ************************************************************************** //
  43. unit_test_monitor_t::error_level
  44. unit_test_monitor_t::execute_and_translate( test_case const& tc )
  45. {
  46. try {
  47. p_catch_system_errors.value = runtime_config::catch_sys_errors();
  48. p_timeout.value = tc.p_timeout.get();
  49. p_auto_start_dbg.value = runtime_config::auto_start_dbg();
  50. p_use_alt_stack.value = runtime_config::use_alt_stack();
  51. p_detect_fp_exceptions.value = runtime_config::detect_fp_exceptions();
  52. execute( callback0<int>( zero_return_wrapper( tc.test_func() ) ) );
  53. }
  54. catch( execution_exception const& ex ) {
  55. framework::exception_caught( ex );
  56. framework::test_unit_aborted( framework::current_test_case() );
  57. // translate execution_exception::error_code to error_level
  58. switch( ex.code() ) {
  59. case execution_exception::no_error: return test_ok;
  60. case execution_exception::user_error: return unexpected_exception;
  61. case execution_exception::cpp_exception_error: return unexpected_exception;
  62. case execution_exception::system_error: return os_exception;
  63. case execution_exception::timeout_error: return os_timeout;
  64. case execution_exception::user_fatal_error:
  65. case execution_exception::system_fatal_error: return fatal_error;
  66. default: return unexpected_exception;
  67. }
  68. }
  69. return test_ok;
  70. }
  71. //____________________________________________________________________________//
  72. } // namespace unit_test
  73. } // namespace boost
  74. //____________________________________________________________________________//
  75. #include <boost/test/detail/enable_warnings.hpp>
  76. #endif // BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER