More work on mock functors

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@55 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2009-09-27 19:52:36 +00:00
parent ed5ae2b859
commit 8e1499ee61
3 changed files with 20 additions and 7 deletions

View file

@ -54,9 +54,9 @@ namespace mock
: impl_( new expectation_impl( root, name ) ) : impl_( new expectation_impl( root, name ) )
{} {}
void set_name( const std::string& name ) void tag( const std::string& name )
{ {
impl_->set_name( name ); impl_->tag( name );
} }
void set_parent( node& parent ) void set_parent( node& parent )
{ {
@ -122,7 +122,7 @@ namespace mock
context(), it->file(), it->line() ); context(), it->file(), it->line() );
} }
void set_name( const std::string& name ) void tag( const std::string& name )
{ {
name_ = name; name_ = name;
} }

View file

@ -99,7 +99,7 @@ namespace detail
template< typename E > template< typename E >
void tag( E& e, const object& o, const std::string& type_name, const std::string& name ) void tag( E& e, const object& o, const std::string& type_name, const std::string& name )
{ {
e.set_name( type_name + o.tag() + "::" + name ); e.tag( type_name + o.tag() + "::" + name );
} }
template< typename E, typename T > template< typename E, typename T >
void tag( E& e, const T&, const std::string& type_name, const std::string& name, void tag( E& e, const T&, const std::string& type_name, const std::string& name,
@ -107,13 +107,13 @@ namespace detail
BOOST_DEDUCED_TYPENAME boost::is_base_of< object, T >::type BOOST_DEDUCED_TYPENAME boost::is_base_of< object, T >::type
>::type* = 0 ) >::type* = 0 )
{ {
e.set_name( type_name + "::" + name ); e.tag( type_name + "::" + name );
} }
template< typename E > template< typename E >
E& configure( typename E::expectation_tag, const std::string& name, E& e ) E& configure( typename E::expectation_tag, const std::string& name, E& e )
{ {
e.set_name( name ); e.tag( name );
return e; return e;
} }
template< typename E, typename T > template< typename E, typename T >
@ -129,6 +129,12 @@ namespace detail
{ {
typedef T base_type; typedef T base_type;
}; };
inline std::string name( const std::string& object,
const std::string& tag )
{
return tag == "_" ? object : tag;
}
} }
} }
@ -141,7 +147,8 @@ namespace detail
#define MOCK_MOCKER(o, t) \ #define MOCK_MOCKER(o, t) \
mock::detail::configure( mock::detail::ref( o ).exp##t, \ mock::detail::configure( mock::detail::ref( o ).exp##t, \
BOOST_PP_STRINGIZE(t), mock::detail::ref( o ) ) mock::detail::name( BOOST_PP_STRINGIZE(o), BOOST_PP_STRINGIZE(t) ), \
mock::detail::ref( o ) )
#define MOCK_METHOD_ARG(z, n, arg) BOOST_PP_COMMA_IF(n) \ #define MOCK_METHOD_ARG(z, n, arg) BOOST_PP_COMMA_IF(n) \
BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)),_type) \ BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)),_type) \

View file

@ -193,3 +193,9 @@ BOOST_AUTO_TEST_CASE( custom_mock_object_without_macros_is_named )
my_custom_mock_object m; my_custom_mock_object m;
BOOST_CHECK_EQUAL( "my_custom_mock_object::my_method", to_string( MOCK_MOCKER( m, my_method ) ) ); BOOST_CHECK_EQUAL( "my_custom_mock_object::my_method", to_string( MOCK_MOCKER( m, my_method ) ) );
} }
BOOST_AUTO_TEST_CASE( mock_functor_is_named )
{
MOCK_FUNCTOR( void() ) f;
BOOST_CHECK_EQUAL( "f", to_string( MOCK_MOCKER( f, _ ) ) );
}