Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@666 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-05-21 11:10:34 +00:00
parent c697b48802
commit bd2fc97bb9
3 changed files with 15 additions and 7 deletions

View file

@ -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

View file

@ -13,9 +13,9 @@
#include "lambda.hpp"
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/make_shared.hpp>
#include <boost/function.hpp>
#include <boost/ref.hpp>
#include <boost/any.hpp>
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_;
};

View file

@ -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() );