diff --git a/src/libraries/turtle/action.hpp b/src/libraries/turtle/action.hpp index 988b280..5e1b61d 100644 --- a/src/libraries/turtle/action.hpp +++ b/src/libraries/turtle/action.hpp @@ -11,9 +11,8 @@ #include "config.hpp" #include -#include +#include #include -#include #include #include @@ -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( ¬hing ), 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_; }; diff --git a/src/tests/turtle_test/function_test.cpp b/src/tests/turtle_test/function_test.cpp index ea54a9c..fa5d263 100644 --- a/src/tests/turtle_test/function_test.cpp +++ b/src/tests/turtle_test/function_test.cpp @@ -15,6 +15,7 @@ #define MOCK_ERROR_POLICY mock_error #include +#include #define CHECK_CALLS( calls ) \ BOOST_CHECK_EQUAL( calls, expected_call_count ); \ diff --git a/src/tests/turtle_test/max_args_test.cpp b/src/tests/turtle_test/max_args_test.cpp index c101395..5db0914 100644 --- a/src/tests/turtle_test/max_args_test.cpp +++ b/src/tests/turtle_test/max_args_test.cpp @@ -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) ) ); } diff --git a/src/tests/turtle_test/mock_test.cpp b/src/tests/turtle_test/mock_test.cpp index a6bf1f9..9163b84 100644 --- a/src/tests/turtle_test/mock_test.cpp +++ b/src/tests/turtle_test/mock_test.cpp @@ -9,6 +9,7 @@ #define MOCK_USE_BOOST_TEST #include #include +#include #include #define BOOST_LIB_NAME boost_unit_test_framework