diff --git a/build/vc100/turtle.vcxproj b/build/vc100/turtle.vcxproj index cb19bc6..b53cd31 100644 --- a/build/vc100/turtle.vcxproj +++ b/build/vc100/turtle.vcxproj @@ -23,7 +23,6 @@ - @@ -39,6 +38,7 @@ + @@ -51,6 +51,7 @@ + diff --git a/build/vc100/turtle.vcxproj.filters b/build/vc100/turtle.vcxproj.filters index aec3090..f4eff3e 100644 --- a/build/vc100/turtle.vcxproj.filters +++ b/build/vc100/turtle.vcxproj.filters @@ -67,9 +67,6 @@ Source Files\detail - - Source Files\detail - Source Files\detail @@ -124,5 +121,11 @@ Source Files\detail + + Source Files + + + Source Files\detail + \ No newline at end of file diff --git a/build/vc100/turtle_test.vcxproj b/build/vc100/turtle_test.vcxproj index 0b1bc7e..44721cc 100644 --- a/build/vc100/turtle_test.vcxproj +++ b/build/vc100/turtle_test.vcxproj @@ -22,7 +22,6 @@ - @@ -32,6 +31,7 @@ + diff --git a/build/vc100/turtle_test.vcxproj.filters b/build/vc100/turtle_test.vcxproj.filters index a0f662a..5a0a82d 100644 --- a/build/vc100/turtle_test.vcxproj.filters +++ b/build/vc100/turtle_test.vcxproj.filters @@ -54,8 +54,8 @@ Source Files\detail - - Source Files\detail + + Source Files \ No newline at end of file diff --git a/test/detail/test_check.cpp b/test/test_matcher.cpp similarity index 62% rename from test/detail/test_check.cpp rename to test/test_matcher.cpp index 107b532..607e60b 100644 --- a/test/detail/test_check.cpp +++ b/test/test_matcher.cpp @@ -6,29 +6,29 @@ // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#include +#include #include namespace { template< typename Expected, typename Actual > - bool check( Expected expected, Actual actual ) + bool match( Expected expected, Actual actual ) { - return mock::detail::check< Actual, Expected >( expected )( actual ); + return mock::matcher< Actual, Expected >( expected )( actual ); } } BOOST_AUTO_TEST_CASE( int_and_int_can_be_compared ) { - BOOST_CHECK( check( 3, 3 ) ); - BOOST_CHECK( ! check( 3, 4 ) ); - BOOST_CHECK( ! check( 4, 3 ) ); + BOOST_CHECK( match( 3, 3 ) ); + BOOST_CHECK( ! match( 3, 4 ) ); + BOOST_CHECK( ! match( 4, 3 ) ); } BOOST_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared ) { - BOOST_CHECK( check( 3, boost::cref( 3 ) ) ); - BOOST_CHECK( ! check( 4, boost::cref( 3 ) ) ); + BOOST_CHECK( match( 3, boost::cref( 3 ) ) ); + BOOST_CHECK( ! match( 4, boost::cref( 3 ) ) ); } namespace @@ -51,27 +51,27 @@ namespace BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_pointer_can_be_compared, fixture ) { const char* expected = "same text"; - BOOST_CHECK( check( expected, actual ) ); + BOOST_CHECK( match( expected, actual ) ); const char* unexpected = "different text"; - BOOST_CHECK( ! check( actual, unexpected ) ); + BOOST_CHECK( ! match( actual, unexpected ) ); } BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_string_literal_can_be_compared, fixture ) { - BOOST_CHECK( check( "same text", actual ) ); - BOOST_CHECK( ! check( "different text", actual ) ); + BOOST_CHECK( match( "same text", actual ) ); + BOOST_CHECK( ! match( "different text", actual ) ); } BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_const_char_array_can_be_compared, fixture ) { const char expected[10] = "same text"; - BOOST_CHECK( check( expected, actual ) ); + BOOST_CHECK( match( expected, actual ) ); const char unexpected[15] = "different text"; - BOOST_CHECK( ! check( unexpected, actual ) ); + BOOST_CHECK( ! match( unexpected, actual ) ); } BOOST_FIXTURE_TEST_CASE( const_char_pointer_and_std_string_can_be_compared, fixture ) { - BOOST_CHECK( check( std::string( "same text" ), actual ) ); - BOOST_CHECK( ! check( std::string( "different text" ), actual ) ); + BOOST_CHECK( match( std::string( "same text" ), actual ) ); + BOOST_CHECK( ! match( std::string( "different text" ), actual ) ); } diff --git a/turtle/detail/expectation_template.hpp b/turtle/detail/expectation_template.hpp index b759fc5..880b19c 100644 --- a/turtle/detail/expectation_template.hpp +++ b/turtle/detail/expectation_template.hpp @@ -11,13 +11,13 @@ #define MOCK_EXPECTATION_INITIALIZE(z, n, d) \ BOOST_PP_COMMA_IF(n) c##n##_( \ - new check< arg##n##_type, constraint< any > >( mock::any ) ) + new matcher< arg##n##_type, constraint< any > >( mock::any ) ) #define MOCK_EXPECTATION_WITH(z, n, d) \ - c##n##_.reset( new check< arg##n##_type, Constraint_##n >( c##n ) ); + c##n##_.reset( new matcher< arg##n##_type, Constraint_##n >( c##n ) ); #define MOCK_EXPECTATION_MEMBER(z, n, d) \ - boost::shared_ptr< check_base< arg##n##_type > > c##n##_; + boost::shared_ptr< matcher_base< arg##n##_type > > c##n##_; #define MOCK_EXPECTATION_ARGS(z, n, d) \ BOOST_PP_COMMA_IF(n) arg##n##_type a##n diff --git a/turtle/detail/function.hpp b/turtle/detail/function.hpp index ec2339e..f286694 100644 --- a/turtle/detail/function.hpp +++ b/turtle/detail/function.hpp @@ -13,7 +13,7 @@ #include "../error.hpp" #include "../log.hpp" #include "../constraints.hpp" -#include "check.hpp" +#include "../matcher.hpp" #include "action.hpp" #include "verifiable.hpp" #include "type_name.hpp" diff --git a/turtle/detail/matcher_base.hpp b/turtle/detail/matcher_base.hpp new file mode 100644 index 0000000..7ed24fc --- /dev/null +++ b/turtle/detail/matcher_base.hpp @@ -0,0 +1,38 @@ +// 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_MATCHER_BASE_HPP_INCLUDED +#define MOCK_MATCHER_BASE_HPP_INCLUDED + +#include +#include + +namespace mock +{ +namespace detail +{ + template< typename Actual > + class matcher_base : boost::noncopyable + { + public: + virtual ~matcher_base() {} + + virtual bool operator()( Actual ) = 0; + + friend std::ostream& operator<<( std::ostream& s, const matcher_base& c ) + { + c.serialize( s ); + return s; + } + private: + virtual void serialize( std::ostream& ) const = 0; + }; +} +} // mock + +#endif // MOCK_MATCHER_BASE_HPP_INCLUDED diff --git a/turtle/detail/check.hpp b/turtle/matcher.hpp similarity index 61% rename from turtle/detail/check.hpp rename to turtle/matcher.hpp index 0691ded..53a4802 100644 --- a/turtle/detail/check.hpp +++ b/turtle/matcher.hpp @@ -6,43 +6,24 @@ // (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 +#ifndef MOCK_MATCHER_HPP_INCLUDED +#define MOCK_MATCHER_HPP_INCLUDED -#include "is_functor.hpp" -#include "../log.hpp" -#include "../constraint.hpp" +#include "log.hpp" +#include "constraint.hpp" +#include "detail/is_functor.hpp" +#include "detail/matcher_base.hpp" #include -#include #include #include 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 > + class matcher : public detail::matcher_base< Actual > { public: - explicit check( Expected expected ) + explicit matcher( Expected expected ) : expected_( expected ) {} virtual bool operator()( Actual actual ) @@ -59,10 +40,11 @@ namespace detail }; template<> - class check< const char*, const char* > : public check_base< const char* > + class matcher< const char*, const char* > + : public detail::matcher_base< const char* > { public: - explicit check( const char* expected ) + explicit matcher( const char* expected ) : expected_( expected ) {} virtual bool operator()( const char* actual ) @@ -79,11 +61,11 @@ namespace detail }; template< typename Actual, typename Constraint > - class check< Actual, mock::constraint< Constraint > > - : public check_base< Actual > + class matcher< Actual, mock::constraint< Constraint > > + : public detail::matcher_base< Actual > { public: - explicit check( const constraint< Constraint >& c ) + explicit matcher( const constraint< Constraint >& c ) : c_( c.f_ ) {} virtual bool operator()( Actual actual ) @@ -100,14 +82,14 @@ namespace detail }; template< typename Actual, typename Functor > - class check< Actual, Functor, + class matcher< Actual, Functor, BOOST_DEDUCED_TYPENAME boost::enable_if< - is_functor< Functor > + detail::is_functor< Functor > >::type - > : public check_base< Actual > + > : public detail::matcher_base< Actual > { public: - explicit check( const Functor& f ) + explicit matcher( const Functor& f ) : f_( f ) {} virtual bool operator()( Actual actual ) @@ -122,7 +104,6 @@ namespace detail private: Functor f_; }; -} } // mock -#endif // MOCK_CHECK_HPP_INCLUDED +#endif // MOCK_MATCHER_HPP_INCLUDED