mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Refactoring
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@132 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
fb4df4527b
commit
a21b3d2c2f
4 changed files with 59 additions and 54 deletions
|
|
@ -6,8 +6,8 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef MOCK_MATCHER_HPP_INCLUDED
|
||||
#define MOCK_MATCHER_HPP_INCLUDED
|
||||
#ifndef MOCK_EXPECTATION_HPP_INCLUDED
|
||||
#define MOCK_EXPECTATION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "invocation.hpp"
|
||||
|
|
@ -106,49 +106,49 @@ namespace detail
|
|||
};
|
||||
|
||||
template< typename Result, typename Signature, int >
|
||||
class matcher
|
||||
class expectation
|
||||
{
|
||||
};
|
||||
|
||||
#define MOCK_MATCHER_METHODS \
|
||||
matcher& in( sequence& s ) \
|
||||
#define MOCK_EXPECTATION_METHODS \
|
||||
expectation& in( sequence& s ) \
|
||||
{ \
|
||||
add( s ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& once() \
|
||||
expectation& once() \
|
||||
{ \
|
||||
expect( new detail::once() ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& never() \
|
||||
expectation& never() \
|
||||
{ \
|
||||
expect( new detail::never() ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& exactly( std::size_t count ) \
|
||||
expectation& exactly( std::size_t count ) \
|
||||
{ \
|
||||
expect( new detail::exactly( count ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& at_least( std::size_t min ) \
|
||||
expectation& at_least( std::size_t min ) \
|
||||
{ \
|
||||
expect( new detail::at_least( min ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& at_most( std::size_t max ) \
|
||||
expectation& at_most( std::size_t max ) \
|
||||
{ \
|
||||
expect( new detail::at_most( max ) ); \
|
||||
return *this; \
|
||||
} \
|
||||
matcher& between( std::size_t min, std::size_t max ) \
|
||||
expectation& between( std::size_t min, std::size_t max ) \
|
||||
{ \
|
||||
expect( new detail::between( min, max ) ); \
|
||||
return *this; \
|
||||
}
|
||||
|
||||
template< typename Result, typename Signature >
|
||||
class matcher< Result, Signature, 0 >
|
||||
class expectation< Result, Signature, 0 >
|
||||
: public matcher_base, public action< Result, Signature >
|
||||
{
|
||||
public:
|
||||
|
|
@ -157,15 +157,15 @@ namespace detail
|
|||
return i_->is_valid();
|
||||
}
|
||||
|
||||
MOCK_MATCHER_METHODS
|
||||
MOCK_EXPECTATION_METHODS
|
||||
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m )
|
||||
friend std::ostream& operator<<( std::ostream& s, const expectation& m )
|
||||
{
|
||||
return s << (m.i_->is_valid() ? '.' : 'v') << ' ' << *m.i_;
|
||||
}
|
||||
};
|
||||
|
||||
#define MOCK_MATCHER_TYPEDEF(z, n, d) \
|
||||
#define MOCK_EXPECTATION_TYPEDEF(z, n, d) \
|
||||
typedef BOOST_DEDUCED_TYPENAME \
|
||||
boost::mpl::at_c< \
|
||||
BOOST_DEDUCED_TYPENAME \
|
||||
|
|
@ -173,57 +173,57 @@ namespace detail
|
|||
n \
|
||||
>::type arg##n##_type; \
|
||||
typedef detail::check< arg##n##_type > constraint##n##_type;
|
||||
#define MOCK_MATCHER_CONSTRUCTOR(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_( mock::any )
|
||||
#define MOCK_MATCHER_WITH(z, n, d) c##n##_ = constraint##n##_type( c##n );
|
||||
#define MOCK_MATCHER_MEMBER(z, n, d) constraint##n##_type c##n##_;
|
||||
#define MOCK_MATCHER_ARGS(z, n, d) BOOST_PP_COMMA_IF(n) arg##n##_type a##n
|
||||
#define MOCK_MATCHER_IS_VALID(z, n, d) && c##n##_( a##n )
|
||||
#define MOCK_MATCHER_SERIALIZE(z, n, d) BOOST_PP_IF(n, << ", " <<,) m.c##n##_
|
||||
#define MOCK_MATCHER(z, n, d) \
|
||||
#define MOCK_EXPECTATION_CONSTRUCTOR(z, n, d) BOOST_PP_COMMA_IF(n) c##n##_( mock::any )
|
||||
#define MOCK_EXPECTATION_WITH(z, n, d) c##n##_ = constraint##n##_type( c##n );
|
||||
#define MOCK_EXPECTATION_MEMBER(z, n, d) constraint##n##_type c##n##_;
|
||||
#define MOCK_EXPECTATION_ARGS(z, n, d) BOOST_PP_COMMA_IF(n) arg##n##_type a##n
|
||||
#define MOCK_EXPECTATION_IS_VALID(z, n, d) && c##n##_( a##n )
|
||||
#define MOCK_EXPECTATION_SERIALIZE(z, n, d) BOOST_PP_IF(n, << ", " <<,) m.c##n##_
|
||||
#define MOCK_EXPECTATION(z, n, d) \
|
||||
template< typename Result, typename Signature > \
|
||||
class matcher< Result, Signature, n > \
|
||||
class expectation< Result, Signature, n > \
|
||||
: public matcher_base, public action< Result, Signature > \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_TYPEDEF, BOOST_PP_EMPTY) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_TYPEDEF, BOOST_PP_EMPTY) \
|
||||
public: \
|
||||
matcher() \
|
||||
: BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_CONSTRUCTOR, BOOST_PP_EMPTY) \
|
||||
expectation() \
|
||||
: BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_CONSTRUCTOR, BOOST_PP_EMPTY) \
|
||||
{} \
|
||||
template< BOOST_PP_ENUM_PARAMS(n, typename C) > \
|
||||
matcher& with( BOOST_PP_ENUM_BINARY_PARAMS(n, const C, & c) ) \
|
||||
expectation& with( BOOST_PP_ENUM_BINARY_PARAMS(n, const C, & c) ) \
|
||||
{ \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_WITH, BOOST_PP_EMPTY) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_WITH, BOOST_PP_EMPTY) \
|
||||
return *this; \
|
||||
} \
|
||||
bool is_valid( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_ARGS, BOOST_PP_EMPTY) ) const \
|
||||
bool is_valid( BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_ARGS, BOOST_PP_EMPTY) ) const \
|
||||
{ \
|
||||
return i_->is_valid() \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_IS_VALID, BOOST_PP_EMPTY); \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_IS_VALID, BOOST_PP_EMPTY); \
|
||||
} \
|
||||
MOCK_MATCHER_METHODS \
|
||||
friend std::ostream& operator<<( std::ostream& s, const matcher& m ) \
|
||||
MOCK_EXPECTATION_METHODS \
|
||||
friend std::ostream& operator<<( std::ostream& s, const expectation& m ) \
|
||||
{ \
|
||||
return s << (m.i_->is_valid() ? '.' : 'v') << ' ' << *m.i_ << ".with( " \
|
||||
<< \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_SERIALIZE, BOOST_PP_EMPTY) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_SERIALIZE, BOOST_PP_EMPTY) \
|
||||
<< " )"; \
|
||||
} \
|
||||
private: \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_MATCHER_MEMBER, BOOST_PP_EMPTY) \
|
||||
BOOST_PP_REPEAT_FROM_TO(0, n, MOCK_EXPECTATION_MEMBER, BOOST_PP_EMPTY) \
|
||||
};
|
||||
BOOST_PP_REPEAT_FROM_TO(1, MOCK_NUM_ARGS, MOCK_MATCHER, BOOST_PP_EMPTY)
|
||||
BOOST_PP_REPEAT_FROM_TO(1, MOCK_NUM_ARGS, MOCK_EXPECTATION, BOOST_PP_EMPTY)
|
||||
|
||||
#undef MOCK_MATCHER_METHODS
|
||||
#undef MOCK_MATCHER_TYPEDEF
|
||||
#undef MOCK_MATCHER_CONSTRUCTOR
|
||||
#undef MOCK_MATCHER_WITH
|
||||
#undef MOCK_MATCHER_MEMBER
|
||||
#undef MOCK_MATCHER_ARGS
|
||||
#undef MOCK_MATCHER_IS_VALID
|
||||
#undef MOCK_MATCHER_SERIALIZE
|
||||
#undef MOCK_MATCHER
|
||||
#undef MOCK_EXPECTATION_METHODS
|
||||
#undef MOCK_EXPECTATION_TYPEDEF
|
||||
#undef MOCK_EXPECTATION_CONSTRUCTOR
|
||||
#undef MOCK_EXPECTATION_WITH
|
||||
#undef MOCK_EXPECTATION_MEMBER
|
||||
#undef MOCK_EXPECTATION_ARGS
|
||||
#undef MOCK_EXPECTATION_IS_VALID
|
||||
#undef MOCK_EXPECTATION_SERIALIZE
|
||||
#undef MOCK_EXPECTATION
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_MATCHER_HPP_INCLUDED
|
||||
#endif // #ifndef MOCK_EXPECTATION_HPP_INCLUDED
|
||||
|
|
@ -6,13 +6,13 @@
|
|||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#ifndef MOCK_EXPECTATION_HPP_INCLUDED
|
||||
#define MOCK_EXPECTATION_HPP_INCLUDED
|
||||
#ifndef MOCK_FUNCTION_HPP_INCLUDED
|
||||
#define MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
||||
#include "config.hpp"
|
||||
#include "error.hpp"
|
||||
#include "verifiable.hpp"
|
||||
#include "matcher.hpp"
|
||||
#include "expectation.hpp"
|
||||
#include "node.hpp"
|
||||
#include "root.hpp"
|
||||
#include "format.hpp"
|
||||
|
|
@ -51,7 +51,7 @@ namespace mock
|
|||
};
|
||||
|
||||
private:
|
||||
typedef detail::matcher< result_type, Signature, arity::value > matcher_type;
|
||||
typedef detail::expectation< result_type, Signature, arity::value > matcher_type;
|
||||
|
||||
public:
|
||||
struct expectation_tag
|
||||
|
|
@ -305,4 +305,4 @@ namespace mock
|
|||
};
|
||||
}
|
||||
|
||||
#endif // #ifndef MOCK_EXPECTATION_HPP_INCLUDED
|
||||
#endif // #ifndef MOCK_FUNCTION_HPP_INCLUDED
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ namespace
|
|||
{
|
||||
MOCK_METHOD_EXT( my_method, 1, int( int ), my_method )
|
||||
};
|
||||
|
||||
void f() {}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( basic_mock_object_usage )
|
||||
|
|
@ -64,6 +66,9 @@ BOOST_AUTO_TEST_CASE( basic_mock_object_usage )
|
|||
BOOST_CHECK_EQUAL( 0, m.my_method( 13 ) );
|
||||
mock::verify();
|
||||
mock::reset();
|
||||
// MOCK_EXPECT( m, my_method ).once().with( &f ).returns( 7 );
|
||||
// MOCK_EXPECT( m, my_method ).once().with( mock::equal( "" ) ).returns( 7 );
|
||||
// MOCK_EXPECT( m, my_method ).once().with( "" ).returns( 7 );
|
||||
MOCK_EXPECT( m, my_method ).once().with( 42 ).returns( 7 );
|
||||
BOOST_CHECK_EQUAL( 7, m.my_method( 42 ) );
|
||||
mock::verify();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue