summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2011-02-02 10:07:04 +0000
committervladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2011-02-02 10:07:04 +0000
commit30552030bea75bf2d27c49437e757b8a5d3b2e98 (patch)
treedfb2f65d0932332b217c19dd22ed62d18e70e2c9 /src
parent34b3f298ed6c093e36511e235fff9d7501ec4395 (diff)
downloadgtest-30552030bea75bf2d27c49437e757b8a5d3b2e98.tar.gz
gtest-30552030bea75bf2d27c49437e757b8a5d3b2e98.tar.bz2
gtest-30552030bea75bf2d27c49437e757b8a5d3b2e98.tar.xz
Adds null check for file locations in XML output printer.
git-svn-id: http://googletest.googlecode.com/svn/trunk@540 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'src')
-rw-r--r--src/gtest-port.cc32
-rw-r--r--src/gtest.cc5
2 files changed, 35 insertions, 2 deletions
diff --git a/src/gtest-port.cc b/src/gtest-port.cc
index da62fba..4310a73 100644
--- a/src/gtest-port.cc
+++ b/src/gtest-port.cc
@@ -424,6 +424,38 @@ void RE::Init(const char* regex) {
#endif // GTEST_USES_POSIX_RE
+const char kUnknownFile[] = "unknown file";
+
+// Formats a source file path and a line number as they would appear
+// in an error message from the compiler used to compile this code.
+GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
+ const char* const file_name = file == NULL ? kUnknownFile : file;
+
+ if (line < 0) {
+ return String::Format("%s:", file_name).c_str();
+ }
+#ifdef _MSC_VER
+ return String::Format("%s(%d):", file_name, line).c_str();
+#else
+ return String::Format("%s:%d:", file_name, line).c_str();
+#endif // _MSC_VER
+}
+
+// Formats a file location for compiler-independent XML output.
+// Although this function is not platform dependent, we put it next to
+// FormatFileLocation in order to contrast the two functions.
+// Note that FormatCompilerIndependentFileLocation() does NOT append colon
+// to the file location it produces, unlike FormatFileLocation().
+GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
+ const char* file, int line) {
+ const char* const file_name = file == NULL ? kUnknownFile : file;
+
+ if (line < 0)
+ return file_name;
+ else
+ return String::Format("%s:%d", file_name, line).c_str();
+}
+
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
: severity_(severity) {
diff --git a/src/gtest.cc b/src/gtest.cc
index 575a8a5..1c58c6f 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -3245,8 +3245,9 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
<< EscapeXmlAttribute(part.summary()).c_str()
<< "\" type=\"\">";
const String message = RemoveInvalidXmlCharacters(String::Format(
- "%s:%d\n%s",
- part.file_name(), part.line_number(),
+ "%s\n%s",
+ internal::FormatCompilerIndependentFileLocation(
+ part.file_name(), part.line_number()).c_str(),
part.message()).c_str());
OutputXmlCDataSection(stream, message.c_str());
*stream << "</failure>\n";