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

@ -53,8 +53,10 @@
<ClInclude Include="..\..\turtle\log.hpp" /> <ClInclude Include="..\..\turtle\log.hpp" />
<ClInclude Include="..\..\turtle\mock.hpp" /> <ClInclude Include="..\..\turtle\mock.hpp" />
<ClInclude Include="..\..\turtle\object.hpp" /> <ClInclude Include="..\..\turtle\object.hpp" />
<ClInclude Include="..\..\turtle\reset.hpp" />
<ClInclude Include="..\..\turtle\sequence.hpp" /> <ClInclude Include="..\..\turtle\sequence.hpp" />
<ClInclude Include="..\..\turtle\stream.hpp" /> <ClInclude Include="..\..\turtle\stream.hpp" />
<ClInclude Include="..\..\turtle\verify.hpp" />
</ItemGroup> </ItemGroup>
<PropertyGroup Label="Globals"> <PropertyGroup Label="Globals">
<ProjectGuid>{831F2DEE-1E35-4533-A3B2-12C01BA8DA1D}</ProjectGuid> <ProjectGuid>{831F2DEE-1E35-4533-A3B2-12C01BA8DA1D}</ProjectGuid>

View file

@ -118,5 +118,11 @@
<ClInclude Include="..\..\turtle\format.hpp"> <ClInclude Include="..\..\turtle\format.hpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\turtle\verify.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\reset.hpp">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -7,7 +7,8 @@
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
#include "mock_error.hpp" #include "mock_error.hpp"
#include <turtle/object.hpp> #include <turtle/reset.hpp>
#include <turtle/verify.hpp>
#include <turtle/detail/function.hpp> #include <turtle/detail/function.hpp>
#include <boost/test/auto_unit_test.hpp> #include <boost/test/auto_unit_test.hpp>

View file

@ -47,18 +47,4 @@
#undef BOOST_PP_FILENAME_1 #undef BOOST_PP_FILENAME_1
#undef BOOST_PP_ITERATION_LIMITS #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 #endif // MOCK_FUNCTION_HPP_INCLUDED

View file

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

View file

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

View file

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