From 77a99b8893c2868dc5e1206f31f27738e0528490 Mon Sep 17 00:00:00 2001 From: mat007 Date: Sat, 1 Sep 2012 17:22:19 +0000 Subject: [PATCH] Added tests for mock::detail::check git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@544 860be788-9bd5-4423-9f1e-828f051e677b --- build/vc100/turtle_test.vcxproj | 1 + build/vc100/turtle_test.vcxproj.filters | 3 +++ test/detail/test_check.cpp | 32 +++++++++++++++++++++++++ turtle/detail/check.hpp | 6 ++--- 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/detail/test_check.cpp diff --git a/build/vc100/turtle_test.vcxproj b/build/vc100/turtle_test.vcxproj index c92c1d5..0b1bc7e 100644 --- a/build/vc100/turtle_test.vcxproj +++ b/build/vc100/turtle_test.vcxproj @@ -22,6 +22,7 @@ + diff --git a/build/vc100/turtle_test.vcxproj.filters b/build/vc100/turtle_test.vcxproj.filters index d759aa9..a0f662a 100644 --- a/build/vc100/turtle_test.vcxproj.filters +++ b/build/vc100/turtle_test.vcxproj.filters @@ -54,5 +54,8 @@ Source Files\detail + + Source Files\detail + \ No newline at end of file diff --git a/test/detail/test_check.cpp b/test/detail/test_check.cpp new file mode 100644 index 0000000..a4250c6 --- /dev/null +++ b/test/detail/test_check.cpp @@ -0,0 +1,32 @@ +// 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) + +#include +#include + +namespace +{ + template< typename Expected, typename Actual > + bool check( Expected expected, Actual actual ) + { + return mock::detail::check< Expected, Actual >( 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_AUTO_TEST_CASE( ref_to_int_and_int_can_be_compared ) +{ + BOOST_CHECK( check< int >( boost::cref( 3 ), 3 ) ); + BOOST_CHECK( ! check< int >( boost::cref( 3 ), 4 ) ); +} diff --git a/turtle/detail/check.hpp b/turtle/detail/check.hpp index 6fd462a..55f6054 100644 --- a/turtle/detail/check.hpp +++ b/turtle/detail/check.hpp @@ -44,11 +44,11 @@ namespace detail explicit check( Expected expected ) : expected_( expected ) {} - private: virtual bool operator()( Actual actual ) { return actual == boost::unwrap_ref( expected_ ); } + private: virtual void serialize( std::ostream& s ) const { s << mock::format( expected_ ); @@ -65,11 +65,11 @@ namespace detail explicit check( const constraint< Constraint >& c ) : c_( c.f_ ) {} - private: virtual bool operator()( Actual actual ) { return c_( actual ); } + private: virtual void serialize( std::ostream& s ) const { s << mock::format( c_ ); @@ -89,11 +89,11 @@ namespace detail explicit check( const Functor& f ) : f_( f ) {} - private: virtual bool operator()( Actual actual ) { return f_( actual ); } + private: virtual void serialize( std::ostream& s ) const { s << mock::format( f_ );