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
f4abce46
Commit
f4abce46
authored
Aug 22, 2017
by
Gennadiy Civil
Committed by
GitHub
Aug 22, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into vs-projects-fix
parents
88269cd3
863e0264
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
8 deletions
+47
-8
gmock-matchers.h
googlemock/include/gmock/gmock-matchers.h
+27
-8
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+20
-0
No files found.
googlemock/include/gmock/gmock-matchers.h
View file @
f4abce46
...
...
@@ -2232,7 +2232,10 @@ class FieldMatcher {
// Implements the Property() matcher for matching a property
// (i.e. return value of a getter method) of an object.
template
<
typename
Class
,
typename
PropertyType
>
//
// Property is a const-qualified member function of Class returning
// PropertyType.
template
<
typename
Class
,
typename
PropertyType
,
typename
Property
>
class
PropertyMatcher
{
public
:
// The property may have a reference type, so 'const PropertyType&'
...
...
@@ -2241,8 +2244,7 @@ class PropertyMatcher {
// PropertyType being a reference or not.
typedef
GTEST_REFERENCE_TO_CONST_
(
PropertyType
)
RefToConstProperty
;
PropertyMatcher
(
PropertyType
(
Class
::*
property
)()
const
,
const
Matcher
<
RefToConstProperty
>&
matcher
)
PropertyMatcher
(
Property
property
,
const
Matcher
<
RefToConstProperty
>&
matcher
)
:
property_
(
property
),
matcher_
(
matcher
)
{}
void
DescribeTo
(
::
std
::
ostream
*
os
)
const
{
...
...
@@ -2295,7 +2297,7 @@ class PropertyMatcher {
return
MatchAndExplainImpl
(
false_type
(),
*
p
,
listener
);
}
Property
Type
(
Class
::*
property_
)()
const
;
Property
property_
;
const
Matcher
<
RefToConstProperty
>
matcher_
;
GTEST_DISALLOW_ASSIGN_
(
PropertyMatcher
);
...
...
@@ -3908,11 +3910,13 @@ inline PolymorphicMatcher<
// Property(&Foo::str, StartsWith("hi"))
// matches a Foo object x iff x.str() starts with "hi".
template
<
typename
Class
,
typename
PropertyType
,
typename
PropertyMatcher
>
inline
PolymorphicMatcher
<
internal
::
PropertyMatcher
<
Class
,
PropertyType
>
>
Property
(
PropertyType
(
Class
::*
property
)()
const
,
const
PropertyMatcher
&
matcher
)
{
inline
PolymorphicMatcher
<
internal
::
PropertyMatcher
<
Class
,
PropertyType
,
PropertyType
(
Class
::*
)()
const
>
>
Property
(
PropertyType
(
Class
::*
property
)()
const
,
const
PropertyMatcher
&
matcher
)
{
return
MakePolymorphicMatcher
(
internal
::
PropertyMatcher
<
Class
,
PropertyType
>
(
internal
::
PropertyMatcher
<
Class
,
PropertyType
,
PropertyType
(
Class
::*
)()
const
>
(
property
,
MatcherCast
<
GTEST_REFERENCE_TO_CONST_
(
PropertyType
)
>
(
matcher
)));
// The call to MatcherCast() is required for supporting inner
...
...
@@ -3921,6 +3925,21 @@ inline PolymorphicMatcher<
// to compile where bar() returns an int32 and m is a matcher for int64.
}
#if GTEST_LANG_CXX11
// The same as above but for reference-qualified member functions.
template
<
typename
Class
,
typename
PropertyType
,
typename
PropertyMatcher
>
inline
PolymorphicMatcher
<
internal
::
PropertyMatcher
<
Class
,
PropertyType
,
PropertyType
(
Class
::*
)()
const
&>
>
Property
(
PropertyType
(
Class
::*
property
)()
const
&
,
const
PropertyMatcher
&
matcher
)
{
return
MakePolymorphicMatcher
(
internal
::
PropertyMatcher
<
Class
,
PropertyType
,
PropertyType
(
Class
::*
)()
const
&>
(
property
,
MatcherCast
<
GTEST_REFERENCE_TO_CONST_
(
PropertyType
)
>
(
matcher
)));
}
#endif
// Creates a matcher that matches an object iff the result of applying
// a callable to x matches 'matcher'.
// For example,
...
...
googlemock/test/gmock-matchers_test.cc
View file @
f4abce46
...
...
@@ -3588,10 +3588,15 @@ class AClass {
// A getter that returns a reference to const.
const
std
::
string
&
s
()
const
{
return
s_
;
}
#if GTEST_LANG_CXX11
const
std
::
string
&
s_ref
()
const
&
{
return
s_
;
}
#endif
void
set_s
(
const
std
::
string
&
new_s
)
{
s_
=
new_s
;
}
// A getter that returns a reference to non-const.
double
&
x
()
const
{
return
x_
;
}
private
:
int
n_
;
std
::
string
s_
;
...
...
@@ -3635,6 +3640,21 @@ TEST(PropertyTest, WorksForReferenceToConstProperty) {
EXPECT_FALSE
(
m
.
Matches
(
a
));
}
#if GTEST_LANG_CXX11
// Tests that Property(&Foo::property, ...) works when property() is
// ref-qualified.
TEST
(
PropertyTest
,
WorksForRefQualifiedProperty
)
{
Matcher
<
const
AClass
&>
m
=
Property
(
&
AClass
::
s_ref
,
StartsWith
(
"hi"
));
AClass
a
;
a
.
set_s
(
"hill"
);
EXPECT_TRUE
(
m
.
Matches
(
a
));
a
.
set_s
(
"hole"
);
EXPECT_FALSE
(
m
.
Matches
(
a
));
}
#endif
// Tests that Property(&Foo::property, ...) works when property()
// returns a reference to non-const.
TEST
(
PropertyTest
,
WorksForReferenceToNonConstProperty
)
{
...
...
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