diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index 3ce24f0..a911a38 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -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 diff --git a/turtle/detail/action.hpp b/turtle/detail/action.hpp index 38a1982..9b4ce12 100644 --- a/turtle/detail/action.hpp +++ b/turtle/detail/action.hpp @@ -12,6 +12,7 @@ #include "lambda.hpp" #include #include +#include #include #include #include @@ -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 >