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
097407fd
Commit
097407fd
authored
Jan 12, 2019
by
Abseil Team
Committed by
Gennadiy Civil
Jan 14, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Deduplicate testing::ReferenceWrapper with std::reference_wrapper. Minor cleanups in matchers_test. PiperOrigin-RevId: 229022872
parent
0599a7b8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
105 deletions
+19
-105
gmock-actions.h
googlemock/include/gmock/gmock-actions.h
+5
-29
gmock-actions_test.cc
googlemock/test/gmock-actions_test.cc
+3
-5
gmock-matchers_test.cc
googlemock/test/gmock-matchers_test.cc
+0
-63
gtest-printers.h
googletest/include/gtest/gtest-printers.h
+1
-2
googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+10
-6
No files found.
googlemock/include/gmock/gmock-actions.h
View file @
097407fd
...
@@ -936,33 +936,6 @@ class IgnoreResultAction {
...
@@ -936,33 +936,6 @@ class IgnoreResultAction {
GTEST_DISALLOW_ASSIGN_
(
IgnoreResultAction
);
GTEST_DISALLOW_ASSIGN_
(
IgnoreResultAction
);
};
};
// A ReferenceWrapper<T> object represents a reference to type T,
// which can be either const or not. It can be explicitly converted
// from, and implicitly converted to, a T&. Unlike a reference,
// ReferenceWrapper<T> can be copied and can survive template type
// inference. This is used to support by-reference arguments in the
// InvokeArgument<N>(...) action. The idea was from "reference
// wrappers" in tr1, which we don't have in our source tree yet.
template
<
typename
T
>
class
ReferenceWrapper
{
public
:
// Constructs a ReferenceWrapper<T> object from a T&.
explicit
ReferenceWrapper
(
T
&
l_value
)
:
pointer_
(
&
l_value
)
{}
// NOLINT
// Allows a ReferenceWrapper<T> object to be implicitly converted to
// a T&.
operator
T
&
()
const
{
return
*
pointer_
;
}
private
:
T
*
pointer_
;
};
// Allows the expression ByRef(x) to be printed as a reference to x.
template
<
typename
T
>
void
PrintTo
(
const
ReferenceWrapper
<
T
>&
ref
,
::
std
::
ostream
*
os
)
{
T
&
value
=
ref
;
UniversalPrinter
<
T
&>::
Print
(
value
,
os
);
}
template
<
typename
InnerAction
,
size_t
...
I
>
template
<
typename
InnerAction
,
size_t
...
I
>
struct
WithArgsAction
{
struct
WithArgsAction
{
InnerAction
action
;
InnerAction
action
;
...
@@ -1219,9 +1192,12 @@ inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
...
@@ -1219,9 +1192,12 @@ inline internal::IgnoreResultAction<A> IgnoreResult(const A& an_action) {
// where Base is a base class of Derived, just write:
// where Base is a base class of Derived, just write:
//
//
// ByRef<const Base>(derived)
// ByRef<const Base>(derived)
//
// N.B. ByRef is redundant with std::ref, std::cref and std::reference_wrapper.
// However, it may still be used for consistency with ByMove().
template
<
typename
T
>
template
<
typename
T
>
inline
internal
::
ReferenceW
rapper
<
T
>
ByRef
(
T
&
l_value
)
{
// NOLINT
inline
::
std
::
reference_w
rapper
<
T
>
ByRef
(
T
&
l_value
)
{
// NOLINT
return
internal
::
ReferenceW
rapper
<
T
>
(
l_value
);
return
::
std
::
reference_w
rapper
<
T
>
(
l_value
);
}
}
}
// namespace testing
}
// namespace testing
...
...
googlemock/test/gmock-actions_test.cc
View file @
097407fd
...
@@ -1164,13 +1164,12 @@ TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
...
@@ -1164,13 +1164,12 @@ TEST_F(SetErrnoAndReturnTest, CompatibleTypes) {
// Tests ByRef().
// Tests ByRef().
// Tests that
ReferenceWrapper<T>
is copyable.
// Tests that
the result of ByRef()
is copyable.
TEST
(
ByRefTest
,
IsCopyable
)
{
TEST
(
ByRefTest
,
IsCopyable
)
{
const
std
::
string
s1
=
"Hi"
;
const
std
::
string
s1
=
"Hi"
;
const
std
::
string
s2
=
"Hello"
;
const
std
::
string
s2
=
"Hello"
;
::
testing
::
internal
::
ReferenceWrapper
<
const
std
::
string
>
ref_wrapper
=
auto
ref_wrapper
=
ByRef
(
s1
);
ByRef
(
s1
);
const
std
::
string
&
r1
=
ref_wrapper
;
const
std
::
string
&
r1
=
ref_wrapper
;
EXPECT_EQ
(
&
s1
,
&
r1
);
EXPECT_EQ
(
&
s1
,
&
r1
);
...
@@ -1179,8 +1178,7 @@ TEST(ByRefTest, IsCopyable) {
...
@@ -1179,8 +1178,7 @@ TEST(ByRefTest, IsCopyable) {
const
std
::
string
&
r2
=
ref_wrapper
;
const
std
::
string
&
r2
=
ref_wrapper
;
EXPECT_EQ
(
&
s2
,
&
r2
);
EXPECT_EQ
(
&
s2
,
&
r2
);
::
testing
::
internal
::
ReferenceWrapper
<
const
std
::
string
>
ref_wrapper1
=
auto
ref_wrapper1
=
ByRef
(
s1
);
ByRef
(
s1
);
// Copies ref_wrapper1 to ref_wrapper.
// Copies ref_wrapper1 to ref_wrapper.
ref_wrapper
=
ref_wrapper1
;
ref_wrapper
=
ref_wrapper1
;
const
std
::
string
&
r3
=
ref_wrapper
;
const
std
::
string
&
r3
=
ref_wrapper
;
...
...
googlemock/test/gmock-matchers_test.cc
View file @
097407fd
...
@@ -80,65 +80,6 @@ using std::pair;
...
@@ -80,65 +80,6 @@ using std::pair;
using
std
::
set
;
using
std
::
set
;
using
std
::
stringstream
;
using
std
::
stringstream
;
using
std
::
vector
;
using
std
::
vector
;
using
testing
::
_
;
using
testing
::
A
;
using
testing
::
AllArgs
;
using
testing
::
AllOf
;
using
testing
::
An
;
using
testing
::
AnyOf
;
using
testing
::
ByRef
;
using
testing
::
ContainsRegex
;
using
testing
::
DoubleEq
;
using
testing
::
DoubleNear
;
using
testing
::
EndsWith
;
using
testing
::
Eq
;
using
testing
::
ExplainMatchResult
;
using
testing
::
Field
;
using
testing
::
FloatEq
;
using
testing
::
FloatNear
;
using
testing
::
Ge
;
using
testing
::
Gt
;
using
testing
::
HasSubstr
;
using
testing
::
IsEmpty
;
using
testing
::
IsNull
;
using
testing
::
Key
;
using
testing
::
Le
;
using
testing
::
Lt
;
using
testing
::
MakeMatcher
;
using
testing
::
MakePolymorphicMatcher
;
using
testing
::
Matcher
;
using
testing
::
MatcherCast
;
using
testing
::
MatcherInterface
;
using
testing
::
Matches
;
using
testing
::
MatchesRegex
;
using
testing
::
MatchResultListener
;
using
testing
::
NanSensitiveDoubleEq
;
using
testing
::
NanSensitiveDoubleNear
;
using
testing
::
NanSensitiveFloatEq
;
using
testing
::
NanSensitiveFloatNear
;
using
testing
::
Ne
;
using
testing
::
Not
;
using
testing
::
NotNull
;
using
testing
::
Pair
;
using
testing
::
Pointee
;
using
testing
::
Pointwise
;
using
testing
::
PolymorphicMatcher
;
using
testing
::
Property
;
using
testing
::
Ref
;
using
testing
::
ResultOf
;
using
testing
::
SizeIs
;
using
testing
::
StartsWith
;
using
testing
::
StrCaseEq
;
using
testing
::
StrCaseNe
;
using
testing
::
StrEq
;
using
testing
::
StringMatchResultListener
;
using
testing
::
StrNe
;
using
testing
::
Truly
;
using
testing
::
TypedEq
;
using
testing
::
UnorderedPointwise
;
using
testing
::
Value
;
using
testing
::
WhenSorted
;
using
testing
::
WhenSortedBy
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
DummyMatchResultListener
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPair
;
using
testing
::
internal
::
ElementMatcherPairs
;
using
testing
::
internal
::
ElementMatcherPairs
;
...
@@ -6995,10 +6936,6 @@ class PredicateFormatterFromMatcherTest : public ::testing::Test {
...
@@ -6995,10 +6936,6 @@ class PredicateFormatterFromMatcherTest : public ::testing::Test {
matcher
);
matcher
);
return
predicate_formatter
(
"dummy-name"
,
behavior
);
return
predicate_formatter
(
"dummy-name"
,
behavior
);
}
}
const
std
::
string
kMatcherType
=
"testing::gmock_matchers_test::PredicateFormatterFromMatcherTest::"
"Behavior"
;
};
};
TEST_F
(
PredicateFormatterFromMatcherTest
,
ShortCircuitOnSuccess
)
{
TEST_F
(
PredicateFormatterFromMatcherTest
,
ShortCircuitOnSuccess
)
{
...
...
googletest/include/gtest/gtest-printers.h
View file @
097407fd
...
@@ -637,8 +637,7 @@ inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
...
@@ -637,8 +637,7 @@ inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; }
template
<
typename
T
>
template
<
typename
T
>
void
PrintTo
(
std
::
reference_wrapper
<
T
>
ref
,
::
std
::
ostream
*
os
)
{
void
PrintTo
(
std
::
reference_wrapper
<
T
>
ref
,
::
std
::
ostream
*
os
)
{
// Delegate to wrapped value.
UniversalPrinter
<
T
&>::
Print
(
ref
.
get
(),
os
);
PrintTo
(
ref
.
get
(),
os
);
}
}
// Helper function for printing a tuple. T must be instantiated with
// Helper function for printing a tuple. T must be instantiated with
...
...
googletest/test/googletest-printers-test.cc
View file @
097407fd
...
@@ -1023,16 +1023,20 @@ TEST(PrintNullptrT, Basic) {
...
@@ -1023,16 +1023,20 @@ TEST(PrintNullptrT, Basic) {
TEST
(
PrintReferenceWrapper
,
Printable
)
{
TEST
(
PrintReferenceWrapper
,
Printable
)
{
int
x
=
5
;
int
x
=
5
;
EXPECT_EQ
(
"5"
,
Print
(
std
::
ref
(
x
)));
EXPECT_EQ
(
"
@"
+
PrintPointer
(
&
x
)
+
"
5"
,
Print
(
std
::
ref
(
x
)));
EXPECT_EQ
(
"5"
,
Print
(
std
::
cref
(
x
)));
EXPECT_EQ
(
"
@"
+
PrintPointer
(
&
x
)
+
"
5"
,
Print
(
std
::
cref
(
x
)));
}
}
TEST
(
PrintReferenceWrapper
,
Unprintable
)
{
TEST
(
PrintReferenceWrapper
,
Unprintable
)
{
::
foo
::
UnprintableInFoo
up
;
::
foo
::
UnprintableInFoo
up
;
EXPECT_EQ
(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>"
,
EXPECT_EQ
(
Print
(
std
::
ref
(
up
)));
"@"
+
PrintPointer
(
&
up
)
+
EXPECT_EQ
(
"16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>"
,
" 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>"
,
Print
(
std
::
cref
(
up
)));
Print
(
std
::
ref
(
up
)));
EXPECT_EQ
(
"@"
+
PrintPointer
(
&
up
)
+
" 16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>"
,
Print
(
std
::
cref
(
up
)));
}
}
// Tests printing user-defined unprintable types.
// Tests printing user-defined unprintable types.
...
...
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