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
f8304d76
Commit
f8304d76
authored
Jan 05, 2021
by
Abseil Team
Committed by
Derek Mauro
Jan 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Googletest export
Add support for printing incomplete types in the universal printer. PiperOrigin-RevId: 350154637
parent
95a9bdd9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
5 deletions
+19
-5
gtest-printers.h
googletest/include/gtest/gtest-printers.h
+12
-5
googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+7
-0
No files found.
googletest/include/gtest/gtest-printers.h
View file @
f8304d76
...
...
@@ -261,16 +261,23 @@ struct ConvertibleToStringViewPrinter {
GTEST_API_
void
PrintBytesInObjectTo
(
const
unsigned
char
*
obj_bytes
,
size_t
count
,
::
std
::
ostream
*
os
);
struct
FallbackPrinter
{
template
<
typename
T
>
struct
RawBytesPrinter
{
// SFINAE on `sizeof` to make sure we have a complete type.
template
<
typename
T
,
size_t
=
sizeof
(
T
)
>
static
void
PrintValue
(
const
T
&
value
,
::
std
::
ostream
*
os
)
{
PrintBytesInObjectTo
(
static_cast
<
const
unsigned
char
*>
(
reinterpret_cast
<
const
void
*>
(
std
::
addressof
(
value
))),
reinterpret_cast
<
const
unsigned
char
*>
(
std
::
addressof
(
value
)),
sizeof
(
value
),
os
);
}
};
struct
FallbackPrinter
{
template
<
typename
T
>
static
void
PrintValue
(
const
T
&
,
::
std
::
ostream
*
os
)
{
*
os
<<
"(incomplete type)"
;
}
};
// Try every printer in order and return the first one that works.
template
<
typename
T
,
typename
E
,
typename
Printer
,
typename
...
Printers
>
struct
FindFirstPrinter
:
FindFirstPrinter
<
T
,
E
,
Printers
...
>
{};
...
...
@@ -297,7 +304,7 @@ void PrintWithFallback(const T& value, ::std::ostream* os) {
T
,
void
,
ContainerPrinter
,
FunctionPointerPrinter
,
PointerPrinter
,
internal_stream_operator_without_lexical_name_lookup
::
StreamPrinter
,
ProtobufPrinter
,
ConvertibleToIntegerPrinter
,
ConvertibleToStringViewPrinter
,
FallbackPrinter
>::
type
;
ConvertibleToStringViewPrinter
,
RawBytesPrinter
,
FallbackPrinter
>::
type
;
Printer
::
PrintValue
(
value
,
os
);
}
...
...
googletest/test/googletest-printers-test.cc
View file @
f8304d76
...
...
@@ -1695,6 +1695,13 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ
(
"
\"\\\"
Line
\\
0 1
\\\"\\
nLine 2
\"
"
,
ss2
.
str
());
}
TEST
(
UniversalPrintTest
,
IncompleteType
)
{
struct
Incomplete
;
char
some_object
=
0
;
EXPECT_EQ
(
"(incomplete type)"
,
PrintToString
(
reinterpret_cast
<
Incomplete
&>
(
some_object
)));
}
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithStd
,
PrintsEmptyTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
make_tuple
());
EXPECT_EQ
(
0u
,
result
.
size
());
...
...
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