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
7123d831
Commit
7123d831
authored
Nov 17, 2014
by
kosak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix gmock Action behaviour when return type is Wrapper
parent
506340a6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
gmock-actions.h
include/gmock/gmock-actions.h
+6
-2
gmock-actions_test.cc
test/gmock-actions_test.cc
+20
-0
No files found.
include/gmock/gmock-actions.h
View file @
7123d831
...
@@ -534,16 +534,20 @@ class ReturnAction {
...
@@ -534,16 +534,20 @@ class ReturnAction {
// Result without considering explicit constructors, thus resolving the
// Result without considering explicit constructors, thus resolving the
// ambiguity. value_ is then initialized using its copy constructor.
// ambiguity. value_ is then initialized using its copy constructor.
explicit
Impl
(
const
linked_ptr
<
R
>&
value
)
explicit
Impl
(
const
linked_ptr
<
R
>&
value
)
:
value_
(
ImplicitCast_
<
Result
>
(
*
value
))
{}
:
value_before_cast_
(
*
value
),
value_
(
ImplicitCast_
<
Result
>
(
value_before_cast_
))
{}
virtual
Result
Perform
(
const
ArgumentTuple
&
)
{
return
value_
;
}
virtual
Result
Perform
(
const
ArgumentTuple
&
)
{
return
value_
;
}
private
:
private
:
GTEST_COMPILE_ASSERT_
(
!
is_reference
<
Result
>::
value
,
GTEST_COMPILE_ASSERT_
(
!
is_reference
<
Result
>::
value
,
Result_cannot_be_a_reference_type
);
Result_cannot_be_a_reference_type
);
// We save the value before casting just in case it is being cast to a
// wrapper type.
R
value_before_cast_
;
Result
value_
;
Result
value_
;
GTEST_DISALLOW_ASSIGN_
(
Impl
);
GTEST_DISALLOW_
COPY_AND_
ASSIGN_
(
Impl
);
};
};
// Partially specialize for ByMoveWrapper. This version of ReturnAction will
// Partially specialize for ByMoveWrapper. This version of ReturnAction will
...
...
test/gmock-actions_test.cc
View file @
7123d831
...
@@ -509,6 +509,26 @@ TEST(ReturnTest, AcceptsStringLiteral) {
...
@@ -509,6 +509,26 @@ TEST(ReturnTest, AcceptsStringLiteral) {
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
make_tuple
()));
EXPECT_EQ
(
"world"
,
a2
.
Perform
(
make_tuple
()));
}
}
// Test struct which wraps a vector of integers. Used in
// 'SupportsWrapperReturnType' test.
struct
IntegerVectorWrapper
{
std
::
vector
<
int
>
*
v
;
IntegerVectorWrapper
(
std
::
vector
<
int
>&
_v
)
:
v
(
&
_v
)
{}
// NOLINT
};
// Tests that Return() works when return type is a wrapper type.
TEST
(
ReturnTest
,
SupportsWrapperReturnType
)
{
// Initialize vector of integers.
std
::
vector
<
int
>
v
;
for
(
int
i
=
0
;
i
<
5
;
++
i
)
v
.
push_back
(
i
);
// Return() called with 'v' as argument. The Action will return the same data
// as 'v' (copy) but it will be wrapped in an IntegerVectorWrapper.
Action
<
IntegerVectorWrapper
()
>
a
=
Return
(
v
);
const
std
::
vector
<
int
>&
result
=
*
(
a
.
Perform
(
make_tuple
()).
v
);
EXPECT_THAT
(
result
,
::
testing
::
ElementsAre
(
0
,
1
,
2
,
3
,
4
));
}
// Tests that Return(v) is covaraint.
// Tests that Return(v) is covaraint.
struct
Base
{
struct
Base
{
...
...
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