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
25905b9f
Commit
25905b9f
authored
Jan 02, 2019
by
Gennadiy Civil
Browse files
Merge branch 'master' of
https://github.com/google/googletest
parents
4665eee1
3bedb5a9
Changes
143
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
471 additions
and
639 deletions
+471
-639
googletest/src/gtest-printers.cc
googletest/src/gtest-printers.cc
+1
-1
googletest/src/gtest.cc
googletest/src/gtest.cc
+60
-75
googletest/src/gtest_main.cc
googletest/src/gtest_main.cc
+16
-0
googletest/test/BUILD.bazel
googletest/test/BUILD.bazel
+27
-53
googletest/test/googletest-catch-exceptions-test_.cc
googletest/test/googletest-catch-exceptions-test_.cc
+13
-13
googletest/test/googletest-death-test-test.cc
googletest/test/googletest-death-test-test.cc
+74
-24
googletest/test/googletest-death-test_ex_test.cc
googletest/test/googletest-death-test_ex_test.cc
+1
-1
googletest/test/googletest-env-var-test.py
googletest/test/googletest-env-var-test.py
+2
-2
googletest/test/googletest-filepath-test.cc
googletest/test/googletest-filepath-test.cc
+3
-3
googletest/test/googletest-filter-unittest.py
googletest/test/googletest-filter-unittest.py
+8
-5
googletest/test/googletest-json-output-unittest.py
googletest/test/googletest-json-output-unittest.py
+17
-1
googletest/test/googletest-linked-ptr-test.cc
googletest/test/googletest-linked-ptr-test.cc
+0
-151
googletest/test/googletest-listener-test.cc
googletest/test/googletest-listener-test.cc
+19
-27
googletest/test/googletest-options-test.cc
googletest/test/googletest-options-test.cc
+8
-2
googletest/test/googletest-output-test-golden-lin.txt
googletest/test/googletest-output-test-golden-lin.txt
+86
-5
googletest/test/googletest-output-test.py
googletest/test/googletest-output-test.py
+1
-1
googletest/test/googletest-output-test_.cc
googletest/test/googletest-output-test_.cc
+71
-34
googletest/test/googletest-param-test-test.cc
googletest/test/googletest-param-test-test.cc
+52
-90
googletest/test/googletest-port-test.cc
googletest/test/googletest-port-test.cc
+2
-9
googletest/test/googletest-printers-test.cc
googletest/test/googletest-printers-test.cc
+10
-142
No files found.
googletest/src/gtest-printers.cc
View file @
25905b9f
...
...
@@ -348,7 +348,7 @@ void PrintTo(const wchar_t* s, ostream* os) {
*
os
<<
"NULL"
;
}
else
{
*
os
<<
ImplicitCast_
<
const
void
*>
(
s
)
<<
" pointing to "
;
PrintCharsAsStringTo
(
s
,
std
::
wcslen
(
s
),
os
);
PrintCharsAsStringTo
(
s
,
wcslen
(
s
),
os
);
}
}
#endif // wchar_t is native
...
...
googletest/src/gtest.cc
View file @
25905b9f
...
...
@@ -423,9 +423,6 @@ void AssertHelper::operator=(const Message& message) const {
);
// NOLINT
}
// Mutex for linked pointers.
GTEST_API_
GTEST_DEFINE_STATIC_MUTEX_
(
g_linked_ptr_mutex
);
// A copy of all command line arguments. Set by InitGoogleTest().
static
::
std
::
vector
<
std
::
string
>
g_argvs
;
...
...
@@ -445,7 +442,7 @@ static ::std::vector<std::string> g_argvs;
FilePath
GetCurrentExecutableName
()
{
FilePath
result
;
#if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
|| GTEST_OS_OS2
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]).
RemoveExtension
(
"exe"
));
#else
result
.
Set
(
FilePath
(
GetArgvs
()[
0
]));
...
...
@@ -905,11 +902,10 @@ TimeInMillis GetTimeInMillis() {
// value using delete[]. Returns the wide string, or NULL if the
// input is NULL.
LPCWSTR
String
::
AnsiToUtf16
(
const
char
*
ansi
)
{
if
(
!
ansi
)
return
NULL
;
if
(
!
ansi
)
return
nullptr
;
const
int
length
=
strlen
(
ansi
);
const
int
unicode_length
=
MultiByteToWideChar
(
CP_ACP
,
0
,
ansi
,
length
,
NULL
,
0
);
MultiByteToWideChar
(
CP_ACP
,
0
,
ansi
,
length
,
nullptr
,
0
);
WCHAR
*
unicode
=
new
WCHAR
[
unicode_length
+
1
];
MultiByteToWideChar
(
CP_ACP
,
0
,
ansi
,
length
,
unicode
,
unicode_length
);
...
...
@@ -922,13 +918,12 @@ LPCWSTR String::AnsiToUtf16(const char* ansi) {
// value using delete[]. Returns the ANSI string, or NULL if the
// input is NULL.
const
char
*
String
::
Utf16ToAnsi
(
LPCWSTR
utf16_str
)
{
if
(
!
utf16_str
)
return
NULL
;
const
int
ansi_length
=
WideCharToMultiByte
(
CP_ACP
,
0
,
utf16_str
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
if
(
!
utf16_str
)
return
nullptr
;
const
int
ansi_length
=
WideCharToMultiByte
(
CP_ACP
,
0
,
utf16_str
,
-
1
,
nullptr
,
0
,
nullptr
,
nullptr
);
char
*
ansi
=
new
char
[
ansi_length
+
1
];
WideCharToMultiByte
(
CP_ACP
,
0
,
utf16_str
,
-
1
,
ansi
,
ansi_length
,
NULL
,
NULL
);
WideCharToMultiByte
(
CP_ACP
,
0
,
utf16_str
,
-
1
,
ansi
,
ansi_length
,
nullptr
,
nullptr
);
ansi
[
ansi_length
]
=
0
;
return
ansi
;
}
...
...
@@ -1725,12 +1720,12 @@ AssertionResult HRESULTFailureHelper(const char* expr,
// Gets the system's human readable message string for this HRESULT.
char
error_text
[
kBufSize
]
=
{
'\0'
};
DWORD
message_length
=
::
FormatMessageA
(
kFlags
,
0
,
// no source, we're asking system
0
,
// no source, we're asking system
hr
,
// the error
0
,
// no line width restrictions
0
,
// no line width restrictions
error_text
,
// output buffer
kBufSize
,
// buf size
NULL
);
// no arguments for inserts
kBufSize
,
// buf size
nullptr
);
// no arguments for inserts
// Trims tailing white space (FormatMessage leaves a trailing CR-LF)
for
(;
message_length
&&
IsSpace
(
error_text
[
message_length
-
1
]);
--
message_length
)
{
...
...
@@ -2402,7 +2397,7 @@ namespace internal {
static
std
::
string
FormatCxxExceptionMessage
(
const
char
*
description
,
const
char
*
location
)
{
Message
message
;
if
(
description
!=
NULL
)
{
if
(
description
!=
nullptr
)
{
message
<<
"C++ exception with description
\"
"
<<
description
<<
"
\"
"
;
}
else
{
message
<<
"Unknown C++ exception"
;
...
...
@@ -2500,7 +2495,7 @@ Result HandleExceptionsInMethodIfSupported(
}
catch
(...)
{
// NOLINT
internal
::
ReportFailureInUnknownLocation
(
TestPartResult
::
kFatalFailure
,
FormatCxxExceptionMessage
(
NULL
,
location
));
FormatCxxExceptionMessage
(
nullptr
,
location
));
}
return
static_cast
<
Result
>
(
0
);
#else
...
...
@@ -2520,8 +2515,9 @@ void Test::Run() {
internal
::
UnitTestImpl
*
const
impl
=
internal
::
GetUnitTestImpl
();
impl
->
os_stack_trace_getter
()
->
UponLeavingGTest
();
internal
::
HandleExceptionsInMethodIfSupported
(
this
,
&
Test
::
SetUp
,
"SetUp()"
);
// We will run the test only if SetUp() was successful.
if
(
!
HasFatalFailure
())
{
// We will run the test only if SetUp() was successful and didn't call
// GTEST_SKIP().
if
(
!
HasFatalFailure
()
&&
!
IsSkipped
())
{
impl
->
os_stack_trace_getter
()
->
UponLeavingGTest
();
internal
::
HandleExceptionsInMethodIfSupported
(
this
,
&
Test
::
TestBody
,
"the test body"
);
...
...
@@ -2698,9 +2694,10 @@ void TestInfo::Run() {
factory_
,
&
internal
::
TestFactoryBase
::
CreateTest
,
"the test fixture's constructor"
);
// Runs the test if the constructor didn't generate a fatal failure.
// Runs the test if the constructor didn't generate a fatal failure or invoke
// GTEST_SKIP().
// Note that the object will not be null
if
(
!
Test
::
HasFatalFailure
())
{
if
(
!
Test
::
HasFatalFailure
()
&&
!
Test
::
IsSkipped
()
)
{
// This doesn't throw as all user code that can throw are wrapped into
// exception handling code.
test
->
Run
();
...
...
@@ -3114,19 +3111,19 @@ class PrettyUnitTestResultPrinter : public TestEventListener {
}
// The following methods override what's in the TestEventListener class.
virtual
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
);
virtual
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
);
virtual
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestCaseStart
(
const
TestCase
&
test_case
);
virtual
void
OnTestStart
(
const
TestInfo
&
test_info
);
virtual
void
OnTestPartResult
(
const
TestPartResult
&
result
);
virtual
void
OnTestEnd
(
const
TestInfo
&
test_info
);
virtual
void
OnTestCaseEnd
(
const
TestCase
&
test_case
);
virtual
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
);
virtual
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
);
virtual
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
{}
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
override
;
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
;
void
OnTestPartResult
(
const
TestPartResult
&
result
)
override
;
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
;
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
override
;
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{}
private:
static
void
PrintFailedTests
(
const
UnitTest
&
unit_test
);
...
...
@@ -3355,7 +3352,7 @@ void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
class
TestEventRepeater
:
public
TestEventListener
{
public:
TestEventRepeater
()
:
forwarding_enabled_
(
true
)
{}
virtual
~
TestEventRepeater
();
~
TestEventRepeater
()
override
;
void
Append
(
TestEventListener
*
listener
);
TestEventListener
*
Release
(
TestEventListener
*
listener
);
...
...
@@ -3364,19 +3361,19 @@ class TestEventRepeater : public TestEventListener {
bool
forwarding_enabled
()
const
{
return
forwarding_enabled_
;
}
void
set_forwarding_enabled
(
bool
enable
)
{
forwarding_enabled_
=
enable
;
}
virtual
void
OnTestProgramStart
(
const
UnitTest
&
unit_test
);
virtual
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
);
virtual
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
);
virtual
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
unit_test
);
virtual
void
OnTestCaseStart
(
const
TestCase
&
test_case
);
virtual
void
OnTestStart
(
const
TestInfo
&
test_info
);
virtual
void
OnTestPartResult
(
const
TestPartResult
&
result
);
virtual
void
OnTestEnd
(
const
TestInfo
&
test_info
);
virtual
void
OnTestCaseEnd
(
const
TestCase
&
test_case
);
virtual
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
);
virtual
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
unit_test
);
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
);
virtual
void
OnTestProgramEnd
(
const
UnitTest
&
unit_test
);
void
OnTestProgramStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnTestIterationStart
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
unit_test
)
override
;
void
OnTestCaseStart
(
const
TestCase
&
test_case
)
override
;
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
;
void
OnTestPartResult
(
const
TestPartResult
&
result
)
override
;
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
;
void
OnTestCaseEnd
(
const
TestCase
&
test_case
)
override
;
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
unit_test
)
override
;
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
unit_test
)
override
;
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
OnTestProgramEnd
(
const
UnitTest
&
unit_test
)
override
;
private:
// Controls whether events will be forwarded to listeners_. Set to false
...
...
@@ -3469,7 +3466,7 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
public:
explicit
XmlUnitTestResultPrinter
(
const
char
*
output_file
);
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
);
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
void
ListTestsMatchingFilter
(
const
std
::
vector
<
TestCase
*>&
test_cases
);
// Prints an XML summary of all unit tests.
...
...
@@ -3674,8 +3671,7 @@ static bool PortableLocaltime(time_t seconds, struct tm* out) {
// MINGW <time.h> provides neither localtime_r nor localtime_s, but uses
// Windows' localtime(), which has a thread-local tm buffer.
struct
tm
*
tm_ptr
=
localtime
(
&
seconds
);
// NOLINT
if
(
tm_ptr
==
NULL
)
return
false
;
if
(
tm_ptr
==
nullptr
)
return
false
;
*
out
=
*
tm_ptr
;
return
true
;
#else
...
...
@@ -3765,7 +3761,8 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
}
OutputXmlAttribute
(
stream
,
kTestcase
,
"status"
,
test_info
.
should_run
()
?
"run"
:
"notrun"
);
result
.
Skipped
()
?
"skipped"
:
test_info
.
should_run
()
?
"run"
:
"notrun"
);
OutputXmlAttribute
(
stream
,
kTestcase
,
"time"
,
FormatTimeInMillisAsSeconds
(
result
.
elapsed_time
()));
OutputXmlAttribute
(
stream
,
kTestcase
,
"classname"
,
test_case_name
);
...
...
@@ -3928,7 +3925,7 @@ class JsonUnitTestResultPrinter : public EmptyTestEventListener {
public:
explicit
JsonUnitTestResultPrinter
(
const
char
*
output_file
);
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
);
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
iteration
)
override
;
// Prints an JSON summary of all unit tests.
static
void
PrintJsonTestList
(
::
std
::
ostream
*
stream
,
...
...
@@ -4130,6 +4127,7 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
}
OutputJsonKey
(
stream
,
kTestcase
,
"status"
,
result
.
Skipped
()
?
"SKIPPED"
:
test_info
.
should_run
()
?
"RUN"
:
"NOTRUN"
,
kIndent
);
OutputJsonKey
(
stream
,
kTestcase
,
"time"
,
FormatTimeInMillisAsDuration
(
result
.
elapsed_time
()),
kIndent
);
...
...
@@ -4541,24 +4539,17 @@ void TestEventListeners::SuppressEventForwarding() {
// call this before main() starts, from which point on the return
// value will never change.
UnitTest
*
UnitTest
::
GetInstance
()
{
// When compiled with MSVC 7.1 in optimized mode, destroying the
// UnitTest object upon exiting the program messes up the exit code,
// causing successful tests to appear failed. We have to use a
// different implementation in this case to bypass the compiler bug.
// This implementation makes the compiler happy, at the cost of
// leaking the UnitTest object.
// CodeGear C++Builder insists on a public destructor for the
// default implementation. Use this implementation to keep good OO
// design with private destructor.
#if
(_MSC_VER == 1310 && !defined(_DEBUG)) ||
defined(__BORLANDC__)
#if defined(__BORLANDC__)
static
UnitTest
*
const
instance
=
new
UnitTest
;
return
instance
;
#else
static
UnitTest
instance
;
return
&
instance
;
#endif //
(_MSC_VER == 1310 && !defined(_DEBUG)) ||
defined(__BORLANDC__)
#endif // defined(__BORLANDC__)
}
// Gets the number of successful test cases.
...
...
@@ -4730,11 +4721,11 @@ void UnitTest::AddTestPartResult(
// with clang/gcc we can achieve the same effect on x86 by invoking int3
asm
(
"int3"
);
#else
// Dereference
NULL
through a volatile pointer to prevent the compiler
// Dereference
nullptr
through a volatile pointer to prevent the compiler
// from removing. We use this rather than abort() or __builtin_trap() for
// portability: Symbian doesn't implement abort() well, and some debuggers
// don't correctly trap abort().
*
static_cast
<
volatile
int
*>
(
NULL
)
=
1
;
*
static_cast
<
volatile
int
*>
(
nullptr
)
=
1
;
#endif // GTEST_OS_WINDOWS
}
else
if
(
GTEST_FLAG
(
throw_on_failure
))
{
#if GTEST_HAS_EXCEPTIONS
...
...
@@ -4816,18 +4807,12 @@ int UnitTest::Run() {
_set_error_mode
(
_OUT_TO_STDERR
);
# endif
# if
_MSC_VER >= 1400
&& !GTEST_OS_WINDOWS_MOBILE
# if
defined(_MSC_VER)
&& !GTEST_OS_WINDOWS_MOBILE
// In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
// executed. Google Test will notify the user of any unexpected
// failure via stderr.
//
// VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
// Users of prior VC versions shall suffer the agony and pain of
// clicking through the countless debug dialogs.
// FIXME: find a way to suppress the abort dialog() in the
// debug mode when compiled with VC 7.1 or lower.
if
(
!
GTEST_FLAG
(
break_on_failure
))
_set_abort_behavior
(
0x0
,
// Clear the following flags:
...
...
@@ -5807,7 +5792,7 @@ static const char kColorEncodedHelpMessage[] =
" @G--"
GTEST_FLAG_PREFIX_
"output=@Y(@Gjson@Y|@Gxml@Y)[@G:@YDIRECTORY_PATH@G"
GTEST_PATH_SEP_
"@Y|@G:@YFILE_PATH]@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
"
" file name. @YFILE_PATH@D defaults to @Gtest_detail.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
"
...
...
@@ -6026,7 +6011,7 @@ std::string TempDir() {
return
"
\\
temp
\\
"
;
#elif GTEST_OS_WINDOWS
const
char
*
temp_dir
=
internal
::
posix
::
GetEnv
(
"TEMP"
);
if
(
temp_dir
==
NULL
||
temp_dir
[
0
]
==
'\0'
)
if
(
temp_dir
==
nullptr
||
temp_dir
[
0
]
==
'\0'
)
return
"
\\
temp
\\
"
;
else
if
(
temp_dir
[
strlen
(
temp_dir
)
-
1
]
==
'\\'
)
return
temp_dir
;
...
...
googletest/src/gtest_main.cc
View file @
25905b9f
...
...
@@ -30,8 +30,24 @@
#include <stdio.h>
#include "gtest/gtest.h"
#ifdef ARDUINO
void
setup
()
{
// Since Arduino doesn't have a command line, fake out the argc/argv arguments
int
argc
=
1
;
const
auto
arg0
=
"PlatformIO"
;
char
*
argv0
=
const_cast
<
char
*>
(
arg0
);
char
**
argv
=
&
argv0
;
testing
::
InitGoogleTest
(
&
argc
,
argv
);
}
void
loop
()
{
RUN_ALL_TESTS
();
}
#else
GTEST_API_
int
main
(
int
argc
,
char
**
argv
)
{
printf
(
"Running main() from %s
\n
"
,
__FILE__
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
#endif
googletest/test/BUILD.bazel
View file @
25905b9f
...
...
@@ -34,22 +34,7 @@
licenses
([
"notice"
])
config_setting
(
name
=
"windows"
,
values
=
{
"cpu"
:
"x64_windows"
},
)
config_setting
(
name
=
"windows_msvc"
,
values
=
{
"cpu"
:
"x64_windows_msvc"
},
)
config_setting
(
name
=
"has_absl"
,
values
=
{
"define"
:
"absl=1"
},
)
#on windows exclude gtest-tuple.h and googletest-tuple-test.cc
#on windows exclude gtest-tuple.h
cc_test
(
name
=
"gtest_all_test"
,
size
=
"small"
,
...
...
@@ -62,7 +47,6 @@ cc_test(
],
exclude
=
[
"gtest-unittest-api_test.cc"
,
"googletest-tuple-test.cc"
,
"googletest/src/gtest-all.cc"
,
"gtest_all_test.cc"
,
"gtest-death-test_ex_test.cc"
,
...
...
@@ -74,28 +58,23 @@ cc_test(
"googletest-env-var-test_.cc"
,
"googletest-filter-unittest_.cc"
,
"googletest-break-on-failure-unittest_.cc"
,
"googletest-listener-test.cc"
,
"googletest-output-test_.cc"
,
"googletest-list-tests-unittest_.cc"
,
"googletest-shuffle-test_.cc"
,
"googletest-uninitialized-test_.cc"
,
"googletest-death-test_ex_test.cc"
,
"googletest-param-test-test"
,
"googletest-throw-on-failure-test_.cc"
,
"googletest-param-test-invalid-name1-test_.cc"
,
"googletest-param-test-invalid-name2-test_.cc"
,
"googletest-listener-test.cc"
,
"googletest-output-test_.cc"
,
"googletest-list-tests-unittest_.cc"
,
"googletest-shuffle-test_.cc"
,
"googletest-uninitialized-test_.cc"
,
"googletest-death-test_ex_test.cc"
,
"googletest-param-test-test"
,
"googletest-throw-on-failure-test_.cc"
,
"googletest-param-test-invalid-name1-test_.cc"
,
"googletest-param-test-invalid-name2-test_.cc"
,
],
)
+
select
({
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"googletest-tuple-test.cc"
,
],
"//conditions:default"
:
[],
}),
copts
=
select
({
"//:windows"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//:windows_msvc"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=0"
],
"//conditions:default"
:
[
"-DGTEST_USE_OWN_TR1_TUPLE=1"
],
}),
includes
=
[
...
...
@@ -106,15 +85,11 @@ cc_test(
],
linkopts
=
select
({
"//:windows"
:
[],
"//:windows_msvc"
:
[],
"//conditions:default"
:
[
"-pthread"
,
],
"//conditions:default"
:
[
"-pthread"
],
}),
deps
=
[
"//:gtest_main"
],
)
# Tests death tests.
cc_test
(
name
=
"googletest-death-test-test"
,
...
...
@@ -199,13 +174,12 @@ cc_binary(
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"googletest-output-test"
,
size
=
"small"
,
srcs
=
[
"googletest-output-test.py"
],
args
=
select
({
":has_absl"
:
[],
"
//
:has_absl"
:
[],
"//conditions:default"
:
[
"--no_stacktrace_support"
],
}),
data
=
[
...
...
@@ -260,7 +234,6 @@ py_test(
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"googletest-break-on-failure-unittest_"
,
testonly
=
1
,
...
...
@@ -268,8 +241,6 @@ cc_binary(
deps
=
[
"//:gtest"
],
)
py_test
(
name
=
"googletest-break-on-failure-unittest"
,
size
=
"small"
,
...
...
@@ -278,7 +249,6 @@ py_test(
deps
=
[
":gtest_test_utils"
],
)
cc_test
(
name
=
"gtest_assert_by_exception_test"
,
size
=
"small"
,
...
...
@@ -286,8 +256,6 @@ cc_test(
deps
=
[
"//:gtest"
],
)
cc_binary
(
name
=
"googletest-throw-on-failure-test_"
,
testonly
=
1
,
...
...
@@ -303,7 +271,6 @@ py_test(
deps
=
[
":gtest_test_utils"
],
)
cc_binary
(
name
=
"googletest-list-tests-unittest_"
,
testonly
=
1
,
...
...
@@ -311,6 +278,13 @@ cc_binary(
deps
=
[
"//:gtest"
],
)
cc_test
(
name
=
"gtest_skip_test"
,
size
=
"small"
,
srcs
=
[
"gtest_skip_test.cc"
],
deps
=
[
"//:gtest_main"
],
)
py_test
(
name
=
"googletest-list-tests-unittest"
,
size
=
"small"
,
...
...
@@ -381,7 +355,7 @@ py_test(
"gtest_xml_test_utils.py"
,
],
args
=
select
({
":has_absl"
:
[],
"
//
:has_absl"
:
[],
"//conditions:default"
:
[
"--no_stacktrace_support"
],
}),
data
=
[
...
...
@@ -452,7 +426,6 @@ py_test(
deps
=
[
":gtest_test_utils"
],
)
py_test
(
name
=
"googletest-json-outfiles-test"
,
size
=
"small"
,
...
...
@@ -474,18 +447,19 @@ py_test(
"googletest-json-output-unittest.py"
,
"gtest_json_test_utils.py"
,
],
args
=
select
({
"//:has_absl"
:
[],
"//conditions:default"
:
[
"--no_stacktrace_support"
],
}),
data
=
[
# We invoke gtest_no_test_unittest to verify the JSON output
# when the test program contains no test definition.
":gtest_no_test_unittest"
,
":gtest_xml_output_unittest_"
,
],
args
=
select
({
":has_absl"
:
[],
"//conditions:default"
:
[
"--no_stacktrace_support"
],
}),
deps
=
[
":gtest_test_utils"
],
)
# Verifies interaction of death tests and exceptions.
cc_test
(
name
=
"googletest-death-test_ex_catch_test"
,
...
...
googletest/test/googletest-catch-exceptions-test_.cc
View file @
25905b9f
...
...
@@ -116,17 +116,17 @@ class CxxExceptionInConstructorTest : public Test {
}
protected:
~
CxxExceptionInConstructorTest
()
{
~
CxxExceptionInConstructorTest
()
override
{
ADD_FAILURE
()
<<
"CxxExceptionInConstructorTest destructor "
<<
"called unexpectedly."
;
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
ADD_FAILURE
()
<<
"CxxExceptionInConstructorTest::SetUp() "
<<
"called unexpectedly."
;
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
ADD_FAILURE
()
<<
"CxxExceptionInConstructorTest::TearDown() "
<<
"called unexpectedly."
;
}
...
...
@@ -157,19 +157,19 @@ class CxxExceptionInSetUpTestCaseTest : public Test {
}
protected:
~
CxxExceptionInSetUpTestCaseTest
()
{
~
CxxExceptionInSetUpTestCaseTest
()
override
{
printf
(
"%s"
,
"CxxExceptionInSetUpTestCaseTest destructor "
"called as expected.
\n
"
);
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
printf
(
"%s"
,
"CxxExceptionInSetUpTestCaseTest::SetUp() "
"called as expected.
\n
"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
printf
(
"%s"
,
"CxxExceptionInSetUpTestCaseTest::TearDown() "
"called as expected.
\n
"
);
...
...
@@ -200,15 +200,15 @@ class CxxExceptionInSetUpTest : public Test {
}
protected:
~
CxxExceptionInSetUpTest
()
{
~
CxxExceptionInSetUpTest
()
override
{
printf
(
"%s"
,
"CxxExceptionInSetUpTest destructor "
"called as expected.
\n
"
);
}
virtual
void
SetUp
()
{
throw
std
::
runtime_error
(
"Standard C++ exception"
);
}
void
SetUp
()
override
{
throw
std
::
runtime_error
(
"Standard C++ exception"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
printf
(
"%s"
,
"CxxExceptionInSetUpTest::TearDown() "
"called as expected.
\n
"
);
...
...
@@ -229,13 +229,13 @@ class CxxExceptionInTearDownTest : public Test {
}
protected:
~
CxxExceptionInTearDownTest
()
{
~
CxxExceptionInTearDownTest
()
override
{
printf
(
"%s"
,
"CxxExceptionInTearDownTest destructor "
"called as expected.
\n
"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
throw
std
::
runtime_error
(
"Standard C++ exception"
);
}
};
...
...
@@ -251,13 +251,13 @@ class CxxExceptionInTestBodyTest : public Test {
}
protected:
~
CxxExceptionInTestBodyTest
()
{
~
CxxExceptionInTestBodyTest
()
override
{
printf
(
"%s"
,
"CxxExceptionInTestBodyTest destructor "
"called as expected.
\n
"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
printf
(
"%s"
,
"CxxExceptionInTestBodyTest::TearDown() "
"called as expected.
\n
"
);
...
...
googletest/test/googletest-death-test-test.cc
View file @
25905b9f
...
...
@@ -31,6 +31,7 @@
// Tests for death tests.
#include "gtest/gtest-death-test.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-filepath.h"
...
...
@@ -59,6 +60,8 @@ using testing::internal::AlwaysTrue;
namespace
posix
=
::
testing
::
internal
::
posix
;
using
testing
::
ContainsRegex
;
using
testing
::
Matcher
;
using
testing
::
Message
;
using
testing
::
internal
::
DeathTest
;
using
testing
::
internal
::
DeathTestFactory
;
...
...
@@ -97,6 +100,8 @@ class ReplaceDeathTestFactory {
}
// namespace internal
}
// namespace testing
namespace
{
void
DieWithMessage
(
const
::
std
::
string
&
message
)
{
fprintf
(
stderr
,
"%s"
,
message
.
c_str
());
fflush
(
stderr
);
// Make sure the text is printed before the process exits.
...
...
@@ -123,9 +128,7 @@ class TestForDeathTest : public testing::Test {
protected:
TestForDeathTest
()
:
original_dir_
(
FilePath
::
GetCurrentDir
())
{}
virtual
~
TestForDeathTest
()
{
posix
::
ChDir
(
original_dir_
.
c_str
());
}
~
TestForDeathTest
()
override
{
posix
::
ChDir
(
original_dir_
.
c_str
());
}
// A static member function that's expected to die.
static
void
StaticMemberFunction
()
{
DieInside
(
"StaticMemberFunction"
);
}
...
...
@@ -297,14 +300,14 @@ TEST_F(TestForDeathTest, SingleStatement) {
EXPECT_DEATH
(
_exit
(
1
),
""
)
<<
1
<<
2
<<
3
;
}
# if GTEST_USES_PCRE
void
DieWithEmbeddedNul
()
{
fprintf
(
stderr
,
"Hello%cmy null world.
\n
"
,
'\0'
);
fflush
(
stderr
);
_exit
(
1
);
}
# 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
)
{
...
...
@@ -452,16 +455,12 @@ TEST_F(TestForDeathTest, MixedStyles) {
# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
namespace
{
bool
pthread_flag
;
void
SetPthreadFlag
()
{
pthread_flag
=
true
;
}
}
// namespace
TEST_F
(
TestForDeathTest
,
DoesNotExecuteAtforkHooks
)
{
if
(
!
testing
::
GTEST_FLAG
(
death_test_use_fork
))
{
testing
::
GTEST_FLAG
(
death_test_style
)
=
"threadsafe"
;
...
...
@@ -499,6 +498,10 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
const
::
string
regex_str
(
regex_c_str
);
EXPECT_DEATH
(
GlobalFunction
(),
regex_str
);
// This one is tricky; a temporary pointer into another temporary. Reference
// lifetime extension of the pointer is not sufficient.
EXPECT_DEATH
(
GlobalFunction
(),
::
string
(
regex_c_str
).
c_str
());
# endif // GTEST_HAS_GLOBAL_STRING
# if !GTEST_USES_PCRE
...
...
@@ -506,6 +509,10 @@ TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
const
::
std
::
string
regex_std_str
(
regex_c_str
);
EXPECT_DEATH
(
GlobalFunction
(),
regex_std_str
);
// This one is tricky; a temporary pointer into another temporary. Reference
// lifetime extension of the pointer is not sufficient.
EXPECT_DEATH
(
GlobalFunction
(),
::
std
::
string
(
regex_c_str
).
c_str
());
# endif // !GTEST_USES_PCRE
}
...
...
@@ -876,9 +883,9 @@ TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
class
MockDeathTestFactory
:
public
DeathTestFactory
{
public:
MockDeathTestFactory
();
virtual
bool
Create
(
const
char
*
statement
,
const
::
te
sting
::
internal
::
RE
*
regex
,
const
char
*
file
,
int
line
,
DeathTest
**
test
);
bool
Create
(
const
char
*
statement
,
testing
::
Matcher
<
const
std
::
st
r
ing
&>
matcher
,
const
char
*
file
,
int
line
,
DeathTest
**
test
)
override
;
// Sets the parameters for subsequent calls to Create.
void
SetParameters
(
bool
create
,
DeathTest
::
TestRole
role
,
...
...
@@ -933,22 +940,20 @@ class MockDeathTest : public DeathTest {
TestRole
role
,
int
status
,
bool
passed
)
:
parent_
(
parent
),
role_
(
role
),
status_
(
status
),
passed_
(
passed
)
{
}
virtual
~
MockDeathTest
()
{
parent_
->
test_deleted_
=
true
;
}
virtual
TestRole
AssumeRole
()
{
~
MockDeathTest
()
override
{
parent_
->
test_deleted_
=
true
;
}
TestRole
AssumeRole
()
override
{
++
parent_
->
assume_role_calls_
;
return
role_
;
}
virtual
int
Wait
()
{
int
Wait
()
override
{
++
parent_
->
wait_calls_
;
return
status_
;
}
virtual
bool
Passed
(
bool
exit_status_ok
)
{
bool
Passed
(
bool
exit_status_ok
)
override
{
parent_
->
passed_args_
.
push_back
(
exit_status_ok
);
return
passed_
;
}
virtual
void
Abort
(
AbortReason
reason
)
{
void
Abort
(
AbortReason
reason
)
override
{
parent_
->
abort_args_
.
push_back
(
reason
);
}
...
...
@@ -992,11 +997,9 @@ void MockDeathTestFactory::SetParameters(bool create,
// Sets test to NULL (if create_ is false) or to the address of a new
// MockDeathTest object with parameters taken from the last call
// to SetParameters (if create_ is true). Always returns true.
bool
MockDeathTestFactory
::
Create
(
const
char
*
/*statement*/
,
const
::
testing
::
internal
::
RE
*
/*regex*/
,
const
char
*
/*file*/
,
int
/*line*/
,
DeathTest
**
test
)
{
bool
MockDeathTestFactory
::
Create
(
const
char
*
/*statement*/
,
testing
::
Matcher
<
const
std
::
string
&>
/*matcher*/
,
const
char
*
/*file*/
,
int
/*line*/
,
DeathTest
**
test
)
{
test_deleted_
=
false
;
if
(
create_
)
{
*
test
=
new
MockDeathTest
(
this
,
role_
,
status_
,
passed_
);
...
...
@@ -1318,8 +1321,49 @@ TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
},
"Inside"
);
}
void
DieWithMessage
(
const
char
*
message
)
{
fputs
(
message
,
stderr
);
fflush
(
stderr
);
// Make sure the text is printed before the process exits.
_exit
(
1
);
}
TEST
(
MatcherDeathTest
,
DoesNotBreakBareRegexMatching
)
{
// googletest tests this, of course; here we ensure that including googlemock
// has not broken it.
EXPECT_DEATH
(
DieWithMessage
(
"O, I die, Horatio."
),
"I d[aeiou]e"
);
}
TEST
(
MatcherDeathTest
,
MonomorphicMatcherMatches
)
{
EXPECT_DEATH
(
DieWithMessage
(
"Behind O, I am slain!"
),
Matcher
<
const
std
::
string
&>
(
ContainsRegex
(
"I am slain"
)));
}
TEST
(
MatcherDeathTest
,
MonomorphicMatcherDoesNotMatch
)
{
EXPECT_NONFATAL_FAILURE
(
EXPECT_DEATH
(
DieWithMessage
(
"Behind O, I am slain!"
),
Matcher
<
const
std
::
string
&>
(
ContainsRegex
(
"Ow, I am slain"
))),
"Expected: contains regular expression
\"
Ow, I am slain
\"
"
);
}
TEST
(
MatcherDeathTest
,
PolymorphicMatcherMatches
)
{
EXPECT_DEATH
(
DieWithMessage
(
"The rest is silence."
),
ContainsRegex
(
"rest is silence"
));
}
TEST
(
MatcherDeathTest
,
PolymorphicMatcherDoesNotMatch
)
{
EXPECT_NONFATAL_FAILURE
(
EXPECT_DEATH
(
DieWithMessage
(
"The rest is silence."
),
ContainsRegex
(
"rest is science"
)),
"Expected: contains regular expression
\"
rest is science
\"
"
);
}
}
// namespace
#else // !GTEST_HAS_DEATH_TEST follows
namespace
{
using
testing
::
internal
::
CaptureStderr
;
using
testing
::
internal
::
GetCapturedStderr
;
...
...
@@ -1368,8 +1412,12 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
EXPECT_EQ
(
1
,
n
);
}
}
// namespace
#endif // !GTEST_HAS_DEATH_TEST
namespace
{
// Tests that the death test macros expand to code which may or may not
// be followed by operator<<, and that in either case the complete text
// comprises only a single C++ statement.
...
...
@@ -1420,3 +1468,5 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
TEST
(
NotADeathTest
,
Test
)
{
SUCCEED
();
}
}
// namespace
googletest/test/googletest-death-test_ex_test.cc
View file @
25905b9f
...
...
@@ -59,7 +59,7 @@ TEST(CxxExceptionDeathTest, ExceptionIsFailure) {
class
TestException
:
public
std
::
exception
{
public:
virtual
const
char
*
what
()
const
throw
()
{
return
"exceptional message"
;
}
const
char
*
what
()
const
throw
()
override
{
return
"exceptional message"
;
}
};
TEST
(
CxxExceptionDeathTest
,
PrintsMessageForStdExceptions
)
{
...
...
googletest/test/googletest-env-var-test.py
View file @
25905b9f
...
...
@@ -45,8 +45,8 @@ environ = os.environ.copy()
def
AssertEq
(
expected
,
actual
):
if
expected
!=
actual
:
print
'Expected: %s'
%
(
expected
,)
print
' Actual: %s'
%
(
actual
,)
print
(
'Expected: %s'
%
(
expected
,)
)
print
(
' Actual: %s'
%
(
actual
,)
)
raise
AssertionError
...
...
googletest/test/googletest-filepath-test.cc
View file @
25905b9f
...
...
@@ -80,7 +80,7 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
const
FilePath
cwd
=
FilePath
::
GetCurrentDir
();
posix
::
ChDir
(
original_dir
.
c_str
());
# if GTEST_OS_WINDOWS
# if GTEST_OS_WINDOWS
|| GTEST_OS_OS2
// Skips the ":".
const
char
*
const
cwd_without_drive
=
strchr
(
cwd
.
c_str
(),
':'
);
...
...
@@ -479,7 +479,7 @@ TEST(AssignmentOperatorTest, ConstAssignedToNonConst) {
class
DirectoryCreationTest
:
public
Test
{
protected:
virtual
void
SetUp
()
{
void
SetUp
()
override
{
testdata_path_
.
Set
(
FilePath
(
TempDir
()
+
GetCurrentExecutableName
().
string
()
+
"_directory_creation"
GTEST_PATH_SEP_
"test"
GTEST_PATH_SEP_
));
...
...
@@ -496,7 +496,7 @@ class DirectoryCreationTest : public Test {
posix
::
RmDir
(
testdata_path_
.
c_str
());
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
remove
(
testdata_file_
.
c_str
());
remove
(
unique_file0_
.
c_str
());
remove
(
unique_file1_
.
c_str
());
...
...
googletest/test/googletest-filter-unittest.py
View file @
25905b9f
...
...
@@ -42,7 +42,10 @@ we test that here also.
import
os
import
re
import
sets
try
:
from
sets
import
Set
as
set
# For Python 2.3 compatibility
except
ImportError
:
pass
import
sys
import
gtest_test_utils
...
...
@@ -57,7 +60,7 @@ CAN_PASS_EMPTY_ENV = False
if
sys
.
executable
:
os
.
environ
[
'EMPTY_VAR'
]
=
''
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
EMPTY_VAR
\'
in os.environ'
])
[
sys
.
executable
,
'-c'
,
'import os; print
(
\'
EMPTY_VAR
\'
in os.environ
)
'
])
CAN_PASS_EMPTY_ENV
=
eval
(
child
.
output
)
...
...
@@ -72,7 +75,7 @@ if sys.executable:
os
.
environ
[
'UNSET_VAR'
]
=
'X'
del
os
.
environ
[
'UNSET_VAR'
]
child
=
gtest_test_utils
.
Subprocess
(
[
sys
.
executable
,
'-c'
,
'import os; print
\'
UNSET_VAR
\'
not in os.environ'
[
sys
.
executable
,
'-c'
,
'import os; print
(
\'
UNSET_VAR
\'
not in os.environ
)
'
])
CAN_UNSET_ENV
=
eval
(
child
.
output
)
...
...
@@ -245,14 +248,14 @@ class GTestFilterUnitTest(gtest_test_utils.TestCase):
for
slice_var
in
list_of_sets
:
full_partition
.
extend
(
slice_var
)
self
.
assertEqual
(
len
(
set_var
),
len
(
full_partition
))
self
.
assertEqual
(
set
s
.
Set
(
set_var
),
set
s
.
Set
(
full_partition
))
self
.
assertEqual
(
set
(
set_var
),
set
(
full_partition
))
def
AdjustForParameterizedTests
(
self
,
tests_to_run
):
"""Adjust tests_to_run in case value parameterized tests are disabled."""
global
param_tests_present
if
not
param_tests_present
:
return
list
(
set
s
.
Set
(
tests_to_run
)
-
set
s
.
Set
(
PARAM_TESTS
))
return
list
(
set
(
tests_to_run
)
-
set
(
PARAM_TESTS
))
else
:
return
tests_to_run
...
...
googletest/test/googletest-json-output-unittest.py
View file @
25905b9f
...
...
@@ -57,7 +57,7 @@ else:
STACK_TRACE_TEMPLATE
=
''
EXPECTED_NON_EMPTY
=
{
u
'tests'
:
2
3
,
u
'tests'
:
2
4
,
u
'failures'
:
4
,
u
'disabled'
:
2
,
u
'errors'
:
0
,
...
...
@@ -123,6 +123,22 @@ EXPECTED_NON_EMPTY = {
}
]
},
{
u
'name'
:
u
'SkippedTest'
,
u
'tests'
:
1
,
u
'failures'
:
0
,
u
'disabled'
:
0
,
u
'errors'
:
0
,
u
'time'
:
u
'*'
,
u
'testsuite'
:
[
{
u
'name'
:
u
'Skipped'
,
u
'status'
:
u
'SKIPPED'
,
u
'time'
:
u
'*'
,
u
'classname'
:
u
'SkippedTest'
}
]
},
{
u
'name'
:
u
'MixedResultTest'
,
u
'tests'
:
3
,
...
...
googletest/test/googletest-linked-ptr-test.cc
deleted
100644 → 0
View file @
4665eee1
// Copyright 2003, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// 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 <stdlib.h>
#include "gtest/internal/gtest-linked_ptr.h"
#include "gtest/gtest.h"
namespace
{
using
testing
::
Message
;
using
testing
::
internal
::
linked_ptr
;
int
num
;
Message
*
history
=
nullptr
;
// Class which tracks allocation/deallocation
class
A
{
public:
A
()
:
mynum
(
num
++
)
{
*
history
<<
"A"
<<
mynum
<<
" ctor
\n
"
;
}
virtual
~
A
()
{
*
history
<<
"A"
<<
mynum
<<
" dtor
\n
"
;
}
virtual
void
Use
()
{
*
history
<<
"A"
<<
mynum
<<
" use
\n
"
;
}
protected:
int
mynum
;
};
// Subclass
class
B
:
public
A
{
public:
B
()
{
*
history
<<
"B"
<<
mynum
<<
" ctor
\n
"
;
}
~
B
()
{
*
history
<<
"B"
<<
mynum
<<
" dtor
\n
"
;
}
virtual
void
Use
()
{
*
history
<<
"B"
<<
mynum
<<
" use
\n
"
;
}
};
class
LinkedPtrTest
:
public
testing
::
Test
{
public:
LinkedPtrTest
()
{
num
=
0
;
history
=
new
Message
;
}
virtual
~
LinkedPtrTest
()
{
delete
history
;
history
=
nullptr
;
}
};
TEST_F
(
LinkedPtrTest
,
GeneralTest
)
{
{
linked_ptr
<
A
>
a0
,
a1
,
a2
;
// Use explicit function call notation here to suppress self-assign warning.
a0
.
operator
=
(
a0
);
a1
=
a2
;
ASSERT_EQ
(
a0
.
get
(),
static_cast
<
A
*>
(
nullptr
));
ASSERT_EQ
(
a1
.
get
(),
static_cast
<
A
*>
(
nullptr
));
ASSERT_EQ
(
a2
.
get
(),
static_cast
<
A
*>
(
nullptr
));
ASSERT_TRUE
(
a0
==
nullptr
);
ASSERT_TRUE
(
a1
==
nullptr
);
ASSERT_TRUE
(
a2
==
nullptr
);
{
linked_ptr
<
A
>
a3
(
new
A
);
a0
=
a3
;
ASSERT_TRUE
(
a0
==
a3
);
ASSERT_TRUE
(
a0
!=
nullptr
);
ASSERT_TRUE
(
a0
.
get
()
==
a3
);
ASSERT_TRUE
(
a0
==
a3
.
get
());
linked_ptr
<
A
>
a4
(
a0
);
a1
=
a4
;
linked_ptr
<
A
>
a5
(
new
A
);
ASSERT_TRUE
(
a5
.
get
()
!=
a3
);
ASSERT_TRUE
(
a5
!=
a3
.
get
());
a2
=
a5
;
linked_ptr
<
B
>
b0
(
new
B
);
linked_ptr
<
A
>
a6
(
b0
);
ASSERT_TRUE
(
b0
==
a6
);
ASSERT_TRUE
(
a6
==
b0
);
ASSERT_TRUE
(
b0
!=
nullptr
);
a5
=
b0
;
a5
=
b0
;
a3
->
Use
();
a4
->
Use
();
a5
->
Use
();
a6
->
Use
();
b0
->
Use
();
(
*
b0
).
Use
();
b0
.
get
()
->
Use
();
}
a0
->
Use
();
a1
->
Use
();
a2
->
Use
();
a1
=
a2
;
a2
.
reset
(
new
A
);
a0
.
reset
();
linked_ptr
<
A
>
a7
;
}
ASSERT_STREQ
(
"A0 ctor
\n
"
"A1 ctor
\n
"
"A2 ctor
\n
"
"B2 ctor
\n
"
"A0 use
\n
"
"A0 use
\n
"
"B2 use
\n
"
"B2 use
\n
"
"B2 use
\n
"
"B2 use
\n
"
"B2 use
\n
"
"B2 dtor
\n
"
"A2 dtor
\n
"
"A0 use
\n
"
"A0 use
\n
"
"A1 use
\n
"
"A3 ctor
\n
"
"A0 dtor
\n
"
"A3 dtor
\n
"
"A1 dtor
\n
"
,
history
->
GetString
().
c_str
());
}
}
// Unnamed namespace
googletest/test/googletest-listener-test.cc
View file @
25905b9f
...
...
@@ -57,63 +57,63 @@ class EventRecordingListener : public TestEventListener {
explicit
EventRecordingListener
(
const
char
*
name
)
:
name_
(
name
)
{}
protected:
virtual
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnTestProgramStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestProgramStart"
));
}
virtual
void
OnTestIterationStart
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
{
void
OnTestIterationStart
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
override
{
Message
message
;
message
<<
GetFullMethodName
(
"OnTestIterationStart"
)
<<
"("
<<
iteration
<<
")"
;
g_events
->
push_back
(
message
.
GetString
());
}
virtual
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnEnvironmentsSetUpStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsSetUpStart"
));
}
virtual
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnEnvironmentsSetUpEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsSetUpEnd"
));
}
virtual
void
OnTestCaseStart
(
const
TestCase
&
/*test_case*/
)
{
void
OnTestCaseStart
(
const
TestCase
&
/*test_case*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestCaseStart"
));
}
virtual
void
OnTestStart
(
const
TestInfo
&
/*test_info*/
)
{
void
OnTestStart
(
const
TestInfo
&
/*test_info*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestStart"
));
}
virtual
void
OnTestPartResult
(
const
TestPartResult
&
/*test_part_result*/
)
{
void
OnTestPartResult
(
const
TestPartResult
&
/*test_part_result*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestPartResult"
));
}
virtual
void
OnTestEnd
(
const
TestInfo
&
/*test_info*/
)
{
void
OnTestEnd
(
const
TestInfo
&
/*test_info*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestEnd"
));
}
virtual
void
OnTestCaseEnd
(
const
TestCase
&
/*test_case*/
)
{
void
OnTestCaseEnd
(
const
TestCase
&
/*test_case*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestCaseEnd"
));
}
virtual
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnEnvironmentsTearDownStart
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsTearDownStart"
));
}
virtual
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnEnvironmentsTearDownEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnEnvironmentsTearDownEnd"
));
}
virtual
void
OnTestIterationEnd
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
{
void
OnTestIterationEnd
(
const
UnitTest
&
/*unit_test*/
,
int
iteration
)
override
{
Message
message
;
message
<<
GetFullMethodName
(
"OnTestIterationEnd"
)
<<
"("
<<
iteration
<<
")"
;
g_events
->
push_back
(
message
.
GetString
());
}
virtual
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
{
void
OnTestProgramEnd
(
const
UnitTest
&
/*unit_test*/
)
override
{
g_events
->
push_back
(
GetFullMethodName
(
"OnTestProgramEnd"
));
}
...
...
@@ -127,13 +127,9 @@ class EventRecordingListener : public TestEventListener {
class
EnvironmentInvocationCatcher
:
public
Environment
{
protected:
virtual
void
SetUp
()
{
g_events
->
push_back
(
"Environment::SetUp"
);
}
void
SetUp
()
override
{
g_events
->
push_back
(
"Environment::SetUp"
);
}
virtual
void
TearDown
()
{
g_events
->
push_back
(
"Environment::TearDown"
);
}
void
TearDown
()
override
{
g_events
->
push_back
(
"Environment::TearDown"
);
}
};
class
ListenerTest
:
public
Test
{
...
...
@@ -146,13 +142,9 @@ class ListenerTest : public Test {
g_events
->
push_back
(
"ListenerTest::TearDownTestCase"
);
}
virtual
void
SetUp
()
{
g_events
->
push_back
(
"ListenerTest::SetUp"
);
}
void
SetUp
()
override
{
g_events
->
push_back
(
"ListenerTest::SetUp"
);
}
virtual
void
TearDown
()
{
g_events
->
push_back
(
"ListenerTest::TearDown"
);
}
void
TearDown
()
override
{
g_events
->
push_back
(
"ListenerTest::TearDown"
);
}
};
TEST_F
(
ListenerTest
,
DoesFoo
)
{
...
...
googletest/test/googletest-options-test.cc
View file @
25905b9f
...
...
@@ -102,6 +102,12 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
_strcmpi
(
"gtest-options-ex_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_all_test"
,
exe_str
.
c_str
())
==
0
||
_strcmpi
(
"gtest_dll_test"
,
exe_str
.
c_str
())
==
0
;
#elif GTEST_OS_OS2
const
bool
success
=
strcasecmp
(
"googletest-options-test"
,
exe_str
.
c_str
())
==
0
||
strcasecmp
(
"gtest-options-ex_test"
,
exe_str
.
c_str
())
==
0
||
strcasecmp
(
"gtest_all_test"
,
exe_str
.
c_str
())
==
0
||
strcasecmp
(
"gtest_dll_test"
,
exe_str
.
c_str
())
==
0
;
#elif GTEST_OS_FUCHSIA
const
bool
success
=
exe_str
==
"app"
;
#else
...
...
@@ -120,7 +126,7 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
class
XmlOutputChangeDirTest
:
public
Test
{
protected:
virtual
void
SetUp
()
{
void
SetUp
()
override
{
original_working_dir_
=
FilePath
::
GetCurrentDir
();
posix
::
ChDir
(
".."
);
// This will make the test fail if run from the root directory.
...
...
@@ -128,7 +134,7 @@ class XmlOutputChangeDirTest : public Test {
FilePath
::
GetCurrentDir
().
string
());
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
posix
::
ChDir
(
original_working_dir_
.
string
().
c_str
());
}
...
...
googletest/test/googletest-output-test-golden-lin.txt
View file @
25905b9f
...
...
@@ -12,7 +12,7 @@ Expected equality of these values:
3
Stack trace: (omitted)
[0;32m[==========] [mRunning
76
tests from 3
4
test cases.
[0;32m[==========] [mRunning
83
tests from 3
8
test cases.
[0;32m[----------] [mGlobal test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
...
...
@@ -870,6 +870,84 @@ Expected non-fatal failure.
Stack trace: (omitted)
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[0;32m[----------] [m2 tests from DynamicFixture
DynamicFixture::SetUpTestCase
[0;32m[ RUN ] [mDynamicFixture.DynamicTestPass
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[0;32m[ OK ] [mDynamicFixture.DynamicTestPass
[0;32m[ RUN ] [mDynamicFixture.DynamicTestFail
DynamicFixture()
DynamicFixture::SetUp
googletest-output-test_.cc:#: Failure
Value of: Pass
Actual: false
Expected: true
Stack trace: (omitted)
DynamicFixture::TearDown
~DynamicFixture()
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
DynamicFixture::TearDownTestCase
[0;32m[----------] [m1 test from DynamicFixtureAnotherName
DynamicFixture::SetUpTestCase
[0;32m[ RUN ] [mDynamicFixtureAnotherName.DynamicTestPass
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[0;32m[ OK ] [mDynamicFixtureAnotherName.DynamicTestPass
DynamicFixture::TearDownTestCase
[0;32m[----------] [m2 tests from BadDynamicFixture1
DynamicFixture::SetUpTestCase
[0;32m[ RUN ] [mBadDynamicFixture1.FixtureBase
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[0;32m[ OK ] [mBadDynamicFixture1.FixtureBase
[0;32m[ RUN ] [mBadDynamicFixture1.TestBase
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test case must use the same test fixture
class, so mixing TEST_F and TEST in the same test case is
illegal. In test case BadDynamicFixture1,
test FixtureBase is defined using TEST_F but
test TestBase is defined using TEST. You probably
want to change the TEST to TEST_F or move it to another test
case.
Stack trace: (omitted)
~DynamicFixture()
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
DynamicFixture::TearDownTestCase
[0;32m[----------] [m2 tests from BadDynamicFixture2
DynamicFixture::SetUpTestCase
[0;32m[ RUN ] [mBadDynamicFixture2.FixtureBase
DynamicFixture()
DynamicFixture::SetUp
DynamicFixture::TearDown
~DynamicFixture()
[0;32m[ OK ] [mBadDynamicFixture2.FixtureBase
[0;32m[ RUN ] [mBadDynamicFixture2.Derived
DynamicFixture()
gtest.cc:#: Failure
Failed
All tests in the same test case must use the same test fixture
class. However, in test case BadDynamicFixture2,
you defined test FixtureBase and test Derived
using two different test fixture classes. This can happen if
the two classes are from different namespaces or translation
units and have the same name. You should probably rename one
of the classes to put the tests into different test cases.
Stack trace: (omitted)
~DynamicFixture()
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
DynamicFixture::TearDownTestCase
[0;32m[----------] [m1 test from PrintingFailingParams/FailingParamTest
[0;32m[ RUN ] [mPrintingFailingParams/FailingParamTest.Fails/0
googletest-output-test_.cc:#: Failure
...
...
@@ -906,9 +984,9 @@ Failed
Expected fatal failure.
Stack trace: (omitted)
[0;32m[==========] [m
76
tests from 3
4
test cases ran.
[0;32m[ PASSED ] [m
26
tests.
[0;31m[ FAILED ] [m5
0
tests, listed below:
[0;32m[==========] [m
83
tests from 3
8
test cases ran.
[0;32m[ PASSED ] [m
30
tests.
[0;31m[ FAILED ] [m5
3
tests, listed below:
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
...
...
@@ -957,10 +1035,13 @@ Stack trace: (omitted)
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectFatalFailure
[0;31m[ FAILED ] [mExpectFailureWithThreadsTest.ExpectNonFatalFailure
[0;31m[ FAILED ] [mScopedFakeTestPartResultReporterTest.InterceptOnlyCurrentThread
[0;31m[ FAILED ] [mDynamicFixture.DynamicTestFail
[0;31m[ FAILED ] [mBadDynamicFixture1.TestBase
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
5
0
FAILED TESTS
5
3
FAILED TESTS
[0;33m YOU HAVE 1 DISABLED TEST
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
...
...
googletest/test/googletest-output-test.py
View file @
25905b9f
...
...
@@ -287,7 +287,7 @@ class GTestOutputTest(gtest_test_utils.TestCase):
# sequences when we read the golden file irrespective of an operating
# system used. Therefore, we need to strip those \r's from newlines
# unconditionally.
golden
=
ToUnixLineEnding
(
golden_file
.
read
())
golden
=
ToUnixLineEnding
(
golden_file
.
read
()
.
decode
()
)
golden_file
.
close
()
# We want the test to pass regardless of certain features being
...
...
googletest/test/googletest-output-test_.cc
View file @
25905b9f
...
...
@@ -364,15 +364,13 @@ class NonFatalFailureInFixtureConstructorTest : public testing::Test {
ADD_FAILURE
()
<<
"Expected failure #1, in the test fixture c'tor."
;
}
~
NonFatalFailureInFixtureConstructorTest
()
{
~
NonFatalFailureInFixtureConstructorTest
()
override
{
ADD_FAILURE
()
<<
"Expected failure #5, in the test fixture d'tor."
;
}
virtual
void
SetUp
()
{
ADD_FAILURE
()
<<
"Expected failure #2, in SetUp()."
;
}
void
SetUp
()
override
{
ADD_FAILURE
()
<<
"Expected failure #2, in SetUp()."
;
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
ADD_FAILURE
()
<<
"Expected failure #4, in TearDown."
;
}
};
...
...
@@ -389,17 +387,17 @@ class FatalFailureInFixtureConstructorTest : public testing::Test {
Init
();
}
~
FatalFailureInFixtureConstructorTest
()
{
~
FatalFailureInFixtureConstructorTest
()
override
{
ADD_FAILURE
()
<<
"Expected failure #2, in the test fixture d'tor."
;
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
ADD_FAILURE
()
<<
"UNEXPECTED failure in SetUp(). "
<<
"We should never get here, as the test fixture c'tor "
<<
"had a fatal failure."
;
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
ADD_FAILURE
()
<<
"UNEXPECTED failure in TearDown(). "
<<
"We should never get here, as the test fixture c'tor "
<<
"had a fatal failure."
;
...
...
@@ -420,18 +418,15 @@ TEST_F(FatalFailureInFixtureConstructorTest, FailureInConstructor) {
// Tests non-fatal failures in SetUp().
class
NonFatalFailureInSetUpTest
:
public
testing
::
Test
{
protected:
virtual
~
NonFatalFailureInSetUpTest
()
{
Deinit
();
}
~
NonFatalFailureInSetUpTest
()
override
{
Deinit
();
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
printf
(
"(expecting 4 failures)
\n
"
);
ADD_FAILURE
()
<<
"Expected failure #1, in SetUp()."
;
}
virtual
void
TearDown
()
{
FAIL
()
<<
"Expected failure #3, in TearDown()."
;
}
void
TearDown
()
override
{
FAIL
()
<<
"Expected failure #3, in TearDown()."
;
}
private:
void
Deinit
()
{
FAIL
()
<<
"Expected failure #4, in the test fixture d'tor."
;
...
...
@@ -445,18 +440,15 @@ TEST_F(NonFatalFailureInSetUpTest, FailureInSetUp) {
// Tests fatal failures in SetUp().
class
FatalFailureInSetUpTest
:
public
testing
::
Test
{
protected:
virtual
~
FatalFailureInSetUpTest
()
{
Deinit
();
}
~
FatalFailureInSetUpTest
()
override
{
Deinit
();
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
printf
(
"(expecting 3 failures)
\n
"
);
FAIL
()
<<
"Expected failure #1, in SetUp()."
;
}
virtual
void
TearDown
()
{
FAIL
()
<<
"Expected failure #2, in TearDown()."
;
}
void
TearDown
()
override
{
FAIL
()
<<
"Expected failure #2, in TearDown()."
;
}
private:
void
Deinit
()
{
FAIL
()
<<
"Expected failure #3, in the test fixture d'tor."
;
...
...
@@ -508,7 +500,7 @@ static void ThreadRoutine(SpawnThreadNotifications* notifications) {
class
DeathTestAndMultiThreadsTest
:
public
testing
::
Test
{
protected:
// Starts a thread and waits for it to begin.
virtual
void
SetUp
()
{
void
SetUp
()
override
{
thread_
.
reset
(
new
ThreadWithParam
<
SpawnThreadNotifications
*>
(
&
ThreadRoutine
,
&
notifications_
,
nullptr
));
notifications_
.
spawn_thread_started
.
WaitForNotification
();
...
...
@@ -518,14 +510,13 @@ class DeathTestAndMultiThreadsTest : public testing::Test {
// a manager thread might still be left running that will interfere
// with later death tests. This is unfortunate, but this class
// cleans up after itself as best it can.
virtual
void
TearDown
()
{
void
TearDown
()
override
{
notifications_
.
spawn_thread_ok_to_terminate
.
Notify
();
}
private:
SpawnThreadNotifications
notifications_
;
testing
::
internal
::
scoped_ptr
<
ThreadWithParam
<
SpawnThreadNotifications
*>
>
thread_
;
std
::
unique_ptr
<
ThreadWithParam
<
SpawnThreadNotifications
*>
>
thread_
;
};
#endif // GTEST_IS_THREADSAFE
...
...
@@ -1033,16 +1024,64 @@ TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
"Some other non-fatal failure."
);
}
class
DynamicFixture
:
public
testing
::
Test
{
protected:
DynamicFixture
()
{
printf
(
"DynamicFixture()
\n
"
);
}
~
DynamicFixture
()
override
{
printf
(
"~DynamicFixture()
\n
"
);
}
void
SetUp
()
override
{
printf
(
"DynamicFixture::SetUp
\n
"
);
}
void
TearDown
()
override
{
printf
(
"DynamicFixture::TearDown
\n
"
);
}
static
void
SetUpTestCase
()
{
printf
(
"DynamicFixture::SetUpTestCase
\n
"
);
}
static
void
TearDownTestCase
()
{
printf
(
"DynamicFixture::TearDownTestCase
\n
"
);
}
};
template
<
bool
Pass
>
class
DynamicTest
:
public
DynamicFixture
{
public:
void
TestBody
()
override
{
EXPECT_TRUE
(
Pass
);
}
};
auto
dynamic_test
=
(
// Register two tests with the same fixture correctly.
testing
::
RegisterTest
(
"DynamicFixture"
,
"DynamicTestPass"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
DynamicFixture
*
{
return
new
DynamicTest
<
true
>
;
}),
testing
::
RegisterTest
(
"DynamicFixture"
,
"DynamicTestFail"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
DynamicFixture
*
{
return
new
DynamicTest
<
false
>
;
}),
// Register the same fixture with another name. That's fine.
testing
::
RegisterTest
(
"DynamicFixtureAnotherName"
,
"DynamicTestPass"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
DynamicFixture
*
{
return
new
DynamicTest
<
true
>
;
}),
// Register two tests with the same fixture incorrectly.
testing
::
RegisterTest
(
"BadDynamicFixture1"
,
"FixtureBase"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
DynamicFixture
*
{
return
new
DynamicTest
<
true
>
;
}),
testing
::
RegisterTest
(
"BadDynamicFixture1"
,
"TestBase"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
testing
::
Test
*
{
return
new
DynamicTest
<
true
>
;
}),
// Register two tests with the same fixture incorrectly by ommiting the
// return type.
testing
::
RegisterTest
(
"BadDynamicFixture2"
,
"FixtureBase"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
->
DynamicFixture
*
{
return
new
DynamicTest
<
true
>
;
}),
testing
::
RegisterTest
(
"BadDynamicFixture2"
,
"Derived"
,
nullptr
,
nullptr
,
__FILE__
,
__LINE__
,
[]()
{
return
new
DynamicTest
<
true
>
;
}));
// Two test environments for testing testing::AddGlobalTestEnvironment().
class
FooEnvironment
:
public
testing
::
Environment
{
public:
virtual
void
SetUp
()
{
printf
(
"%s"
,
"FooEnvironment::SetUp() called.
\n
"
);
}
void
SetUp
()
override
{
printf
(
"%s"
,
"FooEnvironment::SetUp() called.
\n
"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
printf
(
"%s"
,
"FooEnvironment::TearDown() called.
\n
"
);
FAIL
()
<<
"Expected fatal failure."
;
}
...
...
@@ -1050,11 +1089,9 @@ class FooEnvironment : public testing::Environment {
class
BarEnvironment
:
public
testing
::
Environment
{
public:
virtual
void
SetUp
()
{
printf
(
"%s"
,
"BarEnvironment::SetUp() called.
\n
"
);
}
void
SetUp
()
override
{
printf
(
"%s"
,
"BarEnvironment::SetUp() called.
\n
"
);
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
printf
(
"%s"
,
"BarEnvironment::TearDown() called.
\n
"
);
ADD_FAILURE
()
<<
"Expected non-fatal failure."
;
}
...
...
googletest/test/googletest-param-test-test.cc
View file @
25905b9f
...
...
@@ -49,19 +49,13 @@ using ::std::sort;
using
::
testing
::
AddGlobalTestEnvironment
;
using
::
testing
::
Bool
;
using
::
testing
::
Combine
;
using
::
testing
::
Message
;
using
::
testing
::
Range
;
using
::
testing
::
TestWithParam
;
using
::
testing
::
Values
;
using
::
testing
::
ValuesIn
;
# if GTEST_HAS_COMBINE
using
::
testing
::
Combine
;
using
::
testing
::
get
;
using
::
testing
::
make_tuple
;
using
::
testing
::
tuple
;
# endif // GTEST_HAS_COMBINE
using
::
testing
::
internal
::
ParamGenerator
;
using
::
testing
::
internal
::
UnitTestOptions
;
...
...
@@ -73,49 +67,9 @@ using ::testing::internal::UnitTestOptions;
// EXPECT_THAT() and the matchers know how to print tuples.
template
<
typename
T
>
::
std
::
string
PrintValue
(
const
T
&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
value
;
return
stream
.
str
();
}
# if GTEST_HAS_COMBINE
// These overloads allow printing tuples in our tests. We cannot
// define an operator<< for tuples, as that definition needs to be in
// the std namespace in order to be picked up by Google Test via
// Argument-Dependent Lookup, yet defining anything in the std
// namespace in non-STL code is undefined behavior.
template
<
typename
T1
,
typename
T2
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
")"
;
return
stream
.
str
();
}
template
<
typename
T1
,
typename
T2
,
typename
T3
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
,
T3
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
")"
;
return
stream
.
str
();
}
template
<
typename
T1
,
typename
T2
,
typename
T3
,
typename
T4
,
typename
T5
,
typename
T6
,
typename
T7
,
typename
T8
,
typename
T9
,
typename
T10
>
::
std
::
string
PrintValue
(
const
tuple
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
,
T7
,
T8
,
T9
,
T10
>&
value
)
{
::
std
::
stringstream
stream
;
stream
<<
"("
<<
get
<
0
>
(
value
)
<<
", "
<<
get
<
1
>
(
value
)
<<
", "
<<
get
<
2
>
(
value
)
<<
", "
<<
get
<
3
>
(
value
)
<<
", "
<<
get
<
4
>
(
value
)
<<
", "
<<
get
<
5
>
(
value
)
<<
", "
<<
get
<
6
>
(
value
)
<<
", "
<<
get
<
7
>
(
value
)
<<
", "
<<
get
<
8
>
(
value
)
<<
", "
<<
get
<
9
>
(
value
)
<<
")"
;
return
stream
.
str
();
return
testing
::
PrintToString
(
value
);
}
# endif // GTEST_HAS_COMBINE
// Verifies that a sequence generated by the generator and accessed
// via the iterator object matches the expected one using Google Test
// assertions.
...
...
@@ -450,31 +404,28 @@ TEST(BoolTest, BoolWorks) {
VerifyGenerator
(
gen
,
expected_values
);
}
# if GTEST_HAS_COMBINE
// Tests that Combine() with two parameters generates the expected sequence.
TEST
(
CombineTest
,
CombineWithTwoParameters
)
{
const
char
*
foo
=
"foo"
;
const
char
*
bar
=
"bar"
;
const
ParamGenerator
<
tuple
<
const
char
*
,
int
>
>
gen
=
const
ParamGenerator
<
std
::
tuple
<
const
char
*
,
int
>
>
gen
=
Combine
(
Values
(
foo
,
bar
),
Values
(
3
,
4
));
tuple
<
const
char
*
,
int
>
expected_values
[]
=
{
make_tuple
(
foo
,
3
),
make_tuple
(
foo
,
4
),
make_tuple
(
bar
,
3
),
make_tuple
(
bar
,
4
)};
std
::
tuple
<
const
char
*
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
foo
,
3
),
std
::
make_tuple
(
foo
,
4
),
std
::
make_tuple
(
bar
,
3
),
std
::
make_tuple
(
bar
,
4
)};
VerifyGenerator
(
gen
,
expected_values
);
}
// Tests that Combine() with three parameters generates the expected sequence.
TEST
(
CombineTest
,
CombineWithThreeParameters
)
{
const
ParamGenerator
<
tuple
<
int
,
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
3
,
4
),
Values
(
5
,
6
));
tuple
<
int
,
int
,
int
>
expected_values
[]
=
{
make_tuple
(
0
,
3
,
5
),
make_tuple
(
0
,
3
,
6
),
make_tuple
(
0
,
4
,
5
),
make_tuple
(
0
,
4
,
6
),
make_tuple
(
1
,
3
,
5
),
make_tuple
(
1
,
3
,
6
),
make_tuple
(
1
,
4
,
5
),
make_tuple
(
1
,
4
,
6
)};
const
ParamGenerator
<
std
::
tuple
<
int
,
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
3
,
4
),
Values
(
5
,
6
));
std
::
tuple
<
int
,
int
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
0
,
3
,
5
),
std
::
make_tuple
(
0
,
3
,
6
),
std
::
make_tuple
(
0
,
4
,
5
),
std
::
make_tuple
(
0
,
4
,
6
),
std
::
make_tuple
(
1
,
3
,
5
),
std
::
make_tuple
(
1
,
3
,
6
),
std
::
make_tuple
(
1
,
4
,
5
),
std
::
make_tuple
(
1
,
4
,
6
)};
VerifyGenerator
(
gen
,
expected_values
);
}
...
...
@@ -482,10 +433,11 @@ TEST(CombineTest, CombineWithThreeParameters) {
// sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the second parameter.
TEST
(
CombineTest
,
CombineWithFirstParameterSingleValue
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
42
),
Values
(
0
,
1
));
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
42
),
Values
(
0
,
1
));
tuple
<
int
,
int
>
expected_values
[]
=
{
make_tuple
(
42
,
0
),
make_tuple
(
42
,
1
)};
std
::
tuple
<
int
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
42
,
0
),
std
::
make_tuple
(
42
,
1
)};
VerifyGenerator
(
gen
,
expected_values
);
}
...
...
@@ -493,26 +445,27 @@ TEST(CombineTest, CombineWithFirstParameterSingleValue) {
// sequence generates a sequence with the number of elements equal to the
// number of elements in the sequence generated by the first parameter.
TEST
(
CombineTest
,
CombineWithSecondParameterSingleValue
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
42
));
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
42
));
tuple
<
int
,
int
>
expected_values
[]
=
{
make_tuple
(
0
,
42
),
make_tuple
(
1
,
42
)};
std
::
tuple
<
int
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
0
,
42
),
std
::
make_tuple
(
1
,
42
)};
VerifyGenerator
(
gen
,
expected_values
);
}
// Tests that when the first parameter produces an empty sequence,
// Combine() produces an empty sequence, too.
TEST
(
CombineTest
,
CombineWithFirstParameterEmptyRange
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Range
(
0
,
0
),
Values
(
0
,
1
));
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Combine
(
Range
(
0
,
0
),
Values
(
0
,
1
));
VerifyGeneratorIsEmpty
(
gen
);
}
// Tests that when the second parameter produces an empty sequence,
// Combine() produces an empty sequence, too.
TEST
(
CombineTest
,
CombineWithSecondParameterEmptyRange
)
{
const
ParamGenerator
<
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Range
(
1
,
1
));
const
ParamGenerator
<
std
::
tuple
<
int
,
int
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Range
(
1
,
1
));
VerifyGeneratorIsEmpty
(
gen
);
}
...
...
@@ -521,17 +474,15 @@ TEST(CombineTest, CombineWithSecondParameterEmptyRange) {
TEST
(
CombineTest
,
CombineWithMaxNumberOfParameters
)
{
const
char
*
foo
=
"foo"
;
const
char
*
bar
=
"bar"
;
const
ParamGenerator
<
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
>
gen
=
Combine
(
Values
(
foo
,
bar
),
Values
(
1
),
Values
(
2
),
Values
(
3
),
Values
(
4
),
Values
(
5
),
Values
(
6
),
Values
(
7
),
Values
(
8
),
Values
(
9
));
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
expected_values
[]
=
{
make_tuple
(
foo
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
),
make_tuple
(
bar
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
)};
const
ParamGenerator
<
std
::
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
>
gen
=
Combine
(
Values
(
foo
,
bar
),
Values
(
1
),
Values
(
2
),
Values
(
3
),
Values
(
4
),
Values
(
5
),
Values
(
6
),
Values
(
7
),
Values
(
8
),
Values
(
9
));
std
::
tuple
<
const
char
*
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
,
int
>
expected_values
[]
=
{
std
::
make_tuple
(
foo
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
),
std
::
make_tuple
(
bar
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
)};
VerifyGenerator
(
gen
,
expected_values
);
}
...
...
@@ -551,12 +502,12 @@ class NonDefaultConstructAssignString {
};
TEST
(
CombineTest
,
NonDefaultConstructAssign
)
{
const
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
const
ParamGenerator
<
std
::
tuple
<
int
,
NonDefaultConstructAssignString
>
>
gen
=
Combine
(
Values
(
0
,
1
),
Values
(
NonDefaultConstructAssignString
(
"A"
),
NonDefaultConstructAssignString
(
"B"
)));
ParamGenerator
<
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
it
=
gen
.
begin
();
ParamGenerator
<
std
::
tuple
<
int
,
NonDefaultConstructAssignString
>
>::
iterator
it
=
gen
.
begin
();
EXPECT_EQ
(
0
,
std
::
get
<
0
>
(
*
it
));
EXPECT_EQ
(
"A"
,
std
::
get
<
1
>
(
*
it
).
str
());
...
...
@@ -577,7 +528,6 @@ TEST(CombineTest, NonDefaultConstructAssign) {
EXPECT_TRUE
(
it
==
gen
.
end
());
}
# endif // GTEST_HAS_COMBINE
// Tests that an generator produces correct sequence after being
// assigned from another generator.
...
...
@@ -612,7 +562,7 @@ class TestGenerationEnvironment : public ::testing::Environment {
void
TearDownExecuted
()
{
tear_down_count_
++
;
}
void
TestBodyExecuted
()
{
test_body_count_
++
;
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
// If all MultipleTestGenerationTest tests have been de-selected
// by the filter flag, the following checks make no sense.
bool
perform_check
=
false
;
...
...
@@ -669,11 +619,11 @@ class TestGenerationTest : public TestWithParam<int> {
Environment
::
Instance
()
->
FixtureConstructorExecuted
();
current_parameter_
=
GetParam
();
}
virtual
void
SetUp
()
{
void
SetUp
()
override
{
Environment
::
Instance
()
->
SetUpExecuted
();
EXPECT_EQ
(
current_parameter_
,
GetParam
());
}
virtual
void
TearDown
()
{
void
TearDown
()
override
{
Environment
::
Instance
()
->
TearDownExecuted
();
EXPECT_EQ
(
current_parameter_
,
GetParam
());
}
...
...
@@ -1081,6 +1031,18 @@ TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
// Tests param generator working with Enums
enum
MyEnums
{
ENUM1
=
1
,
ENUM2
=
3
,
ENUM3
=
8
,
};
class
MyEnumTest
:
public
testing
::
TestWithParam
<
MyEnums
>
{};
TEST_P
(
MyEnumTest
,
ChecksParamMoreThanZero
)
{
EXPECT_GE
(
10
,
GetParam
());
}
INSTANTIATE_TEST_CASE_P
(
MyEnumTests
,
MyEnumTest
,
::
testing
::
Values
(
ENUM1
,
ENUM2
,
0
));
int
main
(
int
argc
,
char
**
argv
)
{
// Used in TestGenerationTest test case.
...
...
googletest/test/googletest-port-test.cc
View file @
25905b9f
...
...
@@ -37,6 +37,7 @@
#endif // GTEST_OS_MAC
#include <list>
#include <memory>
#include <utility> // For std::pair and std::make_pair.
#include <vector>
...
...
@@ -218,14 +219,6 @@ TEST(IteratorTraitsTest, WorksForPointerToConst) {
IteratorTraits
<
const
void
*
const
*>::
value_type
>
();
}
// Tests that the element_type typedef is available in scoped_ptr and refers
// to the parameter type.
TEST
(
ScopedPtrTest
,
DefinesElementType
)
{
StaticAssertTypeEq
<
int
,
::
testing
::
internal
::
scoped_ptr
<
int
>::
element_type
>
();
}
// FIXME: Implement THE REST of scoped_ptr tests.
TEST
(
GtestCheckSyntaxTest
,
BehavesLikeASingleStatement
)
{
if
(
AlwaysFalse
())
GTEST_CHECK_
(
false
)
<<
"This should never be executed; "
...
...
@@ -1095,7 +1088,7 @@ TEST(MutexTest, OnlyOneThreadCanLockAtATime) {
typedef
ThreadWithParam
<
pair
<
AtomicCounterWithMutex
*
,
int
>
>
ThreadType
;
const
int
kCycleCount
=
20
;
const
int
kThreadCount
=
7
;
s
coped
_ptr
<
ThreadType
>
counting_threads
[
kThreadCount
];
s
td
::
unique
_ptr
<
ThreadType
>
counting_threads
[
kThreadCount
];
Notification
threads_can_start
;
// Creates and runs kThreadCount threads that increment locked_counter
// kCycleCount times each.
...
...
googletest/test/googletest-printers-test.cc
View file @
25905b9f
...
...
@@ -37,29 +37,20 @@
#include <string.h>
#include <algorithm>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include "gtest/gtest-printers.h"
#include "gtest/gtest.h"
#if GTEST_HAS_UNORDERED_MAP_
# include <unordered_map> // NOLINT
#endif // GTEST_HAS_UNORDERED_MAP_
#if GTEST_HAS_UNORDERED_SET_
# include <unordered_set> // NOLINT
#endif // GTEST_HAS_UNORDERED_SET_
#if GTEST_HAS_STD_FORWARD_LIST_
# include <forward_list> // NOLINT
#endif // GTEST_HAS_STD_FORWARD_LIST_
// Some user-defined types for testing the universal value printer.
// An anonymous enum type.
...
...
@@ -192,8 +183,14 @@ class PathLike {
public:
struct
iterator
{
typedef
PathLike
value_type
;
iterator
&
operator
++
();
PathLike
&
operator
*
();
};
using
value_type
=
char
;
using
const_iterator
=
iterator
;
PathLike
()
{}
iterator
begin
()
const
{
return
iterator
();
}
...
...
@@ -228,9 +225,7 @@ using ::testing::internal::Strings;
using
::
testing
::
internal
::
UniversalPrint
;
using
::
testing
::
internal
::
UniversalPrinter
;
using
::
testing
::
internal
::
UniversalTersePrint
;
#if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_
using
::
testing
::
internal
::
UniversalTersePrintTupleFieldsToStrings
;
#endif
// Prints a value to a string using the universal value printer. This
// is a helper for testing UniversalPrinter<T>::Print() for various types.
...
...
@@ -816,7 +811,6 @@ TEST(PrintStlContainerTest, NonEmptyDeque) {
EXPECT_EQ
(
"{ 1, 3 }"
,
Print
(
non_empty
));
}
#if GTEST_HAS_UNORDERED_MAP_
TEST
(
PrintStlContainerTest
,
OneElementHashMap
)
{
::
std
::
unordered_map
<
int
,
char
>
map1
;
...
...
@@ -836,9 +830,7 @@ TEST(PrintStlContainerTest, HashMultiMap) {
<<
" where Print(map1) returns
\"
"
<<
result
<<
"
\"
."
;
}
#endif // GTEST_HAS_UNORDERED_MAP_
#if GTEST_HAS_UNORDERED_SET_
TEST
(
PrintStlContainerTest
,
HashSet
)
{
::
std
::
unordered_set
<
int
>
set1
;
...
...
@@ -875,7 +867,6 @@ TEST(PrintStlContainerTest, HashMultiSet) {
EXPECT_TRUE
(
std
::
equal
(
a
,
a
+
kSize
,
numbers
.
begin
()));
}
#endif // GTEST_HAS_UNORDERED_SET_
TEST
(
PrintStlContainerTest
,
List
)
{
const
std
::
string
a
[]
=
{
"hello"
,
"world"
};
...
...
@@ -917,14 +908,12 @@ TEST(PrintStlContainerTest, MultiSet) {
EXPECT_EQ
(
"{ 1, 1, 1, 2, 5 }"
,
Print
(
set1
));
}
#if GTEST_HAS_STD_FORWARD_LIST_
TEST
(
PrintStlContainerTest
,
SinglyLinkedList
)
{
int
a
[]
=
{
9
,
2
,
8
};
const
std
::
forward_list
<
int
>
ints
(
a
,
a
+
3
);
EXPECT_EQ
(
"{ 9, 2, 8 }"
,
Print
(
ints
));
}
#endif // GTEST_HAS_STD_FORWARD_LIST_
TEST
(
PrintStlContainerTest
,
Pair
)
{
pair
<
const
bool
,
int
>
p
(
true
,
5
);
...
...
@@ -991,67 +980,6 @@ TEST(PrintStlContainerTest, ConstIterator) {
EXPECT_EQ
(
"1-byte object <00>"
,
Print
(
it
));
}
#if GTEST_HAS_TR1_TUPLE
// Tests printing ::std::tr1::tuples.
// Tuples of various arities.
TEST
(
PrintTr1TupleTest
,
VariousSizes
)
{
::
std
::
tr1
::
tuple
<>
t0
;
EXPECT_EQ
(
"()"
,
Print
(
t0
));
::
std
::
tr1
::
tuple
<
int
>
t1
(
5
);
EXPECT_EQ
(
"(5)"
,
Print
(
t1
));
::
std
::
tr1
::
tuple
<
char
,
bool
>
t2
(
'a'
,
true
);
EXPECT_EQ
(
"('a' (97, 0x61), true)"
,
Print
(
t2
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
>
t3
(
false
,
2
,
3
);
EXPECT_EQ
(
"(false, 2, 3)"
,
Print
(
t3
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
>
t4
(
false
,
2
,
3
,
4
);
EXPECT_EQ
(
"(false, 2, 3, 4)"
,
Print
(
t4
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
,
bool
>
t5
(
false
,
2
,
3
,
4
,
true
);
EXPECT_EQ
(
"(false, 2, 3, 4, true)"
,
Print
(
t5
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
>
t6
(
false
,
2
,
3
,
4
,
true
,
6
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6)"
,
Print
(
t6
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
>
t7
(
false
,
2
,
3
,
4
,
true
,
6
,
7
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7)"
,
Print
(
t7
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
,
bool
>
t8
(
false
,
2
,
3
,
4
,
true
,
6
,
7
,
true
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7, true)"
,
Print
(
t8
));
::
std
::
tr1
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
,
bool
,
int
>
t9
(
false
,
2
,
3
,
4
,
true
,
6
,
7
,
true
,
9
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7, true, 9)"
,
Print
(
t9
));
const
char
*
const
str
=
"8"
;
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::
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
,
// 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
\"
)"
,
Print
(
t10
));
}
// Nested tuples.
TEST
(
PrintTr1TupleTest
,
NestedTuple
)
{
::
std
::
tr1
::
tuple
<
::
std
::
tr1
::
tuple
<
int
,
bool
>
,
char
>
nested
(
::
std
::
tr1
::
make_tuple
(
5
,
true
),
'a'
);
EXPECT_EQ
(
"((5, true), 'a' (97, 0x61))"
,
Print
(
nested
));
}
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
// Tests printing ::std::tuples.
// Tuples of various arities.
...
...
@@ -1071,32 +999,12 @@ TEST(PrintStdTupleTest, VariousSizes) {
::
std
::
tuple
<
bool
,
int
,
int
,
int
>
t4
(
false
,
2
,
3
,
4
);
EXPECT_EQ
(
"(false, 2, 3, 4)"
,
Print
(
t4
));
::
std
::
tuple
<
bool
,
int
,
int
,
int
,
bool
>
t5
(
false
,
2
,
3
,
4
,
true
);
EXPECT_EQ
(
"(false, 2, 3, 4, true)"
,
Print
(
t5
));
::
std
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
>
t6
(
false
,
2
,
3
,
4
,
true
,
6
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6)"
,
Print
(
t6
));
::
std
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
>
t7
(
false
,
2
,
3
,
4
,
true
,
6
,
7
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7)"
,
Print
(
t7
));
::
std
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
,
bool
>
t8
(
false
,
2
,
3
,
4
,
true
,
6
,
7
,
true
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7, true)"
,
Print
(
t8
));
::
std
::
tuple
<
bool
,
int
,
int
,
int
,
bool
,
int
,
int
,
bool
,
int
>
t9
(
false
,
2
,
3
,
4
,
true
,
6
,
7
,
true
,
9
);
EXPECT_EQ
(
"(false, 2, 3, 4, true, 6, 7, true, 9)"
,
Print
(
t9
));
const
char
*
const
str
=
"8"
;
// VC++ 2010's implementation of tuple of C++0x is deficient, requiring
// an explicit type cast of NULL to be used.
::
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
,
// NOLINT
ImplicitCast_
<
void
*>
(
NULL
)
,
"10"
);
nullptr
,
"10"
);
EXPECT_EQ
(
"(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, "
+
PrintPointer
(
str
)
+
" pointing to
\"
8
\"
, NULL,
\"
10
\"
)"
,
Print
(
t10
));
...
...
@@ -1109,8 +1017,6 @@ TEST(PrintStdTupleTest, NestedTuple) {
EXPECT_EQ
(
"((5, true), 'a' (97, 0x61))"
,
Print
(
nested
));
}
#endif // GTEST_HAS_TR1_TUPLE
TEST
(
PrintNullptrT
,
Basic
)
{
EXPECT_EQ
(
"(nullptr)"
,
Print
(
nullptr
));
}
...
...
@@ -1662,42 +1568,6 @@ TEST(UniversalPrintTest, WorksForCharArray) {
EXPECT_EQ
(
"
\"\\\"
Line
\\
0 1
\\\"\\
nLine 2
\"
"
,
ss2
.
str
());
}
#if GTEST_HAS_TR1_TUPLE
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithTr1
,
PrintsEmptyTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
tr1
::
make_tuple
());
EXPECT_EQ
(
0u
,
result
.
size
());
}
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithTr1
,
PrintsOneTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
tr1
::
make_tuple
(
1
));
ASSERT_EQ
(
1u
,
result
.
size
());
EXPECT_EQ
(
"1"
,
result
[
0
]);
}
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithTr1
,
PrintsTwoTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
tr1
::
make_tuple
(
1
,
'a'
));
ASSERT_EQ
(
2u
,
result
.
size
());
EXPECT_EQ
(
"1"
,
result
[
0
]);
EXPECT_EQ
(
"'a' (97, 0x61)"
,
result
[
1
]);
}
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithTr1
,
PrintsTersely
)
{
const
int
n
=
1
;
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
tr1
::
tuple
<
const
int
&
,
const
char
*>
(
n
,
"a"
));
ASSERT_EQ
(
2u
,
result
.
size
());
EXPECT_EQ
(
"1"
,
result
[
0
]);
EXPECT_EQ
(
"
\"
a
\"
"
,
result
[
1
]);
}
#endif // GTEST_HAS_TR1_TUPLE
#if GTEST_HAS_STD_TUPLE_
TEST
(
UniversalTersePrintTupleFieldsToStringsTestWithStd
,
PrintsEmptyTuple
)
{
Strings
result
=
UniversalTersePrintTupleFieldsToStrings
(
::
std
::
make_tuple
());
EXPECT_EQ
(
0u
,
result
.
size
());
...
...
@@ -1727,8 +1597,6 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
EXPECT_EQ
(
"
\"
a
\"
"
,
result
[
1
]);
}
#endif // GTEST_HAS_STD_TUPLE_
#if GTEST_HAS_ABSL
TEST
(
PrintOptionalTest
,
Basic
)
{
...
...
Prev
1
2
3
4
5
6
7
8
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