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:
Alexander Grund 2022-01-25 17:32:22 +01:00
parent c910d1db8c
commit 3d5ac2b94a
No known key found for this signature in database
GPG key ID: AA48A0760367A42B
4 changed files with 38 additions and 41 deletions

View file

@ -14,6 +14,7 @@ Released -
* Replaced Boost facilities with std:: equivalents where existing in C++14 * Replaced Boost facilities with std:: equivalents where existing in C++14
* Removed MOCK_*_TPL as they are no longer required, use the non _TPL variant even for templates * Removed MOCK_*_TPL as they are no longer required, use the non _TPL variant even for templates
* Added MOCK_PROTECT_FUNCTION_SIG to pass function signatures with commas in the return type * Added MOCK_PROTECT_FUNCTION_SIG to pass function signatures with commas in the return type
* Remove support for protecting function signatures via BOOST_IDENTITY_TYPE, use MOCK_PROTECT_FUNCTION_SIG instead
[endsect] [endsect]

View file

@ -229,15 +229,9 @@ MOCK_CLASS(mock_class)
MOCK_METHOD(method, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>())) MOCK_METHOD(method, 0, MOCK_PROTECT_FUNCTION_SIG(std::map<int, int>()))
}; };
//] //]
MOCK_CLASS(legacy_mock_class)
{
MOCK_METHOD(method, 0, BOOST_IDENTITY_TYPE((std::map<int, int>())))
};
static_assert(std::is_same<decltype(std::declval<mock_class>().method()), std::map<int, int>>::value, static_assert(std::is_same<decltype(std::declval<mock_class>().method()), std::map<int, int>>::value,
"Wrong return value"); "Wrong return value");
static_assert(std::is_same<decltype(std::declval<legacy_mock_class>().method()), std::map<int, int>>::value,
"Wrong return value");
} // namespace member_function_example_8 } // namespace member_function_example_8

View file

@ -16,39 +16,42 @@
#include "type_name.hpp" #include "type_name.hpp"
#include <boost/preprocessor/repetition/repeat.hpp> #include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/stringize.hpp> #include <boost/preprocessor/stringize.hpp>
#include <type_traits>
// Internal compatibility macro if function signature is passed via BOOST_IDENTITY_TYPE namespace mock { namespace detail {
// TODO: Remove support for doing that and move remove_pointer_t to MOCK_PROTECT_FUNCTION_SIG /// Used in MOCK_PROTECT_FUNCTION_SIG to unwrap the passed function signature
#define MOCK_FUNCTION_TYPE(...) std::remove_pointer_t<__VA_ARGS__> 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_HELPER(t) t##_mock(mock::detail::root, BOOST_PP_STRINGIZE(t))
#define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.") #define MOCK_ANONYMOUS_HELPER(t) t##_mock(mock::detail::root, "?.")
#define MOCK_METHOD_HELPER(S, t) \ #define MOCK_METHOD_HELPER(S, t) \
mutable mock::detail::function<MOCK_FUNCTION_TYPE(S)> t##_mock_; \ mutable mock::detail::function<S> t##_mock_; \
mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(const mock::detail::context&, \ mock::detail::function<S>& t##_mock(const mock::detail::context&, const boost::unit_test::const_string& instance) \
const boost::unit_test::const_string& instance) const \ const \
{ \ { \
mock::detail::configure(*this, \ mock::detail::configure(*this, \
t##_mock_, \ t##_mock_, \
instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \ instance.substr(0, instance.rfind(BOOST_PP_STRINGIZE(t))), \
mock::detail::make_type_name(*this), \ mock::detail::make_type_name(*this), \
BOOST_PP_STRINGIZE(t)); \ BOOST_PP_STRINGIZE(t)); \
return t##_mock_; \ 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_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_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_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_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) \ #define MOCK_METHOD_AUX(M, n, S, t, c) \
MOCK_DECL(M, n, S, c) \ MOCK_DECL(M, n, S, c) \
{ \ { \
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \ static_assert(n == mock::detail::function_arity<S>::value, "Arity mismatch"); \
return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \ return MOCK_ANONYMOUS_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
} }
#define MOCK_METHOD_EXT(M, n, S, t) \ #define MOCK_METHOD_EXT(M, n, S, t) \
@ -62,24 +65,23 @@
MOCK_METHOD_AUX(M, n, S, t, ) \ MOCK_METHOD_AUX(M, n, S, t, ) \
MOCK_METHOD_HELPER(S, t) MOCK_METHOD_HELPER(S, t)
#define MOCK_FUNCTION_HELPER(S, t, s) \ #define MOCK_FUNCTION_HELPER(S, t, s) \
s mock::detail::function<MOCK_FUNCTION_TYPE(S)>& t##_mock(mock::detail::context& context, \ s mock::detail::function<S>& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \
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); \
return f(context, instance); \
} }
#define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \ #define MOCK_CONSTRUCTOR_AUX(T, n, A, t) \
T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \ T(MOCK_DECL_PARAMS(n, void A)) { MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, void A)); } \
MOCK_FUNCTION_HELPER(void A, t, static) MOCK_FUNCTION_HELPER(void A, t, static)
#define MOCK_FUNCTION_AUX(F, n, S, t, s) \ #define MOCK_FUNCTION_AUX(F, n, S, t, s) \
MOCK_FUNCTION_HELPER(S, t, s) \ MOCK_FUNCTION_HELPER(S, t, s) \
s MOCK_DECL(F, n, S, ) \ s MOCK_DECL(F, n, S, ) \
{ \ { \
static_assert(n == mock::detail::function_arity<MOCK_FUNCTION_TYPE(S)>::value, "Arity mismatch"); \ static_assert(n == mock::detail::function_arity<S>::value, "Arity mismatch"); \
return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \ return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \
} }
#define MOCK_VARIADIC_ELEM_0(e0, ...) e0 #define MOCK_VARIADIC_ELEM_0(e0, ...) e0

View file

@ -26,11 +26,11 @@
/// MOCK_PROTECT_FUNCTION_SIG( signature ) /// MOCK_PROTECT_FUNCTION_SIG( signature )
/// Use this with MOCK_FUNCTION/MOCK_*_METHOD if the return type contains commas /// 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 ) /// MOCK_FUNCTOR( name, signature )
/// Define a callable variable/member /// 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 ) /// MOCK_CONVERSION_OPERATOR( [calling convention] name, type, identifier )
/// generates both const and non-const conversion operators /// generates both const and non-const conversion operators