git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@170 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2010-07-28 12:34:16 +00:00
parent d63d5d2c1f
commit f3173c7770
4 changed files with 26 additions and 22 deletions

View file

@ -11,9 +11,8 @@
#include "config.hpp"
#include <boost/spirit/home/phoenix/bind/bind_function.hpp>
#include <boost/spirit/home/phoenix/statement/sequence.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <memory>
@ -26,12 +25,22 @@ namespace detail
{
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
typedef BOOST_DEDUCED_TYPENAME
boost::remove_reference<
BOOST_DEDUCED_TYPENAME boost::remove_const< Result >::type
>::type result_type;
public:
template< typename Value >
void returns( Value v )
{
set( v );
r_.reset( new result_type( v ) );
f_ = boost::phoenix::val( boost::ref( *r_ ) );
}
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
f_ = boost::phoenix::val( r );
}
void calls( const functor_type& f )
@ -53,22 +62,6 @@ namespace detail
}
private:
void set( Result r )
{
f_ = (boost::phoenix::bind( &nothing ), boost::bind( &identity, r ));
}
template< typename Y >
void set( const boost::reference_wrapper< Y >& r )
{
f_ = boost::phoenix::val( r );
}
static void nothing()
{}
static Result identity( Result r )
{
return r;
}
template< typename Exception >
static Result throw_exception( const Exception& e )
@ -76,6 +69,7 @@ namespace detail
throw e;
}
boost::shared_ptr< result_type > r_;
functor_type f_;
};

View file

@ -15,6 +15,7 @@
#define MOCK_ERROR_POLICY mock_error
#include <turtle/mock.hpp>
#include <boost/bind.hpp>
#define CHECK_CALLS( calls ) \
BOOST_CHECK_EQUAL( calls, expected_call_count ); \

View file

@ -24,13 +24,21 @@ namespace
{
struct my_custom_mock
{
MOCK_METHOD_EXT( my_method_with_max_number_of_args, MOCK_MAX_ARGS, void( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, int) ), my_method_with_max_number_of_args )
MOCK_METHOD_EXT( method, MOCK_MAX_ARGS, void( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, int) ), method )
MOCK_METHOD_EXT( method2, MOCK_MAX_ARGS, int( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, int) ), method2 )
};
}
BOOST_AUTO_TEST_CASE( call_mock_method_with_max_number_of_args )
{
my_custom_mock m;
MOCK_EXPECT( m, my_method_with_max_number_of_args ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) );
m.my_method_with_max_number_of_args( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) );
MOCK_EXPECT( m, method ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) );
m.method( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) );
}
BOOST_AUTO_TEST_CASE( call_mock_method_with_max_number_of_args_and_returning_something )
{
my_custom_mock m;
MOCK_EXPECT( m, method2 ).once().with( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) ).returns( 42 );
BOOST_CHECK_EQUAL( 42, m.method2( BOOST_PP_ENUM(MOCK_MAX_ARGS, TEXT, 0) ) );
}

View file

@ -9,6 +9,7 @@
#define MOCK_USE_BOOST_TEST
#include <turtle/mock.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/bind.hpp>
#include <boost/test/auto_unit_test.hpp>
#define BOOST_LIB_NAME boost_unit_test_framework