turtle/turtle/detail/check.hpp
mat007 8cdf6f5934 Cleanup
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@498 860be788-9bd5-4423-9f1e-828f051e677b
2012-07-22 07:07:47 +00:00

107 lines
2.7 KiB
C++

// http://turtle.sourceforge.net
//
// 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 "operators.hpp"
#include "../log.hpp"
#include "../is_functor.hpp"
#include <boost/utility/enable_if.hpp>
#include <boost/noncopyable.hpp>
#include <boost/ref.hpp>
namespace mock
{
namespace detail
{
template< typename Actual >
class check_base : boost::noncopyable
{
public:
virtual ~check_base() {}
virtual bool operator()( Actual ) = 0;
friend std::ostream& operator<<( std::ostream& s, const check_base& c )
{
c.serialize( s );
return s;
}
private:
virtual void serialize( std::ostream& ) const = 0;
};
template< typename Actual, typename Expected, typename Enable = void >
class check : public check_base< Actual >
{
public:
explicit check( Expected expected )
: expected_( expected )
{}
private:
virtual bool operator()( Actual actual )
{
return actual == boost::unwrap_ref( expected_ );
}
virtual void serialize( std::ostream& s ) const
{
s << mock::format( expected_ );
}
private:
Expected expected_;
};
template< typename Actual, typename Constraint >
class check< Actual, mock::constraint< Constraint > >
: public check_base< Actual >
{
public:
explicit check( const constraint< Constraint >& c )
: c_( c.f_ )
{}
private:
virtual bool operator()( Actual actual )
{
return c_( actual );
}
virtual void serialize( std::ostream& s ) const
{
s << mock::format( c_ );
}
private:
Constraint c_;
};
template< typename Actual, typename Functor >
class check< Actual, Functor,
BOOST_DEDUCED_TYPENAME boost::enable_if<
is_functor< Functor >
>::type
> : public check_base< Actual >
{
public:
explicit check( const Functor& f )
: f_( f )
{}
private:
virtual bool operator()( Actual actual )
{
return f_( actual );
}
virtual void serialize( std::ostream& s ) const
{
s << mock::format( f_ );
}
private:
Functor f_;
};
}
} // mock
#endif // MOCK_CHECK_HPP_INCLUDED