Added round parenthesis support in function signatures

git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@600 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
mat007 2013-03-07 07:17:02 +00:00
parent 68ae1ada45
commit 6491d11d19
2 changed files with 35 additions and 14 deletions

View file

@ -291,6 +291,17 @@ BOOST_AUTO_TEST_CASE( mock_static_function_is_named )
BOOST_CHECK_EQUAL( "static_function_class::f", to_string( MOCK_HELPER( static_function_class::f ) ) );
}
namespace
{
MOCK_CLASS( round_parenthesized_signature )
{
MOCK_METHOD_EXT( m0, 0, (std::map< int, int >()), m0 )
MOCK_STATIC_METHOD( m1, 0, (std::map< int, int >()), m1 )
MOCK_FUNCTOR( f0, (std::map< int, int >()) );
};
MOCK_FUNCTION( fun0, 0, (std::map< int, int >()), fun0 )
}
#ifndef BOOST_NO_VARIADIC_MACROS
namespace
@ -315,9 +326,6 @@ namespace
MOCK_STATIC_METHOD( m9, 0, void(), m9 )
};
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
{};
template< typename T >
MOCK_CLASS( variadic_tpl )
{
@ -331,8 +339,12 @@ namespace
MOCK_STATIC_METHOD_TPL( m9, 0, T(), m9 )
};
MOCK_BASE_CLASS( comma_base, std::map< int, int > )
{};
MOCK_FUNCTION( fun1, 0, void() )
MOCK_FUNCTION( fun2, 0, void(), fun2 )
MOCK_FUNCTION( fun3, 0, (std::map< int, int >()) )
MOCK_FUNCTOR( f_variadic, std::map< int, int >() );
}

View file

@ -21,8 +21,13 @@
#include "detail/cleanup.hpp"
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/utility/identity_type.hpp>
#include <boost/mpl/assert.hpp>
#define MOCK_FUNCTION_TYPE(S) \
BOOST_DEDUCED_TYPENAME boost::remove_pointer< \
BOOST_DEDUCED_TYPENAME BOOST_IDENTITY_TYPE((S)) >::type
#define MOCK_CLASS(T) \
struct T : mock::object
@ -31,14 +36,14 @@
#define MOCK_BASE_CLASS(T, I) \
struct T : I, mock::object, mock::detail::base< I >
#define MOCK_FUNCTOR(f, S) \
mock::detail::functor< S > f, f##_mock
mock::detail::functor< MOCK_FUNCTION_TYPE(S) > f, f##_mock
#else // BOOST_NO_VARIADIC_MACROS
#define MOCK_BASE_CLASS(T, ...) \
struct T : __VA_ARGS__, mock::object, mock::detail::base< __VA_ARGS__ >
#define MOCK_FUNCTOR(f, ...) \
mock::detail::functor< __VA_ARGS__ > f, f##_mock
mock::detail::functor< MOCK_FUNCTION_TYPE((__VA_ARGS__)) > f, f##_mock
#endif // BOOST_NO_VARIADIC_MACROS
@ -48,8 +53,8 @@
t##_mock( mock::detail::root, "?." )
#define MOCK_METHOD_HELPER(S, t) \
mutable mock::detail::function< S > t##_mock_; \
mock::detail::function< S >& t##_mock( \
mutable mock::detail::function< MOCK_FUNCTION_TYPE(S) > t##_mock_; \
mock::detail::function< MOCK_FUNCTION_TYPE(S) >& t##_mock( \
const mock::detail::context&, \
boost::unit_test::const_string instance ) const \
{ \
@ -63,16 +68,19 @@
#define MOCK_PARAM(z, n, d) \
BOOST_PP_COMMA_IF(n) d, n >::type p##n
#define MOCK_PARAMS(n, S, tpn) \
BOOST_PP_REPEAT(n, MOCK_PARAM, tpn mock::detail::parameter< S)
BOOST_PP_REPEAT(n, MOCK_PARAM, \
tpn mock::detail::parameter< MOCK_FUNCTION_TYPE(S))
#define MOCK_DECL(M, n, S, c, tpn) \
tpn boost::function_types::result_type< S >::type M( \
MOCK_PARAMS(n, S, tpn) ) c
tpn boost::function_types::result_type< \
MOCK_FUNCTION_TYPE(S) >::type M( \
MOCK_PARAMS(n, S, tpn) ) c
#define MOCK_METHOD_AUX(M, n, S, t, c, tpn) \
MOCK_DECL(M, n, S, c, tpn) \
{ \
BOOST_MPL_ASSERT_RELATION( n, ==, \
boost::function_types::function_arity< S >::value ); \
boost::function_types::function_arity< \
MOCK_FUNCTION_TYPE(S) >::value ); \
return MOCK_ANONYMOUS_HELPER(t)( \
BOOST_PP_ENUM_PARAMS(n, p) ); \
}
@ -111,11 +119,11 @@
MOCK_METHOD_HELPER(T(), t)
#define MOCK_FUNCTION_HELPER(S, t, s) \
s mock::detail::function< S >& t##_mock( \
s mock::detail::function< MOCK_FUNCTION_TYPE(S) >& t##_mock( \
mock::detail::context& context, \
boost::unit_test::const_string instance ) \
{ \
static mock::detail::function< S > f; \
static mock::detail::function< MOCK_FUNCTION_TYPE(S) > f; \
return f( context, instance ); \
}
@ -140,7 +148,8 @@
s MOCK_DECL(F, n, S,,tpn) \
{ \
BOOST_MPL_ASSERT_RELATION( n, ==, \
boost::function_types::function_arity< S >::value ); \
boost::function_types::function_arity< \
MOCK_FUNCTION_TYPE(S) >::value ); \
return MOCK_HELPER(t)( BOOST_PP_ENUM_PARAMS(n, p) ); \
}