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
a7a7f51d
"docs/deployment/frameworks/anyscale.md" did not exist on "2ca8867f0322aac5927d6b6741619ec36349c7ac"
Unverified
Commit
a7a7f51d
authored
Mar 05, 2018
by
Tanzinul Islam
Committed by
GitHub
Mar 05, 2018
Browse files
Merge branch 'master' into fix_death_test_child_mingw_wer_issue1116
parents
4ba3803f
6c73adfc
Changes
138
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1018 additions
and
267 deletions
+1018
-267
googletest/src/gtest-death-test.cc
googletest/src/gtest-death-test.cc
+19
-14
googletest/src/gtest-filepath.cc
googletest/src/gtest-filepath.cc
+5
-7
googletest/src/gtest-internal-inl.h
googletest/src/gtest-internal-inl.h
+6
-14
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+9
-11
googletest/src/gtest-printers.cc
googletest/src/gtest-printers.cc
+92
-7
googletest/src/gtest-test-part.cc
googletest/src/gtest-test-part.cc
+0
-8
googletest/src/gtest-typed-test.cc
googletest/src/gtest-typed-test.cc
+1
-0
googletest/src/gtest.cc
googletest/src/gtest.cc
+446
-98
googletest/src/gtest_main.cc
googletest/src/gtest_main.cc
+1
-1
googletest/test/BUILD.bazel
googletest/test/BUILD.bazel
+266
-4
googletest/test/gtest-death-test_test.cc
googletest/test/gtest-death-test_test.cc
+7
-11
googletest/test/gtest-filepath_test.cc
googletest/test/gtest-filepath_test.cc
+2
-12
googletest/test/gtest-options_test.cc
googletest/test/gtest-options_test.cc
+0
-8
googletest/test/gtest-param-test2_test.cc
googletest/test/gtest-param-test2_test.cc
+1
-5
googletest/test/gtest-param-test_test.cc
googletest/test/gtest-param-test_test.cc
+52
-25
googletest/test/gtest-param-test_test.h
googletest/test/gtest-param-test_test.h
+0
-4
googletest/test/gtest-port_test.cc
googletest/test/gtest-port_test.cc
+2
-10
googletest/test/gtest-printers_test.cc
googletest/test/gtest-printers_test.cc
+107
-26
googletest/test/gtest-typed-test2_test.cc
googletest/test/gtest-typed-test2_test.cc
+1
-1
googletest/test/gtest-typed-test_test.cc
googletest/test/gtest-typed-test_test.cc
+1
-1
No files found.
googletest/src/gtest-death-test.cc
View file @
a7a7f51d
...
...
@@ -66,22 +66,18 @@
#include "gtest/gtest-message.h"
#include "gtest/internal/gtest-string.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick exists to
// prevent the accidental inclusion of gtest-internal-inl.h in the
// user's code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
namespace
testing
{
// Constants.
// The default death test style.
static
const
char
kDefaultDeathTestStyle
[]
=
"fast"
;
//
// This is defined in internal/gtest-port.h as "fast", but can be overridden by
// a definition in internal/custom/gtest-port.h. The recommended value, which is
// used internally at Google, is "threadsafe".
static
const
char
kDefaultDeathTestStyle
[]
=
GTEST_DEFAULT_DEATH_TEST_STYLE
;
GTEST_DEFINE_string_
(
death_test_style
,
...
...
@@ -259,7 +255,7 @@ enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// message is propagated back to the parent process. Otherwise, the
// message is simply printed to stderr. In either case, the program
// then exits with status 1.
void
DeathTestAbort
(
const
std
::
string
&
message
)
{
static
void
DeathTestAbort
(
const
std
::
string
&
message
)
{
// On a POSIX system, this function may be called from a threadsafe-style
// death test child process, which operates on a very small stack. Use
// the heap for any additional non-minuscule memory requirements.
...
...
@@ -563,7 +559,13 @@ bool DeathTestImpl::Passed(bool status_ok) {
break
;
case
DIED
:
if
(
status_ok
)
{
# if GTEST_USES_PCRE
// PCRE regexes support embedded NULs.
// GTEST_USES_PCRE is defined only in google3 mode
const
bool
matched
=
RE
::
PartialMatch
(
error_message
,
*
regex
());
# else
const
bool
matched
=
RE
::
PartialMatch
(
error_message
.
c_str
(),
*
regex
());
# endif // GTEST_USES_PCRE
if
(
matched
)
{
success
=
true
;
}
else
{
...
...
@@ -985,6 +987,7 @@ static int ExecDeathTestChildMain(void* child_arg) {
}
# endif // !GTEST_OS_QNX
# if GTEST_HAS_CLONE
// Two utility routines that together determine the direction the stack
// grows.
// This could be accomplished more elegantly by a single recursive
...
...
@@ -994,20 +997,22 @@ static int ExecDeathTestChildMain(void* child_arg) {
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
// correct answer.
void
StackLowerThanAddress
(
const
void
*
ptr
,
bool
*
result
)
GTEST_NO_INLINE_
;
void
StackLowerThanAddress
(
const
void
*
ptr
,
bool
*
result
)
{
static
void
StackLowerThanAddress
(
const
void
*
ptr
,
bool
*
result
)
GTEST_NO_INLINE_
;
static
void
StackLowerThanAddress
(
const
void
*
ptr
,
bool
*
result
)
{
int
dummy
;
*
result
=
(
&
dummy
<
ptr
);
}
// Make sure AddressSanitizer does not tamper with the stack here.
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
bool
StackGrowsDown
()
{
static
bool
StackGrowsDown
()
{
int
dummy
;
bool
result
;
StackLowerThanAddress
(
&
dummy
,
&
result
);
return
result
;
}
# endif // GTEST_HAS_CLONE
// Spawns a child process with the same executable as the current process in
// a thread-safe manner and instructs it to run the death test. The
...
...
@@ -1223,7 +1228,7 @@ bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
// Recreates the pipe and event handles from the provided parameters,
// signals the event, and returns a file descriptor wrapped around the pipe
// handle. This function is called in the child process only.
int
GetStatusFileDescriptor
(
unsigned
int
parent_process_id
,
static
int
GetStatusFileDescriptor
(
unsigned
int
parent_process_id
,
size_t
write_handle_as_size_t
,
size_t
event_handle_as_size_t
)
{
AutoHandle
parent_process_handle
(
::
OpenProcess
(
PROCESS_DUP_HANDLE
,
...
...
googletest/src/gtest-filepath.cc
View file @
a7a7f51d
...
...
@@ -26,14 +26,12 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: keith.ray@gmail.com (Keith Ray)
#include "gtest/gtest-message.h"
#include "gtest/internal/gtest-filepath.h"
#include "gtest/internal/gtest-port.h"
#include <stdlib.h>
#include "gtest/internal/gtest-port.h"
#include "gtest/gtest-message.h"
#if GTEST_OS_WINDOWS_MOBILE
# include <windows.h>
...
...
@@ -48,6 +46,8 @@
# include <climits> // Some Linux distributions define PATH_MAX here.
#endif // GTEST_OS_WINDOWS_MOBILE
#include "gtest/internal/gtest-string.h"
#if GTEST_OS_WINDOWS
# define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX)
...
...
@@ -58,8 +58,6 @@
# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#endif // GTEST_OS_WINDOWS
#include "gtest/internal/gtest-string.h"
namespace
testing
{
namespace
internal
{
...
...
@@ -130,7 +128,7 @@ FilePath FilePath::RemoveExtension(const char* extension) const {
return
*
this
;
}
// Returns a pointer to the last occurence of a valid path separator in
// Returns a pointer to the last occur
r
ence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found.
const
char
*
FilePath
::
FindLastPathSeparator
()
const
{
...
...
googletest/src/gtest-internal-inl.h
View file @
a7a7f51d
...
...
@@ -37,14 +37,6 @@
#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
#define GTEST_SRC_GTEST_INTERNAL_INL_H_
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
// part of Google Test's implementation; otherwise it's undefined.
#if !GTEST_IMPLEMENTATION_
// If this file is included from the user's code, just say no.
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
# error "It must not be included except by Google Test itself."
#endif // GTEST_IMPLEMENTATION_
#ifndef _WIN32_WCE
# include <errno.h>
#endif // !_WIN32_WCE
...
...
@@ -67,7 +59,7 @@
# include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS
#include "gtest/gtest.h"
// NOLINT
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
namespace
testing
{
...
...
@@ -94,6 +86,7 @@ const char kFilterFlag[] = "filter";
const
char
kListTestsFlag
[]
=
"list_tests"
;
const
char
kOutputFlag
[]
=
"output"
;
const
char
kPrintTimeFlag
[]
=
"print_time"
;
const
char
kPrintUTF8Flag
[]
=
"print_utf8"
;
const
char
kRandomSeedFlag
[]
=
"random_seed"
;
const
char
kRepeatFlag
[]
=
"repeat"
;
const
char
kShuffleFlag
[]
=
"shuffle"
;
...
...
@@ -174,6 +167,7 @@ class GTestFlagSaver {
list_tests_
=
GTEST_FLAG
(
list_tests
);
output_
=
GTEST_FLAG
(
output
);
print_time_
=
GTEST_FLAG
(
print_time
);
print_utf8_
=
GTEST_FLAG
(
print_utf8
);
random_seed_
=
GTEST_FLAG
(
random_seed
);
repeat_
=
GTEST_FLAG
(
repeat
);
shuffle_
=
GTEST_FLAG
(
shuffle
);
...
...
@@ -195,6 +189,7 @@ class GTestFlagSaver {
GTEST_FLAG
(
list_tests
)
=
list_tests_
;
GTEST_FLAG
(
output
)
=
output_
;
GTEST_FLAG
(
print_time
)
=
print_time_
;
GTEST_FLAG
(
print_utf8
)
=
print_utf8_
;
GTEST_FLAG
(
random_seed
)
=
random_seed_
;
GTEST_FLAG
(
repeat
)
=
repeat_
;
GTEST_FLAG
(
shuffle
)
=
shuffle_
;
...
...
@@ -216,6 +211,7 @@ class GTestFlagSaver {
bool
list_tests_
;
std
::
string
output_
;
bool
print_time_
;
bool
print_utf8_
;
internal
::
Int32
random_seed_
;
internal
::
Int32
repeat_
;
bool
shuffle_
;
...
...
@@ -664,13 +660,11 @@ class GTEST_API_ UnitTestImpl {
tear_down_tc
)
->
AddTestInfo
(
test_info
);
}
#if GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
internal
::
ParameterizedTestCaseRegistry
&
parameterized_test_registry
()
{
return
parameterized_test_registry_
;
}
#endif // GTEST_HAS_PARAM_TEST
// Sets the TestCase object for the test that's currently running.
void
set_current_test_case
(
TestCase
*
a_current_test_case
)
{
...
...
@@ -845,14 +839,12 @@ class GTEST_API_ UnitTestImpl {
// shuffled order.
std
::
vector
<
int
>
test_case_indices_
;
#if GTEST_HAS_PARAM_TEST
// ParameterizedTestRegistry object used to register value-parameterized
// tests.
internal
::
ParameterizedTestCaseRegistry
parameterized_test_registry_
;
// Indicates whether RegisterParameterizedTests() has been called already.
bool
parameterized_tests_registered_
;
#endif // GTEST_HAS_PARAM_TEST
// Index of the last death test case registered. Initially -1.
int
last_death_test_case_
;
...
...
@@ -1032,7 +1024,7 @@ class TestResultAccessor {
#if GTEST_CAN_STREAM_RESULTS_
// Streams test results to the given port on the given host machine.
class
GTEST_API_
StreamingListener
:
public
EmptyTestEventListener
{
class
StreamingListener
:
public
EmptyTestEventListener
{
public:
// Abstract base class for writing strings to a socket.
class
AbstractSocketWriter
{
...
...
googletest/src/gtest-port.cc
View file @
a7a7f51d
...
...
@@ -67,15 +67,7 @@
#include "gtest/gtest-message.h"
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-string.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick exists to
// prevent the accidental inclusion of gtest-internal-inl.h in the
// user's code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
namespace
testing
{
namespace
internal
{
...
...
@@ -671,7 +663,7 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
}
// Helper function used by ValidateRegex() to format error messages.
std
::
string
FormatRegexSyntaxError
(
const
char
*
regex
,
int
index
)
{
static
std
::
string
FormatRegexSyntaxError
(
const
char
*
regex
,
int
index
)
{
return
(
Message
()
<<
"Syntax error at index "
<<
index
<<
" in simple regular expression
\"
"
<<
regex
<<
"
\"
: "
).
GetString
();
}
...
...
@@ -923,6 +915,7 @@ GTestLog::~GTestLog() {
posix
::
Abort
();
}
}
// Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close)
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4996
)
...
...
@@ -1015,7 +1008,8 @@ static CapturedStream* g_captured_stderr = NULL;
static
CapturedStream
*
g_captured_stdout
=
NULL
;
// Starts capturing an output stream (stdout/stderr).
void
CaptureStream
(
int
fd
,
const
char
*
stream_name
,
CapturedStream
**
stream
)
{
static
void
CaptureStream
(
int
fd
,
const
char
*
stream_name
,
CapturedStream
**
stream
)
{
if
(
*
stream
!=
NULL
)
{
GTEST_LOG_
(
FATAL
)
<<
"Only one "
<<
stream_name
<<
" capturer can exist at a time."
;
...
...
@@ -1024,7 +1018,7 @@ void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
}
// Stops capturing the output stream and returns the captured string.
std
::
string
GetCapturedStream
(
CapturedStream
**
captured_stream
)
{
static
std
::
string
GetCapturedStream
(
CapturedStream
**
captured_stream
)
{
const
std
::
string
content
=
(
*
captured_stream
)
->
GetCapturedString
();
delete
*
captured_stream
;
...
...
@@ -1055,6 +1049,10 @@ std::string GetCapturedStderr() {
#endif // GTEST_HAS_STREAM_REDIRECTION
size_t
GetFileSize
(
FILE
*
file
)
{
fseek
(
file
,
0
,
SEEK_END
);
return
static_cast
<
size_t
>
(
ftell
(
file
));
...
...
googletest/src/gtest-printers.cc
View file @
a7a7f51d
...
...
@@ -43,12 +43,13 @@
// defines Foo.
#include "gtest/gtest-printers.h"
#include <ctype.h>
#include <stdio.h>
#include <cctype>
#include <cwchar>
#include <ostream> // NOLINT
#include <string>
#include "gtest/internal/gtest-port.h"
#include "src/gtest-internal-inl.h"
namespace
testing
{
...
...
@@ -123,7 +124,7 @@ namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one
// of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hex
i
decimal escape sequence (e.g. '\x7F'), or
// - as a hex
a
decimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
enum
CharFormat
{
kAsIs
,
...
...
@@ -180,7 +181,10 @@ static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
*
os
<<
static_cast
<
char
>
(
c
);
return
kAsIs
;
}
else
{
*
os
<<
"
\\
x"
+
String
::
FormatHexInt
(
static_cast
<
UnsignedChar
>
(
c
));
ostream
::
fmtflags
flags
=
os
->
flags
();
*
os
<<
"
\\
x"
<<
std
::
hex
<<
std
::
uppercase
<<
static_cast
<
int
>
(
static_cast
<
UnsignedChar
>
(
c
));
os
->
flags
(
flags
);
return
kHexEscape
;
}
}
...
...
@@ -227,7 +231,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
return
;
*
os
<<
" ("
<<
static_cast
<
int
>
(
c
);
// For more convenience, we print c's code again in hex
i
decimal,
// For more convenience, we print c's code again in hex
a
decimal,
// unless c was already printed in the form '\x##' or the code is in
// [1, 9].
if
(
format
==
kHexEscape
||
(
1
<=
c
&&
c
<=
9
))
{
...
...
@@ -259,11 +263,12 @@ template <typename CharType>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
void
PrintCharsAsStringTo
(
static
CharFormat
PrintCharsAsStringTo
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
const
char
*
const
kQuoteBegin
=
sizeof
(
CharType
)
==
1
?
"
\"
"
:
"L
\"
"
;
*
os
<<
kQuoteBegin
;
bool
is_previous_hex
=
false
;
CharFormat
print_format
=
kAsIs
;
for
(
size_t
index
=
0
;
index
<
len
;
++
index
)
{
const
CharType
cur
=
begin
[
index
];
if
(
is_previous_hex
&&
IsXDigit
(
cur
))
{
...
...
@@ -273,8 +278,13 @@ static void PrintCharsAsStringTo(
*
os
<<
"
\"
"
<<
kQuoteBegin
;
}
is_previous_hex
=
PrintAsStringLiteralTo
(
cur
,
os
)
==
kHexEscape
;
// Remember if any characters required hex escaping.
if
(
is_previous_hex
)
{
print_format
=
kHexEscape
;
}
}
*
os
<<
"
\"
"
;
return
print_format
;
}
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
...
...
@@ -344,15 +354,90 @@ void PrintTo(const wchar_t* s, ostream* os) {
}
#endif // wchar_t is native
namespace
{
bool
ContainsUnprintableControlCodes
(
const
char
*
str
,
size_t
length
)
{
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
for
(
size_t
i
=
0
;
i
<
length
;
i
++
)
{
unsigned
char
ch
=
*
s
++
;
if
(
std
::
iscntrl
(
ch
))
{
switch
(
ch
)
{
case
'\t'
:
case
'\n'
:
case
'\r'
:
break
;
default:
return
true
;
}
}
}
return
false
;
}
bool
IsUTF8TrailByte
(
unsigned
char
t
)
{
return
0x80
<=
t
&&
t
<=
0xbf
;
}
bool
IsValidUTF8
(
const
char
*
str
,
size_t
length
)
{
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
for
(
size_t
i
=
0
;
i
<
length
;)
{
unsigned
char
lead
=
s
[
i
++
];
if
(
lead
<=
0x7f
)
{
continue
;
// single-byte character (ASCII) 0..7F
}
if
(
lead
<
0xc2
)
{
return
false
;
// trail byte or non-shortest form
}
else
if
(
lead
<=
0xdf
&&
(
i
+
1
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
]))
{
++
i
;
// 2-byte character
}
else
if
(
0xe0
<=
lead
&&
lead
<=
0xef
&&
(
i
+
2
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
])
&&
IsUTF8TrailByte
(
s
[
i
+
1
])
&&
// check for non-shortest form and surrogate
(
lead
!=
0xe0
||
s
[
i
]
>=
0xa0
)
&&
(
lead
!=
0xed
||
s
[
i
]
<
0xa0
))
{
i
+=
2
;
// 3-byte character
}
else
if
(
0xf0
<=
lead
&&
lead
<=
0xf4
&&
(
i
+
3
)
<=
length
&&
IsUTF8TrailByte
(
s
[
i
])
&&
IsUTF8TrailByte
(
s
[
i
+
1
])
&&
IsUTF8TrailByte
(
s
[
i
+
2
])
&&
// check for non-shortest form
(
lead
!=
0xf0
||
s
[
i
]
>=
0x90
)
&&
(
lead
!=
0xf4
||
s
[
i
]
<
0x90
))
{
i
+=
3
;
// 4-byte character
}
else
{
return
false
;
}
}
return
true
;
}
void
ConditionalPrintAsText
(
const
char
*
str
,
size_t
length
,
ostream
*
os
)
{
if
(
!
ContainsUnprintableControlCodes
(
str
,
length
)
&&
IsValidUTF8
(
str
,
length
))
{
*
os
<<
"
\n
As Text:
\"
"
<<
str
<<
"
\"
"
;
}
}
}
// anonymous namespace
// Prints a ::string object.
#if GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
if
(
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
)
==
kHexEscape
)
{
if
(
GTEST_FLAG
(
print_utf8
))
{
ConditionalPrintAsText
(
s
.
data
(),
s
.
size
(),
os
);
}
}
}
#endif // GTEST_HAS_GLOBAL_STRING
void
PrintStringTo
(
const
::
std
::
string
&
s
,
ostream
*
os
)
{
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
);
if
(
PrintCharsAsStringTo
(
s
.
data
(),
s
.
size
(),
os
)
==
kHexEscape
)
{
if
(
GTEST_FLAG
(
print_utf8
))
{
ConditionalPrintAsText
(
s
.
data
(),
s
.
size
(),
os
);
}
}
}
// Prints a ::wstring object.
...
...
googletest/src/gtest-test-part.cc
View file @
a7a7f51d
...
...
@@ -32,15 +32,7 @@
// The Google C++ Testing Framework (Google Test)
#include "gtest/gtest-test-part.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick exists to
// prevent the accidental inclusion of gtest-internal-inl.h in the
// user's code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
namespace
testing
{
...
...
googletest/src/gtest-typed-test.cc
View file @
a7a7f51d
...
...
@@ -30,6 +30,7 @@
// Author: wan@google.com (Zhanyong Wan)
#include "gtest/gtest-typed-test.h"
#include "gtest/gtest.h"
namespace
testing
{
...
...
googletest/src/gtest.cc
View file @
a7a7f51d
...
...
@@ -133,14 +133,7 @@
# include <sys/types.h> // NOLINT
#endif
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
#if GTEST_OS_WINDOWS
# define vsnprintf _vsnprintf
...
...
@@ -167,8 +160,10 @@ static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*";
// A test filter that matches everything.
static
const
char
kUniversalFilter
[]
=
"*"
;
// The default output file for XML output.
static
const
char
kDefaultOutputFile
[]
=
"test_detail.xml"
;
// The default output format.
static
const
char
kDefaultOutputFormat
[]
=
"xml"
;
// The default output file.
static
const
char
kDefaultOutputFile
[]
=
"test_detail"
;
// The environment variable name for the test shard index.
static
const
char
kTestShardIndex
[]
=
"GTEST_SHARD_INDEX"
;
...
...
@@ -238,9 +233,9 @@ GTEST_DEFINE_bool_(list_tests, false,
GTEST_DEFINE_string_
(
output
,
internal
::
StringFromGTestEnv
(
"output"
,
""
),
"A format (
currently must be
\"
xml
\"
), optionally followed
"
"by a colon and an output file name or directory.
A directory
"
"is indicated by a trailing pathname separator. "
"A format (
defaults to
\"
xml
\"
but can be specified to be
\"
json
\"
),
"
"
optionally followed
by a colon and an output file name or directory. "
"
A directory
is indicated by a trailing pathname separator. "
"Examples:
\"
xml:filename.xml
\"
,
\"
xml::directoryname/
\"
. "
"If a directory is specified, output files will be created "
"within that directory, with file-names based on the test "
...
...
@@ -253,6 +248,12 @@ GTEST_DEFINE_bool_(
"True iff "
GTEST_NAME_
" should display elapsed time in text output."
);
GTEST_DEFINE_bool_
(
print_utf8
,
internal
::
BoolFromGTestEnv
(
"print_utf8"
,
true
),
"True iff "
GTEST_NAME_
" prints UTF8 characters as text."
);
GTEST_DEFINE_int32_
(
random_seed
,
internal
::
Int32FromGTestEnv
(
"random_seed"
,
0
),
...
...
@@ -294,7 +295,7 @@ GTEST_DEFINE_bool_(
internal
::
BoolFromGTestEnv
(
"throw_on_failure"
,
false
),
"When this flag is specified, a failed assertion will throw an exception "
"if exceptions are enabled or exit the program with a non-zero code "
"otherwise."
);
"otherwise.
For use with an external test framework.
"
);
#if GTEST_USE_OWN_FLAGFILE_FLAG_
GTEST_DEFINE_string_
(
...
...
@@ -429,12 +430,17 @@ std::string UnitTestOptions::GetAbsolutePathToOutputFile() {
if
(
gtest_output_flag
==
NULL
)
return
""
;
std
::
string
format
=
GetOutputFormat
();
if
(
format
.
empty
())
format
=
std
::
string
(
kDefaultOutputFormat
);
const
char
*
const
colon
=
strchr
(
gtest_output_flag
,
':'
);
if
(
colon
==
NULL
)
return
internal
::
FilePath
::
ConcatPaths
(
return
internal
::
FilePath
::
MakeFileName
(
internal
::
FilePath
(
UnitTest
::
GetInstance
()
->
original_working_dir
()),
internal
::
FilePath
(
kDefaultOutputFile
)).
string
();
internal
::
FilePath
(
kDefaultOutputFile
),
0
,
format
.
c_str
()).
string
();
internal
::
FilePath
output_name
(
colon
+
1
);
if
(
!
output_name
.
IsAbsolutePath
())
...
...
@@ -629,7 +635,7 @@ extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
// This predicate-formatter checks that 'results' contains a test part
// failure of the given type and that the failure message contains the
// given substring.
AssertionResult
HasOneFailure
(
const
char
*
/* results_expr */
,
static
AssertionResult
HasOneFailure
(
const
char
*
/* results_expr */
,
const
char
*
/* type_expr */
,
const
char
*
/* substr_expr */
,
const
TestPartResultArray
&
results
,
...
...
@@ -1662,7 +1668,7 @@ namespace {
AssertionResult
HRESULTFailureHelper
(
const
char
*
expr
,
const
char
*
expected
,
long
hr
)
{
// NOLINT
# if GTEST_OS_WINDOWS_MOBILE
# if GTEST_OS_WINDOWS_MOBILE
|| GTEST_OS_WINDOWS_TV_TITLE
// Windows CE doesn't support FormatMessage.
const
char
error_text
[]
=
""
;
...
...
@@ -1719,7 +1725,7 @@ AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT
// Utility functions for encoding Unicode text (wide strings) in
// UTF-8.
// A Unicode code-point can have upto 21 bits, and is encoded in UTF-8
// A Unicode code-point can have up
to 21 bits, and is encoded in UTF-8
// like this:
//
// Code-point length Encoding
...
...
@@ -2137,7 +2143,8 @@ static std::string FormatWordList(const std::vector<std::string>& words) {
return
word_list
.
GetString
();
}
bool
ValidateTestPropertyName
(
const
std
::
string
&
property_name
,
static
bool
ValidateTestPropertyName
(
const
std
::
string
&
property_name
,
const
std
::
vector
<
std
::
string
>&
reserved_names
)
{
if
(
std
::
find
(
reserved_names
.
begin
(),
reserved_names
.
end
(),
property_name
)
!=
reserved_names
.
end
())
{
...
...
@@ -2435,6 +2442,8 @@ Result HandleExceptionsInMethodIfSupported(
#if GTEST_HAS_EXCEPTIONS
try
{
return
HandleSehExceptionsInMethodIfSupported
(
object
,
method
,
location
);
}
catch
(
const
AssertionException
&
)
{
// NOLINT
// This failure was reported already.
}
catch
(
const
internal
::
GoogleTestFailureException
&
)
{
// NOLINT
// This exception type can only be thrown by a failed Google
// Test assertion with the intention of letting another testing
...
...
@@ -2556,7 +2565,6 @@ TestInfo* MakeAndRegisterTestInfo(
return
test_info
;
}
#if GTEST_HAS_PARAM_TEST
void
ReportInvalidTestCaseType
(
const
char
*
test_case_name
,
CodeLocation
code_location
)
{
Message
errors
;
...
...
@@ -2570,13 +2578,10 @@ void ReportInvalidTestCaseType(const char* test_case_name,
<<
"probably rename one of the classes to put the tests into different
\n
"
<<
"test cases."
;
GTEST_LOG_
(
ERROR
)
<<
FormatFileLocation
(
code_location
.
file
.
c_str
(),
GTEST_LOG_
(
ERROR
)
<<
FormatFileLocation
(
code_location
.
file
.
c_str
(),
code_location
.
line
)
<<
" "
<<
errors
.
GetString
();
}
#endif // GTEST_HAS_PARAM_TEST
}
// namespace internal
namespace
{
...
...
@@ -2614,12 +2619,10 @@ namespace internal {
// and INSTANTIATE_TEST_CASE_P into regular tests and registers those.
// This will be done just once during the program runtime.
void
UnitTestImpl
::
RegisterParameterizedTests
()
{
#if GTEST_HAS_PARAM_TEST
if
(
!
parameterized_tests_registered_
)
{
parameterized_test_registry_
.
RegisterTests
();
parameterized_tests_registered_
=
true
;
}
#endif
}
}
// namespace internal
...
...
@@ -2884,10 +2887,10 @@ enum GTestColor {
};
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
&& !GTEST_OS_WINDOWS_MINGW
// Returns the character attribute for the given color.
WORD
GetColorAttribute
(
GTestColor
color
)
{
static
WORD
GetColorAttribute
(
GTestColor
color
)
{
switch
(
color
)
{
case
COLOR_RED
:
return
FOREGROUND_RED
;
case
COLOR_GREEN
:
return
FOREGROUND_GREEN
;
...
...
@@ -2896,18 +2899,18 @@ WORD GetColorAttribute(GTestColor color) {
}
}
int
GetBitOffset
(
WORD
color_mask
)
{
static
int
GetBitOffset
(
WORD
color_mask
)
{
if
(
color_mask
==
0
)
return
0
;
int
bitOffset
=
0
;
while
((
color_mask
&
1
)
==
0
)
{
while
((
color_mask
&
1
)
==
0
)
{
color_mask
>>=
1
;
++
bitOffset
;
}
return
bitOffset
;
}
WORD
GetNewColor
(
GTestColor
color
,
WORD
old_color_attrs
)
{
static
WORD
GetNewColor
(
GTestColor
color
,
WORD
old_color_attrs
)
{
// Let's reuse the BG
static
const
WORD
background_mask
=
BACKGROUND_BLUE
|
BACKGROUND_GREEN
|
BACKGROUND_RED
|
BACKGROUND_INTENSITY
;
static
const
WORD
foreground_mask
=
FOREGROUND_BLUE
|
FOREGROUND_GREEN
|
FOREGROUND_RED
|
FOREGROUND_INTENSITY
;
...
...
@@ -2927,7 +2930,7 @@ WORD GetNewColor(GTestColor color, WORD old_color_attrs) {
// Returns the ANSI color code for the given color. COLOR_DEFAULT is
// an invalid input.
const
char
*
GetAnsiColorCode
(
GTestColor
color
)
{
static
const
char
*
GetAnsiColorCode
(
GTestColor
color
)
{
switch
(
color
)
{
case
COLOR_RED
:
return
"1"
;
case
COLOR_GREEN
:
return
"2"
;
...
...
@@ -2943,7 +2946,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
const
char
*
const
gtest_color
=
GTEST_FLAG
(
color
).
c_str
();
if
(
String
::
CaseInsensitiveCStringEquals
(
gtest_color
,
"auto"
))
{
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
&& !GTEST_OS_WINDOWS_MINGW
// On Windows the TERM variable is usually not set, but the
// console there does support colors.
return
stdout_is_tty
;
...
...
@@ -2980,7 +2983,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
// This routine must actually emit the characters rather than return a string
// that would be colored when printed, as can be done on Linux.
GTEST_ATTRIBUTE_PRINTF_
(
2
,
3
)
void
ColoredPrintf
(
GTestColor
color
,
const
char
*
fmt
,
...)
{
static
void
ColoredPrintf
(
GTestColor
color
,
const
char
*
fmt
,
...)
{
va_list
args
;
va_start
(
args
,
fmt
);
...
...
@@ -3001,7 +3004,7 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
}
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE && \
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
!GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT
&& !GTEST_OS_WINDOWS_MINGW
const
HANDLE
stdout_handle
=
GetStdHandle
(
STD_OUTPUT_HANDLE
);
// Gets the current text color.
...
...
@@ -3034,7 +3037,7 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
static
const
char
kTypeParamLabel
[]
=
"TypeParam"
;
static
const
char
kValueParamLabel
[]
=
"GetParam()"
;
void
PrintFullTestCommentIfPresent
(
const
TestInfo
&
test_info
)
{
static
void
PrintFullTestCommentIfPresent
(
const
TestInfo
&
test_info
)
{
const
char
*
const
type_param
=
test_info
.
type_param
();
const
char
*
const
value_param
=
test_info
.
value_param
();
...
...
@@ -3108,7 +3111,6 @@ void PrettyUnitTestResultPrinter::OnTestIterationStart(
"Note: Randomizing tests' orders with a seed of %d .
\n
"
,
unit_test
.
random_seed
());
}
ColoredPrintf
(
COLOR_GREEN
,
"[==========] "
);
printf
(
"Running %s from %s.
\n
"
,
FormatTestCount
(
unit_test
.
test_to_run_count
()).
c_str
(),
...
...
@@ -3475,8 +3477,8 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// 3. To interpret the meaning of errno in a thread-safe way,
// we need the strerror_r() function, which is not available on
// Windows.
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
<<
output_file_
<<
"
\"
"
;
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
<<
output_file_
<<
"
\"
"
;
}
std
::
stringstream
stream
;
PrintXmlUnitTest
(
&
stream
,
unit_test
);
...
...
@@ -3775,6 +3777,352 @@ std::string XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
// End XmlUnitTestResultPrinter
// This class generates an JSON output file.
class
JsonUnitTestResultPrinter
:
public
EmptyTestEventListener
{
public:
explicit
JsonUnitTestResultPrinter
(
const
char
*
output_file
);
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
);
private:
// Returns an JSON-escaped copy of the input string str.
static
std
::
string
EscapeJson
(
const
std
::
string
&
str
);
//// Verifies that the given attribute belongs to the given element and
//// streams the attribute as JSON.
static
void
OutputJsonKey
(
std
::
ostream
*
stream
,
const
std
::
string
&
element_name
,
const
std
::
string
&
name
,
const
std
::
string
&
value
,
const
std
::
string
&
indent
,
bool
comma
=
true
);
static
void
OutputJsonKey
(
std
::
ostream
*
stream
,
const
std
::
string
&
element_name
,
const
std
::
string
&
name
,
int
value
,
const
std
::
string
&
indent
,
bool
comma
=
true
);
// Streams a JSON representation of a TestInfo object.
static
void
OutputJsonTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_case_name
,
const
TestInfo
&
test_info
);
// Prints a JSON representation of a TestCase object
static
void
PrintJsonTestCase
(
::
std
::
ostream
*
stream
,
const
TestCase
&
test_case
);
// Prints a JSON summary of unit_test to output stream out.
static
void
PrintJsonUnitTest
(
::
std
::
ostream
*
stream
,
const
UnitTest
&
unit_test
);
// Produces a string representing the test properties in a result as
// a JSON dictionary.
static
std
::
string
TestPropertiesAsJson
(
const
TestResult
&
result
,
const
std
::
string
&
indent
);
// The output file.
const
std
::
string
output_file_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
JsonUnitTestResultPrinter
);
};
// Creates a new JsonUnitTestResultPrinter.
JsonUnitTestResultPrinter
::
JsonUnitTestResultPrinter
(
const
char
*
output_file
)
:
output_file_
(
output_file
)
{
if
(
output_file_
.
empty
())
{
GTEST_LOG_
(
FATAL
)
<<
"JSON output file may not be null"
;
}
}
void
JsonUnitTestResultPrinter
::
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
/*iteration*/
)
{
FILE
*
jsonout
=
NULL
;
FilePath
output_file
(
output_file_
);
FilePath
output_dir
(
output_file
.
RemoveFileName
());
if
(
output_dir
.
CreateDirectoriesRecursively
())
{
jsonout
=
posix
::
FOpen
(
output_file_
.
c_str
(),
"w"
);
}
if
(
jsonout
==
NULL
)
{
// TODO(phosek): report the reason of the failure.
//
// We don't do it for now as:
//
// 1. There is no urgent need for it.
// 2. It's a bit involved to make the errno variable thread-safe on
// all three operating systems (Linux, Windows, and Mac OS).
// 3. To interpret the meaning of errno in a thread-safe way,
// we need the strerror_r() function, which is not available on
// Windows.
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
<<
output_file_
<<
"
\"
"
;
}
std
::
stringstream
stream
;
PrintJsonUnitTest
(
&
stream
,
unit_test
);
fprintf
(
jsonout
,
"%s"
,
StringStreamToString
(
&
stream
).
c_str
());
fclose
(
jsonout
);
}
// Returns an JSON-escaped copy of the input string str.
std
::
string
JsonUnitTestResultPrinter
::
EscapeJson
(
const
std
::
string
&
str
)
{
Message
m
;
for
(
size_t
i
=
0
;
i
<
str
.
size
();
++
i
)
{
const
char
ch
=
str
[
i
];
switch
(
ch
)
{
case
'\\'
:
case
'"'
:
case
'/'
:
m
<<
'\\'
<<
ch
;
break
;
case
'\b'
:
m
<<
"
\\
b"
;
break
;
case
'\t'
:
m
<<
"
\\
t"
;
break
;
case
'\n'
:
m
<<
"
\\
n"
;
break
;
case
'\f'
:
m
<<
"
\\
f"
;
break
;
case
'\r'
:
m
<<
"
\\
r"
;
break
;
default:
if
(
ch
<
' '
)
{
m
<<
"
\\
u00"
<<
String
::
FormatByte
(
static_cast
<
unsigned
char
>
(
ch
));
}
else
{
m
<<
ch
;
}
break
;
}
}
return
m
.
GetString
();
}
// The following routines generate an JSON representation of a UnitTest
// object.
// Formats the given time in milliseconds as seconds.
static
std
::
string
FormatTimeInMillisAsDuration
(
TimeInMillis
ms
)
{
::
std
::
stringstream
ss
;
ss
<<
(
static_cast
<
double
>
(
ms
)
*
1e-3
)
<<
"s"
;
return
ss
.
str
();
}
// Converts the given epoch time in milliseconds to a date string in the
// RFC3339 format, without the timezone information.
static
std
::
string
FormatEpochTimeInMillisAsRFC3339
(
TimeInMillis
ms
)
{
struct
tm
time_struct
;
if
(
!
PortableLocaltime
(
static_cast
<
time_t
>
(
ms
/
1000
),
&
time_struct
))
return
""
;
// YYYY-MM-DDThh:mm:ss
return
StreamableToString
(
time_struct
.
tm_year
+
1900
)
+
"-"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_mon
+
1
)
+
"-"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_mday
)
+
"T"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_hour
)
+
":"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_min
)
+
":"
+
String
::
FormatIntWidth2
(
time_struct
.
tm_sec
)
+
"Z"
;
}
static
inline
std
::
string
Indent
(
int
width
)
{
return
std
::
string
(
width
,
' '
);
}
void
JsonUnitTestResultPrinter
::
OutputJsonKey
(
std
::
ostream
*
stream
,
const
std
::
string
&
element_name
,
const
std
::
string
&
name
,
const
std
::
string
&
value
,
const
std
::
string
&
indent
,
bool
comma
)
{
const
std
::
vector
<
std
::
string
>&
allowed_names
=
GetReservedAttributesForElement
(
element_name
);
GTEST_CHECK_
(
std
::
find
(
allowed_names
.
begin
(),
allowed_names
.
end
(),
name
)
!=
allowed_names
.
end
())
<<
"Key
\"
"
<<
name
<<
"
\"
is not allowed for value
\"
"
<<
element_name
<<
"
\"
."
;
*
stream
<<
indent
<<
"
\"
"
<<
name
<<
"
\"
:
\"
"
<<
EscapeJson
(
value
)
<<
"
\"
"
;
if
(
comma
)
*
stream
<<
",
\n
"
;
}
void
JsonUnitTestResultPrinter
::
OutputJsonKey
(
std
::
ostream
*
stream
,
const
std
::
string
&
element_name
,
const
std
::
string
&
name
,
int
value
,
const
std
::
string
&
indent
,
bool
comma
)
{
const
std
::
vector
<
std
::
string
>&
allowed_names
=
GetReservedAttributesForElement
(
element_name
);
GTEST_CHECK_
(
std
::
find
(
allowed_names
.
begin
(),
allowed_names
.
end
(),
name
)
!=
allowed_names
.
end
())
<<
"Key
\"
"
<<
name
<<
"
\"
is not allowed for value
\"
"
<<
element_name
<<
"
\"
."
;
*
stream
<<
indent
<<
"
\"
"
<<
name
<<
"
\"
: "
<<
StreamableToString
(
value
);
if
(
comma
)
*
stream
<<
",
\n
"
;
}
// Prints a JSON representation of a TestInfo object.
void
JsonUnitTestResultPrinter
::
OutputJsonTestInfo
(
::
std
::
ostream
*
stream
,
const
char
*
test_case_name
,
const
TestInfo
&
test_info
)
{
const
TestResult
&
result
=
*
test_info
.
result
();
const
std
::
string
kTestcase
=
"testcase"
;
const
std
::
string
kIndent
=
Indent
(
10
);
*
stream
<<
Indent
(
8
)
<<
"{
\n
"
;
OutputJsonKey
(
stream
,
kTestcase
,
"name"
,
test_info
.
name
(),
kIndent
);
if
(
test_info
.
value_param
()
!=
NULL
)
{
OutputJsonKey
(
stream
,
kTestcase
,
"value_param"
,
test_info
.
value_param
(),
kIndent
);
}
if
(
test_info
.
type_param
()
!=
NULL
)
{
OutputJsonKey
(
stream
,
kTestcase
,
"type_param"
,
test_info
.
type_param
(),
kIndent
);
}
OutputJsonKey
(
stream
,
kTestcase
,
"status"
,
test_info
.
should_run
()
?
"RUN"
:
"NOTRUN"
,
kIndent
);
OutputJsonKey
(
stream
,
kTestcase
,
"time"
,
FormatTimeInMillisAsDuration
(
result
.
elapsed_time
()),
kIndent
);
OutputJsonKey
(
stream
,
kTestcase
,
"classname"
,
test_case_name
,
kIndent
,
false
);
*
stream
<<
TestPropertiesAsJson
(
result
,
kIndent
);
int
failures
=
0
;
for
(
int
i
=
0
;
i
<
result
.
total_part_count
();
++
i
)
{
const
TestPartResult
&
part
=
result
.
GetTestPartResult
(
i
);
if
(
part
.
failed
())
{
*
stream
<<
",
\n
"
;
if
(
++
failures
==
1
)
{
*
stream
<<
kIndent
<<
"
\"
"
<<
"failures"
<<
"
\"
: [
\n
"
;
}
const
std
::
string
location
=
internal
::
FormatCompilerIndependentFileLocation
(
part
.
file_name
(),
part
.
line_number
());
const
std
::
string
message
=
EscapeJson
(
location
+
"
\n
"
+
part
.
message
());
*
stream
<<
kIndent
<<
" {
\n
"
<<
kIndent
<<
"
\"
failure
\"
:
\"
"
<<
message
<<
"
\"
,
\n
"
<<
kIndent
<<
"
\"
type
\"
:
\"\"\n
"
<<
kIndent
<<
" }"
;
}
}
if
(
failures
>
0
)
*
stream
<<
"
\n
"
<<
kIndent
<<
"]"
;
*
stream
<<
"
\n
"
<<
Indent
(
8
)
<<
"}"
;
}
// Prints an JSON representation of a TestCase object
void
JsonUnitTestResultPrinter
::
PrintJsonTestCase
(
std
::
ostream
*
stream
,
const
TestCase
&
test_case
)
{
const
std
::
string
kTestsuite
=
"testsuite"
;
const
std
::
string
kIndent
=
Indent
(
6
);
*
stream
<<
Indent
(
4
)
<<
"{
\n
"
;
OutputJsonKey
(
stream
,
kTestsuite
,
"name"
,
test_case
.
name
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"tests"
,
test_case
.
reportable_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"failures"
,
test_case
.
failed_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"disabled"
,
test_case
.
reportable_disabled_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"errors"
,
0
,
kIndent
);
OutputJsonKey
(
stream
,
kTestsuite
,
"time"
,
FormatTimeInMillisAsDuration
(
test_case
.
elapsed_time
()),
kIndent
,
false
);
*
stream
<<
TestPropertiesAsJson
(
test_case
.
ad_hoc_test_result
(),
kIndent
)
<<
",
\n
"
;
*
stream
<<
kIndent
<<
"
\"
"
<<
kTestsuite
<<
"
\"
: [
\n
"
;
bool
comma
=
false
;
for
(
int
i
=
0
;
i
<
test_case
.
total_test_count
();
++
i
)
{
if
(
test_case
.
GetTestInfo
(
i
)
->
is_reportable
())
{
if
(
comma
)
{
*
stream
<<
",
\n
"
;
}
else
{
comma
=
true
;
}
OutputJsonTestInfo
(
stream
,
test_case
.
name
(),
*
test_case
.
GetTestInfo
(
i
));
}
}
*
stream
<<
"
\n
"
<<
kIndent
<<
"]
\n
"
<<
Indent
(
4
)
<<
"}"
;
}
// Prints a JSON summary of unit_test to output stream out.
void
JsonUnitTestResultPrinter
::
PrintJsonUnitTest
(
std
::
ostream
*
stream
,
const
UnitTest
&
unit_test
)
{
const
std
::
string
kTestsuites
=
"testsuites"
;
const
std
::
string
kIndent
=
Indent
(
2
);
*
stream
<<
"{
\n
"
;
OutputJsonKey
(
stream
,
kTestsuites
,
"tests"
,
unit_test
.
reportable_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuites
,
"failures"
,
unit_test
.
failed_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuites
,
"disabled"
,
unit_test
.
reportable_disabled_test_count
(),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuites
,
"errors"
,
0
,
kIndent
);
if
(
GTEST_FLAG
(
shuffle
))
{
OutputJsonKey
(
stream
,
kTestsuites
,
"random_seed"
,
unit_test
.
random_seed
(),
kIndent
);
}
OutputJsonKey
(
stream
,
kTestsuites
,
"timestamp"
,
FormatEpochTimeInMillisAsRFC3339
(
unit_test
.
start_timestamp
()),
kIndent
);
OutputJsonKey
(
stream
,
kTestsuites
,
"time"
,
FormatTimeInMillisAsDuration
(
unit_test
.
elapsed_time
()),
kIndent
,
false
);
*
stream
<<
TestPropertiesAsJson
(
unit_test
.
ad_hoc_test_result
(),
kIndent
)
<<
",
\n
"
;
OutputJsonKey
(
stream
,
kTestsuites
,
"name"
,
"AllTests"
,
kIndent
);
*
stream
<<
kIndent
<<
"
\"
"
<<
kTestsuites
<<
"
\"
: [
\n
"
;
bool
comma
=
false
;
for
(
int
i
=
0
;
i
<
unit_test
.
total_test_case_count
();
++
i
)
{
if
(
unit_test
.
GetTestCase
(
i
)
->
reportable_test_count
()
>
0
)
{
if
(
comma
)
{
*
stream
<<
",
\n
"
;
}
else
{
comma
=
true
;
}
PrintJsonTestCase
(
stream
,
*
unit_test
.
GetTestCase
(
i
));
}
}
*
stream
<<
"
\n
"
<<
kIndent
<<
"]
\n
"
<<
"}
\n
"
;
}
// Produces a string representing the test properties in a result as
// a JSON dictionary.
std
::
string
JsonUnitTestResultPrinter
::
TestPropertiesAsJson
(
const
TestResult
&
result
,
const
std
::
string
&
indent
)
{
Message
attributes
;
for
(
int
i
=
0
;
i
<
result
.
test_property_count
();
++
i
)
{
const
TestProperty
&
property
=
result
.
GetTestProperty
(
i
);
attributes
<<
",
\n
"
<<
indent
<<
"
\"
"
<<
property
.
key
()
<<
"
\"
: "
<<
"
\"
"
<<
EscapeJson
(
property
.
value
())
<<
"
\"
"
;
}
return
attributes
.
GetString
();
}
// End JsonUnitTestResultPrinter
#if GTEST_CAN_STREAM_RESULTS_
// Checks if str contains '=', '&', '%' or '\n' characters. If yes,
...
...
@@ -3845,27 +4193,6 @@ void StreamingListener::SocketWriter::MakeConnection() {
// End of class Streaming Listener
#endif // GTEST_CAN_STREAM_RESULTS__
// Class ScopedTrace
// Pushes the given source file location and message onto a per-thread
// trace stack maintained by Google Test.
ScopedTrace
::
ScopedTrace
(
const
char
*
file
,
int
line
,
const
Message
&
message
)
GTEST_LOCK_EXCLUDED_
(
&
UnitTest
::
mutex_
)
{
TraceInfo
trace
;
trace
.
file
=
file
;
trace
.
line
=
line
;
trace
.
message
=
message
.
GetString
();
UnitTest
::
GetInstance
()
->
PushGTestTrace
(
trace
);
}
// Pops the info pushed by the c'tor.
ScopedTrace
::~
ScopedTrace
()
GTEST_LOCK_EXCLUDED_
(
&
UnitTest
::
mutex_
)
{
UnitTest
::
GetInstance
()
->
PopGTestTrace
();
}
// class OsStackTraceGetter
const
char
*
const
OsStackTraceGetterInterface
::
kElidedFramesMarker
=
...
...
@@ -4309,7 +4636,6 @@ const TestInfo* UnitTest::current_test_info() const
// Returns the random seed used at the start of the current test run.
int
UnitTest
::
random_seed
()
const
{
return
impl_
->
random_seed
();
}
#if GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
internal
::
ParameterizedTestCaseRegistry
&
...
...
@@ -4317,7 +4643,6 @@ internal::ParameterizedTestCaseRegistry&
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
return
impl_
->
parameterized_test_registry
();
}
#endif // GTEST_HAS_PARAM_TEST
// Creates an empty UnitTest.
UnitTest
::
UnitTest
()
{
...
...
@@ -4356,10 +4681,8 @@ UnitTestImpl::UnitTestImpl(UnitTest* parent)
&
default_global_test_part_result_reporter_
),
per_thread_test_part_result_reporter_
(
&
default_per_thread_test_part_result_reporter_
),
#if GTEST_HAS_PARAM_TEST
parameterized_test_registry_
(),
parameterized_tests_registered_
(
false
),
#endif // GTEST_HAS_PARAM_TEST
last_death_test_case_
(
-
1
),
current_test_case_
(
NULL
),
current_test_info_
(
NULL
),
...
...
@@ -4426,10 +4749,12 @@ void UnitTestImpl::ConfigureXmlOutput() {
if
(
output_format
==
"xml"
)
{
listeners
()
->
SetDefaultXmlGenerator
(
new
XmlUnitTestResultPrinter
(
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
()));
}
else
if
(
output_format
==
"json"
)
{
listeners
()
->
SetDefaultXmlGenerator
(
new
JsonUnitTestResultPrinter
(
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
()));
}
else
if
(
output_format
!=
""
)
{
GTEST_LOG_
(
WARNING
)
<<
"WARNING: unrecognized output format
\"
"
<<
output_format
<<
"
\"
ignored."
;
<<
output_format
<<
"
\"
ignored."
;
}
}
...
...
@@ -4444,8 +4769,7 @@ void UnitTestImpl::ConfigureStreamingOutput() {
listeners
()
->
Append
(
new
StreamingListener
(
target
.
substr
(
0
,
pos
),
target
.
substr
(
pos
+
1
)));
}
else
{
GTEST_LOG_
(
WARNING
)
<<
"unrecognized streaming target
\"
"
<<
target
GTEST_LOG_
(
WARNING
)
<<
"unrecognized streaming target
\"
"
<<
target
<<
"
\"
ignored."
;
}
}
...
...
@@ -4848,10 +5172,11 @@ int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
(
GTEST_FLAG
(
also_run_disabled_tests
)
||
!
is_disabled
)
&&
matches_filter
;
const
bool
is_selected
=
is_runnable
&&
(
shard_tests
==
IGNORE_SHARDING_PROTOCOL
||
ShouldRunTestOnShard
(
total_shards
,
shard_index
,
num_runnable_tests
));
const
bool
is_in_another_shard
=
shard_tests
!=
IGNORE_SHARDING_PROTOCOL
&&
!
ShouldRunTestOnShard
(
total_shards
,
shard_index
,
num_runnable_tests
);
test_info
->
is_in_another_shard_
=
is_in_another_shard
;
const
bool
is_selected
=
is_runnable
&&
!
is_in_another_shard
;
num_runnable_tests
+=
is_runnable
;
num_selected_tests
+=
is_selected
;
...
...
@@ -5036,7 +5361,7 @@ bool SkipPrefix(const char* prefix, const char** pstr) {
// part can be omitted.
//
// Returns the value of the flag, or NULL if the parsing failed.
const
char
*
ParseFlagValue
(
const
char
*
str
,
static
const
char
*
ParseFlagValue
(
const
char
*
str
,
const
char
*
flag
,
bool
def_optional
)
{
// str and flag must not be NULL.
...
...
@@ -5074,7 +5399,7 @@ const char* ParseFlagValue(const char* str,
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
bool
ParseBoolFlag
(
const
char
*
str
,
const
char
*
flag
,
bool
*
value
)
{
static
bool
ParseBoolFlag
(
const
char
*
str
,
const
char
*
flag
,
bool
*
value
)
{
// Gets the value of the flag as a string.
const
char
*
const
value_str
=
ParseFlagValue
(
str
,
flag
,
true
);
...
...
@@ -5108,7 +5433,9 @@ bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
bool
ParseStringFlag
(
const
char
*
str
,
const
char
*
flag
,
std
::
string
*
value
)
{
static
bool
ParseStringFlag
(
const
char
*
str
,
const
char
*
flag
,
std
::
string
*
value
)
{
// Gets the value of the flag as a string.
const
char
*
const
value_str
=
ParseFlagValue
(
str
,
flag
,
false
);
...
...
@@ -5210,10 +5537,10 @@ static const char kColorEncodedHelpMessage[] =
" Enable/disable colored output. The default is @Gauto@D.
\n
"
" @G--"
GTEST_FLAG_PREFIX_
"print_time=0@D
\n
"
" Don't print the elapsed time of each test.
\n
"
" @G--"
GTEST_FLAG_PREFIX_
"output=xml@Y[@G:@YDIRECTORY_PATH@G"
" @G--"
GTEST_FLAG_PREFIX_
"output=
@Y(@Gjson@Y|@G
xml@Y
)
[@G:@YDIRECTORY_PATH@G"
GTEST_PATH_SEP_
"@Y|@G:@YFILE_PATH]@D
\n
"
" Generate a
n
XML report in the given directory or with the given
file
\n
"
" name. @YFILE_PATH@D defaults to @Gtest_detail.xml@D.
\n
"
" Generate a
JSON or
XML report in the given directory or with the given
\n
"
"
file
name. @YFILE_PATH@D defaults to @Gtest_detail
s
.xml@D.
\n
"
#if GTEST_CAN_STREAM_RESULTS_
" @G--"
GTEST_FLAG_PREFIX_
"stream_result_to=@YHOST@G:@YPORT@D
\n
"
" Stream test results to the given server.
\n
"
...
...
@@ -5227,7 +5554,8 @@ static const char kColorEncodedHelpMessage[] =
" @G--"
GTEST_FLAG_PREFIX_
"break_on_failure@D
\n
"
" Turn assertion failures into debugger break-points.
\n
"
" @G--"
GTEST_FLAG_PREFIX_
"throw_on_failure@D
\n
"
" Turn assertion failures into C++ exceptions.
\n
"
" Turn assertion failures into C++ exceptions for use by an external
\n
"
" test framework.
\n
"
" @G--"
GTEST_FLAG_PREFIX_
"catch_exceptions=0@D
\n
"
" Do not report exceptions as test failures. Instead, allow them
\n
"
" to crash the program or throw a pop-up (on Windows).
\n
"
...
...
@@ -5244,7 +5572,7 @@ static const char kColorEncodedHelpMessage[] =
"(not one in your own code or tests), please report it to
\n
"
"@G<"
GTEST_DEV_EMAIL_
">@D.
\n
"
;
bool
ParseGoogleTestFlag
(
const
char
*
const
arg
)
{
static
bool
ParseGoogleTestFlag
(
const
char
*
const
arg
)
{
return
ParseBoolFlag
(
arg
,
kAlsoRunDisabledTestsFlag
,
&
GTEST_FLAG
(
also_run_disabled_tests
))
||
ParseBoolFlag
(
arg
,
kBreakOnFailureFlag
,
...
...
@@ -5262,6 +5590,7 @@ bool ParseGoogleTestFlag(const char* const arg) {
ParseBoolFlag
(
arg
,
kListTestsFlag
,
&
GTEST_FLAG
(
list_tests
))
||
ParseStringFlag
(
arg
,
kOutputFlag
,
&
GTEST_FLAG
(
output
))
||
ParseBoolFlag
(
arg
,
kPrintTimeFlag
,
&
GTEST_FLAG
(
print_time
))
||
ParseBoolFlag
(
arg
,
kPrintUTF8Flag
,
&
GTEST_FLAG
(
print_utf8
))
||
ParseInt32Flag
(
arg
,
kRandomSeedFlag
,
&
GTEST_FLAG
(
random_seed
))
||
ParseInt32Flag
(
arg
,
kRepeatFlag
,
&
GTEST_FLAG
(
repeat
))
||
ParseBoolFlag
(
arg
,
kShuffleFlag
,
&
GTEST_FLAG
(
shuffle
))
||
...
...
@@ -5274,11 +5603,10 @@ bool ParseGoogleTestFlag(const char* const arg) {
}
#if GTEST_USE_OWN_FLAGFILE_FLAG_
void
LoadFlagsFromFile
(
const
std
::
string
&
path
)
{
static
void
LoadFlagsFromFile
(
const
std
::
string
&
path
)
{
FILE
*
flagfile
=
posix
::
FOpen
(
path
.
c_str
(),
"r"
);
if
(
!
flagfile
)
{
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
<<
GTEST_FLAG
(
flagfile
)
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
<<
GTEST_FLAG
(
flagfile
)
<<
"
\"
"
;
}
std
::
string
contents
(
ReadEntireFile
(
flagfile
));
...
...
@@ -5411,6 +5739,7 @@ std::string TempDir() {
#if defined(GTEST_CUSTOM_TEMPDIR_FUNCTION_)
return
GTEST_CUSTOM_TEMPDIR_FUNCTION_
();
#endif
#if GTEST_OS_WINDOWS_MOBILE
return
"
\\
temp
\\
"
;
#elif GTEST_OS_WINDOWS
...
...
@@ -5428,4 +5757,23 @@ std::string TempDir() {
#endif // GTEST_OS_WINDOWS_MOBILE
}
// Class ScopedTrace
// Pushes the given source file location and message onto a per-thread
// trace stack maintained by Google Test.
void
ScopedTrace
::
PushTrace
(
const
char
*
file
,
int
line
,
std
::
string
message
)
{
internal
::
TraceInfo
trace
;
trace
.
file
=
file
;
trace
.
line
=
line
;
trace
.
message
.
swap
(
message
);
UnitTest
::
GetInstance
()
->
PushGTestTrace
(
trace
);
}
// Pops the info pushed by the c'tor.
ScopedTrace
::~
ScopedTrace
()
GTEST_LOCK_EXCLUDED_
(
&
UnitTest
::
mutex_
)
{
UnitTest
::
GetInstance
()
->
PopGTestTrace
();
}
}
// namespace testing
googletest/src/gtest_main.cc
View file @
a7a7f51d
...
...
@@ -26,9 +26,9 @@
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include <stdio.h>
#include "gtest/gtest.h"
GTEST_API_
int
main
(
int
argc
,
char
**
argv
)
{
...
...
googletest/test/BUILD.bazel
View file @
a7a7f51d
...
...
@@ -57,13 +57,15 @@ cc_test(
"gtest-param-test_test.cc"
,
],
)
+
select
({
"//:win"
:
[],
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"gtest-tuple_test.cc"
,
],
}),
copts
=
select
({
"//:win"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//:windows"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//:windows_msvc"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//conditions:default"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=1"
],
}),
includes
=
[
...
...
@@ -73,7 +75,8 @@ cc_test(
"googletest/test"
,
],
linkopts
=
select
({
"//:win"
:
[],
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"-pthread"
,
],
...
...
@@ -116,3 +119,262 @@ cc_test(
"//:gtest"
,
],
)
cc_test
(
name
=
"gtest_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_unittest.cc"
],
args
=
[
"--heap_check=strict"
],
shard_count
=
2
,
deps
=
[
"//:gtest_main"
],
)
# Py tests
py_library
(
name
=
"gtest_test_utils"
,
testonly
=
1
,
srcs
=
[
"gtest_test_utils.py"
],
)
cc_binary
(
name
=
"gtest_help_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_help_test_.cc"
],
deps
=
[
"//:gtest_main"
],
)
py_test
(
name
=
"gtest_help_test"
,
size
=
"small"
,
srcs
=
[
"gtest_help_test.py"
],
data
=
[
":gtest_help_test_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_output_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_output_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_output_test"
,
size
=
"small"
,
srcs
=
[
"gtest_output_test.py"
],
data
=
[
"gtest_output_test_golden_lin.txt"
,
":gtest_output_test_"
,
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_color_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_color_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_color_test"
,
size
=
"small"
,
srcs
=
[
"gtest_color_test.py"
],
data
=
[
":gtest_color_test_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_env_var_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_env_var_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_env_var_test"
,
size
=
"small"
,
srcs
=
[
"gtest_env_var_test.py"
],
data
=
[
":gtest_env_var_test_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_filter_unittest_"
,
testonly
=
1
,
srcs
=
[
"gtest_filter_unittest_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_filter_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_filter_unittest.py"
],
data
=
[
":gtest_filter_unittest_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_break_on_failure_unittest_"
,
testonly
=
1
,
srcs
=
[
"gtest_break_on_failure_unittest_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_break_on_failure_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_break_on_failure_unittest.py"
],
data
=
[
":gtest_break_on_failure_unittest_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_test
(
name
=
"gtest_assert_by_exception_test"
,
size
=
"small"
,
srcs
=
[
"gtest_assert_by_exception_test.cc"
],
deps
=
[
"//:gtest"
],
)
cc_binary
(
name
=
"gtest_throw_on_failure_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_throw_on_failure_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_throw_on_failure_test"
,
size
=
"small"
,
srcs
=
[
"gtest_throw_on_failure_test.py"
],
data
=
[
":gtest_throw_on_failure_test_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_list_tests_unittest_"
,
testonly
=
1
,
srcs
=
[
"gtest_list_tests_unittest_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_list_tests_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_list_tests_unittest.py"
],
data
=
[
":gtest_list_tests_unittest_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_shuffle_test_"
,
srcs
=
[
"gtest_shuffle_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_shuffle_test"
,
size
=
"small"
,
srcs
=
[
"gtest_shuffle_test.py"
],
data
=
[
":gtest_shuffle_test_"
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_catch_exceptions_no_ex_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_catch_exceptions_test_.cc"
],
deps
=
[
"//:gtest_main"
],
)
cc_binary
(
name
=
"gtest_catch_exceptions_ex_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_catch_exceptions_test_.cc"
],
copts
=
[
"-fexceptions"
],
deps
=
[
"//:gtest_main"
],
)
py_test
(
name
=
"gtest_catch_exceptions_test"
,
size
=
"small"
,
srcs
=
[
"gtest_catch_exceptions_test.py"
],
data
=
[
":gtest_catch_exceptions_ex_test_"
,
":gtest_catch_exceptions_no_ex_test_"
,
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_xml_output_unittest_"
,
testonly
=
1
,
srcs
=
[
"gtest_xml_output_unittest_.cc"
],
deps
=
[
"//:gtest"
],
)
cc_test
(
name
=
"gtest_no_test_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_no_test_unittest.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_xml_output_unittest"
,
size
=
"small"
,
srcs
=
[
"gtest_xml_output_unittest.py"
,
"gtest_xml_test_utils.py"
,
],
data
=
[
# We invoke gtest_no_test_unittest to verify the XML output
# when the test program contains no test definition.
":gtest_no_test_unittest"
,
":gtest_xml_output_unittest_"
,
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_xml_outfile1_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_xml_outfile1_test_.cc"
],
deps
=
[
"//:gtest_main"
],
)
cc_binary
(
name
=
"gtest_xml_outfile2_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_xml_outfile2_test_.cc"
],
deps
=
[
"//:gtest_main"
],
)
py_test
(
name
=
"gtest_xml_outfiles_test"
,
size
=
"small"
,
srcs
=
[
"gtest_xml_outfiles_test.py"
,
"gtest_xml_test_utils.py"
,
],
data
=
[
":gtest_xml_outfile1_test_"
,
":gtest_xml_outfile2_test_"
,
],
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"gtest_uninitialized_test_"
,
testonly
=
1
,
srcs
=
[
"gtest_uninitialized_test_.cc"
],
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"gtest_uninitialized_test"
,
size
=
"medium"
,
srcs
=
[
"gtest_uninitialized_test.py"
],
data
=
[
":gtest_uninitialized_test_"
],
deps
=
[
":gtest_test_utils"
],
)
googletest/test/gtest-death-test_test.cc
View file @
a7a7f51d
...
...
@@ -56,15 +56,7 @@ using testing::internal::AlwaysTrue;
# endif // GTEST_OS_LINUX
# include "gtest/gtest-spi.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
# define GTEST_IMPLEMENTATION_ 1
# include "src/gtest-internal-inl.h"
# undef GTEST_IMPLEMENTATION_
namespace
posix
=
::
testing
::
internal
::
posix
;
...
...
@@ -313,14 +305,14 @@ void DieWithEmbeddedNul() {
}
# if GTEST_USES_PCRE
// Tests that EXPECT_DEATH and ASSERT_DEATH work when the error
// message has a NUL character in it.
TEST_F
(
TestForDeathTest
,
EmbeddedNulInMessage
)
{
// TODO(wan@google.com): <regex.h> doesn't support matching strings
// with embedded NUL characters - find a way to workaround it.
EXPECT_DEATH
(
DieWithEmbeddedNul
(),
"my null world"
);
ASSERT_DEATH
(
DieWithEmbeddedNul
(),
"my null world"
);
}
# endif // GTEST_USES_PCRE
// Tests that death test macros expand to code which interacts well with switch
...
...
@@ -625,7 +617,11 @@ TEST_F(TestForDeathTest, ReturnIsFailure) {
TEST_F
(
TestForDeathTest
,
TestExpectDebugDeath
)
{
int
sideeffect
=
0
;
EXPECT_DEBUG_DEATH
(
DieInDebugElse12
(
&
sideeffect
),
"death.*DieInDebugElse12"
)
// Put the regex in a local variable to make sure we don't get an "unused"
// warning in opt mode.
const
char
*
regex
=
"death.*DieInDebugElse12"
;
EXPECT_DEBUG_DEATH
(
DieInDebugElse12
(
&
sideeffect
),
regex
)
<<
"Must accept a streamed message"
;
# ifdef NDEBUG
...
...
googletest/test/gtest-filepath_test.cc
View file @
a7a7f51d
...
...
@@ -27,28 +27,18 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: keith.ray@gmail.com (Keith Ray)
//
// Google Test filepath utilities
//
// This file tests classes and functions used internally by
// Google Test. They are subject to change without notice.
//
// This file is #included from gtest_unittest.cc, to avoid changing
// build or make-files for some existing Google Test clients. Do not
// #include this file anywhere else!
// This file is #included from gtest-internal.h.
// Do not #include this file anywhere else!
#include "gtest/internal/gtest-filepath.h"
#include "gtest/gtest.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
#if GTEST_OS_WINDOWS_MOBILE
# include <windows.h> // NOLINT
...
...
googletest/test/gtest-options_test.cc
View file @
a7a7f51d
...
...
@@ -27,7 +27,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: keith.ray@gmail.com (Keith Ray)
//
// Google Test UnitTestOptions tests
//
...
...
@@ -46,14 +45,7 @@
# include <direct.h>
#endif // GTEST_OS_WINDOWS_MOBILE
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
namespace
testing
{
namespace
internal
{
...
...
googletest/test/gtest-param-test2_test.cc
View file @
a7a7f51d
...
...
@@ -33,10 +33,7 @@
// Google Test work.
#include "gtest/gtest.h"
#include "test/gtest-param-test_test.h"
#if GTEST_HAS_PARAM_TEST
#include "gtest-param-test_test.h"
using
::
testing
::
Values
;
using
::
testing
::
internal
::
ParamGenerator
;
...
...
@@ -62,4 +59,3 @@ INSTANTIATE_TEST_CASE_P(Sequence2,
InstantiationInMultipleTranslaionUnitsTest
,
Values
(
42
*
3
,
42
*
4
,
42
*
5
));
#endif // GTEST_HAS_PARAM_TEST
googletest/test/gtest-param-test_test.cc
View file @
a7a7f51d
...
...
@@ -35,8 +35,6 @@
#include "gtest/gtest.h"
#if GTEST_HAS_PARAM_TEST
# include <algorithm>
# include <iostream>
# include <list>
...
...
@@ -44,11 +42,7 @@
# include <string>
# include <vector>
// To include gtest-internal-inl.h.
# define GTEST_IMPLEMENTATION_ 1
# include "src/gtest-internal-inl.h" // for UnitTestOptions
# undef GTEST_IMPLEMENTATION_
# include "test/gtest-param-test_test.h"
using
::
std
::
vector
;
...
...
@@ -542,6 +536,51 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) {
VerifyGenerator
(
gen
,
expected_values
);
}
#if GTEST_LANG_CXX11
class
NonDefaultConstructAssignString
{
public:
NonDefaultConstructAssignString
(
const
std
::
string
&
s
)
:
str_
(
s
)
{}
const
std
::
string
&
str
()
const
{
return
str_
;
}
private:
std
::
string
str_
;
// Not default constructible
NonDefaultConstructAssignString
();
// Not assignable
void
operator
=
(
const
NonDefaultConstructAssignString
&
);
};
TEST
(
CombineTest
,
NonDefaultConstructAssign
)
{
const
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
NonDefaultConstructAssignString
(
"A"
),
NonDefaultConstructAssignString
(
"B"
)));
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
it
=
gen
.
begin
();
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"B"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
1
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_EQ
(
1
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"B"
,
std
::
get
<
1
>
(
*
it
).
str
());
++
it
;
EXPECT_TRUE
(
it
==
gen
.
end
());
}
#endif // GTEST_LANG_CXX11
# endif // GTEST_HAS_COMBINE
// Tests that an generator produces correct sequence after being
...
...
@@ -817,8 +856,8 @@ class CustomFunctorNamingTest : public TestWithParam<std::string> {};
TEST_P
(
CustomFunctorNamingTest
,
CustomTestNames
)
{}
struct
CustomParamNameFunctor
{
std
::
string
operator
()(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
o
)
{
return
inf
o
.
param
;
std
::
string
operator
()(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
inf
.
param
;
}
};
...
...
@@ -835,8 +874,8 @@ INSTANTIATE_TEST_CASE_P(AllAllowedCharacters,
CustomParamNameFunctor
());
inline
std
::
string
CustomParamNameFunction
(
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
o
)
{
return
inf
o
.
param
;
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
inf
.
param
;
}
class
CustomFunctionNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
...
...
@@ -854,11 +893,10 @@ INSTANTIATE_TEST_CASE_P(CustomParamNameFunction,
class
CustomLambdaNamingTest
:
public
TestWithParam
<
std
::
string
>
{};
TEST_P
(
CustomLambdaNamingTest
,
CustomTestNames
)
{}
INSTANTIATE_TEST_CASE_P
(
CustomParamNameLambda
,
CustomLambdaNamingTest
,
INSTANTIATE_TEST_CASE_P
(
CustomParamNameLambda
,
CustomLambdaNamingTest
,
Values
(
std
::
string
(
"LambdaName"
)),
[](
const
::
testing
::
TestParamInfo
<
std
::
string
>&
tp
inf
o
)
{
return
tp
inf
o
.
param
;
[](
const
::
testing
::
TestParamInfo
<
std
::
string
>&
inf
)
{
return
inf
.
param
;
});
#endif // GTEST_LANG_CXX11
...
...
@@ -1025,31 +1063,20 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
#endif // GTEST_HAS_PARAM_TEST
TEST
(
CompileTest
,
CombineIsDefinedOnlyWhenGtestHasParamTestIsDefined
)
{
#if GTEST_HAS_COMBINE && !GTEST_HAS_PARAM_TEST
FAIL
()
<<
"GTEST_HAS_COMBINE is defined while GTEST_HAS_PARAM_TEST is not
\n
"
#endif
}
int
main
(
int
argc
,
char
**
argv
)
{
#if GTEST_HAS_PARAM_TEST
// Used in TestGenerationTest test case.
AddGlobalTestEnvironment
(
TestGenerationTest
::
Environment
::
Instance
());
// Used in GeneratorEvaluationTest test case. Tests that the updated value
// will be picked up for instantiating tests in GeneratorEvaluationTest.
GeneratorEvaluationTest
::
set_param_value
(
1
);
#endif // GTEST_HAS_PARAM_TEST
::
testing
::
InitGoogleTest
(
&
argc
,
argv
);
#if GTEST_HAS_PARAM_TEST
// Used in GeneratorEvaluationTest test case. Tests that value updated
// here will NOT be used for instantiating tests in
// GeneratorEvaluationTest.
GeneratorEvaluationTest
::
set_param_value
(
2
);
#endif // GTEST_HAS_PARAM_TEST
return
RUN_ALL_TESTS
();
}
googletest/test/gtest-param-test_test.h
View file @
a7a7f51d
...
...
@@ -39,8 +39,6 @@
#include "gtest/gtest.h"
#if GTEST_HAS_PARAM_TEST
// Test fixture for testing definition and instantiation of a test
// in separate translation units.
class
ExternalInstantiationTest
:
public
::
testing
::
TestWithParam
<
int
>
{
...
...
@@ -52,6 +50,4 @@ class InstantiationInMultipleTranslaionUnitsTest
:
public
::
testing
::
TestWithParam
<
int
>
{
};
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
googletest/test/gtest-port_test.cc
View file @
a7a7f51d
...
...
@@ -45,15 +45,7 @@
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// their code.
#define GTEST_IMPLEMENTATION_ 1
#include "src/gtest-internal-inl.h"
#undef GTEST_IMPLEMENTATION_
using
std
::
make_pair
;
using
std
::
pair
;
...
...
@@ -75,8 +67,8 @@ TEST(IsXDigitTest, WorksForNarrowAscii) {
}
TEST
(
IsXDigitTest
,
ReturnsFalseForNarrowNonAscii
)
{
EXPECT_FALSE
(
IsXDigit
(
'\
x80
'
));
EXPECT_FALSE
(
IsXDigit
(
static_cast
<
char
>
(
'0'
|
'\
x80
'
)));
EXPECT_FALSE
(
IsXDigit
(
static_cast
<
char
>
(
0
x80
)
));
EXPECT_FALSE
(
IsXDigit
(
static_cast
<
char
>
(
'0'
|
0
x80
)));
}
TEST
(
IsXDigitTest
,
WorksForWideAscii
)
{
...
...
googletest/test/gtest-printers_test.cc
View file @
a7a7f51d
...
...
@@ -197,8 +197,7 @@ inline ::std::ostream& operator<<(::std::ostream& os,
// boost::filesystem::path.
class
PathLike
{
public:
struct
iterator
{
struct
iterator
{
typedef
PathLike
value_type
;
};
typedef
iterator
const_iterator
;
...
...
@@ -208,9 +207,7 @@ class PathLike {
iterator
begin
()
const
{
return
iterator
();
}
iterator
end
()
const
{
return
iterator
();
}
friend
::
std
::
ostream
&
operator
<<
(
::
std
::
ostream
&
os
,
const
PathLike
&
)
{
friend
::
std
::
ostream
&
operator
<<
(
::
std
::
ostream
&
os
,
const
PathLike
&
)
{
return
os
<<
"Streamable-PathLike"
;
}
};
...
...
@@ -250,9 +247,9 @@ using ::testing::internal::string;
#if GTEST_HAS_UNORDERED_MAP_
#define GTEST_HAS_HASH_MAP_ 1
template
<
class
Key
,
class
T
>
template
<
class
Key
,
class
T
>
using
hash_map
=
::
std
::
unordered_map
<
Key
,
T
>
;
template
<
class
Key
,
class
T
>
template
<
class
Key
,
class
T
>
using
hash_multimap
=
::
std
::
unordered_multimap
<
Key
,
T
>
;
#elif GTEST_HAS_HASH_MAP_
...
...
@@ -270,19 +267,19 @@ using ::stdext::hash_multimap;
#if GTEST_HAS_UNORDERED_SET_
#define GTEST_HAS_HASH_SET_ 1
template
<
class
Key
>
template
<
class
Key
>
using
hash_set
=
::
std
::
unordered_set
<
Key
>
;
template
<
class
Key
>
template
<
class
Key
>
using
hash_multiset
=
::
std
::
unordered_multiset
<
Key
>
;
#elif GTEST_HAS_HASH_SET_
#ifdef _STLP_HASH_MAP // We got <hash_map> from STLport.
using
::
std
::
hash_
set
;
using
::
std
::
hash_multi
set
;
using
::
std
::
hash_
map
;
using
::
std
::
hash_multi
map
;
#elif _MSC_VER
using
::
stdext
::
hash_
set
;
using
::
stdext
::
hash_multi
set
;
using
::
stdext
::
hash_
map
;
using
::
stdext
::
hash_multi
map
;
#endif
#endif
...
...
@@ -840,22 +837,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
EXPECT_EQ
(
"AllowsGenericStreamingAndImplicitConversionTemplate"
,
Print
(
a
));
}
#if GTEST_HAS_
STRING_PIECE_
#if GTEST_HAS_
ABSL
// Tests printing
StringPiece
.
// Tests printing
::absl::string_view
.
TEST
(
PrintString
P
ie
ce
Test
,
SimpleString
P
ie
ce
)
{
const
StringPiece
sp
=
"Hello"
;
TEST
(
PrintString
V
ie
w
Test
,
SimpleString
V
ie
w
)
{
const
::
absl
::
string_view
sp
=
"Hello"
;
EXPECT_EQ
(
"
\"
Hello
\"
"
,
Print
(
sp
));
}
TEST
(
PrintString
P
ie
ce
Test
,
UnprintableCharacters
)
{
TEST
(
PrintString
V
ie
w
Test
,
UnprintableCharacters
)
{
const
char
str
[]
=
"NUL (
\0
) and
\r\t
"
;
const
StringPiece
sp
(
str
,
sizeof
(
str
)
-
1
);
const
::
absl
::
string_view
sp
(
str
,
sizeof
(
str
)
-
1
);
EXPECT_EQ
(
"
\"
NUL (
\\
0) and
\\
r
\\
t
\"
"
,
Print
(
sp
));
}
#endif // GTEST_HAS_
STRING_PIECE_
#endif // GTEST_HAS_
ABSL
// Tests printing STL containers.
...
...
@@ -1092,7 +1089,7 @@ TEST(PrintTr1TupleTest, VariousSizes) {
::
std
::
tr1
::
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
std
::
string
>
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
2.5
,
str
,
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
2.5
,
str
,
// NOLINT
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
...
...
@@ -1152,7 +1149,7 @@ TEST(PrintStdTupleTest, VariousSizes) {
::
std
::
tuple
<
bool
,
char
,
short
,
testing
::
internal
::
Int32
,
// NOLINT
testing
::
internal
::
Int64
,
float
,
double
,
const
char
*
,
void
*
,
std
::
string
>
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
2.5
,
str
,
t10
(
false
,
'a'
,
static_cast
<
short
>
(
3
),
4
,
5
,
1.5
F
,
-
2.5
,
str
,
// NOLINT
ImplicitCast_
<
void
*>
(
NULL
),
"10"
);
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
...
...
@@ -1330,7 +1327,7 @@ TEST(FormatForComparisonFailureMessageTest, FormatsNonCharArrayAsPointer) {
}
// Tests formatting a char pointer when it's compared with another pointer.
// In this case we want to print it as a raw pointer, as the comparis
i
on is by
// In this case we want to print it as a raw pointer, as the comparison is by
// pointer.
// char pointer vs pointer
...
...
@@ -1555,6 +1552,78 @@ TEST(PrintToStringTest, WorksForCharArrayWithEmbeddedNul) {
EXPECT_PRINT_TO_STRING_
(
mutable_str_with_nul
,
"
\"
hello
\\
0 world
\"
"
);
}
TEST
(
PrintToStringTest
,
ContainsNonLatin
)
{
// Sanity test with valid UTF-8. Prints both in hex and as text.
std
::
string
non_ascii_str
=
::
std
::
string
(
"오전 4:30"
);
EXPECT_PRINT_TO_STRING_
(
non_ascii_str
,
"
\"\\
xEC
\\
x98
\\
xA4
\\
xEC
\\
xA0
\\
x84 4:30
\"\n
"
" As Text:
\"
오전 4:30
\"
"
);
non_ascii_str
=
::
std
::
string
(
"From ä — ẑ"
);
EXPECT_PRINT_TO_STRING_
(
non_ascii_str
,
"
\"
From
\\
xC3
\\
xA4
\\
xE2
\\
x80
\\
x94
\\
xE1
\\
xBA
\\
x91
\"
"
"
\n
As Text:
\"
From ä — ẑ
\"
"
);
}
TEST
(
IsValidUTF8Test
,
IllFormedUTF8
)
{
// The following test strings are ill-formed UTF-8 and are printed
// as hex only (or ASCII, in case of ASCII bytes) because IsValidUTF8() is
// expected to fail, thus output does not contain "As Text:".
static
const
char
*
const
kTestdata
[][
2
]
=
{
// 2-byte lead byte followed by a single-byte character.
{
"
\xC3\x74
"
,
"
\"\\
xC3t
\"
"
},
// Valid 2-byte character followed by an orphan trail byte.
{
"
\xC3\x84\xA4
"
,
"
\"\\
xC3
\\
x84
\\
xA4
\"
"
},
// Lead byte without trail byte.
{
"abc
\xC3
"
,
"
\"
abc
\\
xC3
\"
"
},
// 3-byte lead byte, single-byte character, orphan trail byte.
{
"x
\xE2\x70\x94
"
,
"
\"
x
\\
xE2p
\\
x94
\"
"
},
// Truncated 3-byte character.
{
"
\xE2\x80
"
,
"
\"\\
xE2
\\
x80
\"
"
},
// Truncated 3-byte character followed by valid 2-byte char.
{
"
\xE2\x80\xC3\x84
"
,
"
\"\\
xE2
\\
x80
\\
xC3
\\
x84
\"
"
},
// Truncated 3-byte character followed by a single-byte character.
{
"
\xE2\x80\x7A
"
,
"
\"\\
xE2
\\
x80z
\"
"
},
// 3-byte lead byte followed by valid 3-byte character.
{
"
\xE2\xE2\x80\x94
"
,
"
\"\\
xE2
\\
xE2
\\
x80
\\
x94
\"
"
},
// 4-byte lead byte followed by valid 3-byte character.
{
"
\xF0\xE2\x80\x94
"
,
"
\"\\
xF0
\\
xE2
\\
x80
\\
x94
\"
"
},
// Truncated 4-byte character.
{
"
\xF0\xE2\x80
"
,
"
\"\\
xF0
\\
xE2
\\
x80
\"
"
},
// Invalid UTF-8 byte sequences embedded in other chars.
{
"abc
\xE2\x80\x94\xC3\x74
xyc"
,
"
\"
abc
\\
xE2
\\
x80
\\
x94
\\
xC3txyc
\"
"
},
{
"abc
\xC3\x84\xE2\x80\xC3\x84
xyz"
,
"
\"
abc
\\
xC3
\\
x84
\\
xE2
\\
x80
\\
xC3
\\
x84xyz
\"
"
},
// Non-shortest UTF-8 byte sequences are also ill-formed.
// The classics: xC0, xC1 lead byte.
{
"
\xC0\x80
"
,
"
\"\\
xC0
\\
x80
\"
"
},
{
"
\xC1\x81
"
,
"
\"\\
xC1
\\
x81
\"
"
},
// Non-shortest sequences.
{
"
\xE0\x80\x80
"
,
"
\"\\
xE0
\\
x80
\\
x80
\"
"
},
{
"
\xf0\x80\x80\x80
"
,
"
\"\\
xF0
\\
x80
\\
x80
\\
x80
\"
"
},
// Last valid code point before surrogate range, should be printed as text,
// too.
{
"
\xED\x9F\xBF
"
,
"
\"\\
xED
\\
x9F
\\
xBF
\"\n
As Text:
\"
\"
"
},
// Start of surrogate lead. Surrogates are not printed as text.
{
"
\xED\xA0\x80
"
,
"
\"\\
xED
\\
xA0
\\
x80
\"
"
},
// Last non-private surrogate lead.
{
"
\xED\xAD\xBF
"
,
"
\"\\
xED
\\
xAD
\\
xBF
\"
"
},
// First private-use surrogate lead.
{
"
\xED\xAE\x80
"
,
"
\"\\
xED
\\
xAE
\\
x80
\"
"
},
// Last private-use surrogate lead.
{
"
\xED\xAF\xBF
"
,
"
\"\\
xED
\\
xAF
\\
xBF
\"
"
},
// Mid-point of surrogate trail.
{
"
\xED\xB3\xBF
"
,
"
\"\\
xED
\\
xB3
\\
xBF
\"
"
},
// First valid code point after surrogate range, should be printed as text,
// too.
{
"
\xEE\x80\x80
"
,
"
\"\\
xEE
\\
x80
\\
x80
\"\n
As Text:
\"
\"
"
}
};
for
(
int
i
=
0
;
i
<
int
(
sizeof
(
kTestdata
)
/
sizeof
(
kTestdata
[
0
]));
++
i
)
{
EXPECT_PRINT_TO_STRING_
(
kTestdata
[
i
][
0
],
kTestdata
[
i
][
1
]);
}
}
#undef EXPECT_PRINT_TO_STRING_
TEST
(
UniversalTersePrintTest
,
WorksForNonReference
)
{
...
...
@@ -1696,5 +1765,17 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_ABSL
TEST
(
PrintOptionalTest
,
Basic
)
{
absl
::
optional
<
int
>
value
;
EXPECT_EQ
(
"(nullopt)"
,
PrintToString
(
value
));
value
=
{
7
};
EXPECT_EQ
(
"(7)"
,
PrintToString
(
value
));
EXPECT_EQ
(
"(1.1)"
,
PrintToString
(
absl
::
optional
<
double
>
{
1.1
}));
EXPECT_EQ
(
"(
\"
A
\"
)"
,
PrintToString
(
absl
::
optional
<
std
::
string
>
{
"A"
}));
}
#endif // GTEST_HAS_ABSL
}
// namespace gtest_printers_test
}
// namespace testing
googletest/test/gtest-typed-test2_test.cc
View file @
a7a7f51d
...
...
@@ -31,7 +31,7 @@
#include <vector>
#include "
test/
gtest-typed-test_test.h"
#include "gtest-typed-test_test.h"
#include "gtest/gtest.h"
#if GTEST_HAS_TYPED_TEST_P
...
...
googletest/test/gtest-typed-test_test.cc
View file @
a7a7f51d
...
...
@@ -29,7 +29,7 @@
//
// Author: wan@google.com (Zhanyong Wan)
#include "
test/
gtest-typed-test_test.h"
#include "gtest-typed-test_test.h"
#include <set>
#include <vector>
...
...
Prev
1
2
3
4
5
6
7
Next
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