From ee338d40bbc56d500efc3a42baba713bcbfad3f4 Mon Sep 17 00:00:00 2001 From: mat007 Date: Mon, 10 Oct 2011 22:21:53 +0000 Subject: [PATCH] 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 --- build/vc80/errors_test.vcproj | 4 --- src/libraries/turtle/check.hpp | 8 +++--- ...tom_constraint_call_operator_not_const.cpp | 27 ------------------- src/tests/turtle_test/integration_test.cpp | 19 +++++++++++++ 4 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 src/tests/errors_test/custom_constraint_call_operator_not_const.cpp diff --git a/build/vc80/errors_test.vcproj b/build/vc80/errors_test.vcproj index b273c26..4d8a3d6 100644 --- a/build/vc80/errors_test.vcproj +++ b/build/vc80/errors_test.vcproj @@ -206,10 +206,6 @@ RelativePath="..\..\src\tests\errors_test\constraint_value_of_wrong_type_in_builtin_constraint.cpp" > - - diff --git a/src/libraries/turtle/check.hpp b/src/libraries/turtle/check.hpp index fb35cd6..12a336f 100644 --- a/src/libraries/turtle/check.hpp +++ b/src/libraries/turtle/check.hpp @@ -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 ); } diff --git a/src/tests/errors_test/custom_constraint_call_operator_not_const.cpp b/src/tests/errors_test/custom_constraint_call_operator_not_const.cpp deleted file mode 100644 index add1ca4..0000000 --- a/src/tests/errors_test/custom_constraint_call_operator_not_const.cpp +++ /dev/null @@ -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 - -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() ) ); - } -} diff --git a/src/tests/turtle_test/integration_test.cpp b/src/tests/turtle_test/integration_test.cpp index f226401..7183008 100644 --- a/src/tests/turtle_test/integration_test.cpp +++ b/src/tests/turtle_test/integration_test.cpp @@ -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;