mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Return actions now accept by copy types derived from abstract base types
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@612 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
1ddf17d1c1
commit
02e2b4bbfd
2 changed files with 40 additions and 4 deletions
|
|
@ -431,8 +431,15 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, error_
|
|||
|
||||
namespace
|
||||
{
|
||||
struct A {};
|
||||
struct B : A {};
|
||||
struct A
|
||||
{
|
||||
virtual void f() = 0;
|
||||
};
|
||||
struct B : A
|
||||
{
|
||||
virtual void f()
|
||||
{}
|
||||
};
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_value, error_fixture )
|
||||
|
|
@ -488,6 +495,24 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_auto_ptr_valu
|
|||
BOOST_CHECK_NO_THROW( f() );
|
||||
CHECK_CALLS( 1 );
|
||||
}
|
||||
{
|
||||
mock::detail::function< A&() > f;
|
||||
B b;
|
||||
f.expect().returns( boost::ref( b ) );
|
||||
BOOST_CHECK_NO_THROW( f() );
|
||||
CHECK_CALLS( 1 );
|
||||
}
|
||||
{
|
||||
mock::detail::function< A&() > f;
|
||||
B b;
|
||||
f.expect().returns( b );
|
||||
BOOST_CHECK_NO_THROW( f() );
|
||||
CHECK_CALLS( 1 );
|
||||
}
|
||||
//{
|
||||
// mock::detail::function< A&() > f;
|
||||
// f.expect().returns( 3 );
|
||||
//}
|
||||
}
|
||||
|
||||
namespace
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "lambda.hpp"
|
||||
#include <boost/type_traits/remove_reference.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
|
|
@ -34,12 +35,22 @@ namespace detail
|
|||
|
||||
public:
|
||||
template< typename Value >
|
||||
void returns( Value v )
|
||||
void returns( Value v,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
boost::is_convertible< Value, result_type > >::type* = 0 )
|
||||
{
|
||||
r_.reset( new result_type( v ) );
|
||||
f_ = lambda_type::make_val( boost::ref( *r_ ) );
|
||||
}
|
||||
template< typename Value >
|
||||
void returns( Value v,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
boost::is_convertible< Value, result_type > >::type* = 0 )
|
||||
{
|
||||
// if an error is generated by the line below it means a value
|
||||
// passed to 'returns' was of the wrong type as it cannot be
|
||||
// used to copy construct a Result
|
||||
r_.reset( new result_type( v ) );
|
||||
r_.reset( new Value( v ) );
|
||||
f_ = lambda_type::make_val( boost::ref( *r_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue