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 6// See http://www.boost.org/libs/test for the library home page. 7// 8// File : $RCSfile$ 9// 10// Version : $Revision: 49312 $ 11// 12// Description : implements specific subclass of Executon Monitor used by Unit 13// Test Framework to monitor test cases run. 14// *************************************************************************** 15 16#ifndef BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER 17#define BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER 18 19// Boost.Test 20#include <boost/test/unit_test_monitor.hpp> 21#include <boost/test/unit_test_suite_impl.hpp> 22#include <boost/test/test_tools.hpp> 23#include <boost/test/framework.hpp> 24 25#include <boost/test/detail/unit_test_parameters.hpp> 26 27#include <boost/test/detail/suppress_warnings.hpp> 28 29//____________________________________________________________________________// 30 31namespace boost { 32 33namespace unit_test { 34 35namespace { 36 37template<typename F> 38struct zero_return_wrapper_t { 39 explicit zero_return_wrapper_t( F const& f ) : m_f( f ) {} 40 41 int operator()() { m_f(); return 0; } 42 43 F const& m_f; 44}; 45 46template<typename F> 47zero_return_wrapper_t<F> 48zero_return_wrapper( F const& f ) 49{ 50 return zero_return_wrapper_t<F>( f ); 51} 52 53} 54 55// ************************************************************************** // 56// ************** unit_test_monitor ************** // 57// ************************************************************************** // 58 59unit_test_monitor_t::error_level 60unit_test_monitor_t::execute_and_translate( test_case const& tc ) 61{ 62 try { 63 p_catch_system_errors.value = runtime_config::catch_sys_errors(); 64 p_timeout.value = tc.p_timeout.get(); 65 p_auto_start_dbg.value = runtime_config::auto_start_dbg(); 66 p_use_alt_stack.value = runtime_config::use_alt_stack(); 67 p_detect_fp_exceptions.value = runtime_config::detect_fp_exceptions(); 68 69 execute( callback0<int>( zero_return_wrapper( tc.test_func() ) ) ); 70 } 71 catch( execution_exception const& ex ) { 72 framework::exception_caught( ex ); 73 framework::test_unit_aborted( framework::current_test_case() ); 74 75 // translate execution_exception::error_code to error_level 76 switch( ex.code() ) { 77 case execution_exception::no_error: return test_ok; 78 case execution_exception::user_error: return unexpected_exception; 79 case execution_exception::cpp_exception_error: return unexpected_exception; 80 case execution_exception::system_error: return os_exception; 81 case execution_exception::timeout_error: return os_timeout; 82 case execution_exception::user_fatal_error: 83 case execution_exception::system_fatal_error: return fatal_error; 84 default: return unexpected_exception; 85 } 86 } 87 88 return test_ok; 89} 90 91//____________________________________________________________________________// 92 93} // namespace unit_test 94 95} // namespace boost 96 97//____________________________________________________________________________// 98 99#include <boost/test/detail/enable_warnings.hpp> 100 101#endif // BOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER 102