Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
03062e23
Commit
03062e23
authored
Mar 30, 2011
by
vladlosev
Browse files
Fixes 'formatting error or buffer exceeded' error when outputting long failure messages in XML.
parent
1d8c5af3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
src/gtest.cc
src/gtest.cc
+13
-17
No files found.
src/gtest.cc
View file @
03062e23
...
...
@@ -3032,7 +3032,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
static
String
EscapeXml
(
const
char
*
str
,
bool
is_attribute
);
// Returns the given string with all characters invalid in XML removed.
static
S
tring
RemoveInvalidXmlCharacters
(
const
char
*
str
);
static
s
tring
RemoveInvalidXmlCharacters
(
const
string
&
str
);
// Convenience wrapper around EscapeXml when str is an attribute value.
static
String
EscapeXmlAttribute
(
const
char
*
str
)
{
...
...
@@ -3166,17 +3166,14 @@ String XmlUnitTestResultPrinter::EscapeXml(const char* str, bool is_attribute) {
// Returns the given string with all characters invalid in XML removed.
// Currently invalid characters are dropped from the string. An
// alternative is to replace them with certain characters such as . or ?.
String
XmlUnitTestResultPrinter
::
RemoveInvalidXmlCharacters
(
const
char
*
str
)
{
char
*
const
output
=
new
char
[
strlen
(
str
)
+
1
];
char
*
appender
=
output
;
for
(
char
ch
=
*
str
;
ch
!=
'\0'
;
ch
=
*++
str
)
if
(
IsValidXmlCharacter
(
ch
))
*
appender
++
=
ch
;
*
appender
=
'\0'
;
string
XmlUnitTestResultPrinter
::
RemoveInvalidXmlCharacters
(
const
string
&
str
)
{
string
output
;
output
.
reserve
(
str
.
size
());
for
(
string
::
const_iterator
it
=
str
.
begin
();
it
!=
str
.
end
();
++
it
)
if
(
IsValidXmlCharacter
(
*
it
))
output
.
push_back
(
*
it
);
String
ret_value
(
output
);
delete
[]
output
;
return
ret_value
;
return
output
;
}
// The following routines generate an XML representation of a UnitTest
...
...
@@ -3256,12 +3253,11 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
*
stream
<<
" <failure message=
\"
"
<<
EscapeXmlAttribute
(
part
.
summary
()).
c_str
()
<<
"
\"
type=
\"\"
>"
;
const
String
message
=
RemoveInvalidXmlCharacters
(
String
::
Format
(
"%s
\n
%s"
,
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
()).
c_str
(),
part
.
message
()).
c_str
());
OutputXmlCDataSection
(
stream
,
message
.
c_str
());
const
string
location
=
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
());
const
string
message
=
location
+
"
\n
"
+
part
.
message
();
OutputXmlCDataSection
(
stream
,
RemoveInvalidXmlCharacters
(
message
).
c_str
());
*
stream
<<
"</failure>
\n
"
;
}
}
...
...
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