From a4a30f01a1c7ad139c7a9a7a4e1452d581678e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=83=C2=BCrgen=20Hunold?= Date: Fri, 7 Apr 2017 10:38:56 +0200 Subject: [PATCH] WIP: use std::function if c++11 is available --- doc/examples/example08.run-fail.cpp | 4 +++ include/boost/test/debug.hpp | 11 ++++++-- include/boost/test/execution_monitor.hpp | 24 ++++++++++++------ include/boost/test/impl/execution_monitor.ipp | 11 ++++---- include/boost/test/impl/test_tree.ipp | 4 +-- include/boost/test/impl/unit_test_monitor.ipp | 2 +- include/boost/test/parameterized_test.hpp | 25 ++++++++++++++++--- include/boost/test/tree/decorator.hpp | 11 ++++++-- include/boost/test/tree/fixture.hpp | 17 ++++++++++--- .../boost/test/tree/test_case_template.hpp | 4 +++ include/boost/test/tree/test_unit.hpp | 23 +++++++++++++---- include/boost/test/unit_test_monitor.hpp | 2 +- include/boost/test/unit_test_suite.hpp | 2 +- .../test/utils/runtime/argument_factory.hpp | 4 +++ .../boost/test/utils/runtime/cla/parser.hpp | 13 +++++++--- .../boost/test/utils/runtime/parameter.hpp | 12 ++++++++- .../test-tree-management-test.cpp | 2 +- .../test_unit-order-shuffled-test.cpp | 2 +- .../test_unit-order-test.cpp | 2 +- 19 files changed, 134 insertions(+), 41 deletions(-) diff --git a/doc/examples/example08.run-fail.cpp b/doc/examples/example08.run-fail.cpp index 7e372a391f..83cb0cf97b 100644 --- a/doc/examples/example08.run-fail.cpp +++ b/doc/examples/example08.run-fail.cpp @@ -27,7 +27,11 @@ bool init_unit_test() { double params[] = { 1., 1.1, 1.01, 1.001, 1.0001 }; +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) boost::function test_method = bind( &test_class::test_method, &tester, _1); +#else + std::function test_method = bind( &test_class::test_method, &tester, _1); +#endif framework::master_test_suite(). add( BOOST_PARAM_TEST_CASE( test_method, params, params+5 ) ); diff --git a/include/boost/test/debug.hpp b/include/boost/test/debug.hpp index a8ccae0b97..486f0a47ce 100644 --- a/include/boost/test/debug.hpp +++ b/include/boost/test/debug.hpp @@ -18,8 +18,12 @@ #include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) // Boost #include +#else +#include +#endif // STL #include @@ -72,8 +76,11 @@ struct dbg_startup_info { }; /// Signature of debugger starter routine. Takes an instance of dbg_startup_into as only argument -typedef boost::function dbg_starter; - +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef boost::function dbg_starter; +#else + using dbg_starter = std::function; +#endif // ************************************************************************** // /// Specifies which debugger to use when attaching and optionally what routine to use to start that debugger diff --git a/include/boost/test/execution_monitor.hpp b/include/boost/test/execution_monitor.hpp index adfb0336ca..3bded3cf46 100644 --- a/include/boost/test/execution_monitor.hpp +++ b/include/boost/test/execution_monitor.hpp @@ -25,7 +25,11 @@ #include #include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include +#else +#include +#endif #include @@ -97,6 +101,14 @@ namespace boost { +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef boost::function test_func_t; + typedef boost::function result_func_t; +#else + using test_func_t = std::function; + using result_func_t = std::function; +#endif + /// @defgroup ExecutionMonitor Function Execution Monitor /// @{ /// @section Intro Introduction @@ -196,8 +208,7 @@ class BOOST_TEST_DECL translator_holder_base { // translator holder interface // invokes the function F inside the try/catch guarding against specific exception - virtual int operator()( boost::function const& F ) = 0; - + virtual int operator()( result_func_t const& F ) = 0; // erases specific translator holder from the chain translator_holder_base_ptr erase( translator_holder_base_ptr this_, const_string tag ) { @@ -366,14 +377,14 @@ class BOOST_TEST_DECL execution_monitor { /// @param[in] F Function to monitor /// @returns value returned by function call F(). /// @see vexecute - int execute( boost::function const& F ); + int execute( result_func_t const& F ); /// @brief Execution monitor entry point for functions returning void /// /// This method is semantically identical to execution_monitor::execute, but des't produce any result code. /// @param[in] F Function to monitor /// @see execute - void vexecute( boost::function const& F ); + void vexecute( test_func_t const& F ); // @} // @name Exception translator registration @@ -419,8 +430,7 @@ class BOOST_TEST_DECL execution_monitor { private: // implementation helpers - int catch_signals( boost::function const& F ); - + int catch_signals( result_func_t const& F ); // Data members detail::translator_holder_base_ptr m_custom_translators; boost::scoped_array m_alt_stack; @@ -440,7 +450,7 @@ class translator_holder : public translator_holder_base : translator_holder_base( next, tag ), m_translator( tr ) {} // translator holder interface - virtual int operator()( boost::function const& F ) + virtual int operator()( result_func_t const& F ) { BOOST_TEST_I_TRY { return m_next ? (*m_next)( F ) : F(); diff --git a/include/boost/test/impl/execution_monitor.ipp b/include/boost/test/impl/execution_monitor.ipp index 0c5690ca89..f7780a549f 100644 --- a/include/boost/test/impl/execution_monitor.ipp +++ b/include/boost/test/impl/execution_monitor.ipp @@ -839,7 +839,7 @@ static void boost_execution_monitor_attaching_signal_handler( int sig, siginfo_t // ************************************************************************** // int -execution_monitor::catch_signals( boost::function const& F ) +execution_monitor::catch_signals( result_func_t const& F ) { using namespace detail; @@ -1191,7 +1191,7 @@ execution_monitor::execution_monitor() //____________________________________________________________________________// int -execution_monitor::execute( boost::function const& F ) +execution_monitor::execute( result_func_t const& F ) { if( debug::under_debugger() ) p_catch_system_errors.value = false; @@ -1295,16 +1295,15 @@ execution_monitor::execute( boost::function const& F ) namespace detail { struct forward { - explicit forward( boost::function const& F ) : m_F( F ) {} - + explicit forward( test_func_t const& F ) : m_F( F ) {} int operator()() { m_F(); return 0; } - boost::function const& m_F; + test_func_t const& m_F; }; } // namespace detail void -execution_monitor::vexecute( boost::function const& F ) +execution_monitor::vexecute( test_func_t const& F ) { execute( detail::forward( F ) ); } diff --git a/include/boost/test/impl/test_tree.ipp b/include/boost/test/impl/test_tree.ipp index 08bdad3360..2cfb0f987d 100644 --- a/include/boost/test/impl/test_tree.ipp +++ b/include/boost/test/impl/test_tree.ipp @@ -198,7 +198,7 @@ test_unit::has_label( const_string l ) const // ************** test_case ************** // // ************************************************************************** // -test_case::test_case( const_string name, boost::function const& test_func ) +test_case::test_case( const_string name, test_func_t const& test_func ) : test_unit( name, "", 0, static_cast(type) ) , p_test_func( test_func ) { @@ -207,7 +207,7 @@ test_case::test_case( const_string name, boost::function const& test_fu //____________________________________________________________________________// -test_case::test_case( const_string name, const_string file_name, std::size_t line_num, boost::function const& test_func ) + test_case::test_case( const_string name, const_string file_name, std::size_t line_num, test_func_t const& test_func ) : test_unit( name, file_name, line_num, static_cast(type) ) , p_test_func( test_func ) { diff --git a/include/boost/test/impl/unit_test_monitor.ipp b/include/boost/test/impl/unit_test_monitor.ipp index fdd36f7c3a..d4aa6420df 100644 --- a/include/boost/test/impl/unit_test_monitor.ipp +++ b/include/boost/test/impl/unit_test_monitor.ipp @@ -34,7 +34,7 @@ namespace unit_test { // ************************************************************************** // unit_test_monitor_t::error_level -unit_test_monitor_t::execute_and_translate( boost::function const& func, unsigned timeout ) +unit_test_monitor_t::execute_and_translate( test_func_t const& func, unsigned timeout ) { BOOST_TEST_I_TRY { p_catch_system_errors.value = runtime_config::get( runtime_config::btrt_catch_sys_errors ); diff --git a/include/boost/test/parameterized_test.hpp b/include/boost/test/parameterized_test.hpp index b94e7ec8b3..7496866156 100644 --- a/include/boost/test/parameterized_test.hpp +++ b/include/boost/test/parameterized_test.hpp @@ -20,10 +20,15 @@ #include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include +#else +#include +#endif #include + //____________________________________________________________________________// #define BOOST_PARAM_TEST_CASE( function, begin, end ) \ @@ -53,7 +58,13 @@ namespace ut_detail { template class param_test_case_generator : public test_unit_generator { public: - param_test_case_generator( boost::function const& test_func, +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef boost::function param_func_t; +#else + using param_func_t = std::function; +#endif + + param_test_case_generator( param_func_t const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line, @@ -81,7 +92,7 @@ class param_test_case_generator : public test_unit_generator { private: // Data members - boost::function m_test_func; + param_func_t m_test_func; std::string m_tc_name; const_string m_tc_file; std::size_t m_tc_line; @@ -93,8 +104,11 @@ class param_test_case_generator : public test_unit_generator { template struct user_param_tc_method_invoker { +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) typedef void (UserTestCase::*test_method)( ParamType ); - +#else + using test_method = std::function; +#endif // Constructor user_param_tc_method_invoker( shared_ptr inst, test_method test_method ) : m_inst( inst ), m_test_method( test_method ) {} @@ -112,7 +126,11 @@ struct user_param_tc_method_invoker { template inline ut_detail::param_test_case_generator +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) make_test_case( boost::function const& test_func, +#else +make_test_case( std::function const& test_func, +#endif const_string tc_name, const_string tc_file, std::size_t tc_line, @@ -169,4 +187,3 @@ make_test_case( void (UserTestCase::*test_method )( ParamType ), #include #endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER - diff --git a/include/boost/test/tree/decorator.hpp b/include/boost/test/tree/decorator.hpp index 27c46682a0..28eafa6d94 100644 --- a/include/boost/test/tree/decorator.hpp +++ b/include/boost/test/tree/decorator.hpp @@ -28,8 +28,12 @@ // Boost #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include #include +#else +#include +#endif #include @@ -230,7 +234,7 @@ fixture( Arg const& arg ) //____________________________________________________________________________// inline fixture_t -fixture( boost::function const& setup, boost::function const& teardown = boost::function() ) +fixture( fixture_func_t const& setup, fixture_func_t const& teardown = fixture_func_t() ) { return fixture_t( test_unit_fixture_ptr( new unit_test::function_based_fixture( setup, teardown ) ) ); } @@ -243,8 +247,11 @@ fixture( boost::function const& setup, boost::function const& te class BOOST_TEST_DECL precondition : public decorator::base { public: +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) typedef boost::function predicate_t; - +#else + using predicate_t = std::function; +#endif explicit precondition( predicate_t p ) : m_precondition( p ) {} private: diff --git a/include/boost/test/tree/fixture.hpp b/include/boost/test/tree/fixture.hpp index 7bca5a8de3..ba4f8fe65f 100644 --- a/include/boost/test/tree/fixture.hpp +++ b/include/boost/test/tree/fixture.hpp @@ -21,7 +21,12 @@ // Boost #include #include + +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include +#else +#include +#endif #include @@ -30,6 +35,12 @@ namespace boost { namespace unit_test { +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef boost::function fixture_func_t; +#else + using fixture_func_t = std::function; +#endif + // ************************************************************************** // // ************** test_unit_fixture ************** // // ************************************************************************** // @@ -91,7 +102,7 @@ class class_based_fixture : public test_unit_fixture { class function_based_fixture : public test_unit_fixture { public: // Constructor - function_based_fixture( boost::function const& setup_, boost::function const& teardown_ ) + function_based_fixture( fixture_func_t const& setup_, fixture_func_t const& teardown_ ) : m_setup( setup_ ) , m_teardown( teardown_ ) { @@ -103,8 +114,8 @@ class function_based_fixture : public test_unit_fixture { virtual void teardown() { if( m_teardown ) m_teardown(); } // Data members - boost::function m_setup; - boost::function m_teardown; + fixture_func_t m_setup; + fixture_func_t m_teardown; }; } // namespace unit_test diff --git a/include/boost/test/tree/test_case_template.hpp b/include/boost/test/tree/test_case_template.hpp index 6a1fc3e57b..9d4b29585d 100644 --- a/include/boost/test/tree/test_case_template.hpp +++ b/include/boost/test/tree/test_case_template.hpp @@ -29,7 +29,11 @@ #include #include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include +#else +#include +#endif #if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI) # include diff --git a/include/boost/test/tree/test_unit.hpp b/include/boost/test/tree/test_unit.hpp index 273fa14ff3..35bc6fafdd 100644 --- a/include/boost/test/tree/test_unit.hpp +++ b/include/boost/test/tree/test_unit.hpp @@ -26,9 +26,12 @@ #include // Boost +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) #include #include - +#else +#include +#endif // STL #include #include @@ -51,6 +54,12 @@ class state; typedef std::vector test_unit_id_list; +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef boost::function test_func_t; +#else + using test_func_t = std::function; +#endif + class BOOST_TEST_DECL test_unit { public: enum { type = TUT_ANY }; @@ -64,7 +73,11 @@ class BOOST_TEST_DECL test_unit { typedef std::vector decor_list_t; typedef BOOST_READONLY_PROPERTY(std::vector,(test_unit)) label_list_t; +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) typedef boost::function precondition_t; +#else + using precondition_t = std::function; +#endif typedef BOOST_READONLY_PROPERTY(std::vector,(test_unit)) precond_list_t; // preconditions management @@ -138,11 +151,11 @@ class BOOST_TEST_DECL test_case : public test_unit { enum { type = TUT_CASE }; // Constructor - test_case( const_string tc_name, boost::function const& test_func ); - test_case( const_string tc_name, const_string tc_file, std::size_t tc_line, boost::function const& test_func ); + test_case( const_string tc_name, test_func_t const& test_func ); + test_case( const_string tc_name, const_string tc_file, std::size_t tc_line, test_func_t const& test_func ); // Public property - typedef BOOST_READONLY_PROPERTY(boost::function,(test_case)) test_func; + typedef BOOST_READONLY_PROPERTY(test_func_t,(test_case)) test_func; test_func p_test_func; @@ -244,7 +257,7 @@ struct user_tc_method_invoker { // ************************************************************************** // inline test_case* -make_test_case( boost::function const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line ) +make_test_case( test_func_t const& test_func, const_string tc_name, const_string tc_file, std::size_t tc_line ) { return new test_case( ut_detail::normalize_test_case_name( tc_name ), tc_file, tc_line, test_func ); } diff --git a/include/boost/test/unit_test_monitor.hpp b/include/boost/test/unit_test_monitor.hpp index 1f937fa674..06c7b96aa0 100644 --- a/include/boost/test/unit_test_monitor.hpp +++ b/include/boost/test/unit_test_monitor.hpp @@ -44,7 +44,7 @@ class BOOST_TEST_DECL unit_test_monitor_t : public singleton const& func, unsigned timeout = 0 ); + error_level execute_and_translate( test_func_t const& func, unsigned timeout = 0 ); private: BOOST_TEST_SINGLETON_CONS( unit_test_monitor_t ) diff --git a/include/boost/test/unit_test_suite.hpp b/include/boost/test/unit_test_suite.hpp index b434fa9f97..38c999dd31 100644 --- a/include/boost/test/unit_test_suite.hpp +++ b/include/boost/test/unit_test_suite.hpp @@ -33,7 +33,7 @@ // ************************************************************************** // #define BOOST_TEST_CASE( test_function ) \ -boost::unit_test::make_test_case( boost::function(test_function), \ +boost::unit_test::make_test_case( boost::unit_test::test_func_t(test_function), \ BOOST_TEST_STRINGIZE( test_function ), \ __FILE__, __LINE__ ) #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \ diff --git a/include/boost/test/utils/runtime/argument_factory.hpp b/include/boost/test/utils/runtime/argument_factory.hpp index f3448f8cc4..c09e5725e4 100644 --- a/include/boost/test/utils/runtime/argument_factory.hpp +++ b/include/boost/test/utils/runtime/argument_factory.hpp @@ -24,8 +24,12 @@ #include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) // Boost #include +#else +#include +#endif // STL #include diff --git a/include/boost/test/utils/runtime/cla/parser.hpp b/include/boost/test/utils/runtime/cla/parser.hpp index 9fe8e1bbd9..64761d12d6 100644 --- a/include/boost/test/utils/runtime/cla/parser.hpp +++ b/include/boost/test/utils/runtime/cla/parser.hpp @@ -47,7 +47,11 @@ namespace rt_cla_detail { struct parameter_trie; typedef shared_ptr parameter_trie_ptr; typedef std::map trie_per_char; -typedef std::vector > param_cla_id_list; +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + typedef std::vector > param_cla_id_list; +#else + using param_cla_id_list = std::vector>; +#endif struct parameter_trie { parameter_trie() : m_has_final_candidate( false ) {} @@ -82,8 +86,11 @@ struct parameter_trie { << "parameter cla id " << m_id_candidates.back().get().m_tag ); m_has_final_candidate = final; - m_id_candidates.push_back( ref(param_id) ); - +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + m_id_candidates.push_back( boost::ref(param_id) ); +#else + m_id_candidates.push_back( std::ref(param_id) ); +#endif if( m_id_candidates.size() == 1 ) m_param_candidate = param_candidate; else diff --git a/include/boost/test/utils/runtime/parameter.hpp b/include/boost/test/utils/runtime/parameter.hpp index f11ce9813c..208341b848 100644 --- a/include/boost/test/utils/runtime/parameter.hpp +++ b/include/boost/test/utils/runtime/parameter.hpp @@ -26,9 +26,14 @@ #include // Boost -#include #include +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) +#include +#else +#include +#endif + // STL #include @@ -91,7 +96,12 @@ typedef std::vector param_cla_ids; cstring const help_prefix("////"); class basic_param { + +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) typedef function callback_type; +#else + using callback_type = std::function; +#endif typedef unit_test::readwrite_property bool_property; protected: diff --git a/test/test-organization-ts/test-tree-management-test.cpp b/test/test-organization-ts/test-tree-management-test.cpp index 1a45844c0d..8069d1fdf1 100644 --- a/test/test-organization-ts/test-tree-management-test.cpp +++ b/test/test-organization-ts/test-tree-management-test.cpp @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE( manual_test_case_creation_test ) BOOST_TEST( tc1->p_expected_failures == 0U ); BOOST_TEST( tc1->p_timeout == 0U ); BOOST_TEST( tc1->p_name == const_string( "empty_" ) ); - BOOST_TEST( tc1->p_test_func ); + BOOST_TEST( bool(tc1->p_test_func.get()) ); BOOST_TEST( tc1->p_default_status == test_unit::RS_INHERIT ); BOOST_TEST( tc1->p_run_status == test_unit::RS_INVALID ); BOOST_TEST( !tc1->is_enabled() ); diff --git a/test/test-organization-ts/test_unit-order-shuffled-test.cpp b/test/test-organization-ts/test_unit-order-shuffled-test.cpp index 0588656538..c8f29253c9 100644 --- a/test/test-organization-ts/test_unit-order-shuffled-test.cpp +++ b/test/test-organization-ts/test_unit-order-shuffled-test.cpp @@ -94,7 +94,7 @@ struct test_tree { for(std::size_t s = 0; s < 10; s++) { ut::test_case* tc = boost::unit_test::make_test_case( - boost::function(some_test), + boost::unit_test::test_func_t(some_test), "tc_" + boost::unit_test::utils::string_cast(s), __FILE__, __LINE__ ); tsuites[std::rand() % tsuites.size()]->add(tc); diff --git a/test/test-organization-ts/test_unit-order-test.cpp b/test/test-organization-ts/test_unit-order-test.cpp index a3b639b449..27152c39c4 100644 --- a/test/test-organization-ts/test_unit-order-test.cpp +++ b/test/test-organization-ts/test_unit-order-test.cpp @@ -29,7 +29,7 @@ namespace tt = boost::test_tools; void some_test() {} #define TC( name ) \ -boost::unit_test::make_test_case( boost::function(some_test), \ +boost::unit_test::make_test_case( boost::unit_test::test_func_t(some_test), \ BOOST_TEST_STRINGIZE( name ), \ __FILE__, __LINE__ )