From bd2fc97bb9eab22a1fec8e22fe7ec10fe87f8656 Mon Sep 17 00:00:00 2001 From: mat007 Date: Tue, 21 May 2013 11:10:34 +0000 Subject: [PATCH] Refactoring git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@666 860be788-9bd5-4423-9f1e-828f051e677b --- test/detail/test_function.cpp | 6 ++++++ turtle/detail/action.hpp | 14 ++++++++------ turtle/detail/lambda.hpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/detail/test_function.cpp b/test/detail/test_function.cpp index bd30f5a..fa5b000 100644 --- a/test/detail/test_function.cpp +++ b/test/detail/test_function.cpp @@ -466,6 +466,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, error_ BOOST_CHECK_EQUAL( 0, f() ); CHECK_CALLS( 1 ); } + { + mock::detail::function< unsigned int() > f; + f.expect().returns( 0 ); + BOOST_CHECK_EQUAL( 0u, f() ); + CHECK_CALLS( 1 ); + } } namespace diff --git a/turtle/detail/action.hpp b/turtle/detail/action.hpp index f3447d4..97cb59d 100644 --- a/turtle/detail/action.hpp +++ b/turtle/detail/action.hpp @@ -13,9 +13,9 @@ #include "lambda.hpp" #include #include -#include #include #include +#include namespace mock { @@ -37,14 +37,16 @@ namespace detail template< typename Value > void returns( Value v ) { - r_ = boost::make_shared< Value >( v ); - f_ = lambda_type::make_val( boost::ref( *r_ ) ); + r_ = v; + f_ = lambda_type::make_val( + boost::ref( boost::any_cast< Value& >( r_ ) ) ); } template< typename Value > void returns( Value* v ) { - r_ = boost::make_shared< result_type >( v ); - f_ = lambda_type::make_val( boost::ref( *r_ ) ); + r_ = result_type( v ); + f_ = lambda_type::make_val( + boost::ref( boost::any_cast< result_type& >( r_ ) ) ); } template< typename Y > void returns( const boost::reference_wrapper< Y >& r ) @@ -71,7 +73,7 @@ namespace detail } private: - boost::shared_ptr< result_type > r_; + boost::any r_; functor_type f_; }; diff --git a/turtle/detail/lambda.hpp b/turtle/detail/lambda.hpp index 699088b..0e1ccde 100644 --- a/turtle/detail/lambda.hpp +++ b/turtle/detail/lambda.hpp @@ -39,7 +39,7 @@ namespace detail return detail::bind( &do_identity< T >, t ); } template< typename T > - static functor_type make_val( boost::reference_wrapper< T > t ) + static functor_type make_val( const boost::reference_wrapper< T >& t ) { return detail::bind( &do_ref_identity< T >, t.get_pointer() );