Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
1f9edcd9
Commit
1f9edcd9
authored
Oct 17, 2019
by
Abseil Team
Committed by
Andy Soffer
Oct 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Addressing
https://github.com/google/googletest/issues/2502
Add MOCK_METHOD support for returning function pointers. PiperOrigin-RevId: 275323671
parent
bbe4b736
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
3 deletions
+31
-3
gmock-function-mocker.h
googlemock/include/gmock/gmock-function-mocker.h
+24
-3
gmock-function-mocker_test.cc
googlemock/test/gmock-function-mocker_test.cc
+7
-0
No files found.
googlemock/include/gmock/gmock-function-mocker.h
View file @
1f9edcd9
...
@@ -39,6 +39,13 @@
...
@@ -39,6 +39,13 @@
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
#include "gmock/gmock-generated-function-mockers.h" // NOLINT
#include "gmock/internal/gmock-pp.h"
#include "gmock/internal/gmock-pp.h"
namespace
testing
{
namespace
internal
{
template
<
typename
T
>
using
identity_t
=
T
;
}
// namespace internal
}
// namespace testing
#define MOCK_METHOD(...) \
#define MOCK_METHOD(...) \
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__)
...
@@ -207,10 +214,24 @@
...
@@ -207,10 +214,24 @@
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
#define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype
// 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) \
#define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), GMOCK_PP_REMOVE_PARENS, \
::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \
GMOCK_PP_IDENTITY) \
GMOCK_PP_REMOVE_PARENS, \
(_Ret)(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
GMOCK_PP_IDENTITY)(_Ret)>( \
GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
#define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
GMOCK_PP_COMMA_IF(_i) \
GMOCK_PP_COMMA_IF(_i) \
...
...
googlemock/test/gmock-function-mocker_test.cc
View file @
1f9edcd9
...
@@ -101,6 +101,10 @@ class FooInterface {
...
@@ -101,6 +101,10 @@ class FooInterface {
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
virtual
int
TypeWithComma
(
const
std
::
map
<
int
,
std
::
string
>&
a_map
)
=
0
;
virtual
int
TypeWithTemplatedCopyCtor
(
const
TemplatedCopyable
<
int
>&
)
=
0
;
virtual
int
TypeWithTemplatedCopyCtor
(
const
TemplatedCopyable
<
int
>&
)
=
0
;
virtual
int
(
*
ReturnsFunctionPointer1
(
int
))(
bool
)
=
0
;
using
fn_ptr
=
int
(
*
)(
bool
);
virtual
fn_ptr
ReturnsFunctionPointer2
(
int
)
=
0
;
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
int
,
CTNullary
)()
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
STDMETHOD_
(
bool
,
CTUnary
)(
int
x
)
=
0
;
...
@@ -159,6 +163,9 @@ class MockFoo : public FooInterface {
...
@@ -159,6 +163,9 @@ class MockFoo : public FooInterface {
MOCK_METHOD
(
int
,
TypeWithTemplatedCopyCtor
,
MOCK_METHOD
(
int
,
TypeWithTemplatedCopyCtor
,
(
const
TemplatedCopyable
<
int
>&
));
// NOLINT
(
const
TemplatedCopyable
<
int
>&
));
// NOLINT
MOCK_METHOD
(
int
(
*
)(
bool
),
ReturnsFunctionPointer1
,
(
int
),
());
MOCK_METHOD
(
fn_ptr
,
ReturnsFunctionPointer2
,
(
int
),
());
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
MOCK_METHOD
(
int
,
CTNullary
,
(),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
int
,
CTNullary
,
(),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
bool
,
CTUnary
,
(
int
),
(
Calltype
(
STDMETHODCALLTYPE
)));
MOCK_METHOD
(
bool
,
CTUnary
,
(
int
),
(
Calltype
(
STDMETHODCALLTYPE
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment