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
662fe38e
Commit
662fe38e
authored
May 13, 2021
by
Abseil Team
Committed by
CJ Johnson
May 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Support templating MockFunction over function objects besides std::function. PiperOrigin-RevId: 373586967
parent
d69a1129
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
gmock-spec-builders.h
googlemock/include/gmock/gmock-spec-builders.h
+8
-6
gmock-function-mocker_test.cc
googlemock/test/gmock-function-mocker_test.cc
+18
-6
No files found.
googlemock/include/gmock/gmock-spec-builders.h
View file @
662fe38e
...
@@ -1838,12 +1838,12 @@ corresponding to the provided F argument.
...
@@ -1838,12 +1838,12 @@ corresponding to the provided F argument.
It makes use of MockFunction easier by allowing it to accept more F arguments
It makes use of MockFunction easier by allowing it to accept more F arguments
than just function signatures.
than just function signatures.
Specializations provided here cover
only a signature type itself and
Specializations provided here cover
a signature type itself and any template
std::function. However, if need be it can be easily extended to cover also other
that can be parameterized with a signature, including std::function and
types (like for example boost::function)
.
boost::function
.
*/
*/
template
<
typename
F
>
template
<
typename
F
,
typename
=
void
>
struct
SignatureOf
;
struct
SignatureOf
;
template
<
typename
R
,
typename
...
Args
>
template
<
typename
R
,
typename
...
Args
>
...
@@ -1851,8 +1851,10 @@ struct SignatureOf<R(Args...)> {
...
@@ -1851,8 +1851,10 @@ struct SignatureOf<R(Args...)> {
using
type
=
R
(
Args
...);
using
type
=
R
(
Args
...);
};
};
template
<
typename
F
>
template
<
template
<
typename
>
class
C
,
typename
F
>
struct
SignatureOf
<
std
::
function
<
F
>>
:
SignatureOf
<
F
>
{};
struct
SignatureOf
<
C
<
F
>
,
typename
std
::
enable_if
<
std
::
is_function
<
F
>::
value
>::
type
>
:
SignatureOf
<
F
>
{};
template
<
typename
F
>
template
<
typename
F
>
using
SignatureOfT
=
typename
SignatureOf
<
F
>::
type
;
using
SignatureOfT
=
typename
SignatureOf
<
F
>::
type
;
...
...
googlemock/test/gmock-function-mocker_test.cc
View file @
662fe38e
...
@@ -849,7 +849,7 @@ namespace {
...
@@ -849,7 +849,7 @@ namespace {
template
<
typename
Expected
,
typename
F
>
template
<
typename
Expected
,
typename
F
>
static
constexpr
bool
IsMockFunctionTemplateArgumentDeducedTo
(
static
constexpr
bool
IsMockFunctionTemplateArgumentDeducedTo
(
const
MockFunction
<
F
>&
)
{
const
internal
::
MockFunction
<
F
>&
)
{
return
std
::
is_same
<
F
,
Expected
>::
value
;
return
std
::
is_same
<
F
,
Expected
>::
value
;
}
}
...
@@ -868,14 +868,14 @@ TYPED_TEST(MockMethodMockFunctionSignatureTest,
...
@@ -868,14 +868,14 @@ TYPED_TEST(MockMethodMockFunctionSignatureTest,
IsMockFunctionTemplateArgumentDeducedForRawSignature
)
{
IsMockFunctionTemplateArgumentDeducedForRawSignature
)
{
using
Argument
=
TypeParam
;
using
Argument
=
TypeParam
;
MockFunction
<
Argument
>
foo
;
MockFunction
<
Argument
>
foo
;
EXPECT_TRUE
(
IsMockFunctionTemplateArgumentDeducedTo
<
Argument
>
(
foo
));
EXPECT_TRUE
(
IsMockFunctionTemplateArgumentDeducedTo
<
TypeParam
>
(
foo
));
}
}
TYPED_TEST
(
MockMethodMockFunctionSignatureTest
,
TYPED_TEST
(
MockMethodMockFunctionSignatureTest
,
IsMockFunctionTemplateArgumentDeducedForStdFunction
)
{
IsMockFunctionTemplateArgumentDeducedForStdFunction
)
{
using
Argument
=
std
::
function
<
TypeParam
>
;
using
Argument
=
std
::
function
<
TypeParam
>
;
MockFunction
<
Argument
>
foo
;
MockFunction
<
Argument
>
foo
;
EXPECT_TRUE
(
IsMockFunctionTemplateArgumentDeducedTo
<
Argument
>
(
foo
));
EXPECT_TRUE
(
IsMockFunctionTemplateArgumentDeducedTo
<
TypeParam
>
(
foo
));
}
}
TYPED_TEST
(
TYPED_TEST
(
...
@@ -887,15 +887,27 @@ TYPED_TEST(
...
@@ -887,15 +887,27 @@ TYPED_TEST(
EXPECT_TRUE
((
std
::
is_same
<
ForRawSignature
,
ForStdFunction
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
ForRawSignature
,
ForStdFunction
>::
value
));
}
}
template
<
typename
F
>
struct
AlternateCallable
{
};
TYPED_TEST
(
MockMethodMockFunctionSignatureTest
,
IsMockFunctionTemplateArgumentDeducedForAlternateCallable
)
{
using
Argument
=
AlternateCallable
<
TypeParam
>
;
MockFunction
<
Argument
>
foo
;
EXPECT_TRUE
(
IsMockFunctionTemplateArgumentDeducedTo
<
TypeParam
>
(
foo
));
}
TYPED_TEST
(
TYPED_TEST
(
MockMethodMockFunctionSignatureTest
,
MockMethodMockFunctionSignatureTest
,
IsMockFunction
AsStdFunctionMethodSignatureTheSameForRawSignatureAndStdFunction
)
{
IsMockFunction
CallMethodSignatureTheSameForAlternateCallable
)
{
using
ForRawSignature
=
decltype
(
&
MockFunction
<
TypeParam
>::
AsStdFunction
);
using
ForRawSignature
=
decltype
(
&
MockFunction
<
TypeParam
>::
Call
);
using
ForStdFunction
=
using
ForStdFunction
=
decltype
(
&
MockFunction
<
std
::
function
<
TypeParam
>>::
AsStdFunction
);
decltype
(
&
MockFunction
<
std
::
function
<
TypeParam
>>::
Call
);
EXPECT_TRUE
((
std
::
is_same
<
ForRawSignature
,
ForStdFunction
>::
value
));
EXPECT_TRUE
((
std
::
is_same
<
ForRawSignature
,
ForStdFunction
>::
value
));
}
}
struct
MockMethodSizes0
{
struct
MockMethodSizes0
{
MOCK_METHOD
(
void
,
func
,
());
MOCK_METHOD
(
void
,
func
,
());
};
};
...
...
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