Removed limitation on the operator() of a custom constraint which was required to be const

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@390 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2011-10-10 22:21:53 +00:00
parent dc27632f66
commit ee338d40bb
4 changed files with 23 additions and 35 deletions

View file

@ -64,7 +64,7 @@ namespace detail
public:
virtual ~check_base() {}
virtual bool operator()( Actual ) const = 0;
virtual bool operator()( Actual ) = 0;
friend std::ostream& operator<<( std::ostream& s, const check_base& c )
{
@ -88,7 +88,7 @@ namespace detail
Actual > ));
}
private:
virtual bool operator()( Actual actual ) const
virtual bool operator()( Actual actual )
{
return actual == boost::unwrap_ref( expected_ );
}
@ -111,7 +111,7 @@ namespace detail
BOOST_CONCEPT_ASSERT(( FunctorCompatible< Constraint, Actual > ));
}
private:
virtual bool operator()( Actual actual ) const
virtual bool operator()( Actual actual )
{
return c_( actual );
}
@ -137,7 +137,7 @@ namespace detail
BOOST_CONCEPT_ASSERT(( FunctorCompatible< Functor, Actual > ));
}
private:
virtual bool operator()( Actual actual ) const
virtual bool operator()( Actual actual )
{
return f_( actual );
}

View file

@ -1,27 +0,0 @@
//
// Copyright Mathieu Champlon 2011
//
// 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)
//
#include <turtle/mock.hpp>
namespace
{
MOCK_CLASS( my_class )
{
MOCK_METHOD_EXT( my_method, 1, void( int ), my_method )
};
struct custom_constraint
{
template< typename Actual >
bool operator()( Actual actual );
};
void test_case()
{
my_class c;
MOCK_EXPECT( c, my_method ).with( mock::constraint< custom_constraint >( custom_constraint() ) );
}
}

View file

@ -413,6 +413,25 @@ BOOST_AUTO_TEST_CASE( using_custom_constraint )
BOOST_CHECK_EQUAL( expected, s.str() );
}
namespace
{
struct custom_constraint_with_non_const_operator
{
template< typename Actual >
bool operator()( Actual actual )
{
return actual == 42;
}
};
}
BOOST_AUTO_TEST_CASE( custom_constraint_function_operator_does_not_need_to_be_const )
{
MOCK_FUNCTOR( void( float ) ) f;
MOCK_EXPECT( f, _ ).with( mock::constraint< custom_constraint_with_non_const_operator >( custom_constraint_with_non_const_operator() ) );
f( 42 );
}
BOOST_AUTO_TEST_CASE( boost_reference_wrapper_is_supported_in_value_constraint )
{
MOCK_FUNCTOR( void( const std::string& ) ) f;