mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Remove support for BOOST_IDENTITY_TYPE
MOCK_PROTECT_FUNCTION_SIG should be used instead which even requires less parentheses. Closes #109
This commit is contained in:
parent
c910d1db8c
commit
3d5ac2b94a
4 changed files with 38 additions and 41 deletions
|
|
@ -16,39 +16,42 @@
|
|||
#include "type_name.hpp"
|
||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||
#include <boost/preprocessor/stringize.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
// Internal compatibility macro if function signature is passed via BOOST_IDENTITY_TYPE
|
||||
// TODO: Remove support for doing that and move remove_pointer_t to MOCK_PROTECT_FUNCTION_SIG
|
||||
#define MOCK_FUNCTION_TYPE(...) std::remove_pointer_t<__VA_ARGS__>
|
||||
namespace mock { namespace detail {
|
||||
/// Used in MOCK_PROTECT_FUNCTION_SIG to unwrap the passed function signature
|
||||
template<typename T>
|
||||
using unwrap_function_sig_t = std::remove_pointer_t<parameter_type_t<T>>;
|
||||
}} // namespace mock::detail
|
||||
|
||||
#define MOCK_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
|
||||
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
|
||||
|
||||
#define MOCK_METHOD_HELPER(S, t) \
|
||||
mutable mock::detail::function<MOCK_FUNCTION_TYPE(S)> t##_mock_; \
|
||||
mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(const mock::detail::context&, \
|
||||
const boost::unit_test::const_string& instance) const \
|
||||
{ \
|
||||
mock::detail::configure(*this, \
|
||||
t##_mock_, \
|
||||
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
|
||||
mock::detail::make_type_name(*this), \
|
||||
BOOST_PP_STRINGIZE(t)); \
|
||||
return t##_mock_; \
|
||||
#define MOCK_METHOD_HELPER(S, t) \
|
||||
mutable mock::detail::function<S> t##_mock_; \
|
||||
mock::detail::function<S>& t##_mock(const mock::detail::context&, const boost::unit_test::const_string& instance) \
|
||||
const \
|
||||
{ \
|
||||
mock::detail::configure(*this, \
|
||||
t##_mock_, \
|
||||
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
|
||||
mock::detail::make_type_name(*this), \
|
||||
BOOST_PP_STRINGIZE(t)); \
|
||||
return t##_mock_; \
|
||||
}
|
||||
|
||||
#define MOCK_PARAM(S) mock::detail::parameter_t < MOCK_FUNCTION_TYPE(S)
|
||||
#define MOCK_PARAM(S) mock::detail::parameter_t < S
|
||||
#define MOCK_DECL_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n > p##n
|
||||
#define MOCK_DECL_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_DECL_PARAM, MOCK_PARAM(S))
|
||||
#define MOCK_DECL(M, n, S, c) mock::detail::result_type_t<MOCK_FUNCTION_TYPE(S)> M(MOCK_DECL_PARAMS(n, S)) c
|
||||
#define MOCK_DECL(M, n, S, c) mock::detail::result_type_t<S> M(MOCK_DECL_PARAMS(n, S)) c
|
||||
|
||||
#define MOCK_FORWARD_PARAM(z, n, d) BOOST_PP_COMMA_IF(n) d, n >> (p##n)
|
||||
#define MOCK_FORWARD_PARAMS(n, S) BOOST_PP_REPEAT(n, MOCK_FORWARD_PARAM, std::forward < MOCK_PARAM(S))
|
||||
#define MOCK_METHOD_AUX(M, n, S, t, c) \
|
||||
MOCK_DECL(M, n, S, c) \
|
||||
{ \
|
||||
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
|
||||
#define MOCK_METHOD_AUX(M, n, S, t, c) \
|
||||
MOCK_DECL(M, n, S, c) \
|
||||
{ \
|
||||
static_assert(n == mock::detail::function_arity<S>::value, "Arity mismatch"); \
|
||||
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
|
||||
}
|
||||
|
||||
#define MOCK_METHOD_EXT(M, n, S, t) \
|
||||
|
|
@ -62,24 +65,23 @@
|
|||
MOCK_METHOD_AUX(M, n, S, t, ) \
|
||||
MOCK_METHOD_HELPER(S, t)
|
||||
|
||||
#define MOCK_FUNCTION_HELPER(S, t, s) \
|
||||
s mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(mock::detail::context& context, \
|
||||
boost::unit_test::const_string instance) \
|
||||
{ \
|
||||
static mock::detail::function<MOCK_FUNCTION_TYPE(S)> f; \
|
||||
return f(context, instance); \
|
||||
#define MOCK_FUNCTION_HELPER(S, t, s) \
|
||||
s mock::detail::function<S>& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \
|
||||
{ \
|
||||
static mock::detail::function<S> f; \
|
||||
return f(context, instance); \
|
||||
}
|
||||
|
||||
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \
|
||||
T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \
|
||||
MOCK_FUNCTION_HELPER(void A, t, static)
|
||||
|
||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s) \
|
||||
MOCK_FUNCTION_HELPER(S, t, s) \
|
||||
s MOCK_DECL(F, n, S, ) \
|
||||
{ \
|
||||
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \
|
||||
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
|
||||
#define MOCK_FUNCTION_AUX(F, n, S, t, s) \
|
||||
MOCK_FUNCTION_HELPER(S, t, s) \
|
||||
s MOCK_DECL(F, n, S, ) \
|
||||
{ \
|
||||
static_assert(n == mock::detail::function_arity<S>::value, "Arity mismatch"); \
|
||||
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
|
||||
}
|
||||
|
||||
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0
|
||||
|
|
|
|||
|
|
@ -26,11 +26,11 @@
|
|||
|
||||
/// MOCK_PROTECT_FUNCTION_SIG( signature )
|
||||
/// Use this with MOCK_FUNCTION/MOCK_*_METHOD if the return type contains commas
|
||||
#define MOCK_PROTECT_FUNCTION_SIG(...) mock::detail::parameter_type_t<void(__VA_ARGS__)>
|
||||
#define MOCK_PROTECT_FUNCTION_SIG(...) mock::detail::unwrap_function_sig_t<void(__VA_ARGS__)>
|
||||
|
||||
/// MOCK_FUNCTOR( name, signature )
|
||||
/// Define a callable variable/member
|
||||
#define MOCK_FUNCTOR(name, ...) mock::detail::functor<MOCK_FUNCTION_TYPE(__VA_ARGS__)> name, name##_mock
|
||||
#define MOCK_FUNCTOR(name, ...) mock::detail::functor<__VA_ARGS__> name, name##_mock
|
||||
|
||||
/// MOCK_CONVERSION_OPERATOR( [calling convention] name, type, identifier )
|
||||
/// generates both const and non-const conversion operators
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue