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
6953a725
Commit
6953a725
authored
Jan 13, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allows Field() and Property() to work when the matcher argument is a pointer passed by reference.
parent
e122e457
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
gmock-matchers.h
include/gmock/gmock-matchers.h
+6
-3
gmock-matchers_test.cc
test/gmock-matchers_test.cc
+23
-0
No files found.
include/gmock/gmock-matchers.h
View file @
6953a725
...
@@ -1784,7 +1784,8 @@ template <typename Class, typename FieldType, typename T>
...
@@ -1784,7 +1784,8 @@ template <typename Class, typename FieldType, typename T>
bool
MatchAndExplain
(
const
FieldMatcher
<
Class
,
FieldType
>&
matcher
,
bool
MatchAndExplain
(
const
FieldMatcher
<
Class
,
FieldType
>&
matcher
,
T
&
value
,
MatchResultListener
*
listener
)
{
T
&
value
,
MatchResultListener
*
listener
)
{
return
matcher
.
MatchAndExplain
(
return
matcher
.
MatchAndExplain
(
typename
::
testing
::
internal
::
is_pointer
<
T
>::
type
(),
value
,
listener
);
typename
::
testing
::
internal
::
is_pointer
<
GMOCK_REMOVE_CONST_
(
T
)
>::
type
(),
value
,
listener
);
}
}
// Implements the Property() matcher for matching a property
// Implements the Property() matcher for matching a property
...
@@ -1849,7 +1850,8 @@ template <typename Class, typename PropertyType, typename T>
...
@@ -1849,7 +1850,8 @@ template <typename Class, typename PropertyType, typename T>
bool
MatchAndExplain
(
const
PropertyMatcher
<
Class
,
PropertyType
>&
matcher
,
bool
MatchAndExplain
(
const
PropertyMatcher
<
Class
,
PropertyType
>&
matcher
,
T
&
value
,
MatchResultListener
*
listener
)
{
T
&
value
,
MatchResultListener
*
listener
)
{
return
matcher
.
MatchAndExplain
(
return
matcher
.
MatchAndExplain
(
typename
::
testing
::
internal
::
is_pointer
<
T
>::
type
(),
value
,
listener
);
typename
::
testing
::
internal
::
is_pointer
<
GMOCK_REMOVE_CONST_
(
T
)
>::
type
(),
value
,
listener
);
}
}
// Type traits specifying various features of different functors for ResultOf.
// Type traits specifying various features of different functors for ResultOf.
...
@@ -2018,7 +2020,8 @@ class ContainerEqMatcher {
...
@@ -2018,7 +2020,8 @@ class ContainerEqMatcher {
*
os
<<
"Only in actual: "
;
*
os
<<
"Only in actual: "
;
printed_header
=
true
;
printed_header
=
true
;
}
}
UniversalPrinter
<
typename
LhsStlContainer
::
value_type
>::
Print
(
*
it
,
os
);
UniversalPrinter
<
typename
LhsStlContainer
::
value_type
>::
Print
(
*
it
,
os
);
}
}
}
}
...
...
test/gmock-matchers_test.cc
View file @
6953a725
...
@@ -2648,6 +2648,16 @@ TEST(FieldForPointerTest, WorksForPointerToNonConst) {
...
@@ -2648,6 +2648,16 @@ TEST(FieldForPointerTest, WorksForPointerToNonConst) {
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
}
}
// Tests that Field() works when the argument is a reference to a const pointer.
TEST
(
FieldForPointerTest
,
WorksForReferenceToConstPointer
)
{
Matcher
<
AStruct
*
const
&>
m
=
Field
(
&
AStruct
::
x
,
Ge
(
0
));
AStruct
a
;
EXPECT_TRUE
(
m
.
Matches
(
&
a
));
a
.
x
=
-
1
;
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
}
// Tests that Field() does not match the NULL pointer.
// Tests that Field() does not match the NULL pointer.
TEST
(
FieldForPointerTest
,
DoesNotMatchNull
)
{
TEST
(
FieldForPointerTest
,
DoesNotMatchNull
)
{
Matcher
<
const
AStruct
*>
m
=
Field
(
&
AStruct
::
x
,
_
);
Matcher
<
const
AStruct
*>
m
=
Field
(
&
AStruct
::
x
,
_
);
...
@@ -2846,6 +2856,19 @@ TEST(PropertyForPointerTest, WorksForPointerToNonConst) {
...
@@ -2846,6 +2856,19 @@ TEST(PropertyForPointerTest, WorksForPointerToNonConst) {
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
}
}
// Tests that Property() works when the argument is a reference to a
// const pointer.
TEST
(
PropertyForPointerTest
,
WorksForReferenceToConstPointer
)
{
Matcher
<
AClass
*
const
&>
m
=
Property
(
&
AClass
::
s
,
StartsWith
(
"hi"
));
AClass
a
;
a
.
set_s
(
"hill"
);
EXPECT_TRUE
(
m
.
Matches
(
&
a
));
a
.
set_s
(
"hole"
);
EXPECT_FALSE
(
m
.
Matches
(
&
a
));
}
// Tests that Property() does not match the NULL pointer.
// Tests that Property() does not match the NULL pointer.
TEST
(
PropertyForPointerTest
,
WorksForReferenceToNonConstProperty
)
{
TEST
(
PropertyForPointerTest
,
WorksForReferenceToNonConstProperty
)
{
Matcher
<
const
AClass
*>
m
=
Property
(
&
AClass
::
x
,
_
);
Matcher
<
const
AClass
*>
m
=
Property
(
&
AClass
::
x
,
_
);
...
...
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