aboutsummaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2019-10-17 16:14:42 -0400
committerAndy Soffer <asoffer@google.com>2019-10-18 11:33:59 -0400
commit1f9edcd9698162b48d94e1ef2e6a2ab7ab4e6c56 (patch)
tree242ff712a09fb700a96ae10da78e3407f3d153d3 /googlemock/include/gmock
parentbbe4b7363bbaa7c9e07dbacde11602a4c69504d3 (diff)
downloadgoogletest-1f9edcd9698162b48d94e1ef2e6a2ab7ab4e6c56.tar.gz
googletest-1f9edcd9698162b48d94e1ef2e6a2ab7ab4e6c56.tar.bz2
googletest-1f9edcd9698162b48d94e1ef2e6a2ab7ab4e6c56.zip
Googletest export
Addressing https://github.com/google/googletest/issues/2502 Add MOCK_METHOD support for returning function pointers. PiperOrigin-RevId: 275323671
Diffstat (limited to 'googlemock/include/gmock')
-rw-r--r--googlemock/include/gmock/gmock-function-mocker.h29
1 files changed, 25 insertions, 4 deletions
diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h
index cc1535c8..684db139 100644
--- a/googlemock/include/gmock/gmock-function-mocker.h
+++ b/googlemock/include/gmock/gmock-function-mocker.h
@@ -39,6 +39,13 @@
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
#include "gmock/internal/gmock-pp.h"
+namespace testing {
+namespace internal {
+template <typename T>
+using identity_t = T;
+} // namespace internal
+} // namespace testing
+
#define MOCK_METHOD(...) \
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
@@ -207,10 +214,24 @@
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
-#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
- GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
- GMOCK_PP_IDENTITY) \
- (_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
+// Note: The use of `identity_t` here allows _Ret to represent return types that
+// would normally need to be specified in a different way. For example, a method
+// returning a function pointer must be written as
+//
+// fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...)
+//
+// But we only support placing the return type at the beginning. To handle this,
+// we wrap all calls in identity_t, so that a declaration will be expanded to
+//
+// identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...)
+//
+// This allows us to work around the syntactic oddities of function/method
+// types.
+#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
+ ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \
+ GMOCK_PP_REMOVE_PARENS, \
+ GMOCK_PP_IDENTITY)(_Ret)>( \
+ GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
GMOCK_PP_COMMA_IF(_i) \