Refactoring

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@57 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2009-09-27 21:19:52 +00:00
parent 30480d031a
commit a1ea17ff9f
5 changed files with 79 additions and 60 deletions

View file

@ -50,14 +50,18 @@ namespace mock
{};
expectation_tag exp_;
expectation( const std::string& name = "?" )
: impl_( new expectation_impl( root, name ) )
expectation()
: impl_( new expectation_impl() )
{}
void tag( const std::string& name )
{
impl_->tag( name );
}
const std::string& tag() const
{
return impl_->tag();
}
void set_parent( node& parent )
{
impl_->set_parent( parent );
@ -104,9 +108,9 @@ namespace mock
class expectation_impl : private verifiable
{
public:
expectation_impl( node& parent, const std::string& name )
: name_( name )
, parent_( &parent )
expectation_impl()
: name_( "?" )
, parent_( &root )
, valid_( true )
{
parent_->add( *this );
@ -126,6 +130,10 @@ namespace mock
{
name_ = name;
}
const std::string& tag() const
{
return name_;
}
void set_parent( node& parent )
{
parent_->remove( *this );

View file

@ -97,12 +97,14 @@ namespace detail
>::type* = 0 )
{}
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.tag( type_name + o.tag() + "::" + name );
}
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,
BOOST_DEDUCED_TYPENAME boost::disable_if<
BOOST_DEDUCED_TYPENAME boost::is_base_of< object, T >::type
>::type* = 0 )
@ -111,13 +113,15 @@ namespace detail
}
template< typename E >
E& configure( typename E::expectation_tag, const std::string& name, E& e )
E& configure( typename E::expectation_tag, const std::string& object,
const std::string& name, E& e )
{
e.tag( name );
e.tag( name == "_" ? object : name );
return e;
}
template< typename E, typename T >
E& configure( E& e, const std::string& name, const T& t )
E& configure( E& e, const std::string& /*object*/,
const std::string& name, const T& t )
{
set_parent( e, t );
tag( e, t, type_name< T >(), name );
@ -129,12 +133,6 @@ namespace detail
{
typedef T base_type;
};
inline std::string name( const std::string& object,
const std::string& tag )
{
return tag == "_" ? object : tag;
}
}
}
@ -147,8 +145,7 @@ namespace detail
#define MOCK_MOCKER(o, t) \
mock::detail::configure( mock::detail::ref( o ).exp##t, \
mock::detail::name( BOOST_PP_STRINGIZE(o), BOOST_PP_STRINGIZE(t) ), \
mock::detail::ref( o ) )
BOOST_PP_STRINGIZE(o), BOOST_PP_STRINGIZE(t), mock::detail::ref( o ) )
#define MOCK_METHOD_ARG(z, n, arg) BOOST_PP_COMMA_IF(n) \
BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)),_type) \