Separating reset and verify

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@513 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-07-22 07:14:19 +00:00
parent 9e66d820a6
commit 56edcac48d
9 changed files with 103 additions and 48 deletions

View file

@ -47,18 +47,4 @@
#undef BOOST_PP_FILENAME_1
#undef BOOST_PP_ITERATION_LIMITS
namespace mock
{
template< typename Signature >
bool verify( const detail::function< Signature >& f )
{
return f.verify();
}
template< typename Signature >
void reset( detail::function< Signature >& f )
{
f.reset();
}
} // mock
#endif // MOCK_FUNCTION_HPP_INCLUDED

View file

@ -123,15 +123,6 @@ namespace detail
};
BOOST_TEST_SINGLETON_INST( root )
}
inline bool verify()
{
return detail::root.verify();
}
inline void reset()
{
detail::root.reset();
}
} // mock
#endif // MOCK_ROOT_HPP_INCLUDED

View file

@ -11,6 +11,8 @@
#include "config.hpp"
#include "object.hpp"
#include "reset.hpp"
#include "verify.hpp"
#include "detail/function.hpp"
#include "detail/type_name.hpp"
#include "detail/signature.hpp"

View file

@ -20,18 +20,7 @@
namespace mock
{
class object
{
public:
object()
: impl_( new detail::object_impl() )
{}
protected:
~object()
{}
public:
boost::shared_ptr< detail::object_impl > impl_;
};
class object;
namespace detail
{
@ -39,11 +28,7 @@ namespace detail
E& configure( const object& o, E& e,
boost::unit_test::const_string instance,
boost::optional< type_name > type,
boost::unit_test::const_string name )
{
e.configure( *o.impl_, o.impl_.get(), instance, type, name );
return e;
}
boost::unit_test::const_string name );
template< typename T, typename E >
E& configure( const T& t, E& e,
@ -58,14 +43,30 @@ namespace detail
return e;
}
}
inline bool verify( const object& o )
class object
{
return o.impl_->verify();
}
inline void reset( object& o )
{
o.impl_->reset();
}
public:
object()
: impl_( new detail::object_impl() )
{}
protected:
~object()
{}
private:
friend void reset( const object& o );
friend bool verify( const object& o );
template< typename E >
friend E& detail::configure( const object& o, E& e,
boost::unit_test::const_string instance,
boost::optional< detail::type_name > type,
boost::unit_test::const_string name )
{
e.configure( *o.impl_, o.impl_.get(), instance, type, name );
return e;
}
private:
boost::shared_ptr< detail::object_impl > impl_;
};
} // mock
#endif // MOCK_OBJECT_HPP_INCLUDED

33
turtle/reset.hpp Normal file
View file

@ -0,0 +1,33 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_RESET_HPP_INCLUDED
#define MOCK_RESET_HPP_INCLUDED
#include "object.hpp"
#include "detail/root.hpp"
#include "detail/function.hpp"
namespace mock
{
inline void reset()
{
detail::root.reset();
}
inline void reset( const object& o )
{
o.impl_->reset();
}
template< typename Signature >
void reset( detail::function< Signature >& f )
{
f.reset();
}
} // mock
#endif // MOCK_RESET_HPP_INCLUDED

33
turtle/verify.hpp Normal file
View file

@ -0,0 +1,33 @@
// http://turtle.sourceforge.net
//
// Copyright Mathieu Champlon 2012
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef MOCK_VERIFY_HPP_INCLUDED
#define MOCK_VERIFY_HPP_INCLUDED
#include "object.hpp"
#include "detail/root.hpp"
#include "detail/function.hpp"
namespace mock
{
inline bool verify()
{
return detail::root.verify();
}
inline bool verify( const object& o )
{
return o.impl_->verify();
}
template< typename Signature >
bool verify( const detail::function< Signature >& f )
{
return f.verify();
}
} // mock
#endif // MOCK_VERIFY_HPP_INCLUDED