diff --git a/doc/changelog.qbk b/doc/changelog.qbk index 1a92be0..df78622 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -14,6 +14,7 @@ Released - * 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 * 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] diff --git a/doc/example/reference.cpp b/doc/example/reference.cpp index 17ef2c7..79a1c80 100644 --- a/doc/example/reference.cpp +++ b/doc/example/reference.cpp @@ -229,15 +229,9 @@ MOCK_CLASS(mock_class) MOCK_METHOD(method, 0, MOCK_PROTECT_FUNCTION_SIG(std::map())) }; //] -MOCK_CLASS(legacy_mock_class) -{ - MOCK_METHOD(method, 0, BOOST_IDENTITY_TYPE((std::map()))) -}; static_assert(std::is_same().method()), std::map>::value, "Wrong return value"); -static_assert(std::is_same().method()), std::map>::value, - "Wrong return value"); } // namespace member_function_example_8 diff --git a/include/turtle/detail/mock_impl.hpp b/include/turtle/detail/mock_impl.hpp index 4ac3b8a..79f5d59 100644 --- a/include/turtle/detail/mock_impl.hpp +++ b/include/turtle/detail/mock_impl.hpp @@ -16,39 +16,42 @@ #include "type_name.hpp" #include #include +#include -// 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 + using unwrap_function_sig_t = std::remove_pointer_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 t##_mock_; \ - mock::detail::function& 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 t##_mock_; \ + mock::detail::function& 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 M(MOCK_DECL_PARAMS(n, S)) c +#define MOCK_DECL(M, n, S, c) mock::detail::result_type_t 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::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::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& t##_mock(mock::detail::context& context, \ - boost::unit_test::const_string instance) \ - { \ - static mock::detail::function f; \ - return f(context, instance); \ +#define MOCK_FUNCTION_HELPER(S, t, s) \ + s mock::detail::function& t##_mock(mock::detail::context& context, boost::unit_test::const_string instance) \ + { \ + static mock::detail::function 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::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::value, "Arity mismatch"); \ + return MOCK_HELPER(t)(MOCK_FORWARD_PARAMS(n, S)); \ } #define MOCK_VARIADIC_ELEM_0(e0, ...) e0 diff --git a/include/turtle/mock.hpp b/include/turtle/mock.hpp index 7e610bf..c77b560 100644 --- a/include/turtle/mock.hpp +++ b/include/turtle/mock.hpp @@ -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 +#define MOCK_PROTECT_FUNCTION_SIG(...) mock::detail::unwrap_function_sig_t /// MOCK_FUNCTOR( name, signature ) /// Define a callable variable/member -#define MOCK_FUNCTOR(name, ...) mock::detail::functor 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