mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@666 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
c697b48802
commit
bd2fc97bb9
3 changed files with 15 additions and 7 deletions
|
|
@ -466,6 +466,12 @@ BOOST_FIXTURE_TEST_CASE( triggering_an_expectation_returns_the_set_value, error_
|
||||||
BOOST_CHECK_EQUAL( 0, f() );
|
BOOST_CHECK_EQUAL( 0, f() );
|
||||||
CHECK_CALLS( 1 );
|
CHECK_CALLS( 1 );
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
mock::detail::function< unsigned int() > f;
|
||||||
|
f.expect().returns( 0 );
|
||||||
|
BOOST_CHECK_EQUAL( 0u, f() );
|
||||||
|
CHECK_CALLS( 1 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,9 @@
|
||||||
#include "lambda.hpp"
|
#include "lambda.hpp"
|
||||||
#include <boost/type_traits/remove_reference.hpp>
|
#include <boost/type_traits/remove_reference.hpp>
|
||||||
#include <boost/type_traits/remove_const.hpp>
|
#include <boost/type_traits/remove_const.hpp>
|
||||||
#include <boost/make_shared.hpp>
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/ref.hpp>
|
#include <boost/ref.hpp>
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
|
||||||
namespace mock
|
namespace mock
|
||||||
{
|
{
|
||||||
|
|
@ -37,14 +37,16 @@ namespace detail
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
void returns( Value v )
|
void returns( Value v )
|
||||||
{
|
{
|
||||||
r_ = boost::make_shared< Value >( v );
|
r_ = v;
|
||||||
f_ = lambda_type::make_val( boost::ref( *r_ ) );
|
f_ = lambda_type::make_val(
|
||||||
|
boost::ref( boost::any_cast< Value& >( r_ ) ) );
|
||||||
}
|
}
|
||||||
template< typename Value >
|
template< typename Value >
|
||||||
void returns( Value* v )
|
void returns( Value* v )
|
||||||
{
|
{
|
||||||
r_ = boost::make_shared< result_type >( v );
|
r_ = result_type( v );
|
||||||
f_ = lambda_type::make_val( boost::ref( *r_ ) );
|
f_ = lambda_type::make_val(
|
||||||
|
boost::ref( boost::any_cast< result_type& >( r_ ) ) );
|
||||||
}
|
}
|
||||||
template< typename Y >
|
template< typename Y >
|
||||||
void returns( const boost::reference_wrapper< Y >& r )
|
void returns( const boost::reference_wrapper< Y >& r )
|
||||||
|
|
@ -71,7 +73,7 @@ namespace detail
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::shared_ptr< result_type > r_;
|
boost::any r_;
|
||||||
functor_type f_;
|
functor_type f_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ namespace detail
|
||||||
return detail::bind( &do_identity< T >, t );
|
return detail::bind( &do_identity< T >, t );
|
||||||
}
|
}
|
||||||
template< typename 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(
|
return detail::bind(
|
||||||
&do_ref_identity< T >, t.get_pointer() );
|
&do_ref_identity< T >, t.get_pointer() );
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue