mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Initial import
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@2 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
8081e7006f
commit
8e18676b92
31 changed files with 4062 additions and 0 deletions
66
src/libraries/turtle/check.hpp
Normal file
66
src/libraries/turtle/check.hpp
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_CHECK_HPP_INCLUDED
|
||||
#define MOCK_CHECK_HPP_INCLUDED
|
||||
|
||||
#include "placeholder.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include "format.hpp"
|
||||
#include <boost/function.hpp>
|
||||
#include <stdexcept>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Arg >
|
||||
class check
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< bool( Arg ) > functor_type;
|
||||
|
||||
public:
|
||||
template< typename T >
|
||||
explicit check( const T& t )
|
||||
: functor_( equal( t ).functor_ )
|
||||
, desc_ ( detail::format( t ) )
|
||||
{
|
||||
if( !functor_ )
|
||||
std::invalid_argument( "invalid functor" );
|
||||
}
|
||||
|
||||
template< typename Constraint >
|
||||
explicit check( const placeholder< Constraint >& c )
|
||||
: functor_( c.functor_ )
|
||||
, desc_ ( c.desc_ )
|
||||
{
|
||||
if( !functor_ )
|
||||
std::invalid_argument( "invalid functor" );
|
||||
}
|
||||
|
||||
template< typename Y >
|
||||
bool operator()( Y& y ) const
|
||||
{
|
||||
return functor_( y );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const check& c )
|
||||
{
|
||||
return s << c.desc_;
|
||||
}
|
||||
|
||||
private:
|
||||
functor_type functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_CHECK_HPP_INCLUDED
|
||||
26
src/libraries/turtle/config.hpp
Normal file
26
src/libraries/turtle/config.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2009
|
||||
//
|
||||
// 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_CONFIG_HPP_INCLUDED
|
||||
#define MOCK_CONFIG_HPP_INCLUDED
|
||||
|
||||
#include <boost/preprocessor/comparison/less_equal.hpp>
|
||||
#include <boost/preprocessor/debug/assert.hpp>
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#ifndef MOCK_MAX_ARGS
|
||||
# define MOCK_MAX_ARGS 10
|
||||
#endif // MOCK_MAX_ARGS
|
||||
|
||||
BOOST_PP_ASSERT( BOOST_PP_LESS_EQUAL(MOCK_MAX_ARGS, BOOST_FUNCTION_MAX_ARGS) )
|
||||
|
||||
#ifdef BOOST_TEST_DECL
|
||||
# define MOCK_USE_BOOST_TEST
|
||||
#endif
|
||||
|
||||
#endif // #ifndef MOCK_CONFIG_HPP_INCLUDED
|
||||
132
src/libraries/turtle/constraint.hpp
Normal file
132
src/libraries/turtle/constraint.hpp
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_CONSTRAINT_HPP_INCLUDED
|
||||
#define MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
|
||||
#include "placeholder.hpp"
|
||||
#include "functional.hpp"
|
||||
#include "format.hpp"
|
||||
#include <sstream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Functor, typename Description >
|
||||
const detail::placeholder< Functor > constraint( const Functor& f,
|
||||
const Description& desc )
|
||||
{
|
||||
std::stringstream s;
|
||||
s << std::boolalpha << desc;
|
||||
return detail::placeholder< Functor >( f, s.str() );
|
||||
}
|
||||
template< typename Functor >
|
||||
const detail::placeholder< Functor > constraint( const Functor& f )
|
||||
{
|
||||
return detail::placeholder< Functor >( f, "?" );
|
||||
}
|
||||
template< typename Functor, typename T >
|
||||
const detail::placeholder< Functor > constraint( const Functor& f,
|
||||
const std::string& name,
|
||||
const T& t )
|
||||
{
|
||||
return detail::placeholder< Functor >( f,
|
||||
name + "( " + detail::format( t ) + " )" );
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template<>
|
||||
struct placeholder< nothing >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "any" )
|
||||
{}
|
||||
nothing functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
template<>
|
||||
struct placeholder< negation >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "negate" )
|
||||
{}
|
||||
negation functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
template<>
|
||||
struct placeholder< evaluation >
|
||||
{
|
||||
placeholder()
|
||||
: desc_( "evaluate" )
|
||||
{}
|
||||
evaluation functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
}
|
||||
const detail::placeholder< detail::nothing > any;
|
||||
const detail::placeholder< detail::negation > negate;
|
||||
const detail::placeholder< detail::evaluation > evaluate;
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::equality< T > > equal( T t )
|
||||
{
|
||||
return constraint( detail::equality< T >( t ), "equal", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::identity< T > > same( T& t )
|
||||
{
|
||||
return constraint( detail::identity< T >( boost::ref( t ) ),
|
||||
"same", &t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::inferiority< T > > less( T t )
|
||||
{
|
||||
return constraint( detail::inferiority< T >( t ), "less", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::superiority< T > > greater( T t )
|
||||
{
|
||||
return constraint( detail::superiority< T >( t ), "greater", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder<
|
||||
detail::or_< detail::inferiority< T >, detail::equality< T > > >
|
||||
less_equal( T t )
|
||||
{
|
||||
return constraint( (less( t ) || equal( t )).functor_,
|
||||
"less_equal", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder<
|
||||
detail::or_< detail::superiority< T >, detail::equality< T > > >
|
||||
greater_equal( T t )
|
||||
{
|
||||
return constraint( (greater( t ) || equal( t )).functor_,
|
||||
"greater_equal", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::assignment< T > > assign( T t )
|
||||
{
|
||||
return constraint( detail::assignment< T >( t ), "assign", t );
|
||||
}
|
||||
|
||||
template< typename T >
|
||||
detail::placeholder< detail::retrieval< T > > retrieve( T& t )
|
||||
{
|
||||
return constraint( detail::retrieval< T >( boost::ref( t ) ),
|
||||
"retrieve", t );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_CONSTRAINT_HPP_INCLUDED
|
||||
98
src/libraries/turtle/error.hpp
Normal file
98
src/libraries/turtle/error.hpp
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_ERROR_HPP_INCLUDED
|
||||
#define MOCK_ERROR_HPP_INCLUDED
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <boost/test/test_tools.hpp>
|
||||
#include <boost/test/execution_monitor.hpp>
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class errors_t : public boost::unit_test::singleton< errors_t >
|
||||
{
|
||||
public:
|
||||
long count_;
|
||||
private:
|
||||
friend class boost::unit_test::singleton< errors_t >;
|
||||
errors_t()
|
||||
: count_( 0 )
|
||||
{}
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( errors )
|
||||
}
|
||||
|
||||
class exception : public boost::execution_exception
|
||||
{
|
||||
public:
|
||||
explicit exception( const std::string& s )
|
||||
: boost::execution_exception( boost::execution_exception::user_error, s )
|
||||
{}
|
||||
};
|
||||
|
||||
template< typename Result >
|
||||
struct boost_test_error_policy
|
||||
{
|
||||
static void missing_result_specification()
|
||||
{
|
||||
++detail::errors.count_;
|
||||
static std::string m;
|
||||
m = "mock error : missing result specification";
|
||||
throw mock::exception( m );
|
||||
}
|
||||
|
||||
static Result no_match( const std::string& context )
|
||||
{
|
||||
++detail::errors.count_;
|
||||
static std::string m;
|
||||
m = "mock error : unexpected call : " + context;
|
||||
throw mock::exception( m );
|
||||
}
|
||||
|
||||
static void sequence_failed( const std::string& context,
|
||||
const std::string& /*file*/, int /*line*/ )
|
||||
{
|
||||
++detail::errors.count_;
|
||||
static std::string m;
|
||||
m = "mock error : unexpected call : " + context;
|
||||
throw mock::exception( m );
|
||||
}
|
||||
|
||||
static void verification_failed( const std::string& context,
|
||||
const std::string& file, int line )
|
||||
{
|
||||
notify( "verification failed : " + context, file, line );
|
||||
}
|
||||
|
||||
static void untriggered_expectation( const std::string& context,
|
||||
const std::string& file, int line )
|
||||
{
|
||||
if( detail::errors.count_ == 0 )
|
||||
notify( "untriggered expectation : " + context, file, line );
|
||||
}
|
||||
|
||||
static void notify( const std::string& message,
|
||||
const std::string& file, int line )
|
||||
{
|
||||
boost::test_tools::tt_detail::check_impl(
|
||||
false,
|
||||
boost::unit_test::lazy_ostream::instance() << message,
|
||||
file, (std::size_t)line,
|
||||
boost::test_tools::tt_detail::CHECK,
|
||||
boost::test_tools::tt_detail::CHECK_MSG,
|
||||
0 );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_ERROR_HPP_INCLUDED
|
||||
202
src/libraries/turtle/expectation.hpp
Normal file
202
src/libraries/turtle/expectation.hpp
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_EXPECTATION_HPP_INCLUDED
|
||||
#define MOCK_EXPECTATION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include "matcher.hpp"
|
||||
#include "node.hpp"
|
||||
#include "root.hpp"
|
||||
#include "format.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <ostream>
|
||||
#include <list>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
template< typename Signature,
|
||||
typename ErrorPolicy = boost_test_error_policy<
|
||||
BOOST_DEDUCED_TYPENAME boost::function<
|
||||
Signature >::result_type > > // $$$$ MAT : concept check Signature is actually a signature
|
||||
class expectation : private verifiable
|
||||
{
|
||||
public:
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature >::result_type result_type;
|
||||
typedef detail::matcher< result_type,
|
||||
Signature,
|
||||
ErrorPolicy,
|
||||
boost::function< Signature >::arity >
|
||||
matcher_type;
|
||||
|
||||
expectation( node& parent = root, const std::string& name = "?" )
|
||||
: name_( name )
|
||||
, parent_( &parent )
|
||||
, valid_( true )
|
||||
{
|
||||
parent_->add( *this );
|
||||
}
|
||||
expectation( const std::string& name )
|
||||
: name_( name )
|
||||
, parent_( &root )
|
||||
, valid_( true )
|
||||
{
|
||||
parent_->add( *this );
|
||||
}
|
||||
virtual ~expectation()
|
||||
{
|
||||
parent_->remove( *this );
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
if( valid_ && ! it->verify() )
|
||||
ErrorPolicy::untriggered_expectation(
|
||||
context(), it->file(), it->line() );
|
||||
}
|
||||
|
||||
expectation& set_name( const std::string& name )
|
||||
{
|
||||
name_ = name;
|
||||
return *this;
|
||||
}
|
||||
expectation& set_parent( node& parent )
|
||||
{
|
||||
parent_->remove( *this );
|
||||
parent.add( *this );
|
||||
parent_ = &parent;
|
||||
return *this;
|
||||
}
|
||||
|
||||
virtual bool verify()
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
if( !it->verify() )
|
||||
{
|
||||
valid_ = false;
|
||||
ErrorPolicy::verification_failed( context(),
|
||||
it->file(), it->line() );
|
||||
}
|
||||
return valid_;
|
||||
}
|
||||
virtual void reset()
|
||||
{
|
||||
valid_ = true;
|
||||
matchers_.clear();
|
||||
}
|
||||
|
||||
matcher_type& expect( const std::string& file, int line )
|
||||
{
|
||||
matchers_.push_back( matcher_type() );
|
||||
matchers_.back().set_location( file, line );
|
||||
valid_ = true;
|
||||
return matchers_.back();
|
||||
}
|
||||
matcher_type& expect()
|
||||
{
|
||||
matchers_.push_back( matcher_type() );
|
||||
valid_ = true;
|
||||
return matchers_.back();
|
||||
}
|
||||
|
||||
result_type operator()() const
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
if( it->is_valid() )
|
||||
{
|
||||
if( !it->invoke() )
|
||||
{
|
||||
valid_ = false;
|
||||
ErrorPolicy::sequence_failed( context( "" ),
|
||||
it->file(), it->line() );
|
||||
}
|
||||
return it->functor()();
|
||||
}
|
||||
valid_ = false;
|
||||
return ErrorPolicy::no_match( context( "" ) );
|
||||
}
|
||||
|
||||
#define MOCK_EXPECTATION_PARAMETER(z, n, d) BOOST_PP_COMMA_IF(n) const_cast< A##n & >( a##n )
|
||||
#define MOCK_EXPECTATION_DETAIL(z, n, d) + ", " + detail::format( a##n )
|
||||
#define MOCK_EXPECTATION_PARAMETERS(n) \
|
||||
detail::format( a0 ) BOOST_PP_REPEAT_FROM_TO(1, n, MOCK_EXPECTATION_DETAIL, BOOST_PP_EMPTY)
|
||||
#define MOCK_EXPECTATION_OPERATOR(z, n, d) \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename A) > \
|
||||
result_type operator()( BOOST_PP_ENUM_BINARY_PARAMS(n, const A, & a) ) const \
|
||||
{ \
|
||||
for( matchers_cit it = matchers_.begin(); it != matchers_.end(); ++it ) \
|
||||
if( it->is_valid( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_PARAMETER, BOOST_PP_EMPTY) ) ) \
|
||||
{ \
|
||||
if( !it->invoke() ) \
|
||||
{ \
|
||||
valid_ = false; \
|
||||
ErrorPolicy::sequence_failed( context( MOCK_EXPECTATION_PARAMETERS(n) ), it->file(), it->line() ); \
|
||||
} \
|
||||
return it->functor()( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_PARAMETER, BOOST_PP_EMPTY) ); \
|
||||
} \
|
||||
valid_ = false; \
|
||||
return ErrorPolicy::no_match( context( MOCK_EXPECTATION_PARAMETERS(n) ) ); \
|
||||
}
|
||||
BOOST_PP_REPEAT_FROM_TO(1, MOCK_MAX_ARGS, MOCK_EXPECTATION_OPERATOR, BOOST_PP_EMPTY)
|
||||
#undef MOCK_EXPECTATION_PARAMETER
|
||||
#undef MOCK_EXPECTATION_PARAMETERS
|
||||
#undef MOCK_EXPECTATION_DETAIL
|
||||
#undef MOCK_EXPECTATION_OPERATOR
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const expectation& e )
|
||||
{
|
||||
return s << e.context();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::list< matcher_type > matchers_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
matchers_type::const_iterator matchers_cit;
|
||||
|
||||
void serialize( std::ostream& s ) const
|
||||
{
|
||||
for( matchers_cit it = matchers_.begin();
|
||||
it != matchers_.end(); ++it )
|
||||
s << std::endl << *it;
|
||||
}
|
||||
|
||||
std::string context() const
|
||||
{
|
||||
std::stringstream s;
|
||||
s << *parent_ << name_;
|
||||
serialize( s );
|
||||
return s.str();
|
||||
}
|
||||
std::string context( const std::string& parameters ) const
|
||||
{
|
||||
std::stringstream s;
|
||||
s << *parent_ << name_;
|
||||
if( parameters.empty() )
|
||||
s << "()";
|
||||
else
|
||||
s << "( " << parameters << " )";
|
||||
serialize( s );
|
||||
return s.str();
|
||||
}
|
||||
|
||||
std::string name_;
|
||||
node* parent_;
|
||||
mutable bool valid_;
|
||||
matchers_type matchers_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_EXPECTATION_HPP_INCLUDED
|
||||
78
src/libraries/turtle/format.hpp
Normal file
78
src/libraries/turtle/format.hpp
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_FORMAT_HPP_INCLUDED
|
||||
#define MOCK_FORMAT_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
struct eater
|
||||
{
|
||||
template< typename T >
|
||||
eater( const T& ) {}
|
||||
};
|
||||
|
||||
struct eaten
|
||||
{};
|
||||
|
||||
template< typename S >
|
||||
eaten operator<<( S& s, const eater& );
|
||||
|
||||
template< int I >
|
||||
struct selector
|
||||
{
|
||||
};
|
||||
template<>
|
||||
struct selector< sizeof( std::ostream& ) >
|
||||
{
|
||||
typedef boost::true_type type;
|
||||
};
|
||||
template<>
|
||||
struct selector< sizeof( eaten ) >
|
||||
{
|
||||
typedef boost::false_type type;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
struct is_serializable
|
||||
{
|
||||
static std::ostream& s();
|
||||
static const T& t();
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
selector< sizeof( s() << t() ) >::type type;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
std::string format( const T& t,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
BOOST_DEDUCED_TYPENAME detail::is_serializable< T >::type >::type* = 0 )
|
||||
{
|
||||
std::stringstream s;
|
||||
static_cast< std::ostream& >( s ) << std::boolalpha << t;
|
||||
return s.str();
|
||||
}
|
||||
template< typename T >
|
||||
std::string format( const T&,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
BOOST_DEDUCED_TYPENAME detail::is_serializable< T >::type >::type* = 0 )
|
||||
{
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_FORMAT_HPP_INCLUDED
|
||||
160
src/libraries/turtle/functional.hpp
Normal file
160
src/libraries/turtle/functional.hpp
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_FUNCTIONAL_HPP_INCLUDED
|
||||
#define MOCK_FUNCTIONAL_HPP_INCLUDED
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class nothing
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& ) const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class negation
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return ! y;
|
||||
}
|
||||
};
|
||||
|
||||
class evaluation
|
||||
{
|
||||
public:
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return y();
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class equality
|
||||
{
|
||||
public:
|
||||
explicit equality( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return y == t_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class identity
|
||||
{
|
||||
public:
|
||||
explicit identity( const boost::reference_wrapper< T >& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return &y == t_.get_pointer();
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< T > t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class inferiority
|
||||
{
|
||||
public:
|
||||
explicit inferiority( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return y < t_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class superiority
|
||||
{
|
||||
public:
|
||||
explicit superiority( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return y > t_;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class assignment
|
||||
{
|
||||
public:
|
||||
explicit assignment( const T& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( Y& y ) const
|
||||
{
|
||||
y = t_;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
T t_;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
class retrieval
|
||||
{
|
||||
public:
|
||||
explicit retrieval( const boost::reference_wrapper< T >& t )
|
||||
: t_( t )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y,
|
||||
BOOST_DEDUCED_TYPENAME boost::disable_if<
|
||||
boost::is_convertible< Y*, T >, Y >::type* = 0 ) const
|
||||
{
|
||||
t_.get() = y;
|
||||
return true;
|
||||
}
|
||||
template< typename Y >
|
||||
bool operator()( Y& y,
|
||||
BOOST_DEDUCED_TYPENAME boost::enable_if<
|
||||
boost::is_convertible< Y*, T >, Y >::type* = 0 ) const
|
||||
{
|
||||
t_.get() = &y;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
boost::reference_wrapper< T > t_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_FUNCTIONAL_HPP_INCLUDED
|
||||
176
src/libraries/turtle/invocation.hpp
Normal file
176
src/libraries/turtle/invocation.hpp
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_INVOCATION_HPP_INCLUDED
|
||||
#define MOCK_INVOCATION_HPP_INCLUDED
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <stdexcept>
|
||||
#include <ostream>
|
||||
#include <limits>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class invocation : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
invocation() {}
|
||||
|
||||
virtual ~invocation() {}
|
||||
|
||||
// Trigger invocation
|
||||
// returns false if the invocation has failed
|
||||
virtual bool invoke() = 0;
|
||||
|
||||
// Test whether the invocation is exhausted or not
|
||||
// returns false if the invocation is exhausted
|
||||
virtual bool is_valid() const = 0;
|
||||
|
||||
// Verify invocation
|
||||
virtual bool verify() const = 0;
|
||||
|
||||
friend inline std::ostream& operator<<( std::ostream& s, const invocation& i )
|
||||
{
|
||||
return i.serialize( s );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const = 0;
|
||||
};
|
||||
|
||||
class between : public invocation
|
||||
{
|
||||
public:
|
||||
between( std::size_t min, std::size_t max )
|
||||
: min_ ( min )
|
||||
, max_ ( max )
|
||||
, count_( 0 )
|
||||
{
|
||||
if( min > max )
|
||||
throw std::invalid_argument( "'min' > 'max'" );
|
||||
}
|
||||
|
||||
virtual bool invoke()
|
||||
{
|
||||
if( count_ == max_ )
|
||||
return false;
|
||||
++count_;
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool is_valid() const
|
||||
{
|
||||
return count_ < max_;
|
||||
}
|
||||
|
||||
virtual bool verify() const
|
||||
{
|
||||
return min_ <= count_ && count_ <= max_;
|
||||
}
|
||||
|
||||
protected:
|
||||
const std::size_t min_, max_;
|
||||
std::size_t count_;
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "between( " << count_ << "/[" << min_ << ',' << max_ << "] )";
|
||||
}
|
||||
};
|
||||
|
||||
class exactly : public between
|
||||
{
|
||||
public:
|
||||
explicit exactly( std::size_t count )
|
||||
: between( count, count )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "exactly( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class never : public exactly
|
||||
{
|
||||
public:
|
||||
never()
|
||||
: exactly( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "never()";
|
||||
}
|
||||
};
|
||||
|
||||
class once : public exactly
|
||||
{
|
||||
public:
|
||||
once()
|
||||
: exactly( 1 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "once()";
|
||||
}
|
||||
};
|
||||
|
||||
class at_least : public between
|
||||
{
|
||||
public:
|
||||
explicit at_least( std::size_t min )
|
||||
: between( min, std::numeric_limits< std::size_t >::max() )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_least( " << count_ << '/' << min_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class at_most : public between
|
||||
{
|
||||
public:
|
||||
explicit at_most( std::size_t max )
|
||||
: between( 0, max )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "at_most( " << count_ << '/' << max_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
class unlimited : public at_least
|
||||
{
|
||||
public:
|
||||
unlimited()
|
||||
: at_least( 0 )
|
||||
{}
|
||||
|
||||
private:
|
||||
virtual std::ostream& serialize( std::ostream& s ) const
|
||||
{
|
||||
return s << "unlimited()";
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_INVOCATION_HPP_INCLUDED
|
||||
222
src/libraries/turtle/matcher.hpp
Normal file
222
src/libraries/turtle/matcher.hpp
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_MATCHER_HPP_INCLUDED
|
||||
#define MOCK_MATCHER_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "invocation.hpp"
|
||||
#include "result.hpp"
|
||||
#include "sequence.hpp"
|
||||
#include "check.hpp"
|
||||
#include "constraint.hpp"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
class matcher_base : private orderable
|
||||
{
|
||||
public:
|
||||
matcher_base()
|
||||
: i_( new detail::unlimited() )
|
||||
, file_( "unknown location" )
|
||||
, line_( 0 )
|
||||
{}
|
||||
virtual ~matcher_base()
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->remove( *this );
|
||||
}
|
||||
|
||||
void set_location( const std::string& file, int line )
|
||||
{
|
||||
file_ = file;
|
||||
line_ = line;
|
||||
}
|
||||
|
||||
bool verify() const
|
||||
{
|
||||
return i_->verify();
|
||||
}
|
||||
|
||||
bool invoke() const
|
||||
{
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
if( ! (*it)->is_valid( *this ) )
|
||||
return false;
|
||||
bool result = i_->invoke();
|
||||
for( sequences_cit it = sequences_.begin();
|
||||
it != sequences_.end(); ++it )
|
||||
(*it)->call( *this );
|
||||
return result;
|
||||
}
|
||||
|
||||
matcher_base& in( sequence& s )
|
||||
{
|
||||
s.add( *this );
|
||||
sequences_.push_back( &s );
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::string& file() const
|
||||
{
|
||||
return file_;
|
||||
}
|
||||
int line() const
|
||||
{
|
||||
return line_;
|
||||
}
|
||||
|
||||
protected:
|
||||
boost::shared_ptr< detail::invocation > i_;
|
||||
|
||||
void expect( detail::invocation* i )
|
||||
{
|
||||
i_.reset( i );
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void remove( sequence& s )
|
||||
{
|
||||
sequences_.erase( std::remove( sequences_.begin(),
|
||||
sequences_.end(), &s ), sequences_.end() );
|
||||
}
|
||||
|
||||
typedef std::vector< sequence* > sequences_type;
|
||||
typedef sequences_type::const_iterator sequences_cit;
|
||||
|
||||
sequences_type sequences_;
|
||||
std::string file_;
|
||||
int line_;
|
||||
};
|
||||
|
||||
template< typename Result, typename Signature, typename ErrorPolicy, int >
|
||||
class matcher
|
||||
{
|
||||
};
|
||||
|
||||
#define MOCK_INVOCATIONS \
|
||||
matcher& once() \
|
||||
{ \
|
||||
expect( new detail::once() ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& never() \
|
||||
{ \
|
||||
expect( new detail::never() ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& exactly( std::size_t count ) \
|
||||
{ \
|
||||
expect( new detail::exactly( count ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& at_least( std::size_t min ) \
|
||||
{ \
|
||||
expect( new detail::at_least( min ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& at_most( std::size_t max ) \
|
||||
{ \
|
||||
expect( new detail::at_most( max ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& between( std::size_t min, std::size_t max ) \
|
||||
{ \
|
||||
expect( new detail::at_most( min, max ) ); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
template< typename Result, typename Signature, typename ErrorPolicy >
|
||||
class matcher< Result, Signature, ErrorPolicy, 0 >
|
||||
: public matcher_base, public result< Result, Signature, ErrorPolicy >
|
||||
{
|
||||
public:
|
||||
bool is_valid() const
|
||||
{
|
||||
return i_->is_valid();
|
||||
}
|
||||
|
||||
MOCK_INVOCATIONS
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
{
|
||||
return s << (m.i_->is_valid() ? '.' : 'v')
|
||||
<< " expect( " << *m.i_ << " )";
|
||||
}
|
||||
};
|
||||
|
||||
#define MOCK_MATCHER_TYPEDEF(z, n, d) \
|
||||
typedef BOOST_DEDUCED_TYPENAME \
|
||||
boost::function< Signature >::BOOST_PP_CAT(BOOST_PP_CAT(arg, BOOST_PP_INC(n)), _type) arg##n##_type; \
|
||||
typedef detail::check< arg##n##_type > constraint##n##_type;
|
||||
#define MOCK_MATCHER_CONSTRUCTOR(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_ ( any )
|
||||
#define MOCK_MATCHER_WITH(z, n, d) c##n##_ = constraint##n##_type( c##n );
|
||||
#define MOCK_MATCHER_MEMBER(z, n, d) constraint##n##_type c##n##_;
|
||||
#define MOCK_MATCHER_IS_VALID_PARAMS(z, n, d) BOOST_PP_COMMA_IF(n) arg##n##_type a##n
|
||||
#define MOCK_MATCHER_IS_VALID(z, n, d) && c##n##_( a##n )
|
||||
#define MOCK_MATCHER_SERIALIZE(z, n, d) << ", " << m.c##n##_
|
||||
#define MOCK_MATCHER(z, n, d) \
|
||||
template< typename Result, typename Signature, typename ErrorPolicy > \
|
||||
class matcher< Result, Signature, ErrorPolicy, n > \
|
||||
: public matcher_base, public result< Result, Signature, ErrorPolicy > \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_TYPEDEF, BOOST_PP_EMPTY) \
|
||||
public: \
|
||||
matcher() \
|
||||
: BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_CONSTRUCTOR, BOOST_PP_EMPTY) \
|
||||
{} \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename C) > \
|
||||
matcher& with( BOOST_PP_ENUM_BINARY_PARAMS(n, const C, & c) ) \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_WITH, BOOST_PP_EMPTY) \
|
||||
return *this; \
|
||||
} \
|
||||
bool is_valid( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_IS_VALID_PARAMS, BOOST_PP_EMPTY) ) const \
|
||||
{ \
|
||||
return i_->is_valid() \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_IS_VALID, BOOST_PP_EMPTY); \
|
||||
} \
|
||||
MOCK_INVOCATIONS \
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m ) \
|
||||
{ \
|
||||
return s << (m.i_->is_valid() ? '.' : 'v') \
|
||||
<< " expect( " << *m.i_ << " ).with( " \
|
||||
<< m.c0_ \
|
||||
BOOST_PP_REPEAT_FROM_TO(1, n, MOCK_MATCHER_SERIALIZE, BOOST_PP_EMPTY) \
|
||||
<< " )"; \
|
||||
} \
|
||||
private: \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_MEMBER, BOOST_PP_EMPTY) \
|
||||
};
|
||||
BOOST_PP_REPEAT_FROM_TO(1, MOCK_MAX_ARGS, MOCK_MATCHER, BOOST_PP_EMPTY)
|
||||
|
||||
#undef MOCK_INVOCATIONS
|
||||
#undef MOCK_MATCHER_TYPEDEF
|
||||
#undef MOCK_MATCHER_CONSTRUCTOR
|
||||
#undef MOCK_MATCHER_WITH
|
||||
#undef MOCK_MATCHER_MEMBER
|
||||
#undef MOCK_MATCHER_IS_VALID_PARAMS
|
||||
#undef MOCK_MATCHER_IS_VALID
|
||||
#undef MOCK_MATCHER_SERIALIZE
|
||||
#undef MOCK_MATCHER
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_MATCHER_HPP_INCLUDED
|
||||
91
src/libraries/turtle/node.hpp
Normal file
91
src/libraries/turtle/node.hpp
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_NODE_HPP_INCLUDED
|
||||
#define MOCK_NODE_HPP_INCLUDED
|
||||
|
||||
#include "verifiable.hpp"
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class node : private verifiable
|
||||
{
|
||||
public:
|
||||
node()
|
||||
: parent_( 0 )
|
||||
{}
|
||||
explicit node( node& parent )
|
||||
: verifiable()
|
||||
, parent_( &parent )
|
||||
{
|
||||
if( parent_ )
|
||||
parent_->add( *this );
|
||||
}
|
||||
virtual ~node()
|
||||
{
|
||||
if( parent_ )
|
||||
parent_->remove( *this );
|
||||
}
|
||||
|
||||
void set_parent( node& parent )
|
||||
{
|
||||
if( parent_ )
|
||||
parent_->remove( *this );
|
||||
parent_ = &parent;
|
||||
parent_->add( *this );
|
||||
}
|
||||
|
||||
void add( verifiable& e )
|
||||
{
|
||||
v_.push_back( &e );
|
||||
}
|
||||
void remove( verifiable& e )
|
||||
{
|
||||
v_.erase( std::remove( v_.begin(), v_.end(), &e ), v_.end() );
|
||||
}
|
||||
|
||||
virtual bool verify()
|
||||
{
|
||||
bool valid = true;
|
||||
for( verifiables_cit it = v_.begin(); it != v_.end(); ++it )
|
||||
if( ! (*it)->verify() )
|
||||
valid = false;
|
||||
return valid;
|
||||
}
|
||||
virtual void reset()
|
||||
{
|
||||
std::for_each( v_.begin(), v_.end(),
|
||||
std::mem_fun( &verifiable::reset ) );
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, node& n )
|
||||
{
|
||||
if( n.parent_ )
|
||||
s << *n.parent_;
|
||||
n.serialize( s );
|
||||
return s;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void serialize( std::ostream& s ) const = 0;
|
||||
|
||||
private:
|
||||
typedef std::vector< verifiable* > verifiables_type;
|
||||
typedef verifiables_type::const_iterator verifiables_cit;
|
||||
|
||||
node* parent_;
|
||||
std::vector< verifiable* > v_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_NODE_HPP_INCLUDED
|
||||
47
src/libraries/turtle/object.hpp
Normal file
47
src/libraries/turtle/object.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_OBJECT_HPP_INCLUDED
|
||||
#define MOCK_OBJECT_HPP_INCLUDED
|
||||
|
||||
#include "node.hpp"
|
||||
#include "root.hpp"
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class object : public node
|
||||
{
|
||||
public:
|
||||
explicit object( node& parent = root, const std::string& name = "" )
|
||||
: node( parent )
|
||||
, name_( name )
|
||||
{}
|
||||
explicit object( const std::string& name )
|
||||
: node( root )
|
||||
, name_( name )
|
||||
{}
|
||||
|
||||
void set_name( const std::string& name )
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
private:
|
||||
virtual void serialize( std::ostream& s ) const
|
||||
{
|
||||
s << (name_.empty() ? "?" : name_) << "::";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_OBJECT_HPP_INCLUDED
|
||||
111
src/libraries/turtle/placeholder.hpp
Normal file
111
src/libraries/turtle/placeholder.hpp
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_PLACEHOLDER_HPP_INCLUDED
|
||||
#define MOCK_PLACEHOLDER_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename Functor >
|
||||
struct placeholder
|
||||
{
|
||||
placeholder( const Functor& f, const std::string& desc )
|
||||
: functor_( f )
|
||||
, desc_ ( desc )
|
||||
{}
|
||||
Functor functor_;
|
||||
std::string desc_;
|
||||
};
|
||||
|
||||
template< typename Constraint1, typename Constraint2 >
|
||||
class and_
|
||||
{
|
||||
public:
|
||||
and_( const Constraint1& c1, const Constraint2& c2 )
|
||||
: c1_( c1 )
|
||||
, c2_( c2 )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return c1_( y ) && c2_( y );
|
||||
}
|
||||
private:
|
||||
Constraint1 c1_;
|
||||
Constraint2 c2_;
|
||||
};
|
||||
|
||||
template< typename Constraint1, typename Constraint2 >
|
||||
class or_
|
||||
{
|
||||
public:
|
||||
or_( const Constraint1& c1, const Constraint2& c2 )
|
||||
: c1_( c1 )
|
||||
, c2_( c2 )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return c1_( y ) || c2_( y );
|
||||
}
|
||||
private:
|
||||
Constraint1 c1_;
|
||||
Constraint2 c2_;
|
||||
};
|
||||
|
||||
template< typename Constraint >
|
||||
class not_
|
||||
{
|
||||
public:
|
||||
explicit not_( const Constraint& c )
|
||||
: c_( c )
|
||||
{}
|
||||
template< typename Y >
|
||||
bool operator()( const Y& y ) const
|
||||
{
|
||||
return ! c_( y );
|
||||
}
|
||||
private:
|
||||
Constraint c_;
|
||||
};
|
||||
|
||||
template< typename F1, typename F2 >
|
||||
const placeholder< or_< F1, F2 > >
|
||||
operator||( const placeholder< F1 >& lhs,
|
||||
const placeholder< F2 >& rhs )
|
||||
{
|
||||
return placeholder< or_< F1, F2 > >(
|
||||
or_< F1, F2 >( lhs.functor_, rhs.functor_ ),
|
||||
"(" + lhs.desc_ + " || " + rhs.desc_ + ")" );
|
||||
}
|
||||
|
||||
template< typename F1, typename F2 >
|
||||
const placeholder< and_< F1, F2 > >
|
||||
operator&&( const placeholder< F1 >& lhs,
|
||||
const placeholder< F2 >& rhs )
|
||||
{
|
||||
return placeholder< and_< F1, F2 > >(
|
||||
and_< F1, F2 >( lhs.functor_, rhs.functor_ ),
|
||||
"(" + lhs.desc_ + " && " + rhs.desc_ + ")" );
|
||||
}
|
||||
|
||||
template< typename F >
|
||||
const placeholder< not_< F > >
|
||||
operator!( const placeholder< F >& ph )
|
||||
{
|
||||
return placeholder< not_< F > >(
|
||||
not_< F >( ph.functor_ ), "! " + ph.desc_ );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_PLACEHOLDER_HPP_INCLUDED
|
||||
254
src/libraries/turtle/result.hpp
Normal file
254
src/libraries/turtle/result.hpp
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_RESULT_HPP_INCLUDED
|
||||
#define MOCK_RESULT_HPP_INCLUDED
|
||||
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/ref.hpp>
|
||||
#include <memory>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T, typename Signature, typename ErrorPolicy >
|
||||
class result
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
template< typename Value >
|
||||
void returns( Value v )
|
||||
{
|
||||
set( v );
|
||||
}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( !f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
f_ = boost::bind( &throw_exception< Exception >, e );
|
||||
}
|
||||
|
||||
const functor_type& functor() const
|
||||
{
|
||||
if( !f_ )
|
||||
ErrorPolicy::missing_result_specification();
|
||||
return f_;
|
||||
}
|
||||
|
||||
private:
|
||||
void set( T t )
|
||||
{
|
||||
f_ = boost::bind( &return_value, t );
|
||||
}
|
||||
template< typename Y >
|
||||
void set( const boost::reference_wrapper< Y >& t )
|
||||
{
|
||||
f_ = boost::bind( &return_value, t );
|
||||
}
|
||||
|
||||
static T return_value( T t )
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
static T throw_exception( const Exception& e )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
functor_type f_;
|
||||
};
|
||||
|
||||
template< typename T, typename Signature, typename ErrorPolicy >
|
||||
class result< T*, Signature, ErrorPolicy >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
void returns( T* t )
|
||||
{
|
||||
f_ = boost::bind( &return_value, t );
|
||||
}
|
||||
template< typename Y >
|
||||
void returns( const boost::reference_wrapper< Y >& t )
|
||||
{
|
||||
f_ = boost::bind( &return_value, t );
|
||||
}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( !f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
f_ = boost::bind( &throw_exception< Exception >, e );
|
||||
}
|
||||
|
||||
const functor_type& functor() const
|
||||
{
|
||||
if( !f_ )
|
||||
ErrorPolicy::missing_result_specification();
|
||||
return f_;
|
||||
}
|
||||
|
||||
private:
|
||||
static T* return_value( T* t )
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
static T* throw_exception( const Exception& e )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
functor_type f_;
|
||||
};
|
||||
|
||||
template< typename Signature, typename ErrorPolicy >
|
||||
class result< void, Signature, ErrorPolicy >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
result()
|
||||
: f_( boost::bind( ¬hing ) )
|
||||
{}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( !f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
f_ = boost::bind( &throw_exception< Exception >, e );
|
||||
}
|
||||
|
||||
const functor_type& functor() const
|
||||
{
|
||||
return f_;
|
||||
}
|
||||
|
||||
private:
|
||||
static void nothing()
|
||||
{}
|
||||
|
||||
template< typename Exception >
|
||||
static void throw_exception( const Exception& e )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
functor_type f_;
|
||||
};
|
||||
|
||||
template< typename T, typename Signature, typename ErrorPolicy >
|
||||
class result< std::auto_ptr< T >, Signature, ErrorPolicy >
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function< Signature > functor_type;
|
||||
|
||||
public:
|
||||
result()
|
||||
: t_()
|
||||
, f_()
|
||||
{}
|
||||
result( const result& rhs )
|
||||
: t_( const_cast< result& >( rhs ).t_.release() )
|
||||
, f_( t_.get() ? boost::bind( &return_value, boost::ref( t_ ) ) : rhs.f_ )
|
||||
{}
|
||||
|
||||
template< typename Value >
|
||||
void returns( Value v )
|
||||
{
|
||||
set( v );
|
||||
}
|
||||
|
||||
void calls( const functor_type& f )
|
||||
{
|
||||
if( !f )
|
||||
throw std::invalid_argument( "null functor" );
|
||||
f_ = f;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
void throws( Exception e )
|
||||
{
|
||||
f_ = boost::bind( &throw_exception< Exception >, e );
|
||||
t_.reset();
|
||||
}
|
||||
|
||||
const functor_type& functor() const
|
||||
{
|
||||
if( !f_ )
|
||||
ErrorPolicy::missing_result_specification();
|
||||
return f_;
|
||||
}
|
||||
|
||||
private:
|
||||
template< typename Y >
|
||||
void set( std::auto_ptr< Y > t )
|
||||
{
|
||||
t_ = t;
|
||||
f_ = boost::bind( &return_value, boost::ref( t_ ) );
|
||||
}
|
||||
template< typename Y >
|
||||
void set( const boost::reference_wrapper< Y >& t )
|
||||
{
|
||||
f_ = boost::bind( &return_value, t );
|
||||
t_.reset();
|
||||
}
|
||||
template< typename Y >
|
||||
void set( Y* t )
|
||||
{
|
||||
t_.reset( t );
|
||||
f_ = boost::bind( &return_value, boost::ref( t_ ) );
|
||||
}
|
||||
|
||||
static std::auto_ptr< T > return_value( std::auto_ptr< T > t )
|
||||
{
|
||||
return t;
|
||||
}
|
||||
|
||||
template< typename Exception >
|
||||
static std::auto_ptr< T > throw_exception( const Exception& e )
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
mutable std::auto_ptr< T > t_;
|
||||
functor_type f_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_RESULT_HPP_INCLUDED
|
||||
36
src/libraries/turtle/root.hpp
Normal file
36
src/libraries/turtle/root.hpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_ROOT_HPP_INCLUDED
|
||||
#define MOCK_ROOT_HPP_INCLUDED
|
||||
|
||||
#include "node.hpp"
|
||||
#include <boost/test/utils/trivial_singleton.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class root_t : public boost::unit_test::singleton< root_t >, public node
|
||||
{
|
||||
private:
|
||||
virtual void serialize( std::ostream& /*s*/ ) const
|
||||
{}
|
||||
BOOST_TEST_SINGLETON_CONS( root_t );
|
||||
};
|
||||
BOOST_TEST_SINGLETON_INST( root )
|
||||
|
||||
inline bool verify()
|
||||
{
|
||||
return root.verify();
|
||||
}
|
||||
inline void reset()
|
||||
{
|
||||
root.reset();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_ROOT_HPP_INCLUDED
|
||||
83
src/libraries/turtle/sequence.hpp
Normal file
83
src/libraries/turtle/sequence.hpp
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_SEQUENCE_HPP_INCLUDED
|
||||
#define MOCK_SEQUENCE_HPP_INCLUDED
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class sequence;
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class orderable
|
||||
{
|
||||
public:
|
||||
orderable() {}
|
||||
virtual ~orderable() {}
|
||||
|
||||
virtual void remove( sequence& s ) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
class sequence
|
||||
{
|
||||
public:
|
||||
~sequence()
|
||||
{
|
||||
for( elements_it it = elements_.begin();
|
||||
it != elements_.end(); ++it )
|
||||
(*it)->remove( *this );
|
||||
for( elements_it it = called_.begin();
|
||||
it != called_.end(); ++it )
|
||||
(*it)->remove( *this );
|
||||
}
|
||||
|
||||
void add( detail::orderable& e )
|
||||
{
|
||||
elements_.push_back( &e );
|
||||
}
|
||||
void remove( detail::orderable& e )
|
||||
{
|
||||
elements_.erase( std::remove( elements_.begin(),
|
||||
elements_.end(), &e ), elements_.end() );
|
||||
called_.erase( std::remove( called_.begin(),
|
||||
called_.end(), &e ), called_.end() );
|
||||
}
|
||||
|
||||
bool is_valid( const detail::orderable& e ) const
|
||||
{
|
||||
return std::find( called_.begin(), called_.end(), &e )
|
||||
== called_.end();
|
||||
}
|
||||
|
||||
void call( const detail::orderable& e )
|
||||
{
|
||||
elements_it it =
|
||||
std::find( elements_.begin(), elements_.end(), &e );
|
||||
if( it != elements_.end() )
|
||||
{
|
||||
std::copy( elements_.begin(), it,
|
||||
std::back_inserter( called_ ) );
|
||||
elements_.erase( elements_.begin(), it );
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef std::vector< detail::orderable* > elements_type;
|
||||
typedef elements_type::iterator elements_it;
|
||||
|
||||
elements_type elements_;
|
||||
elements_type called_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_SEQUENCE_HPP_INCLUDED
|
||||
156
src/libraries/turtle/tools.hpp
Normal file
156
src/libraries/turtle/tools.hpp
Normal file
|
|
@ -0,0 +1,156 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_TOOLS_HPP_INCLUDED
|
||||
#define MOCK_TOOLS_HPP_INCLUDED
|
||||
|
||||
#include "error.hpp"
|
||||
#include "object.hpp"
|
||||
#include "expectation.hpp"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/preprocessor/cat.hpp>
|
||||
#include <boost/preprocessor/inc.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <boost/preprocessor/seq/push_back.hpp>
|
||||
#include <boost/preprocessor/seq/pop_back.hpp>
|
||||
#include <boost/function_types/result_type.hpp>
|
||||
#include <boost/function_types/parameter_types.hpp>
|
||||
#include <boost/function_types/function_type.hpp>
|
||||
#include <boost/mpl/vector.hpp>
|
||||
#include <boost/mpl/erase.hpp>
|
||||
#include <boost/mpl/insert_range.hpp>
|
||||
#include <boost/mpl/back_inserter.hpp>
|
||||
#define BOOST_TYPEOF_SILENT
|
||||
#include <boost/typeof/typeof.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename T >
|
||||
T& ref( T& t )
|
||||
{
|
||||
return t;
|
||||
}
|
||||
template< typename T >
|
||||
T& ref( T* t )
|
||||
{
|
||||
if( ! t )
|
||||
throw std::invalid_argument( "derefencing null pointer" );
|
||||
return *t;
|
||||
}
|
||||
template< typename T >
|
||||
T& ref( std::auto_ptr< T >& t )
|
||||
{
|
||||
if( ! t.get() )
|
||||
throw std::invalid_argument( "derefencing null pointer" );
|
||||
return *t;
|
||||
}
|
||||
template< typename T >
|
||||
T& ref( boost::shared_ptr< T >& t )
|
||||
{
|
||||
if( ! t.get() )
|
||||
throw std::invalid_argument( "derefencing null pointer" );
|
||||
return *t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MOCK_MIXIN(T) \
|
||||
template< typename U > struct T##_mock_mixin : U \
|
||||
{ \
|
||||
explicit T##_mock_mixin( const std::string& tag = "" ) \
|
||||
{ \
|
||||
mock::object::set_name( BOOST_PP_STRINGIZE(T) + tag ); \
|
||||
} \
|
||||
explicit T##_mock_mixin( mock::node& parent, const std::string& tag = "" ) \
|
||||
{ \
|
||||
mock::object::set_name( BOOST_PP_STRINGIZE(T) + tag ); \
|
||||
mock::node::set_parent( parent ); \
|
||||
} \
|
||||
}; \
|
||||
struct T##_super_class; \
|
||||
typedef T##_mock_mixin< T##_super_class > T;
|
||||
#define MOCK_INTERFACE(T, I) \
|
||||
MOCK_MIXIN(T) \
|
||||
struct T##_typedef { typedef I interface_type; }; \
|
||||
struct T##_super_class : I, mock::object, private T##_typedef
|
||||
#define MOCK_CLASS(T) \
|
||||
MOCK_MIXIN(T) \
|
||||
struct T##_super_class : mock::object
|
||||
|
||||
namespace mock
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template< typename M >
|
||||
struct signature
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function_types::result_type< M >::type result;
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function_types::parameter_types< M >::type parameters;
|
||||
typedef BOOST_DEDUCED_TYPENAME
|
||||
boost::function_types::function_type<
|
||||
BOOST_DEDUCED_TYPENAME boost::mpl::push_front<
|
||||
BOOST_DEDUCED_TYPENAME boost::mpl::pop_front<
|
||||
BOOST_DEDUCED_TYPENAME boost::mpl::copy<
|
||||
parameters,
|
||||
boost::mpl::back_inserter<
|
||||
boost::mpl::vector<>
|
||||
>
|
||||
>::type
|
||||
>::type,
|
||||
result
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#define MOCK_METHOD_ARG(z, n, S) BOOST_PP_COMMA_IF(n) \
|
||||
BOOST_PP_CAT(BOOST_PP_CAT(boost::function< S >::arg, BOOST_PP_INC(n)),_type) \
|
||||
BOOST_PP_CAT(a, BOOST_PP_INC(n))
|
||||
#define MOCK_METHOD_ARGS(n, S) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_METHOD_ARG, S)
|
||||
#define MOCK_MOCKER_ARG(z, n, d) \
|
||||
BOOST_PP_COMMA_IF(n) BOOST_PP_CAT(a, BOOST_PP_INC(n))
|
||||
#define MOCK_MOCKER_ARGS(n, M) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MOCKER_ARG, BOOST_PP_EMPTY)
|
||||
#define MOCK_METHOD_STUB(M, n, S, t, c) \
|
||||
boost::function< S >::result_type M( MOCK_METHOD_ARGS(n, S) ) c \
|
||||
{ \
|
||||
return MOCK_MOCKER(*this, t)( MOCK_MOCKER_ARGS(n, M) ); \
|
||||
}
|
||||
#define MOCK_METHOD_EXPECTATION(S, t) \
|
||||
mutable mock::expectation< S > t##_exp;
|
||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_STUB(M, n, S, t,) \
|
||||
MOCK_METHOD_STUB(M, n, S, t, const) \
|
||||
MOCK_METHOD_EXPECTATION(S, t)
|
||||
#define MOCK_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_STUB(M, n, S, t, const) \
|
||||
MOCK_METHOD_EXPECTATION(S, t)
|
||||
#define MOCK_NON_CONST_METHOD_EXT(M, n, S, t) \
|
||||
MOCK_METHOD_STUB(M, n, S, t,) \
|
||||
MOCK_METHOD_EXPECTATION(S, t)
|
||||
#define MOCK_METHOD(M, n) \
|
||||
MOCK_METHOD_EXT(M, n, MOCK_SIGNATURE(&interface_type::M), M)
|
||||
#define MOCK_SIGNATURE(pM) \
|
||||
mock::detail::signature< BOOST_TYPEOF(pM) >::type
|
||||
#define MOCK_MOCKER(m, t) \
|
||||
mock::detail::ref( m ).t##_exp.set_name( BOOST_PP_STRINGIZE(t) ).set_parent( \
|
||||
const_cast< mock::object& >( dynamic_cast< const mock::object& >( mock::detail::ref( m ) ) ) )
|
||||
|
||||
#define MOCK_EXPECT(m,t) MOCK_MOCKER(m,t).expect( __FILE__, __LINE__ )
|
||||
#define MOCK_RESET(m,t) MOCK_MOCKER(m,t).reset()
|
||||
#define MOCK_VERIFY(m,t) MOCK_MOCKER(m,t).verify()
|
||||
|
||||
#endif // #ifndef MOCK_TOOLS_HPP_INCLUDED
|
||||
30
src/libraries/turtle/verifiable.hpp
Normal file
30
src/libraries/turtle/verifiable.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//
|
||||
// Copyright Mathieu Champlon 2008
|
||||
//
|
||||
// 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_VERIFIABLE_HPP_INCLUDED
|
||||
#define MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace mock
|
||||
{
|
||||
class verifiable : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
verifiable() {}
|
||||
virtual ~verifiable() {}
|
||||
|
||||
// return false if verification fails
|
||||
virtual bool verify() = 0;
|
||||
|
||||
// return to the initial state where calling verify won't throw
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_VERIFIABLE_HPP_INCLUDED
|
||||
Loading…
Add table
Add a link
Reference in a new issue