Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 16 | #ifndef NDNBOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER |
| 17 | #define NDNBOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 18 | |
| 19 | // Boost.Test |
| 20 | #include <ndnboost/test/unit_test_monitor.hpp> |
| 21 | #include <ndnboost/test/unit_test_suite_impl.hpp> |
| 22 | #include <ndnboost/test/test_tools.hpp> |
| 23 | #include <ndnboost/test/framework.hpp> |
| 24 | |
| 25 | #include <ndnboost/test/detail/unit_test_parameters.hpp> |
| 26 | |
| 27 | #include <ndnboost/test/detail/suppress_warnings.hpp> |
| 28 | |
| 29 | //____________________________________________________________________________// |
| 30 | |
| 31 | namespace ndnboost { |
| 32 | |
| 33 | namespace unit_test { |
| 34 | |
| 35 | namespace { |
| 36 | |
| 37 | template<typename F> |
| 38 | struct 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 | |
| 46 | template<typename F> |
| 47 | zero_return_wrapper_t<F> |
| 48 | zero_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 | |
| 59 | unit_test_monitor_t::error_level |
| 60 | unit_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 ndnboost |
| 96 | |
| 97 | //____________________________________________________________________________// |
| 98 | |
| 99 | #include <ndnboost/test/detail/enable_warnings.hpp> |
| 100 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 101 | #endif // NDNBOOST_TEST_UNIT_TEST_MONITOR_IPP_012205GER |