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
9d7455f9
Commit
9d7455f9
authored
Feb 02, 2011
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds null check for file locations in XML output printer.
parent
40d0ba7a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
16 deletions
+83
-16
gtest-internal.h
include/gtest/internal/gtest-internal.h
+0
-14
gtest-port.h
include/gtest/internal/gtest-port.h
+10
-0
gtest-port.cc
src/gtest-port.cc
+32
-0
gtest.cc
src/gtest.cc
+3
-2
gtest-port_test.cc
test/gtest-port_test.cc
+38
-0
No files found.
include/gtest/internal/gtest-internal.h
View file @
9d7455f9
...
@@ -536,20 +536,6 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
...
@@ -536,20 +536,6 @@ GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr,
#endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
// Formats a source file path and a line number as they would appear
// in a compiler error message.
inline
String
FormatFileLocation
(
const
char
*
file
,
int
line
)
{
const
char
*
const
file_name
=
file
==
NULL
?
"unknown file"
:
file
;
if
(
line
<
0
)
{
return
String
::
Format
(
"%s:"
,
file_name
);
}
#ifdef _MSC_VER
return
String
::
Format
(
"%s(%d):"
,
file_name
,
line
);
#else
return
String
::
Format
(
"%s:%d:"
,
file_name
,
line
);
#endif // _MSC_VER
}
// Types of SetUpTestCase() and TearDownTestCase() functions.
// Types of SetUpTestCase() and TearDownTestCase() functions.
typedef
void
(
*
SetUpTestCaseFunc
)();
typedef
void
(
*
SetUpTestCaseFunc
)();
typedef
void
(
*
TearDownTestCaseFunc
)();
typedef
void
(
*
TearDownTestCaseFunc
)();
...
...
include/gtest/internal/gtest-port.h
View file @
9d7455f9
...
@@ -848,6 +848,16 @@ class GTEST_API_ RE {
...
@@ -848,6 +848,16 @@ class GTEST_API_ RE {
GTEST_DISALLOW_ASSIGN_
(
RE
);
GTEST_DISALLOW_ASSIGN_
(
RE
);
};
};
// 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
);
// 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.
GTEST_API_
::
std
::
string
FormatCompilerIndependentFileLocation
(
const
char
*
file
,
int
line
);
// Defines logging utilities:
// Defines logging utilities:
// GTEST_LOG_(severity) - logs messages at the specified severity level. The
// GTEST_LOG_(severity) - logs messages at the specified severity level. The
// message itself is streamed into the macro.
// message itself is streamed into the macro.
...
...
src/gtest-port.cc
View file @
9d7455f9
...
@@ -424,6 +424,38 @@ void RE::Init(const char* regex) {
...
@@ -424,6 +424,38 @@ void RE::Init(const char* regex) {
#endif // GTEST_USES_POSIX_RE
#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
)
GTestLog
::
GTestLog
(
GTestLogSeverity
severity
,
const
char
*
file
,
int
line
)
:
severity_
(
severity
)
{
:
severity_
(
severity
)
{
...
...
src/gtest.cc
View file @
9d7455f9
...
@@ -3245,8 +3245,9 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
...
@@ -3245,8 +3245,9 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
<<
EscapeXmlAttribute
(
part
.
summary
()).
c_str
()
<<
EscapeXmlAttribute
(
part
.
summary
()).
c_str
()
<<
"
\"
type=
\"\"
>"
;
<<
"
\"
type=
\"\"
>"
;
const
String
message
=
RemoveInvalidXmlCharacters
(
String
::
Format
(
const
String
message
=
RemoveInvalidXmlCharacters
(
String
::
Format
(
"%s:%d
\n
%s"
,
"%s
\n
%s"
,
part
.
file_name
(),
part
.
line_number
(),
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
()).
c_str
(),
part
.
message
()).
c_str
());
part
.
message
()).
c_str
());
OutputXmlCDataSection
(
stream
,
message
.
c_str
());
OutputXmlCDataSection
(
stream
,
message
.
c_str
());
*
stream
<<
"</failure>
\n
"
;
*
stream
<<
"</failure>
\n
"
;
...
...
test/gtest-port_test.cc
View file @
9d7455f9
...
@@ -209,6 +209,44 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
...
@@ -209,6 +209,44 @@ TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
GTEST_CHECK_
(
true
)
<<
"Check failed in switch case"
;
GTEST_CHECK_
(
true
)
<<
"Check failed in switch case"
;
}
}
// Verifies behavior of FormatFileLocation.
TEST
(
FormatFileLocationTest
,
FormatsFileLocation
)
{
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"foo.cc"
,
FormatFileLocation
(
"foo.cc"
,
42
));
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"42"
,
FormatFileLocation
(
"foo.cc"
,
42
));
}
TEST
(
FormatFileLocationTest
,
FormatsUnknownFile
)
{
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"unknown file"
,
FormatFileLocation
(
NULL
,
42
));
EXPECT_PRED_FORMAT2
(
IsSubstring
,
"42"
,
FormatFileLocation
(
NULL
,
42
));
}
TEST
(
FormatFileLocationTest
,
FormatsUknownLine
)
{
EXPECT_EQ
(
"foo.cc:"
,
FormatFileLocation
(
"foo.cc"
,
-
1
));
}
TEST
(
FormatFileLocationTest
,
FormatsUknownFileAndLine
)
{
EXPECT_EQ
(
"unknown file:"
,
FormatFileLocation
(
NULL
,
-
1
));
}
// Verifies behavior of FormatCompilerIndependentFileLocation.
TEST
(
FormatCompilerIndependentFileLocationTest
,
FormatsFileLocation
)
{
EXPECT_EQ
(
"foo.cc:42"
,
FormatCompilerIndependentFileLocation
(
"foo.cc"
,
42
));
}
TEST
(
FormatCompilerIndependentFileLocationTest
,
FormatsUknownFile
)
{
EXPECT_EQ
(
"unknown file:42"
,
FormatCompilerIndependentFileLocation
(
NULL
,
42
));
}
TEST
(
FormatCompilerIndependentFileLocationTest
,
FormatsUknownLine
)
{
EXPECT_EQ
(
"foo.cc"
,
FormatCompilerIndependentFileLocation
(
"foo.cc"
,
-
1
));
}
TEST
(
FormatCompilerIndependentFileLocationTest
,
FormatsUknownFileAndLine
)
{
EXPECT_EQ
(
"unknown file"
,
FormatCompilerIndependentFileLocation
(
NULL
,
-
1
));
}
#if GTEST_OS_MAC
#if GTEST_OS_MAC
void
*
ThreadFunc
(
void
*
data
)
{
void
*
ThreadFunc
(
void
*
data
)
{
pthread_mutex_t
*
mutex
=
static_cast
<
pthread_mutex_t
*>
(
data
);
pthread_mutex_t
*
mutex
=
static_cast
<
pthread_mutex_t
*>
(
data
);
...
...
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