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
ada23475
Commit
ada23475
authored
Aug 14, 2012
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Makes gmock's Pointee() work for optional<T> (by Jeffrey Yasskin).
parent
2fd619ed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
gmock-internal-utils.h
include/gmock/internal/gmock-internal-utils.h
+1
-1
gmock-matchers_test.cc
test/gmock-matchers_test.cc
+32
-0
No files found.
include/gmock/internal/gmock-internal-utils.h
View file @
ada23475
...
...
@@ -73,7 +73,7 @@ struct PointeeOf<T*> { typedef T type; }; // NOLINT
// smart pointer, or returns p itself when p is already a raw pointer.
// The following default implementation is for the smart pointer case.
template
<
typename
Pointer
>
inline
typename
Pointer
::
element_type
*
GetRawPointer
(
const
Pointer
&
p
)
{
inline
const
typename
Pointer
::
element_type
*
GetRawPointer
(
const
Pointer
&
p
)
{
return
p
.
get
();
}
// This overloaded version is for the raw pointer case.
...
...
test/gmock-matchers_test.cc
View file @
ada23475
...
...
@@ -2824,6 +2824,38 @@ TEST(PointeeTest, ReferenceToNonConstRawPointer) {
EXPECT_FALSE
(
m
.
Matches
(
p
));
}
// Minimal const-propagating pointer.
template
<
typename
T
>
class
ConstPropagatingPtr
{
public
:
typedef
T
element_type
;
ConstPropagatingPtr
()
:
val_
()
{}
explicit
ConstPropagatingPtr
(
T
*
t
)
:
val_
(
t
)
{}
ConstPropagatingPtr
(
const
ConstPropagatingPtr
&
other
)
:
val_
(
other
.
val_
)
{}
T
*
get
()
{
return
val_
;
}
T
&
operator
*
()
{
return
*
val_
;
}
// Most smart pointers return non-const T* and T& from the next methods.
const
T
*
get
()
const
{
return
val_
;
}
const
T
&
operator
*
()
const
{
return
*
val_
;
}
private
:
T
*
val_
;
};
TEST
(
PointeeTest
,
WorksWithConstPropagatingPointers
)
{
const
Matcher
<
ConstPropagatingPtr
<
int
>
>
m
=
Pointee
(
Lt
(
5
));
int
three
=
3
;
const
ConstPropagatingPtr
<
int
>
co
(
&
three
);
ConstPropagatingPtr
<
int
>
o
(
&
three
);
EXPECT_TRUE
(
m
.
Matches
(
o
));
EXPECT_TRUE
(
m
.
Matches
(
co
));
*
o
=
6
;
EXPECT_FALSE
(
m
.
Matches
(
o
));
EXPECT_FALSE
(
m
.
Matches
(
ConstPropagatingPtr
<
int
>
()));
}
TEST
(
PointeeTest
,
NeverMatchesNull
)
{
const
Matcher
<
const
char
*>
m
=
Pointee
(
_
);
EXPECT_FALSE
(
m
.
Matches
(
NULL
));
...
...
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