git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@191 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-01-15 11:24:52 +00:00
parent f4ceb3cdfc
commit 6e8ed29462
3 changed files with 25 additions and 17 deletions

View file

@ -30,17 +30,19 @@ namespace detail
BOOST_DEDUCED_TYPENAME boost::remove_const< Result >::type
>::type result_type;
typedef lambda< Result, Signature > lambda;
public:
template< typename Value >
void returns( Value v )
{
r_.reset( new result_type( v ) );
f_ = lambda< Signature >::make_val( boost::ref( *r_ ) );
f_ = lambda::make_val( boost::ref( *r_ ) );
}
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
f_ = lambda< Signature >::make_val( r );
f_ = lambda::make_val( r );
}
void calls( const functor_type& f )
@ -53,7 +55,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = lambda< Signature >::make_throw( e );
f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@ -72,15 +74,17 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
typedef lambda< Result*, Signature > lambda;
public:
void returns( Result* r )
{
f_ = lambda< Signature >::make_val( r );
f_ = lambda::make_val( r );
}
template< typename Y >
void returns( const boost::reference_wrapper< Y >& r )
{
f_ = lambda< Signature >::make_val( r );
f_ = lambda::make_val( r );
}
void calls( const functor_type& f )
@ -93,7 +97,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = lambda< Signature >::make_throw( e );
f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@ -111,9 +115,11 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
typedef lambda< void, Signature > lambda;
public:
action()
: f_( lambda< Signature >::make_nothing() )
: f_( lambda::make_nothing() )
{}
void calls( const functor_type& f )
@ -126,7 +132,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = lambda< Signature >::make_throw( e );
f_ = lambda::make_throw( e );
}
const functor_type& functor() const
@ -144,6 +150,8 @@ namespace detail
typedef BOOST_DEDUCED_TYPENAME
boost::function< Signature > functor_type;
typedef lambda< std::auto_ptr< Result >, Signature > lambda;
public:
action()
: r_()
@ -151,7 +159,7 @@ namespace detail
{}
action( const action& rhs )
: r_( const_cast< action& >( rhs ).r_.release() )
, f_( r_.get() ? lambda< Signature >::make_val( boost::ref( r_ ) ) : rhs.f_ )
, f_( r_.get() ? lambda::make_val( boost::ref( r_ ) ) : rhs.f_ )
{}
template< typename Value >
@ -170,7 +178,7 @@ namespace detail
template< typename Exception >
void throws( Exception e )
{
f_ = lambda< Signature >::make_throw( e );
f_ = lambda::make_throw( e );
r_.reset();
}
@ -184,19 +192,19 @@ namespace detail
void set( std::auto_ptr< Y > r )
{
r_ = r;
f_ = lambda< Signature >::make_val( boost::ref( r_ ) );
f_ = lambda::make_val( boost::ref( r_ ) );
}
template< typename Y >
void set( const boost::reference_wrapper< Y >& r )
{
f_ = lambda< Signature >::make_val( r );
f_ = lambda::make_val( r );
r_.reset();
}
template< typename Y >
void set( Y* r )
{
r_.reset( r );
f_ = lambda< Signature >::make_val( boost::ref( r_ ) );
f_ = lambda::make_val( boost::ref( r_ ) );
}
mutable std::auto_ptr< Result > r_;

View file

@ -25,7 +25,7 @@ namespace detail
{
#ifdef MOCK_USE_BOOST_BIND
template< typename Signature >
template< typename Result, typename Signature >
struct lambda
{
typedef BOOST_DEDUCED_TYPENAME
@ -62,7 +62,7 @@ namespace detail
return *t;
}
template< typename T >
static void do_throw( T t )
static Result do_throw( T t )
{
throw t;
}
@ -73,7 +73,7 @@ namespace detail
#else
template< typename Signature >
template< typename Result, typename Signature >
struct lambda
{
typedef BOOST_DEDUCED_TYPENAME

View file

@ -557,7 +557,7 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_calls_the_custom_functor_with
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_throws_the_set_exception, error_fixture )
{
mock::function< void() > f;
mock::function< int() > f;
f.expect().throws( std::runtime_error( "some exception" ) );
try
{