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
af058521
Commit
af058521
authored
Feb 09, 2021
by
Abseil Team
Committed by
Andy Soffer
Feb 11, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Fix #2987 Removing const before passing any types through UniversalPrinter. PiperOrigin-RevId: 356508875
parent
9c2293af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
gtest-printers.h
googletest/include/gtest/gtest-printers.h
+4
-0
googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+34
-0
No files found.
googletest/include/gtest/gtest-printers.h
View file @
af058521
...
...
@@ -677,6 +677,10 @@ class UniversalPrinter {
GTEST_DISABLE_MSC_WARNINGS_POP_
()
};
// Remove any const-qualifiers before passing a type to UniversalPrinter.
template
<
typename
T
>
class
UniversalPrinter
<
const
T
>
:
public
UniversalPrinter
<
T
>
{};
#if GTEST_INTERNAL_HAS_ANY
// Printer for std::any / absl::any
...
...
googletest/test/googletest-printers-test.cc
View file @
af058521
...
...
@@ -229,6 +229,33 @@ class PathLike {
}
// namespace foo
namespace
testing
{
namespace
{
template
<
typename
T
>
class
Wrapper
{
public
:
explicit
Wrapper
(
T
&&
value
)
:
value_
(
std
::
forward
<
T
>
(
value
))
{}
const
T
&
value
()
const
{
return
value_
;
}
private
:
T
value_
;
};
}
// namespace
namespace
internal
{
template
<
typename
T
>
class
UniversalPrinter
<
Wrapper
<
T
>>
{
public
:
static
void
Print
(
const
Wrapper
<
T
>&
w
,
::
std
::
ostream
*
os
)
{
*
os
<<
"Wrapper("
;
UniversalPrint
(
w
.
value
(),
os
);
*
os
<<
')'
;
}
};
}
// namespace internal
namespace
gtest_printers_test
{
using
::
std
::
deque
;
...
...
@@ -1667,6 +1694,13 @@ TEST(UniversalPrintTest, WorksForReference) {
EXPECT_EQ
(
"123"
,
ss
.
str
());
}
TEST
(
UniversalPrintTest
,
WorksForPairWithConst
)
{
std
::
pair
<
const
Wrapper
<
std
::
string
>
,
int
>
p
(
Wrapper
<
std
::
string
>
(
"abc"
),
1
);
::
std
::
stringstream
ss
;
UniversalPrint
(
p
,
&
ss
);
EXPECT_EQ
(
"(Wrapper(
\"
abc
\"
), 1)"
,
ss
.
str
());
}
TEST
(
UniversalPrintTest
,
WorksForCString
)
{
const
char
*
s1
=
"abc"
;
::
std
::
stringstream
ss1
;
...
...
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