Renamed mock::detail::check to mock::matcher

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@567 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2012-09-21 22:19:52 +00:00
parent 3e3746dce5
commit a84c66c714
9 changed files with 88 additions and 65 deletions

View file

@ -23,7 +23,6 @@
<ClInclude Include="..\..\turtle\constraint.hpp" />
<ClInclude Include="..\..\turtle\constraints.hpp" />
<ClInclude Include="..\..\turtle\detail\action.hpp" />
<ClInclude Include="..\..\turtle\detail\check.hpp" />
<ClInclude Include="..\..\turtle\detail\child.hpp" />
<ClInclude Include="..\..\turtle\detail\cleanup.hpp" />
<ClInclude Include="..\..\turtle\detail\context.hpp" />
@ -39,6 +38,7 @@
<ClInclude Include="..\..\turtle\detail\invocation.hpp" />
<ClInclude Include="..\..\turtle\detail\is_functor.hpp" />
<ClInclude Include="..\..\turtle\detail\lambda.hpp" />
<ClInclude Include="..\..\turtle\detail\matcher_base.hpp" />
<ClInclude Include="..\..\turtle\detail\object_impl.hpp" />
<ClInclude Include="..\..\turtle\detail\parameter.hpp" />
<ClInclude Include="..\..\turtle\detail\parent.hpp" />
@ -51,6 +51,7 @@
<ClInclude Include="..\..\turtle\error.hpp" />
<ClInclude Include="..\..\turtle\format.hpp" />
<ClInclude Include="..\..\turtle\log.hpp" />
<ClInclude Include="..\..\turtle\matcher.hpp" />
<ClInclude Include="..\..\turtle\mock.hpp" />
<ClInclude Include="..\..\turtle\object.hpp" />
<ClInclude Include="..\..\turtle\reset.hpp" />

View file

@ -67,9 +67,6 @@
<ClInclude Include="..\..\turtle\detail\action.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\check.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\expectation_template.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
@ -124,5 +121,11 @@
<ClInclude Include="..\..\turtle\detail\cleanup.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\matcher.hpp">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\turtle\detail\matcher_base.hpp">
<Filter>Source Files\detail</Filter>
</ClInclude>
</ItemGroup>
</Project>

View file

@ -22,7 +22,6 @@
<ClInclude Include="..\..\test\mock_error.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\test\detail\test_check.cpp" />
<ClCompile Include="..\..\test\detail\test_function.cpp" />
<ClCompile Include="..\..\test\detail\test_invocation.cpp" />
<ClCompile Include="..\..\test\detail\test_is_functor.cpp" />
@ -32,6 +31,7 @@
<ClCompile Include="..\..\test\test_error.cpp" />
<ClCompile Include="..\..\test\test_integration.cpp" />
<ClCompile Include="..\..\test\test_log.cpp" />
<ClCompile Include="..\..\test\test_matcher.cpp" />
<ClCompile Include="..\..\test\test_max_args.cpp" />
<ClCompile Include="..\..\test\test_mock.cpp" />
<ClCompile Include="..\..\test\test_object.cpp" />

View file

@ -54,8 +54,8 @@
<ClCompile Include="..\..\test\detail\test_is_functor.cpp">
<Filter>Source Files\detail</Filter>
</ClCompile>
<ClCompile Include="..\..\test\detail\test_check.cpp">
<Filter>Source Files\detail</Filter>
<ClCompile Include="..\..\test\test_matcher.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View file

@ -6,29 +6,29 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include <turtle/detail/check.hpp>
#include <turtle/matcher.hpp>
#include <boost/test/auto_unit_test.hpp>
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 ) );
}

View file

@ -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

View file

@ -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"

View file

@ -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 <boost/noncopyable.hpp>
#include <iosfwd>
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

View file

@ -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 <boost/utility/enable_if.hpp>
#include <boost/noncopyable.hpp>
#include <boost/ref.hpp>
#include <cstring>
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