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
cb3f7ce1
Commit
cb3f7ce1
authored
Sep 25, 2019
by
Abseil Team
Committed by
Gennadiy Civil
Sep 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Makes testing::ResultOf() work with non-copyable arguments. PiperOrigin-RevId: 271222632
parent
a783ade7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+4
-2
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+10
-0
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
cb3f7ce1
...
...
@@ -1858,7 +1858,9 @@ struct CallableTraits {
static
void
CheckIsValid
(
Functor
/* functor */
)
{}
template
<
typename
T
>
static
auto
Invoke
(
Functor
f
,
T
arg
)
->
decltype
(
f
(
arg
))
{
return
f
(
arg
);
}
static
auto
Invoke
(
Functor
f
,
const
T
&
arg
)
->
decltype
(
f
(
arg
))
{
return
f
(
arg
);
}
};
// Specialization for function pointers.
...
...
@@ -1889,7 +1891,7 @@ class ResultOfMatcher {
template
<
typename
T
>
operator
Matcher
<
T
>
()
const
{
return
Matcher
<
T
>
(
new
Impl
<
T
>
(
callable_
,
matcher_
));
return
Matcher
<
T
>
(
new
Impl
<
const
T
&
>
(
callable_
,
matcher_
));
}
private
:
...
...
googlemock/test/gmock-matchers_test.cc
View file @
cb3f7ce1
...
...
@@ -4318,6 +4318,16 @@ TEST(ResultOfTest, WorksForLambdas) {
EXPECT_FALSE
(
matcher
.
Matches
(
1
));
}
TEST
(
ResultOfTest
,
WorksForNonCopyableArguments
)
{
Matcher
<
std
::
unique_ptr
<
int
>>
matcher
=
ResultOf
(
[](
const
std
::
unique_ptr
<
int
>&
str_len
)
{
return
std
::
string
(
static_cast
<
size_t
>
(
*
str_len
),
'x'
);
},
"xxx"
);
EXPECT_TRUE
(
matcher
.
Matches
(
std
::
unique_ptr
<
int
>
(
new
int
(
3
))));
EXPECT_FALSE
(
matcher
.
Matches
(
std
::
unique_ptr
<
int
>
(
new
int
(
1
))));
}
const
int
*
ReferencingFunction
(
const
int
&
n
)
{
return
&
n
;
}
struct
ReferencingFunctor
{
...
...
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