mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Assume existance of <functional>
This commit is contained in:
parent
f154a1a22a
commit
9faab7749c
6 changed files with 16 additions and 20 deletions
|
|
@ -7,14 +7,14 @@
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
// http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
|
||||||
//[ invoke_functor_problem
|
//[ invoke_functor_problem
|
||||||
#include <boost/function.hpp>
|
#include <functional>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class base_class
|
class base_class
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void method( const boost::function< void( int ) >& functor ) = 0;
|
virtual void method( const std::function< void( int ) >& functor ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void function( base_class& ); // the function will call 'method' with a functor to be applied
|
void function( base_class& ); // the function will call 'method' with a functor to be applied
|
||||||
|
|
|
||||||
|
|
@ -40,12 +40,6 @@
|
||||||
# error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher
|
# error BOOST_FT_MAX_ARITY must be set to MOCK_MAX_ARGS + 1 or higher
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
|
||||||
# ifndef MOCK_NO_HDR_FUNCTIONAL
|
|
||||||
# define MOCK_HDR_FUNCTIONAL
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX)
|
#if !defined(BOOST_NO_CXX11_HDR_MUTEX) && !defined(BOOST_NO_0X_HDR_MUTEX)
|
||||||
# ifndef MOCK_NO_HDR_MUTEX
|
# ifndef MOCK_NO_HDR_MUTEX
|
||||||
# define MOCK_HDR_MUTEX
|
# define MOCK_HDR_MUTEX
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,9 @@
|
||||||
#include "../config.hpp"
|
#include "../config.hpp"
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
|
|
@ -25,13 +25,8 @@ namespace detail
|
||||||
class action_base
|
class action_base
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
#ifdef MOCK_HDR_FUNCTIONAL
|
|
||||||
typedef std::function< Signature > functor_type;
|
typedef std::function< Signature > functor_type;
|
||||||
typedef std::function< Result() > action_type;
|
typedef std::function< Result() > action_type;
|
||||||
#else
|
|
||||||
typedef boost::function< Signature > functor_type;
|
|
||||||
typedef boost::function< Result() > action_type;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
const functor_type& functor() const
|
const functor_type& functor() const
|
||||||
|
|
|
||||||
|
|
@ -13,15 +13,15 @@
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <boost/utility/result_of.hpp>
|
#include <boost/utility/result_of.hpp>
|
||||||
#include <boost/scoped_ptr.hpp>
|
#include <boost/scoped_ptr.hpp>
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <functional>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
boost::function< void() > static_f;
|
std::function< void() > static_f;
|
||||||
|
|
||||||
static_assert( std::is_same< void, boost::result_of< mock::detail::function< void() >() >::type >::value, "!");
|
static_assert( std::is_same< void, boost::result_of< mock::detail::function< void() >() >::type >::value, "!");
|
||||||
static_assert( std::is_same< int, boost::result_of< mock::detail::function< int() >() >::type >::value, "!");
|
static_assert( std::is_same< int, boost::result_of< mock::detail::function< int() >() >::type >::value, "!");
|
||||||
|
|
@ -34,13 +34,13 @@ namespace
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
boost::function< void() > functor = f;
|
std::function< void() > functor = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( a_function_can_be_passed_as_functor_using_boost_bind_and_boost_ref, mock_error_fixture )
|
||||||
{
|
{
|
||||||
mock::detail::function< void() > f;
|
mock::detail::function< void() > f;
|
||||||
boost::function< void() > functor = boost::bind( boost::ref( f ) );
|
std::function< void() > functor = boost::bind( boost::ref( f ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// invocations
|
// invocations
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
#endif
|
#endif
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
@ -93,6 +94,11 @@ BOOST_AUTO_TEST_CASE( boost_function_is_functor )
|
||||||
is_functor( boost::function< void(int) >() );
|
is_functor( boost::function< void(int) >() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( std_function_is_functor )
|
||||||
|
{
|
||||||
|
is_functor( std::function< void(int) >() );
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MOCK_LAMBDAS
|
#ifdef MOCK_LAMBDAS
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
|
BOOST_AUTO_TEST_CASE( cxx11_lambda_is_functor )
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
@ -153,7 +154,7 @@ namespace
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( mock_functor_in_namespace_is_supported, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_in_namespace_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
boost::function< int( float, const std::string& ) > func;
|
std::function< int( float, const std::string& ) > func;
|
||||||
MOCK_EXPECT( gf ).once().with( 3, "op" ).returns( 42 );
|
MOCK_EXPECT( gf ).once().with( 3, "op" ).returns( 42 );
|
||||||
func = gf;
|
func = gf;
|
||||||
BOOST_CHECK_EQUAL( 42, func( 3, "op" ) );
|
BOOST_CHECK_EQUAL( 42, func( 3, "op" ) );
|
||||||
|
|
@ -162,7 +163,7 @@ BOOST_FIXTURE_TEST_CASE( mock_functor_in_namespace_is_supported, mock_error_fixt
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_CASE( mock_functor_in_function_is_supported, mock_error_fixture )
|
BOOST_FIXTURE_TEST_CASE( mock_functor_in_function_is_supported, mock_error_fixture )
|
||||||
{
|
{
|
||||||
boost::function< int( float, const std::string& ) > func;
|
std::function< int( float, const std::string& ) > func;
|
||||||
{
|
{
|
||||||
MOCK_FUNCTOR( f, int( float, const std::string& ) );
|
MOCK_FUNCTOR( f, int( float, const std::string& ) );
|
||||||
MOCK_EXPECT( f ).once().with( 3, "op" ).returns( 42 );
|
MOCK_EXPECT( f ).once().with( 3, "op" ).returns( 42 );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue