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
53d49dc4
Commit
53d49dc4
authored
Jan 08, 2015
by
kosak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ReturnNull() support unique_ptr and shared_ptr.
parent
8e838ce0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
1 deletion
+19
-1
gmock-actions.h
include/gmock/gmock-actions.h
+7
-1
gmock-actions_test.cc
test/gmock-actions_test.cc
+12
-0
No files found.
include/gmock/gmock-actions.h
View file @
53d49dc4
...
@@ -583,12 +583,18 @@ class ReturnAction {
...
@@ -583,12 +583,18 @@ class ReturnAction {
// Implements the ReturnNull() action.
// Implements the ReturnNull() action.
class
ReturnNullAction
{
class
ReturnNullAction
{
public
:
public
:
// Allows ReturnNull() to be used in any pointer-returning function.
// Allows ReturnNull() to be used in any pointer-returning function. In C++11
// this is enforced by returning nullptr, and in non-C++11 by asserting a
// pointer type on compile time.
template
<
typename
Result
,
typename
ArgumentTuple
>
template
<
typename
Result
,
typename
ArgumentTuple
>
static
Result
Perform
(
const
ArgumentTuple
&
)
{
static
Result
Perform
(
const
ArgumentTuple
&
)
{
#if GTEST_LANG_CXX11
return
nullptr
;
#else
GTEST_COMPILE_ASSERT_
(
internal
::
is_pointer
<
Result
>::
value
,
GTEST_COMPILE_ASSERT_
(
internal
::
is_pointer
<
Result
>::
value
,
ReturnNull_can_be_used_to_return_a_pointer_only
);
ReturnNull_can_be_used_to_return_a_pointer_only
);
return
NULL
;
return
NULL
;
#endif // GTEST_LANG_CXX11
}
}
};
};
...
...
test/gmock-actions_test.cc
View file @
53d49dc4
...
@@ -604,6 +604,18 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
...
@@ -604,6 +604,18 @@ TEST(ReturnNullTest, WorksInPointerReturningFunction) {
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
true
))
==
NULL
);
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
true
))
==
NULL
);
}
}
#if GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnNull() returns NULL for shared_ptr and unique_ptr returning
// functions.
TEST
(
ReturnNullTest
,
WorksInSmartPointerReturningFunction
)
{
const
Action
<
std
::
unique_ptr
<
const
int
>
()
>
a1
=
ReturnNull
();
EXPECT_TRUE
(
a1
.
Perform
(
make_tuple
())
==
nullptr
);
const
Action
<
std
::
shared_ptr
<
int
>
(
std
::
string
)
>
a2
=
ReturnNull
();
EXPECT_TRUE
(
a2
.
Perform
(
make_tuple
(
"foo"
))
==
nullptr
);
}
#endif // GTEST_HAS_STD_UNIQUE_PTR_
// Tests that ReturnRef(v) works for reference types.
// Tests that ReturnRef(v) works for reference types.
TEST
(
ReturnRefTest
,
WorksForReference
)
{
TEST
(
ReturnRefTest
,
WorksForReference
)
{
const
int
n
=
0
;
const
int
n
=
0
;
...
...
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