Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: use std::function if c++11 <functional> is available #115

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/examples/example08.run-fail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void (double)> test_method = bind( &test_class::test_method, &tester, _1);
#else
std::function<void (double)> test_method = bind( &test_class::test_method, &tester, _1);
#endif

framework::master_test_suite().
add( BOOST_PARAM_TEST_CASE( test_method, params, params+5 ) );
Expand Down
11 changes: 9 additions & 2 deletions include/boost/test/debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
#include <boost/test/detail/config.hpp>
#include <boost/test/utils/basic_cstring/basic_cstring.hpp>

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
// Boost
#include <boost/function/function1.hpp>
#else
#include <functional>
#endif

// STL
#include <string>
Expand Down Expand Up @@ -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<void (dbg_startup_info const&)> dbg_starter;

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
typedef boost::function<void (dbg_startup_info const&)> dbg_starter;
#else
using dbg_starter = std::function<void (dbg_startup_info const&)>;
#endif
// ************************************************************************** //
/// Specifies which debugger to use when attaching and optionally what routine to use to start that debugger

Expand Down
24 changes: 17 additions & 7 deletions include/boost/test/execution_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include <boost/scoped_array.hpp>
#include <boost/type.hpp>
#include <boost/cstdlib.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function/function0.hpp>
#else
#include <functional>
#endif

#include <boost/test/detail/suppress_warnings.hpp>

Expand Down Expand Up @@ -97,6 +101,14 @@

namespace boost {

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
typedef boost::function<void ()> test_func_t;
typedef boost::function<int ()> result_func_t;
#else
using test_func_t = std::function<void ()>;
using result_func_t = std::function<int ()>;
#endif

/// @defgroup ExecutionMonitor Function Execution Monitor
/// @{
/// @section Intro Introduction
Expand Down Expand Up @@ -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<int ()> 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 )
{
Expand Down Expand Up @@ -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<int ()> 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<void ()> const& F );
void vexecute( test_func_t const& F );
// @}

// @name Exception translator registration
Expand Down Expand Up @@ -419,8 +430,7 @@ class BOOST_TEST_DECL execution_monitor {

private:
// implementation helpers
int catch_signals( boost::function<int ()> const& F );

int catch_signals( result_func_t const& F );
// Data members
detail::translator_holder_base_ptr m_custom_translators;
boost::scoped_array<char> m_alt_stack;
Expand All @@ -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<int ()> const& F )
virtual int operator()( result_func_t const& F )
{
BOOST_TEST_I_TRY {
return m_next ? (*m_next)( F ) : F();
Expand Down
11 changes: 5 additions & 6 deletions include/boost/test/impl/execution_monitor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ static void boost_execution_monitor_attaching_signal_handler( int sig, siginfo_t
// ************************************************************************** //

int
execution_monitor::catch_signals( boost::function<int ()> const& F )
execution_monitor::catch_signals( result_func_t const& F )
{
using namespace detail;

Expand Down Expand Up @@ -1191,7 +1191,7 @@ execution_monitor::execution_monitor()
//____________________________________________________________________________//

int
execution_monitor::execute( boost::function<int ()> const& F )
execution_monitor::execute( result_func_t const& F )
{
if( debug::under_debugger() )
p_catch_system_errors.value = false;
Expand Down Expand Up @@ -1295,16 +1295,15 @@ execution_monitor::execute( boost::function<int ()> const& F )
namespace detail {

struct forward {
explicit forward( boost::function<void ()> const& F ) : m_F( F ) {}

explicit forward( test_func_t const& F ) : m_F( F ) {}
int operator()() { m_F(); return 0; }

boost::function<void ()> const& m_F;
test_func_t const& m_F;
};

} // namespace detail
void
execution_monitor::vexecute( boost::function<void ()> const& F )
execution_monitor::vexecute( test_func_t const& F )
{
execute( detail::forward( F ) );
}
Expand Down
4 changes: 2 additions & 2 deletions include/boost/test/impl/test_tree.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ test_unit::has_label( const_string l ) const
// ************** test_case ************** //
// ************************************************************************** //

test_case::test_case( const_string name, boost::function<void ()> const& test_func )
test_case::test_case( const_string name, test_func_t const& test_func )
: test_unit( name, "", 0, static_cast<test_unit_type>(type) )
, p_test_func( test_func )
{
Expand All @@ -207,7 +207,7 @@ test_case::test_case( const_string name, boost::function<void ()> const& test_fu

//____________________________________________________________________________//

test_case::test_case( const_string name, const_string file_name, std::size_t line_num, boost::function<void ()> 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<test_unit_type>(type) )
, p_test_func( test_func )
{
Expand Down
2 changes: 1 addition & 1 deletion include/boost/test/impl/unit_test_monitor.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace unit_test {
// ************************************************************************** //

unit_test_monitor_t::error_level
unit_test_monitor_t::execute_and_translate( boost::function<void ()> 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<bool>( runtime_config::btrt_catch_sys_errors );
Expand Down
25 changes: 21 additions & 4 deletions include/boost/test/parameterized_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
#include <boost/type_traits/remove_const.hpp>

#include <boost/bind.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function/function1.hpp>
#else
#include <functional>
#endif

#include <boost/test/detail/suppress_warnings.hpp>


//____________________________________________________________________________//

#define BOOST_PARAM_TEST_CASE( function, begin, end ) \
Expand Down Expand Up @@ -53,7 +58,13 @@ namespace ut_detail {
template<typename ParamType, typename ParamIter>
class param_test_case_generator : public test_unit_generator {
public:
param_test_case_generator( boost::function<void (ParamType)> const& test_func,
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
typedef boost::function<void (ParamType)> param_func_t;
#else
using param_func_t = std::function<void (ParamType)>;
#endif

param_test_case_generator( param_func_t const& test_func,
const_string tc_name,
const_string tc_file,
std::size_t tc_line,
Expand Down Expand Up @@ -81,7 +92,7 @@ class param_test_case_generator : public test_unit_generator {

private:
// Data members
boost::function<void (ParamType)> 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;
Expand All @@ -93,8 +104,11 @@ class param_test_case_generator : public test_unit_generator {

template<typename UserTestCase,typename ParamType>
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<void (ParamType)>;
#endif
// Constructor
user_param_tc_method_invoker( shared_ptr<UserTestCase> inst, test_method test_method )
: m_inst( inst ), m_test_method( test_method ) {}
Expand All @@ -112,7 +126,11 @@ struct user_param_tc_method_invoker {

template<typename ParamType, typename ParamIter>
inline ut_detail::param_test_case_generator<ParamType,ParamIter>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
make_test_case( boost::function<void (ParamType)> const& test_func,
#else
make_test_case( std::function<void (ParamType)> const& test_func,
#endif
const_string tc_name,
const_string tc_file,
std::size_t tc_line,
Expand Down Expand Up @@ -169,4 +187,3 @@ make_test_case( void (UserTestCase::*test_method )( ParamType ),
#include <boost/test/detail/enable_warnings.hpp>

#endif // BOOST_TEST_PARAMETERIZED_TEST_HPP_021102GER

11 changes: 9 additions & 2 deletions include/boost/test/tree/decorator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@

// Boost
#include <boost/shared_ptr.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function/function0.hpp>
#include <boost/function/function1.hpp>
#else
#include <functional>
#endif

#include <boost/test/detail/suppress_warnings.hpp>

Expand Down Expand Up @@ -230,7 +234,7 @@ fixture( Arg const& arg )
//____________________________________________________________________________//

inline fixture_t
fixture( boost::function<void()> const& setup, boost::function<void()> const& teardown = boost::function<void()>() )
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 ) ) );
}
Expand All @@ -243,8 +247,11 @@ fixture( boost::function<void()> const& setup, boost::function<void()> const& te

class BOOST_TEST_DECL precondition : public decorator::base {
public:
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
typedef boost::function<test_tools::assertion_result (test_unit_id)> predicate_t;

#else
using predicate_t = std::function<test_tools::assertion_result (test_unit_id)>;
#endif
explicit precondition( predicate_t p ) : m_precondition( p ) {}

private:
Expand Down
17 changes: 14 additions & 3 deletions include/boost/test/tree/fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
// Boost
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function/function0.hpp>
#else
#include <functional>
#endif

#include <boost/test/detail/suppress_warnings.hpp>

Expand All @@ -30,6 +35,12 @@
namespace boost {
namespace unit_test {

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
typedef boost::function<void ()> fixture_func_t;
#else
using fixture_func_t = std::function<void ()>;
#endif

// ************************************************************************** //
// ************** test_unit_fixture ************** //
// ************************************************************************** //
Expand Down Expand Up @@ -91,7 +102,7 @@ class class_based_fixture<F,void> : public test_unit_fixture {
class function_based_fixture : public test_unit_fixture {
public:
// Constructor
function_based_fixture( boost::function<void ()> const& setup_, boost::function<void ()> const& teardown_ )
function_based_fixture( fixture_func_t const& setup_, fixture_func_t const& teardown_ )
: m_setup( setup_ )
, m_teardown( teardown_ )
{
Expand All @@ -103,8 +114,8 @@ class function_based_fixture : public test_unit_fixture {
virtual void teardown() { if( m_teardown ) m_teardown(); }

// Data members
boost::function<void ()> m_setup;
boost::function<void ()> m_teardown;
fixture_func_t m_setup;
fixture_func_t m_teardown;
};

} // namespace unit_test
Expand Down
4 changes: 4 additions & 0 deletions include/boost/test/tree/test_case_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@
#include <boost/mpl/identity.hpp>
#include <boost/type.hpp>
#include <boost/type_traits/is_const.hpp>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function/function0.hpp>
#else
#include <functional>
#endif

#if defined(BOOST_NO_TYPEID) || defined(BOOST_NO_RTTI)
# include <boost/current_function.hpp>
Expand Down
Loading