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
9e712372
Unverified
Commit
9e712372
authored
Mar 18, 2022
by
Brad Messer
Committed by
GitHub
Mar 18, 2022
Browse files
Merge branch 'main' into promote-inclusive-behavior
parents
794da715
b007c54f
Changes
135
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
482 additions
and
603 deletions
+482
-603
googletest/samples/sample2_unittest.cc
googletest/samples/sample2_unittest.cc
+2
-2
googletest/samples/sample3-inl.h
googletest/samples/sample3-inl.h
+4
-5
googletest/samples/sample3_unittest.cc
googletest/samples/sample3_unittest.cc
+4
-7
googletest/samples/sample4.cc
googletest/samples/sample4.cc
+5
-9
googletest/samples/sample4_unittest.cc
googletest/samples/sample4_unittest.cc
+1
-1
googletest/samples/sample5_unittest.cc
googletest/samples/sample5_unittest.cc
+3
-10
googletest/samples/sample6_unittest.cc
googletest/samples/sample6_unittest.cc
+1
-4
googletest/samples/sample7_unittest.cc
googletest/samples/sample7_unittest.cc
+1
-5
googletest/samples/sample8_unittest.cc
googletest/samples/sample8_unittest.cc
+2
-4
googletest/samples/sample9_unittest.cc
googletest/samples/sample9_unittest.cc
+10
-17
googletest/src/gtest-all.cc
googletest/src/gtest-all.cc
+1
-1
googletest/src/gtest-assertion-result.cc
googletest/src/gtest-assertion-result.cc
+3
-7
googletest/src/gtest-death-test.cc
googletest/src/gtest-death-test.cc
+203
-230
googletest/src/gtest-filepath.cc
googletest/src/gtest-filepath.cc
+38
-40
googletest/src/gtest-internal-inl.h
googletest/src/gtest-internal-inl.h
+30
-35
googletest/src/gtest-matchers.cc
googletest/src/gtest-matchers.cc
+3
-2
googletest/src/gtest-port.cc
googletest/src/gtest-port.cc
+135
-157
googletest/src/gtest-printers.cc
googletest/src/gtest-printers.cc
+26
-51
googletest/src/gtest-test-part.cc
googletest/src/gtest-test-part.cc
+8
-11
googletest/src/gtest-typed-test.cc
googletest/src/gtest-typed-test.cc
+2
-5
No files found.
googletest/samples/sample2_unittest.cc
View file @
9e712372
...
...
@@ -38,6 +38,7 @@
// needed.
#include "sample2.h"
#include "gtest/gtest.h"
namespace
{
// In this example, we test the MyString class (a simple string).
...
...
@@ -77,8 +78,7 @@ const char kHelloString[] = "Hello, world!";
TEST
(
MyString
,
ConstructorFromCString
)
{
const
MyString
s
(
kHelloString
);
EXPECT_EQ
(
0
,
strcmp
(
s
.
c_string
(),
kHelloString
));
EXPECT_EQ
(
sizeof
(
kHelloString
)
/
sizeof
(
kHelloString
[
0
])
-
1
,
s
.
Length
());
EXPECT_EQ
(
sizeof
(
kHelloString
)
/
sizeof
(
kHelloString
[
0
])
-
1
,
s
.
Length
());
}
// Tests the copy c'tor.
...
...
googletest/samples/sample3-inl.h
View file @
9e712372
...
...
@@ -34,7 +34,6 @@
#include <stddef.h>
// Queue is a simple queue implemented as a singled-linked list.
//
// The element type must support copy constructor.
...
...
@@ -62,7 +61,7 @@ class QueueNode {
:
element_
(
an_element
),
next_
(
nullptr
)
{}
// We disable the default assignment operator and copy c'tor.
const
QueueNode
&
operator
=
(
const
QueueNode
&
);
const
QueueNode
&
operator
=
(
const
QueueNode
&
);
QueueNode
(
const
QueueNode
&
);
E
element_
;
...
...
@@ -84,7 +83,7 @@ class Queue {
// 1. Deletes every node.
QueueNode
<
E
>*
node
=
head_
;
QueueNode
<
E
>*
next
=
node
->
next
();
for
(;
;)
{
for
(;;)
{
delete
node
;
node
=
next
;
if
(
node
==
nullptr
)
break
;
...
...
@@ -162,11 +161,11 @@ class Queue {
private:
QueueNode
<
E
>*
head_
;
// The first node of the queue.
QueueNode
<
E
>*
last_
;
// The last node of the queue.
size_t
size_
;
// The number of elements in the queue.
size_t
size_
;
// The number of elements in the queue.
// We disallow copying a queue.
Queue
(
const
Queue
&
);
const
Queue
&
operator
=
(
const
Queue
&
);
const
Queue
&
operator
=
(
const
Queue
&
);
};
#endif // GOOGLETEST_SAMPLES_SAMPLE3_INL_H_
googletest/samples/sample3_unittest.cc
View file @
9e712372
...
...
@@ -67,7 +67,6 @@ namespace {
class
QueueTestSmpl3
:
public
testing
::
Test
{
protected:
// You should make the members protected s.t. they can be
// accessed from sub-classes.
// virtual void SetUp() will be called before each test is run. You
// should define it if you need to initialize the variables.
// Otherwise, this can be skipped.
...
...
@@ -85,15 +84,13 @@ class QueueTestSmpl3 : public testing::Test {
// }
// A helper function that some test uses.
static
int
Double
(
int
n
)
{
return
2
*
n
;
}
static
int
Double
(
int
n
)
{
return
2
*
n
;
}
// A helper function for testing Queue::Map().
void
MapTester
(
const
Queue
<
int
>
*
q
)
{
void
MapTester
(
const
Queue
<
int
>*
q
)
{
// Creates a new queue, where each element is twice as big as the
// corresponding one in q.
const
Queue
<
int
>
*
const
new_q
=
q
->
Map
(
Double
);
const
Queue
<
int
>*
const
new_q
=
q
->
Map
(
Double
);
// Verifies that the new queue has the same size as q.
ASSERT_EQ
(
q
->
Size
(),
new_q
->
Size
());
...
...
@@ -124,7 +121,7 @@ TEST_F(QueueTestSmpl3, DefaultConstructor) {
// Tests Dequeue().
TEST_F
(
QueueTestSmpl3
,
Dequeue
)
{
int
*
n
=
q0_
.
Dequeue
();
int
*
n
=
q0_
.
Dequeue
();
EXPECT_TRUE
(
n
==
nullptr
);
n
=
q1_
.
Dequeue
();
...
...
googletest/samples/sample4.cc
View file @
9e712372
...
...
@@ -29,26 +29,22 @@
// A sample program demonstrating using Google C++ testing framework.
#include <stdio.h>
#include "sample4.h"
#include <stdio.h>
// Returns the current counter value, and increments it.
int
Counter
::
Increment
()
{
return
counter_
++
;
}
int
Counter
::
Increment
()
{
return
counter_
++
;
}
// Returns the current counter value, and decrements it.
// counter can not be less than 0, return 0 in this case
int
Counter
::
Decrement
()
{
if
(
counter_
==
0
)
{
return
counter_
;
}
else
{
}
else
{
return
counter_
--
;
}
}
// Prints the current counter value to STDOUT.
void
Counter
::
Print
()
const
{
printf
(
"%d"
,
counter_
);
}
void
Counter
::
Print
()
const
{
printf
(
"%d"
,
counter_
);
}
googletest/samples/sample4_unittest.cc
View file @
9e712372
...
...
@@ -27,8 +27,8 @@
// (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 "sample4.h"
#include "gtest/gtest.h"
namespace
{
...
...
googletest/samples/sample5_unittest.cc
View file @
9e712372
...
...
@@ -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.
// This sample teaches how to reuse a test fixture in multiple test
// cases by deriving sub-fixtures from it.
//
...
...
@@ -45,9 +44,10 @@
#include <limits.h>
#include <time.h>
#include "gtest/gtest.h"
#include "sample1.h"
#include "sample3-inl.h"
#include "gtest/gtest.h"
namespace
{
// In this sample, we want to ensure that every test finishes within
// ~5 seconds. If a test takes longer to run, we consider it a
...
...
@@ -81,7 +81,6 @@ class QuickTest : public testing::Test {
time_t
start_time_
;
};
// We derive a fixture named IntegerFunctionTest from the QuickTest
// fixture. All tests using this fixture will be automatically
// required to be quick.
...
...
@@ -90,7 +89,6 @@ class IntegerFunctionTest : public QuickTest {
// Therefore the body is empty.
};
// Now we can write tests in the IntegerFunctionTest test case.
// Tests Factorial()
...
...
@@ -110,7 +108,6 @@ TEST_F(IntegerFunctionTest, Factorial) {
EXPECT_EQ
(
40320
,
Factorial
(
8
));
}
// Tests IsPrime()
TEST_F
(
IntegerFunctionTest
,
IsPrime
)
{
// Tests negative input.
...
...
@@ -131,7 +128,6 @@ TEST_F(IntegerFunctionTest, IsPrime) {
EXPECT_TRUE
(
IsPrime
(
23
));
}
// The next test case (named "QueueTest") also needs to be quick, so
// we derive another fixture from QuickTest.
//
...
...
@@ -163,13 +159,10 @@ class QueueTest : public QuickTest {
Queue
<
int
>
q2_
;
};
// Now, let's write tests using the QueueTest fixture.
// Tests the default constructor.
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
EXPECT_EQ
(
0u
,
q0_
.
Size
());
}
TEST_F
(
QueueTest
,
DefaultConstructor
)
{
EXPECT_EQ
(
0u
,
q0_
.
Size
());
}
// Tests Dequeue().
TEST_F
(
QueueTest
,
Dequeue
)
{
...
...
googletest/samples/sample6_unittest.cc
View file @
9e712372
...
...
@@ -27,13 +27,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This sample shows how to test common properties of multiple
// implementations of the same interface (aka interface tests).
// The interface and its implementations are in this header.
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
// First, we define some factory functions for creating instances of
...
...
@@ -151,8 +149,7 @@ using testing::Types;
// the PrimeTableTest fixture defined earlier:
template
<
class
T
>
class
PrimeTableTest2
:
public
PrimeTableTest
<
T
>
{
};
class
PrimeTableTest2
:
public
PrimeTableTest
<
T
>
{};
// Then, declare the test case. The argument is the name of the test
// fixture, and also the name of the test case (as usual). The _P
...
...
googletest/samples/sample7_unittest.cc
View file @
9e712372
...
...
@@ -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.
// This sample shows how to test common properties of multiple
// implementations of an interface (aka interface tests) using
// value-parameterized tests. Each test in the test case has
...
...
@@ -36,7 +35,6 @@
// The interface and its implementations are in this header.
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
...
...
@@ -50,9 +48,7 @@ using ::testing::Values;
// SetUp() method and delete them in TearDown() method.
typedef
PrimeTable
*
CreatePrimeTableFunc
();
PrimeTable
*
CreateOnTheFlyPrimeTable
()
{
return
new
OnTheFlyPrimeTable
();
}
PrimeTable
*
CreateOnTheFlyPrimeTable
()
{
return
new
OnTheFlyPrimeTable
();
}
template
<
size_t
max_precalculated
>
PrimeTable
*
CreatePreCalculatedPrimeTable
()
{
...
...
googletest/samples/sample8_unittest.cc
View file @
9e712372
...
...
@@ -27,14 +27,12 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This sample shows how to test code relying on some global flag variables.
// Combine() helps with generating all possible combinations of such flags,
// and each test is given one combination as a parameter.
// Use class definitions to test from this header.
#include "prime_tables.h"
#include "gtest/gtest.h"
namespace
{
...
...
@@ -79,10 +77,10 @@ class HybridPrimeTable : public PrimeTable {
int
max_precalculated_
;
};
using
::
testing
::
TestWithParam
;
using
::
testing
::
Bool
;
using
::
testing
::
Values
;
using
::
testing
::
Combine
;
using
::
testing
::
TestWithParam
;
using
::
testing
::
Values
;
// To test all code paths for HybridPrimeTable we must test it with numbers
// both within and outside PreCalculatedPrimeTable's capacity and also with
...
...
googletest/samples/sample9_unittest.cc
View file @
9e712372
...
...
@@ -26,7 +26,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.
// This sample shows how to use Google Test listener API to implement
// an alternative console output and how to use the UnitTest reflection API
// to enumerate test suites and tests and to inspect their results.
...
...
@@ -38,10 +37,10 @@
using
::
testing
::
EmptyTestEventListener
;
using
::
testing
::
InitGoogleTest
;
using
::
testing
::
Test
;
using
::
testing
::
TestSuite
;
using
::
testing
::
TestEventListeners
;
using
::
testing
::
TestInfo
;
using
::
testing
::
TestPartResult
;
using
::
testing
::
TestSuite
;
using
::
testing
::
UnitTest
;
namespace
{
// Provides alternative output mode which produces minimal amount of
...
...
@@ -59,29 +58,23 @@ class TersePrinter : public EmptyTestEventListener {
// Called before a test starts.
void
OnTestStart
(
const
TestInfo
&
test_info
)
override
{
fprintf
(
stdout
,
"*** Test %s.%s starting.
\n
"
,
test_info
.
test_suite_name
(),
fprintf
(
stdout
,
"*** Test %s.%s starting.
\n
"
,
test_info
.
test_suite_name
(),
test_info
.
name
());
fflush
(
stdout
);
}
// Called after a failed assertion or a SUCCEED() invocation.
void
OnTestPartResult
(
const
TestPartResult
&
test_part_result
)
override
{
fprintf
(
stdout
,
"%s in %s:%d
\n
%s
\n
"
,
fprintf
(
stdout
,
"%s in %s:%d
\n
%s
\n
"
,
test_part_result
.
failed
()
?
"*** Failure"
:
"Success"
,
test_part_result
.
file_name
(),
test_part_result
.
line_number
(),
test_part_result
.
file_name
(),
test_part_result
.
line_number
(),
test_part_result
.
summary
());
fflush
(
stdout
);
}
// Called after a test ends.
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
{
fprintf
(
stdout
,
"*** Test %s.%s ending.
\n
"
,
test_info
.
test_suite_name
(),
fprintf
(
stdout
,
"*** Test %s.%s ending.
\n
"
,
test_info
.
test_suite_name
(),
test_info
.
name
());
fflush
(
stdout
);
}
...
...
@@ -101,14 +94,15 @@ TEST(CustomOutputTest, Fails) {
}
}
// namespace
int
main
(
int
argc
,
char
**
argv
)
{
int
main
(
int
argc
,
char
**
argv
)
{
InitGoogleTest
(
&
argc
,
argv
);
bool
terse_output
=
false
;
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"--terse_output"
)
==
0
)
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"--terse_output"
)
==
0
)
terse_output
=
true
;
else
printf
(
"%s
\n
"
,
"Run this program with --terse_output to change the way "
printf
(
"%s
\n
"
,
"Run this program with --terse_output to change the way "
"it prints its output."
);
UnitTest
&
unit_test
=
*
UnitTest
::
GetInstance
();
...
...
@@ -149,8 +143,7 @@ int main(int argc, char **argv) {
}
// Test that were meant to fail should not affect the test program outcome.
if
(
unexpectedly_failed_tests
==
0
)
ret_val
=
0
;
if
(
unexpectedly_failed_tests
==
0
)
ret_val
=
0
;
return
ret_val
;
}
googletest/src/gtest-all.cc
View file @
9e712372
...
...
@@ -38,7 +38,6 @@
#include "gtest/gtest.h"
// The following lines pull in the real gtest *.cc files.
#include "src/gtest.cc"
#include "src/gtest-assertion-result.cc"
#include "src/gtest-death-test.cc"
#include "src/gtest-filepath.cc"
...
...
@@ -47,3 +46,4 @@
#include "src/gtest-printers.cc"
#include "src/gtest-test-part.cc"
#include "src/gtest-typed-test.cc"
#include "src/gtest.cc"
googletest/src/gtest-assertion-result.cc
View file @
9e712372
...
...
@@ -33,8 +33,8 @@
#include "gtest/gtest-assertion-result.h"
#include <utility>
#include <string>
#include <utility>
#include "gtest/gtest-message.h"
...
...
@@ -63,14 +63,10 @@ AssertionResult AssertionResult::operator!() const {
}
// Makes a successful assertion result.
AssertionResult
AssertionSuccess
()
{
return
AssertionResult
(
true
);
}
AssertionResult
AssertionSuccess
()
{
return
AssertionResult
(
true
);
}
// Makes a failed assertion result.
AssertionResult
AssertionFailure
()
{
return
AssertionResult
(
false
);
}
AssertionResult
AssertionFailure
()
{
return
AssertionResult
(
false
);
}
// Makes a failed assertion result with the given failure message.
// Deprecated; use AssertionFailure() << message.
...
...
googletest/src/gtest-death-test.cc
View file @
9e712372
...
...
@@ -35,49 +35,49 @@
#include <functional>
#include <utility>
#include "gtest/internal/gtest-port.h"
#include "gtest/internal/custom/gtest.h"
#include "gtest/internal/gtest-port.h"
#if GTEST_HAS_DEATH_TEST
#
if GTEST_OS_MAC
#
include <crt_externs.h>
#
endif // GTEST_OS_MAC
#
include <errno.h>
#
include <fcntl.h>
#
include <limits.h>
#
if GTEST_OS_LINUX
#
include <signal.h>
#
endif // GTEST_OS_LINUX
#
include <stdarg.h>
#
if GTEST_OS_WINDOWS
#
include <windows.h>
#
else
#
include <sys/mman.h>
#
include <sys/wait.h>
#
endif // GTEST_OS_WINDOWS
#
if GTEST_OS_QNX
#
include <spawn.h>
#
endif // GTEST_OS_QNX
#
if GTEST_OS_FUCHSIA
#
include <lib/fdio/fd.h>
#
include <lib/fdio/io.h>
#
include <lib/fdio/spawn.h>
#
include <lib/zx/channel.h>
#
include <lib/zx/port.h>
#
include <lib/zx/process.h>
#
include <lib/zx/socket.h>
#
include <zircon/processargs.h>
#
include <zircon/syscalls.h>
#
include <zircon/syscalls/policy.h>
#
include <zircon/syscalls/port.h>
#
endif // GTEST_OS_FUCHSIA
#if GTEST_OS_MAC
#include <crt_externs.h>
#endif // GTEST_OS_MAC
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#if GTEST_OS_LINUX
#include <signal.h>
#endif // GTEST_OS_LINUX
#include <stdarg.h>
#if GTEST_OS_WINDOWS
#include <windows.h>
#else
#include <sys/mman.h>
#include <sys/wait.h>
#endif // GTEST_OS_WINDOWS
#if GTEST_OS_QNX
#include <spawn.h>
#endif // GTEST_OS_QNX
#if GTEST_OS_FUCHSIA
#include <lib/fdio/fd.h>
#include <lib/fdio/io.h>
#include <lib/fdio/spawn.h>
#include <lib/zx/channel.h>
#include <lib/zx/port.h>
#include <lib/zx/process.h>
#include <lib/zx/socket.h>
#include <zircon/processargs.h>
#include <zircon/syscalls.h>
#include <zircon/syscalls/policy.h>
#include <zircon/syscalls/port.h>
#endif // GTEST_OS_FUCHSIA
#endif // GTEST_HAS_DEATH_TEST
...
...
@@ -137,9 +137,9 @@ namespace internal {
// Valid only for fast death tests. Indicates the code is running in the
// child process of a fast style death test.
#
if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
static
bool
g_in_fast_death_test_child
=
false
;
#
endif
#endif
// Returns a Boolean value indicating whether the caller is currently
// executing in the context of the death test child process. Tools such as
...
...
@@ -147,13 +147,13 @@ static bool g_in_fast_death_test_child = false;
// tests. IMPORTANT: This is an internal utility. Using it may break the
// implementation of death tests. User code MUST NOT use it.
bool
InDeathTestChild
()
{
#
if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
// On Windows and Fuchsia, death tests are thread-safe regardless of the value
// of the death_test_style flag.
return
!
GTEST_FLAG_GET
(
internal_run_death_test
).
empty
();
#
else
#else
if
(
GTEST_FLAG_GET
(
death_test_style
)
==
"threadsafe"
)
return
!
GTEST_FLAG_GET
(
internal_run_death_test
).
empty
();
...
...
@@ -165,40 +165,38 @@ bool InDeathTestChild() {
}
// namespace internal
// ExitedWithCode constructor.
ExitedWithCode
::
ExitedWithCode
(
int
exit_code
)
:
exit_code_
(
exit_code
)
{
}
ExitedWithCode
::
ExitedWithCode
(
int
exit_code
)
:
exit_code_
(
exit_code
)
{}
// ExitedWithCode function-call operator.
bool
ExitedWithCode
::
operator
()(
int
exit_status
)
const
{
#
if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
return
exit_status
==
exit_code_
;
#
else
#else
return
WIFEXITED
(
exit_status
)
&&
WEXITSTATUS
(
exit_status
)
==
exit_code_
;
#
endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
}
#
if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// KilledBySignal constructor.
KilledBySignal
::
KilledBySignal
(
int
signum
)
:
signum_
(
signum
)
{
}
KilledBySignal
::
KilledBySignal
(
int
signum
)
:
signum_
(
signum
)
{}
// KilledBySignal function-call operator.
bool
KilledBySignal
::
operator
()(
int
exit_status
)
const
{
#
if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
#if defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
{
bool
result
;
if
(
GTEST_KILLED_BY_SIGNAL_OVERRIDE_
(
signum_
,
exit_status
,
&
result
))
{
return
result
;
}
}
#
endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
#endif // defined(GTEST_KILLED_BY_SIGNAL_OVERRIDE_)
return
WIFSIGNALED
(
exit_status
)
&&
WTERMSIG
(
exit_status
)
==
signum_
;
}
#
endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
namespace
internal
{
...
...
@@ -209,23 +207,23 @@ namespace internal {
static
std
::
string
ExitSummary
(
int
exit_code
)
{
Message
m
;
#
if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
m
<<
"Exited with exit status "
<<
exit_code
;
#
else
#else
if
(
WIFEXITED
(
exit_code
))
{
m
<<
"Exited with exit status "
<<
WEXITSTATUS
(
exit_code
);
}
else
if
(
WIFSIGNALED
(
exit_code
))
{
m
<<
"Terminated by signal "
<<
WTERMSIG
(
exit_code
);
}
#
ifdef WCOREDUMP
#ifdef WCOREDUMP
if
(
WCOREDUMP
(
exit_code
))
{
m
<<
" (core dumped)"
;
}
#
endif
#
endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
#endif
#endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
return
m
.
GetString
();
}
...
...
@@ -236,7 +234,7 @@ bool ExitedUnsuccessfully(int exit_status) {
return
!
ExitedWithCode
(
0
)(
exit_status
);
}
#
if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// Generates a textual failure message when a death test finds more than
// one thread running, or cannot determine the number of threads, prior
// to executing the given statement. It is the responsibility of the
...
...
@@ -257,7 +255,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) {
<<
" this is the last message you see before your test times out."
;
return
msg
.
GetString
();
}
#
endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
#endif // !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
// Flag characters for reporting a death test that did not die.
static
const
char
kDeathTestLived
=
'L'
;
...
...
@@ -307,14 +305,14 @@ static void DeathTestAbort(const std::string& message) {
// A replacement for CHECK that calls DeathTestAbort if the assertion
// fails.
#
define GTEST_DEATH_TEST_CHECK_(expression) \
do { \
if (!::testing::internal::IsTrue(expression)) { \
DeathTestAbort( \
::std::string("CHECK failed: File ") + __FILE__ + ", line "
\
+
::testing::internal::StreamableToString(__LINE__) +
": "
\
+ #expression);
\
} \
#define GTEST_DEATH_TEST_CHECK_(expression)
\
do {
\
if (!::testing::internal::IsTrue(expression)) {
\
DeathTestAbort(
::std::string("CHECK failed: File ") + __FILE__ +
\
", line " +
\
::testing::internal::StreamableToString(__LINE__) + \
": " + #expression);
\
}
\
} while (::testing::internal::AlwaysFalse())
// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
...
...
@@ -324,23 +322,23 @@ static void DeathTestAbort(const std::string& message) {
// evaluates the expression as long as it evaluates to -1 and sets
// errno to EINTR. If the expression evaluates to -1 but errno is
// something other than EINTR, DeathTestAbort is called.
#
define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
do { \
int gtest_retval; \
do { \
gtest_retval = (expression); \
} while (gtest_retval == -1 && errno == EINTR); \
if (gtest_retval == -1) { \
DeathTestAbort( \
::std::string("CHECK failed: File ") + __FILE__ + ", line "
\
+
::testing::internal::StreamableToString(__LINE__) +
": "
\
+ #expression + " != -1"); \
} \
#define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression)
\
do {
\
int gtest_retval;
\
do {
\
gtest_retval = (expression);
\
} while (gtest_retval == -1 && errno == EINTR);
\
if (gtest_retval == -1) {
\
DeathTestAbort(
::std::string("CHECK failed: File ") + __FILE__ +
\
", line " +
\
::testing::internal::StreamableToString(__LINE__) + \
": "
+ #expression + " != -1");
\
}
\
} while (::testing::internal::AlwaysFalse())
// Returns the message describing the last system error in errno.
std
::
string
GetLastErrnoDescription
()
{
return
errno
==
0
?
""
:
posix
::
StrError
(
errno
);
return
errno
==
0
?
""
:
posix
::
StrError
(
errno
);
}
// This is called from a death test parent process to read a failure
...
...
@@ -373,8 +371,9 @@ static void FailFromInternalError(int fd) {
DeathTest
::
DeathTest
()
{
TestInfo
*
const
info
=
GetUnitTestImpl
()
->
current_test_info
();
if
(
info
==
nullptr
)
{
DeathTestAbort
(
"Cannot run a death test outside of a TEST or "
"TEST_F construct"
);
DeathTestAbort
(
"Cannot run a death test outside of a TEST or "
"TEST_F construct"
);
}
}
...
...
@@ -503,9 +502,7 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
set_read_fd
(
-
1
);
}
std
::
string
DeathTestImpl
::
GetErrorLogs
()
{
return
GetCapturedStderr
();
}
std
::
string
DeathTestImpl
::
GetErrorLogs
()
{
return
GetCapturedStderr
();
}
// Signals that the death test code which should have exited, didn't.
// Should be called only in a death test child process.
...
...
@@ -515,9 +512,9 @@ void DeathTestImpl::Abort(AbortReason reason) {
// The parent process considers the death test to be a failure if
// it finds any data in our pipe. So, here we write a single flag byte
// to the pipe, then exit.
const
char
status_ch
=
reason
==
TEST_DID_NOT_DIE
?
kDeathTest
Lived
:
reason
==
TEST_THREW_EXCEPTION
?
kDeathTestThrew
:
kDeathTestReturned
;
const
char
status_ch
=
reason
==
TEST_DID_NOT_DIE
?
kDeathTestLived
:
reason
==
TEST_THREW_EXCEPTION
?
kDeathTest
Threw
:
kDeathTestReturned
;
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
posix
::
Write
(
write_fd
(),
&
status_ch
,
1
));
// We are leaking the descriptor here because on some platforms (i.e.,
...
...
@@ -536,7 +533,7 @@ void DeathTestImpl::Abort(AbortReason reason) {
// much easier.
static
::
std
::
string
FormatDeathTestOutput
(
const
::
std
::
string
&
output
)
{
::
std
::
string
ret
;
for
(
size_t
at
=
0
;
;
)
{
for
(
size_t
at
=
0
;
;
)
{
const
size_t
line_end
=
output
.
find
(
'\n'
,
at
);
ret
+=
"[ DEATH ] "
;
if
(
line_end
==
::
std
::
string
::
npos
)
{
...
...
@@ -571,8 +568,7 @@ static ::std::string FormatDeathTestOutput(const ::std::string& output) {
// the first failing condition, in the order given above, is the one that is
// reported. Also sets the last death test message string.
bool
DeathTestImpl
::
Passed
(
bool
status_ok
)
{
if
(
!
spawned
())
return
false
;
if
(
!
spawned
())
return
false
;
const
std
::
string
error_message
=
GetErrorLogs
();
...
...
@@ -583,15 +579,18 @@ bool DeathTestImpl::Passed(bool status_ok) {
switch
(
outcome
())
{
case
LIVED
:
buffer
<<
" Result: failed to die.
\n
"
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
break
;
case
THREW
:
buffer
<<
" Result: threw an exception.
\n
"
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
break
;
case
RETURNED
:
buffer
<<
" Result: illegal return in test statement.
\n
"
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
<<
" Error msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
break
;
case
DIED
:
if
(
status_ok
)
{
...
...
@@ -608,7 +607,8 @@ bool DeathTestImpl::Passed(bool status_ok) {
}
else
{
buffer
<<
" Result: died but not with expected exit code:
\n
"
<<
" "
<<
ExitSummary
(
status
())
<<
"
\n
"
<<
"Actual msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
<<
"Actual msg:
\n
"
<<
FormatDeathTestOutput
(
error_message
);
}
break
;
case
IN_PROGRESS
:
...
...
@@ -621,7 +621,7 @@ bool DeathTestImpl::Passed(bool status_ok) {
return
success
;
}
#
if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
// WindowsDeathTest implements death tests on Windows. Due to the
// specifics of starting new processes on Windows, death tests there are
// always threadsafe, and Google Test considers the
...
...
@@ -682,14 +682,12 @@ class WindowsDeathTest : public DeathTestImpl {
// status, or 0 if no child process exists. As a side effect, sets the
// outcome data member.
int
WindowsDeathTest
::
Wait
()
{
if
(
!
spawned
())
return
0
;
if
(
!
spawned
())
return
0
;
// Wait until the child either signals that it has acquired the write end
// of the pipe or it dies.
const
HANDLE
wait_handles
[
2
]
=
{
child_handle_
.
Get
(),
event_handle_
.
Get
()
};
switch
(
::
WaitForMultipleObjects
(
2
,
wait_handles
,
const
HANDLE
wait_handles
[
2
]
=
{
child_handle_
.
Get
(),
event_handle_
.
Get
()};
switch
(
::
WaitForMultipleObjects
(
2
,
wait_handles
,
FALSE
,
// Waits for any of the handles.
INFINITE
))
{
case
WAIT_OBJECT_0
:
...
...
@@ -710,9 +708,8 @@ int WindowsDeathTest::Wait() {
// returns immediately if the child has already exited, regardless of
// whether previous calls to WaitForMultipleObjects synchronized on this
// handle or not.
GTEST_DEATH_TEST_CHECK_
(
WAIT_OBJECT_0
==
::
WaitForSingleObject
(
child_handle_
.
Get
(),
INFINITE
));
GTEST_DEATH_TEST_CHECK_
(
WAIT_OBJECT_0
==
::
WaitForSingleObject
(
child_handle_
.
Get
(),
INFINITE
));
DWORD
status_code
;
GTEST_DEATH_TEST_CHECK_
(
::
GetExitCodeProcess
(
child_handle_
.
Get
(),
&
status_code
)
!=
FALSE
);
...
...
@@ -745,12 +742,12 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
SECURITY_ATTRIBUTES
handles_are_inheritable
=
{
sizeof
(
SECURITY_ATTRIBUTES
),
nullptr
,
TRUE
};
HANDLE
read_handle
,
write_handle
;
GTEST_DEATH_TEST_CHECK_
(
::
CreatePipe
(
&
read_handle
,
&
write_handle
,
&
handles_are_inheritable
,
0
)
// Default buffer size.
!=
FALSE
);
set_read_fd
(
::
_open_osfhandle
(
reinterpret_cast
<
intptr_t
>
(
read_handle
),
O_RDONLY
));
GTEST_DEATH_TEST_CHECK_
(
::
CreatePipe
(
&
read_handle
,
&
write_handle
,
&
handles_are_inheritable
,
0
)
// Default buffer size.
!=
FALSE
);
set_read_fd
(
::
_open_osfhandle
(
reinterpret_cast
<
intptr_t
>
(
read_handle
),
O_RDONLY
));
write_handle_
.
Reset
(
write_handle
);
event_handle_
.
Reset
(
::
CreateEvent
(
&
handles_are_inheritable
,
...
...
@@ -777,9 +774,8 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
executable_path
,
_MAX_PATH
));
std
::
string
command_line
=
std
::
string
(
::
GetCommandLineA
())
+
" "
+
filter_flag
+
"
\"
"
+
internal_flag
+
"
\"
"
;
std
::
string
command_line
=
std
::
string
(
::
GetCommandLineA
())
+
" "
+
filter_flag
+
"
\"
"
+
internal_flag
+
"
\"
"
;
DeathTest
::
set_last_death_test_message
(
""
);
...
...
@@ -812,7 +808,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
return
OVERSEE_TEST
;
}
#
elif GTEST_OS_FUCHSIA
#elif GTEST_OS_FUCHSIA
class
FuchsiaDeathTest
:
public
DeathTestImpl
{
public:
...
...
@@ -858,18 +854,13 @@ class Arguments {
template
<
typename
Str
>
void
AddArguments
(
const
::
std
::
vector
<
Str
>&
arguments
)
{
for
(
typename
::
std
::
vector
<
Str
>::
const_iterator
i
=
arguments
.
begin
();
i
!=
arguments
.
end
();
++
i
)
{
i
!=
arguments
.
end
();
++
i
)
{
args_
.
insert
(
args_
.
end
()
-
1
,
posix
::
StrDup
(
i
->
c_str
()));
}
}
char
*
const
*
Argv
()
{
return
&
args_
[
0
];
}
char
*
const
*
Argv
()
{
return
&
args_
[
0
];
}
int
size
()
{
return
static_cast
<
int
>
(
args_
.
size
())
-
1
;
}
int
size
()
{
return
static_cast
<
int
>
(
args_
.
size
())
-
1
;
}
private:
std
::
vector
<
char
*>
args_
;
...
...
@@ -883,8 +874,7 @@ int FuchsiaDeathTest::Wait() {
const
int
kSocketKey
=
1
;
const
int
kExceptionKey
=
2
;
if
(
!
spawned
())
return
0
;
if
(
!
spawned
())
return
0
;
// Create a port to wait for socket/task/exception events.
zx_status_t
status_zx
;
...
...
@@ -893,8 +883,8 @@ int FuchsiaDeathTest::Wait() {
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
// Register to wait for the child process to terminate.
status_zx
=
child_process_
.
wait_async
(
port
,
kProcessKey
,
ZX_PROCESS_TERMINATED
,
0
);
status_zx
=
child_process_
.
wait_async
(
port
,
kProcessKey
,
ZX_PROCESS_TERMINATED
,
0
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
// Register to wait for the socket to be readable or closed.
...
...
@@ -903,8 +893,8 @@ int FuchsiaDeathTest::Wait() {
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
// Register to wait for an exception.
status_zx
=
exception_channel_
.
wait_async
(
port
,
kExceptionKey
,
ZX_CHANNEL_READABLE
,
0
);
status_zx
=
exception_channel_
.
wait_async
(
port
,
kExceptionKey
,
ZX_CHANNEL_READABLE
,
0
);
GTEST_DEATH_TEST_CHECK_
(
status_zx
==
ZX_OK
);
bool
process_terminated
=
false
;
...
...
@@ -934,9 +924,9 @@ int FuchsiaDeathTest::Wait() {
size_t
old_length
=
captured_stderr_
.
length
();
size_t
bytes_read
=
0
;
captured_stderr_
.
resize
(
old_length
+
kBufferSize
);
status_zx
=
stderr_socket_
.
read
(
0
,
&
captured_stderr_
.
front
()
+
old_length
,
kBufferSize
,
&
bytes_read
);
status_zx
=
stderr_socket_
.
read
(
0
,
&
captured_stderr_
.
front
()
+
old_length
,
kBufferSize
,
&
bytes_read
);
captured_stderr_
.
resize
(
old_length
+
bytes_read
);
}
while
(
status_zx
==
ZX_OK
);
if
(
status_zx
==
ZX_ERR_PEER_CLOSED
)
{
...
...
@@ -992,11 +982,10 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
const
std
::
string
filter_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
"filter="
+
info
->
test_suite_name
()
+
"."
+
info
->
name
();
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
+
StreamableToString
(
line_
)
+
"|"
+
StreamableToString
(
death_test_index
);
const
std
::
string
internal_flag
=
std
::
string
(
"--"
)
+
GTEST_FLAG_PREFIX_
+
kInternalRunDeathTestFlag
+
"="
+
file_
+
"|"
+
StreamableToString
(
line_
)
+
"|"
+
StreamableToString
(
death_test_index
);
Arguments
args
;
args
.
AddArguments
(
GetInjectableArgvs
());
args
.
AddArgument
(
filter_flag
.
c_str
());
...
...
@@ -1019,8 +1008,7 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
// Create a socket pair will be used to receive the child process' stderr.
zx
::
socket
stderr_producer_socket
;
status
=
zx
::
socket
::
create
(
0
,
&
stderr_producer_socket
,
&
stderr_socket_
);
status
=
zx
::
socket
::
create
(
0
,
&
stderr_producer_socket
,
&
stderr_socket_
);
GTEST_DEATH_TEST_CHECK_
(
status
>=
0
);
int
stderr_producer_fd
=
-
1
;
status
=
...
...
@@ -1037,35 +1025,32 @@ DeathTest::TestRole FuchsiaDeathTest::AssumeRole() {
// Create a child job.
zx_handle_t
child_job
=
ZX_HANDLE_INVALID
;
status
=
zx_job_create
(
zx_job_default
(),
0
,
&
child_job
);
status
=
zx_job_create
(
zx_job_default
(),
0
,
&
child_job
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
zx_policy_basic_t
policy
;
policy
.
condition
=
ZX_POL_NEW_ANY
;
policy
.
policy
=
ZX_POL_ACTION_ALLOW
;
status
=
zx_job_set_policy
(
child_job
,
ZX_JOB_POL_RELATIVE
,
ZX_JOB_POL_BASIC
,
&
policy
,
1
);
status
=
zx_job_set_policy
(
child_job
,
ZX_JOB_POL_RELATIVE
,
ZX_JOB_POL_BASIC
,
&
policy
,
1
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Create an exception channel attached to the |child_job|, to allow
// us to suppress the system default exception handler from firing.
status
=
zx_task_create_exception_channel
(
child_job
,
0
,
exception_channel_
.
reset_and_get_address
());
status
=
zx_task_create_exception_channel
(
child_job
,
0
,
exception_channel_
.
reset_and_get_address
());
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
// Spawn the child process.
status
=
fdio_spawn_etc
(
child_job
,
FDIO_SPAWN_CLONE_ALL
,
args
.
Argv
()[
0
],
args
.
Argv
(),
nullptr
,
2
,
spawn_actions
,
child_process_
.
reset_and_get_address
(),
nullptr
);
status
=
fdio_spawn_etc
(
child_job
,
FDIO_SPAWN_CLONE_ALL
,
args
.
Argv
()[
0
],
args
.
Argv
(),
nullptr
,
2
,
spawn_actions
,
child_process_
.
reset_and_get_address
(),
nullptr
);
GTEST_DEATH_TEST_CHECK_
(
status
==
ZX_OK
);
set_spawned
(
true
);
return
OVERSEE_TEST
;
}
std
::
string
FuchsiaDeathTest
::
GetErrorLogs
()
{
return
captured_stderr_
;
}
std
::
string
FuchsiaDeathTest
::
GetErrorLogs
()
{
return
captured_stderr_
;
}
#else // We are neither on Windows, nor on Fuchsia.
...
...
@@ -1096,8 +1081,7 @@ ForkingDeathTest::ForkingDeathTest(const char* a_statement,
// status, or 0 if no child process exists. As a side effect, sets the
// outcome data member.
int
ForkingDeathTest
::
Wait
()
{
if
(
!
spawned
())
return
0
;
if
(
!
spawned
())
return
0
;
ReadAndInterpretStatusByte
();
...
...
@@ -1176,11 +1160,11 @@ class ExecDeathTest : public ForkingDeathTest {
private:
static
::
std
::
vector
<
std
::
string
>
GetArgvsForDeathTestChildProcess
()
{
::
std
::
vector
<
std
::
string
>
args
=
GetInjectableArgvs
();
#
if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
#if defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
::
std
::
vector
<
std
::
string
>
extra_args
=
GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_
();
args
.
insert
(
args
.
end
(),
extra_args
.
begin
(),
extra_args
.
end
());
#
endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
#endif // defined(GTEST_EXTRA_DEATH_TEST_COMMAND_LINE_ARGS_)
return
args
;
}
// The name of the file in which the death test is located.
...
...
@@ -1207,14 +1191,11 @@ class Arguments {
template
<
typename
Str
>
void
AddArguments
(
const
::
std
::
vector
<
Str
>&
arguments
)
{
for
(
typename
::
std
::
vector
<
Str
>::
const_iterator
i
=
arguments
.
begin
();
i
!=
arguments
.
end
();
++
i
)
{
i
!=
arguments
.
end
();
++
i
)
{
args_
.
insert
(
args_
.
end
()
-
1
,
posix
::
StrDup
(
i
->
c_str
()));
}
}
char
*
const
*
Argv
()
{
return
&
args_
[
0
];
}
char
*
const
*
Argv
()
{
return
&
args_
[
0
];
}
private:
std
::
vector
<
char
*>
args_
;
...
...
@@ -1227,9 +1208,9 @@ struct ExecDeathTestArgs {
int
close_fd
;
// File descriptor to close; the read end of a pipe
};
#
if GTEST_OS_QNX
#if GTEST_OS_QNX
extern
"C"
char
**
environ
;
#
else // GTEST_OS_QNX
#else
// GTEST_OS_QNX
// The main function for a threadsafe-style death test child process.
// This function is called in a clone()-ed process and thus must avoid
// any potentially unsafe operations like malloc or libc functions.
...
...
@@ -1244,8 +1225,8 @@ static int ExecDeathTestChildMain(void* child_arg) {
UnitTest
::
GetInstance
()
->
original_working_dir
();
// We can safely call chdir() as it's a direct system call.
if
(
chdir
(
original_dir
)
!=
0
)
{
DeathTestAbort
(
std
::
string
(
"chdir(
\"
"
)
+
original_dir
+
"
\"
) failed: "
+
GetLastErrnoDescription
());
DeathTestAbort
(
std
::
string
(
"chdir(
\"
"
)
+
original_dir
+
"
\"
) failed: "
+
GetLastErrnoDescription
());
return
EXIT_FAILURE
;
}
...
...
@@ -1256,13 +1237,12 @@ static int ExecDeathTestChildMain(void* child_arg) {
// one path separator.
execv
(
args
->
argv
[
0
],
args
->
argv
);
DeathTestAbort
(
std
::
string
(
"execv("
)
+
args
->
argv
[
0
]
+
", ...) in "
+
original_dir
+
" failed: "
+
GetLastErrnoDescription
());
original_dir
+
" failed: "
+
GetLastErrnoDescription
());
return
EXIT_FAILURE
;
}
#
endif // GTEST_OS_QNX
#endif // GTEST_OS_QNX
#
if GTEST_HAS_CLONE
#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
...
...
@@ -1296,7 +1276,7 @@ static bool StackGrowsDown() {
StackLowerThanAddress
(
&
dummy
,
&
result
);
return
result
;
}
#
endif // GTEST_HAS_CLONE
#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
...
...
@@ -1306,10 +1286,10 @@ static bool StackGrowsDown() {
// spawn(2) there instead. The function dies with an error message if
// anything goes wrong.
static
pid_t
ExecDeathTestSpawnChild
(
char
*
const
*
argv
,
int
close_fd
)
{
ExecDeathTestArgs
args
=
{
argv
,
close_fd
};
ExecDeathTestArgs
args
=
{
argv
,
close_fd
};
pid_t
child_pid
=
-
1
;
#
if GTEST_OS_QNX
#if GTEST_OS_QNX
// Obtains the current directory and sets it to be closed in the child
// process.
const
int
cwd_fd
=
open
(
"."
,
O_RDONLY
);
...
...
@@ -1322,16 +1302,16 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
UnitTest
::
GetInstance
()
->
original_working_dir
();
// We can safely call chdir() as it's a direct system call.
if
(
chdir
(
original_dir
)
!=
0
)
{
DeathTestAbort
(
std
::
string
(
"chdir(
\"
"
)
+
original_dir
+
"
\"
) failed: "
+
GetLastErrnoDescription
());
DeathTestAbort
(
std
::
string
(
"chdir(
\"
"
)
+
original_dir
+
"
\"
) failed: "
+
GetLastErrnoDescription
());
return
EXIT_FAILURE
;
}
int
fd_flags
;
// Set close_fd to be closed after spawn.
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
fd_flags
=
fcntl
(
close_fd
,
F_GETFD
));
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
fcntl
(
close_fd
,
F_SETFD
,
fd_flags
|
FD_CLOEXEC
));
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
fcntl
(
close_fd
,
F_SETFD
,
fd_flags
|
FD_CLOEXEC
));
struct
inheritance
inherit
=
{
0
};
// spawn is a system call.
child_pid
=
spawn
(
args
.
argv
[
0
],
0
,
nullptr
,
&
inherit
,
args
.
argv
,
environ
);
...
...
@@ -1339,8 +1319,8 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
GTEST_DEATH_TEST_CHECK_
(
fchdir
(
cwd_fd
)
!=
-
1
);
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
close
(
cwd_fd
));
#
else
// GTEST_OS_QNX
#
if GTEST_OS_LINUX
#else // GTEST_OS_QNX
#if GTEST_OS_LINUX
// When a SIGPROF signal is received while fork() or clone() are executing,
// the process may hang. To avoid this, we ignore SIGPROF here and re-enable
// it after the call to fork()/clone() is complete.
...
...
@@ -1349,11 +1329,11 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
memset
(
&
ignore_sigprof_action
,
0
,
sizeof
(
ignore_sigprof_action
));
sigemptyset
(
&
ignore_sigprof_action
.
sa_mask
);
ignore_sigprof_action
.
sa_handler
=
SIG_IGN
;
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
sigaction
(
SIGPROF
,
&
ignore_sigprof_action
,
&
saved_sigprof_action
));
#
endif // GTEST_OS_LINUX
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
sigaction
(
SIGPROF
,
&
ignore_sigprof_action
,
&
saved_sigprof_action
));
#endif // GTEST_OS_LINUX
#
if GTEST_HAS_CLONE
#if GTEST_HAS_CLONE
const
bool
use_fork
=
GTEST_FLAG_GET
(
death_test_use_fork
);
if
(
!
use_fork
)
{
...
...
@@ -1373,7 +1353,7 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
const
size_t
kMaxStackAlignment
=
64
;
void
*
const
stack_top
=
static_cast
<
char
*>
(
stack
)
+
(
stack_grows_down
?
stack_size
-
kMaxStackAlignment
:
0
);
(
stack_grows_down
?
stack_size
-
kMaxStackAlignment
:
0
);
GTEST_DEATH_TEST_CHECK_
(
static_cast
<
size_t
>
(
stack_size
)
>
kMaxStackAlignment
&&
reinterpret_cast
<
uintptr_t
>
(
stack_top
)
%
kMaxStackAlignment
==
0
);
...
...
@@ -1382,19 +1362,19 @@ static pid_t ExecDeathTestSpawnChild(char* const* argv, int close_fd) {
GTEST_DEATH_TEST_CHECK_
(
munmap
(
stack
,
stack_size
)
!=
-
1
);
}
#
else
#else
const
bool
use_fork
=
true
;
#
endif // GTEST_HAS_CLONE
#endif // GTEST_HAS_CLONE
if
(
use_fork
&&
(
child_pid
=
fork
())
==
0
)
{
ExecDeathTestChildMain
(
&
args
);
_exit
(
0
);
ExecDeathTestChildMain
(
&
args
);
_exit
(
0
);
}
#
endif // GTEST_OS_QNX
#
if GTEST_OS_LINUX
#endif // GTEST_OS_QNX
#if GTEST_OS_LINUX
GTEST_DEATH_TEST_CHECK_SYSCALL_
(
sigaction
(
SIGPROF
,
&
saved_sigprof_action
,
nullptr
));
#
endif // GTEST_OS_LINUX
#endif // GTEST_OS_LINUX
GTEST_DEATH_TEST_CHECK_
(
child_pid
!=
-
1
);
return
child_pid
;
...
...
@@ -1450,7 +1430,7 @@ DeathTest::TestRole ExecDeathTest::AssumeRole() {
return
OVERSEE_TEST
;
}
#
endif // !GTEST_OS_WINDOWS
#endif // !GTEST_OS_WINDOWS
// Creates a concrete DeathTest-derived class that depends on the
// --gtest_death_test_style flag, and sets the pointer pointed to
...
...
@@ -1464,15 +1444,15 @@ bool DefaultDeathTestFactory::Create(const char* statement,
UnitTestImpl
*
const
impl
=
GetUnitTestImpl
();
const
InternalRunDeathTestFlag
*
const
flag
=
impl
->
internal_run_death_test_flag
();
const
int
death_test_index
=
impl
->
current_test_info
()
->
increment_death_test_count
();
const
int
death_test_index
=
impl
->
current_test_info
()
->
increment_death_test_count
();
if
(
flag
!=
nullptr
)
{
if
(
death_test_index
>
flag
->
index
())
{
DeathTest
::
set_last_death_test_message
(
"Death test count ("
+
StreamableToString
(
death_test_index
)
+
") somehow exceeded expected maximum ("
+
StreamableToString
(
flag
->
index
())
+
")"
);
"Death test count ("
+
StreamableToString
(
death_test_index
)
+
") somehow exceeded expected maximum ("
+
StreamableToString
(
flag
->
index
())
+
")"
);
return
false
;
}
...
...
@@ -1483,21 +1463,21 @@ bool DefaultDeathTestFactory::Create(const char* statement,
}
}
#
if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
if
(
GTEST_FLAG_GET
(
death_test_style
)
==
"threadsafe"
||
GTEST_FLAG_GET
(
death_test_style
)
==
"fast"
)
{
*
test
=
new
WindowsDeathTest
(
statement
,
std
::
move
(
matcher
),
file
,
line
);
}
#
elif GTEST_OS_FUCHSIA
#elif GTEST_OS_FUCHSIA
if
(
GTEST_FLAG_GET
(
death_test_style
)
==
"threadsafe"
||
GTEST_FLAG_GET
(
death_test_style
)
==
"fast"
)
{
*
test
=
new
FuchsiaDeathTest
(
statement
,
std
::
move
(
matcher
),
file
,
line
);
}
#
else
#else
if
(
GTEST_FLAG_GET
(
death_test_style
)
==
"threadsafe"
)
{
*
test
=
new
ExecDeathTest
(
statement
,
std
::
move
(
matcher
),
file
,
line
);
...
...
@@ -1505,7 +1485,7 @@ bool DefaultDeathTestFactory::Create(const char* statement,
*
test
=
new
NoExecDeathTest
(
statement
,
std
::
move
(
matcher
));
}
#
endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
else
{
// NOLINT - this is more readable than unbalanced brackets inside #if.
DeathTest
::
set_last_death_test_message
(
"Unknown death test style
\"
"
+
...
...
@@ -1517,16 +1497,16 @@ bool DefaultDeathTestFactory::Create(const char* statement,
return
true
;
}
#
if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
// 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.
static
int
GetStatusFileDescriptor
(
unsigned
int
parent_process_id
,
size_t
write_handle_as_size_t
,
size_t
event_handle_as_size_t
)
{
size_t
write_handle_as_size_t
,
size_t
event_handle_as_size_t
)
{
AutoHandle
parent_process_handle
(
::
OpenProcess
(
PROCESS_DUP_HANDLE
,
FALSE
,
// Non-inheritable.
parent_process_id
));
FALSE
,
// Non-inheritable.
parent_process_id
));
if
(
parent_process_handle
.
Get
()
==
INVALID_HANDLE_VALUE
)
{
DeathTestAbort
(
"Unable to open parent process "
+
StreamableToString
(
parent_process_id
));
...
...
@@ -1534,8 +1514,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
GTEST_CHECK_
(
sizeof
(
HANDLE
)
<=
sizeof
(
size_t
));
const
HANDLE
write_handle
=
reinterpret_cast
<
HANDLE
>
(
write_handle_as_size_t
);
const
HANDLE
write_handle
=
reinterpret_cast
<
HANDLE
>
(
write_handle_as_size_t
);
HANDLE
dup_write_handle
;
// The newly initialized handle is accessible only in the parent
...
...
@@ -1557,9 +1536,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
HANDLE
dup_event_handle
;
if
(
!::
DuplicateHandle
(
parent_process_handle
.
Get
(),
event_handle
,
::
GetCurrentProcess
(),
&
dup_event_handle
,
0x0
,
FALSE
,
::
GetCurrentProcess
(),
&
dup_event_handle
,
0x0
,
FALSE
,
DUPLICATE_SAME_ACCESS
))
{
DeathTestAbort
(
"Unable to duplicate the event handle "
+
StreamableToString
(
event_handle_as_size_t
)
+
...
...
@@ -1581,7 +1558,7 @@ static int GetStatusFileDescriptor(unsigned int parent_process_id,
return
write_fd
;
}
#
endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
// Returns a newly created InternalRunDeathTestFlag object with fields
// initialized from the GTEST_FLAG(internal_run_death_test) flag if
...
...
@@ -1597,45 +1574,41 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
SplitString
(
GTEST_FLAG_GET
(
internal_run_death_test
),
'|'
,
&
fields
);
int
write_fd
=
-
1
;
#
if GTEST_OS_WINDOWS
#if GTEST_OS_WINDOWS
unsigned
int
parent_process_id
=
0
;
size_t
write_handle_as_size_t
=
0
;
size_t
event_handle_as_size_t
=
0
;
if
(
fields
.
size
()
!=
6
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
)
||
!
ParseNaturalNumber
(
fields
[
3
],
&
parent_process_id
)
||
!
ParseNaturalNumber
(
fields
[
4
],
&
write_handle_as_size_t
)
||
!
ParseNaturalNumber
(
fields
[
5
],
&
event_handle_as_size_t
))
{
if
(
fields
.
size
()
!=
6
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
)
||
!
ParseNaturalNumber
(
fields
[
3
],
&
parent_process_id
)
||
!
ParseNaturalNumber
(
fields
[
4
],
&
write_handle_as_size_t
)
||
!
ParseNaturalNumber
(
fields
[
5
],
&
event_handle_as_size_t
))
{
DeathTestAbort
(
"Bad --gtest_internal_run_death_test flag: "
+
GTEST_FLAG_GET
(
internal_run_death_test
));
}
write_fd
=
GetStatusFileDescriptor
(
parent_process_id
,
write_handle_as_size_t
,
write_fd
=
GetStatusFileDescriptor
(
parent_process_id
,
write_handle_as_size_t
,
event_handle_as_size_t
);
#
elif GTEST_OS_FUCHSIA
#elif GTEST_OS_FUCHSIA
if
(
fields
.
size
()
!=
3
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
))
{
if
(
fields
.
size
()
!=
3
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
))
{
DeathTestAbort
(
"Bad --gtest_internal_run_death_test flag: "
+
GTEST_FLAG_GET
(
internal_run_death_test
));
}
#
else
#else
if
(
fields
.
size
()
!=
4
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
)
||
!
ParseNaturalNumber
(
fields
[
3
],
&
write_fd
))
{
if
(
fields
.
size
()
!=
4
||
!
ParseNaturalNumber
(
fields
[
1
],
&
line
)
||
!
ParseNaturalNumber
(
fields
[
2
],
&
index
)
||
!
ParseNaturalNumber
(
fields
[
3
],
&
write_fd
))
{
DeathTestAbort
(
"Bad --gtest_internal_run_death_test flag: "
+
GTEST_FLAG_GET
(
internal_run_death_test
));
}
#
endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
return
new
InternalRunDeathTestFlag
(
fields
[
0
],
line
,
index
,
write_fd
);
}
...
...
googletest/src/gtest-filepath.cc
View file @
9e712372
...
...
@@ -30,29 +30,31 @@
#include "gtest/internal/gtest-filepath.h"
#include <stdlib.h>
#include "gtest/internal/gtest-port.h"
#include "gtest/gtest-message.h"
#include "gtest/internal/gtest-port.h"
#if GTEST_OS_WINDOWS_MOBILE
#
include <windows.h>
#include <windows.h>
#elif GTEST_OS_WINDOWS
#
include <direct.h>
#
include <io.h>
#include <direct.h>
#include <io.h>
#else
# include <limits.h>
# include <climits> // Some Linux distributions define PATH_MAX here.
#endif // GTEST_OS_WINDOWS_MOBILE
#include <limits.h>
#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
#define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX)
#
define GTEST_PATH_MAX_ PATH_MAX
#define GTEST_PATH_MAX_ PATH_MAX
#elif defined(_XOPEN_PATH_MAX)
#
define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
#define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
#else
#
define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#endif // GTEST_OS_WINDOWS
namespace
testing
{
...
...
@@ -66,16 +68,16 @@ namespace internal {
const
char
kPathSeparator
=
'\\'
;
const
char
kAlternatePathSeparator
=
'/'
;
const
char
kAlternatePathSeparatorString
[]
=
"/"
;
#
if GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback.
const
char
kCurrentDirectoryString
[]
=
"
\\
"
;
// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
const
DWORD
kInvalidFileAttributes
=
0xffffffff
;
#
else
#else
const
char
kCurrentDirectoryString
[]
=
".
\\
"
;
#
endif // GTEST_OS_WINDOWS_MOBILE
#endif // GTEST_OS_WINDOWS_MOBILE
#else
const
char
kPathSeparator
=
'/'
;
const
char
kCurrentDirectoryString
[]
=
"./"
;
...
...
@@ -99,17 +101,17 @@ FilePath FilePath::GetCurrentDir() {
// something reasonable.
return
FilePath
(
kCurrentDirectoryString
);
#elif GTEST_OS_WINDOWS
char
cwd
[
GTEST_PATH_MAX_
+
1
]
=
{
'\0'
};
char
cwd
[
GTEST_PATH_MAX_
+
1
]
=
{
'\0'
};
return
FilePath
(
_getcwd
(
cwd
,
sizeof
(
cwd
))
==
nullptr
?
""
:
cwd
);
#else
char
cwd
[
GTEST_PATH_MAX_
+
1
]
=
{
'\0'
};
char
cwd
[
GTEST_PATH_MAX_
+
1
]
=
{
'\0'
};
char
*
result
=
getcwd
(
cwd
,
sizeof
(
cwd
));
#
if GTEST_OS_NACL
#if GTEST_OS_NACL
// getcwd will likely fail in NaCl due to the sandbox, so return something
// reasonable. The user may have provided a shim implementation for getcwd,
// however, so fallback only when failure is detected.
return
FilePath
(
result
==
nullptr
?
kCurrentDirectoryString
:
cwd
);
#
endif // GTEST_OS_NACL
#endif // GTEST_OS_NACL
return
FilePath
(
result
==
nullptr
?
""
:
cwd
);
#endif // GTEST_OS_WINDOWS_MOBILE
}
...
...
@@ -121,8 +123,8 @@ FilePath FilePath::GetCurrentDir() {
FilePath
FilePath
::
RemoveExtension
(
const
char
*
extension
)
const
{
const
std
::
string
dot_extension
=
std
::
string
(
"."
)
+
extension
;
if
(
String
::
EndsWithCaseInsensitive
(
pathname_
,
dot_extension
))
{
return
FilePath
(
pathname_
.
substr
(
0
,
pathname_
.
length
()
-
dot_extension
.
length
()));
return
FilePath
(
pathname_
.
substr
(
0
,
pathname_
.
length
()
-
dot_extension
.
length
()));
}
return
*
this
;
}
...
...
@@ -178,15 +180,14 @@ FilePath FilePath::RemoveFileName() const {
// than zero (e.g., 12), returns "dir/test_12.xml".
// On Windows platform, uses \ as the separator rather than /.
FilePath
FilePath
::
MakeFileName
(
const
FilePath
&
directory
,
const
FilePath
&
base_name
,
int
number
,
const
FilePath
&
base_name
,
int
number
,
const
char
*
extension
)
{
std
::
string
file
;
if
(
number
==
0
)
{
file
=
base_name
.
string
()
+
"."
+
extension
;
}
else
{
file
=
base_name
.
string
()
+
"_"
+
StreamableToString
(
number
)
+
"."
+
extension
;
file
=
base_name
.
string
()
+
"_"
+
StreamableToString
(
number
)
+
"."
+
extension
;
}
return
ConcatPaths
(
directory
,
FilePath
(
file
));
}
...
...
@@ -195,8 +196,7 @@ FilePath FilePath::MakeFileName(const FilePath& directory,
// On Windows, uses \ as the separator rather than /.
FilePath
FilePath
::
ConcatPaths
(
const
FilePath
&
directory
,
const
FilePath
&
relative_path
)
{
if
(
directory
.
IsEmpty
())
return
relative_path
;
if
(
directory
.
IsEmpty
())
return
relative_path
;
const
FilePath
dir
(
directory
.
RemoveTrailingPathSeparator
());
return
FilePath
(
dir
.
string
()
+
kPathSeparator
+
relative_path
.
string
());
}
...
...
@@ -207,7 +207,7 @@ bool FilePath::FileOrDirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE
LPCWSTR
unicode
=
String
::
AnsiToUtf16
(
pathname_
.
c_str
());
const
DWORD
attributes
=
GetFileAttributes
(
unicode
);
delete
[]
unicode
;
delete
[]
unicode
;
return
attributes
!=
kInvalidFileAttributes
;
#else
posix
::
StatStruct
file_stat
{};
...
...
@@ -222,8 +222,8 @@ bool FilePath::DirectoryExists() const {
#if GTEST_OS_WINDOWS
// Don't strip off trailing separator if path is a root directory on
// Windows (like "C:\\").
const
FilePath
&
path
(
IsRootDirectory
()
?
*
this
:
RemoveTrailingPathSeparator
());
const
FilePath
&
path
(
IsRootDirectory
()
?
*
this
:
RemoveTrailingPathSeparator
());
#else
const
FilePath
&
path
(
*
this
);
#endif
...
...
@@ -231,15 +231,15 @@ bool FilePath::DirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE
LPCWSTR
unicode
=
String
::
AnsiToUtf16
(
path
.
c_str
());
const
DWORD
attributes
=
GetFileAttributes
(
unicode
);
delete
[]
unicode
;
delete
[]
unicode
;
if
((
attributes
!=
kInvalidFileAttributes
)
&&
(
attributes
&
FILE_ATTRIBUTE_DIRECTORY
))
{
result
=
true
;
}
#else
posix
::
StatStruct
file_stat
{};
result
=
posix
::
Stat
(
path
.
c_str
(),
&
file_stat
)
==
0
&&
posix
::
IsDir
(
file_stat
);
result
=
posix
::
Stat
(
path
.
c_str
(),
&
file_stat
)
==
0
&&
posix
::
IsDir
(
file_stat
);
#endif // GTEST_OS_WINDOWS_MOBILE
return
result
;
...
...
@@ -260,10 +260,9 @@ bool FilePath::IsAbsolutePath() const {
const
char
*
const
name
=
pathname_
.
c_str
();
#if GTEST_OS_WINDOWS
return
pathname_
.
length
()
>=
3
&&
((
name
[
0
]
>=
'a'
&&
name
[
0
]
<=
'z'
)
||
(
name
[
0
]
>=
'A'
&&
name
[
0
]
<=
'Z'
))
&&
name
[
1
]
==
':'
&&
IsPathSeparator
(
name
[
2
]);
((
name
[
0
]
>=
'a'
&&
name
[
0
]
<=
'z'
)
||
(
name
[
0
]
>=
'A'
&&
name
[
0
]
<=
'Z'
))
&&
name
[
1
]
==
':'
&&
IsPathSeparator
(
name
[
2
]);
#else
return
IsPathSeparator
(
name
[
0
]);
#endif
...
...
@@ -321,7 +320,7 @@ bool FilePath::CreateFolder() const {
FilePath
removed_sep
(
this
->
RemoveTrailingPathSeparator
());
LPCWSTR
unicode
=
String
::
AnsiToUtf16
(
removed_sep
.
c_str
());
int
result
=
CreateDirectory
(
unicode
,
nullptr
)
?
0
:
-
1
;
delete
[]
unicode
;
delete
[]
unicode
;
#elif GTEST_OS_WINDOWS
int
result
=
_mkdir
(
pathname_
.
c_str
());
#elif GTEST_OS_ESP8266 || GTEST_OS_XTENSA
...
...
@@ -341,9 +340,8 @@ bool FilePath::CreateFolder() const {
// name, otherwise return the name string unmodified.
// On Windows platform, uses \ as the separator, other platforms use /.
FilePath
FilePath
::
RemoveTrailingPathSeparator
()
const
{
return
IsDirectory
()
?
FilePath
(
pathname_
.
substr
(
0
,
pathname_
.
length
()
-
1
))
:
*
this
;
return
IsDirectory
()
?
FilePath
(
pathname_
.
substr
(
0
,
pathname_
.
length
()
-
1
))
:
*
this
;
}
// Removes any redundant separators that might be in the pathname.
...
...
googletest/src/gtest-internal-inl.h
View file @
9e712372
...
...
@@ -35,7 +35,7 @@
#define GOOGLETEST_SRC_GTEST_INTERNAL_INL_H_
#ifndef _WIN32_WCE
#
include <errno.h>
#include <errno.h>
#endif // !_WIN32_WCE
#include <stddef.h>
#include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
...
...
@@ -50,16 +50,16 @@
#include "gtest/internal/gtest-port.h"
#if GTEST_CAN_STREAM_RESULTS_
#
include <arpa/inet.h> // NOLINT
#
include <netdb.h> // NOLINT
#include <arpa/inet.h> // NOLINT
#include <netdb.h>
// NOLINT
#endif
#if GTEST_OS_WINDOWS
#
include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS
#include <windows.h> // NOLINT
#endif
// GTEST_OS_WINDOWS
#include "gtest/gtest.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_
(
4251
\
/* class A needs to have dll-interface to be used by clients of class B */
)
...
...
@@ -109,15 +109,16 @@ GTEST_API_ bool ParseFlag(const char* str, const char* flag, int32_t* value);
// Returns a random seed in range [1, kMaxRandomSeed] based on the
// given --gtest_random_seed flag value.
inline
int
GetRandomSeedFromFlag
(
int32_t
random_seed_flag
)
{
const
unsigned
int
raw_seed
=
(
random_seed_flag
==
0
)
?
static_cast
<
unsigned
int
>
(
GetTimeInMillis
())
:
static_cast
<
unsigned
int
>
(
random_seed_flag
);
const
unsigned
int
raw_seed
=
(
random_seed_flag
==
0
)
?
static_cast
<
unsigned
int
>
(
GetTimeInMillis
())
:
static_cast
<
unsigned
int
>
(
random_seed_flag
);
// Normalizes the actual seed to range [1, kMaxRandomSeed] such that
// it's easy to type.
const
int
normalized_seed
=
static_cast
<
int
>
((
raw_seed
-
1U
)
%
static_cast
<
unsigned
int
>
(
kMaxRandomSeed
))
+
1
;
static_cast
<
unsigned
int
>
(
kMaxRandomSeed
))
+
1
;
return
normalized_seed
;
}
...
...
@@ -261,8 +262,8 @@ GTEST_API_ int32_t Int32FromEnvOrDie(const char* env_var, int32_t default_val);
// returns true if and only if the test should be run on this shard. The test id
// is some arbitrary but unique non-negative integer assigned to each test
// method. Assumes that 0 <= shard_index < total_shards.
GTEST_API_
bool
ShouldRunTestOnShard
(
int
total_shards
,
int
shard_index
,
int
test_id
);
GTEST_API_
bool
ShouldRunTestOnShard
(
int
total_shards
,
int
shard_index
,
int
test_id
);
// STL container utilities.
...
...
@@ -274,8 +275,7 @@ inline int CountIf(const Container& c, Predicate predicate) {
// Solaris has a non-standard signature.
int
count
=
0
;
for
(
auto
it
=
c
.
begin
();
it
!=
c
.
end
();
++
it
)
{
if
(
predicate
(
*
it
))
++
count
;
if
(
predicate
(
*
it
))
++
count
;
}
return
count
;
}
...
...
@@ -459,7 +459,7 @@ struct TraceInfo {
// This is the default global test part result reporter used in UnitTestImpl.
// This class should only be used by UnitTestImpl.
class
DefaultGlobalTestPartResultReporter
:
public
TestPartResultReporterInterface
{
:
public
TestPartResultReporterInterface
{
public:
explicit
DefaultGlobalTestPartResultReporter
(
UnitTestImpl
*
unit_test
);
// Implements the TestPartResultReporterInterface. Reports the test part
...
...
@@ -728,9 +728,7 @@ class GTEST_API_ UnitTestImpl {
}
// Clears the results of ad-hoc test assertions.
void
ClearAdHocTestResult
()
{
ad_hoc_test_result_
.
Clear
();
}
void
ClearAdHocTestResult
()
{
ad_hoc_test_result_
.
Clear
();
}
// Adds a TestProperty to the current TestResult object when invoked in a
// context of a test or a test suite, or to the global property set. If the
...
...
@@ -738,10 +736,7 @@ class GTEST_API_ UnitTestImpl {
// updated.
void
RecordProperty
(
const
TestProperty
&
test_property
);
enum
ReactionToSharding
{
HONOR_SHARDING_PROTOCOL
,
IGNORE_SHARDING_PROTOCOL
};
enum
ReactionToSharding
{
HONOR_SHARDING_PROTOCOL
,
IGNORE_SHARDING_PROTOCOL
};
// Matches the full name of each test against the user-specified
// filter to decide whether the test should run, then records the
...
...
@@ -970,8 +965,9 @@ GTEST_API_ bool IsValidEscape(char ch);
GTEST_API_
bool
AtomMatchesChar
(
bool
escaped
,
char
pattern
,
char
ch
);
GTEST_API_
bool
ValidateRegex
(
const
char
*
regex
);
GTEST_API_
bool
MatchRegexAtHead
(
const
char
*
regex
,
const
char
*
str
);
GTEST_API_
bool
MatchRepetitionAndRegexAtHead
(
bool
escaped
,
char
ch
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
);
GTEST_API_
bool
MatchRepetitionAndRegexAtHead
(
bool
escaped
,
char
ch
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
);
GTEST_API_
bool
MatchRegexAnywhere
(
const
char
*
regex
,
const
char
*
str
);
#endif // GTEST_USES_SIMPLE_RE
...
...
@@ -1073,8 +1069,7 @@ class StreamingListener : public EmptyTestEventListener {
}
~
SocketWriter
()
override
{
if
(
sockfd_
!=
-
1
)
CloseConnection
();
if
(
sockfd_
!=
-
1
)
CloseConnection
();
}
// Sends a string to the socket.
...
...
@@ -1084,9 +1079,8 @@ class StreamingListener : public EmptyTestEventListener {
const
auto
len
=
static_cast
<
size_t
>
(
message
.
length
());
if
(
write
(
sockfd_
,
message
.
c_str
(),
len
)
!=
static_cast
<
ssize_t
>
(
len
))
{
GTEST_LOG_
(
WARNING
)
<<
"stream_result_to: failed to stream to "
<<
host_name_
<<
":"
<<
port_num_
;
GTEST_LOG_
(
WARNING
)
<<
"stream_result_to: failed to stream to "
<<
host_name_
<<
":"
<<
port_num_
;
}
}
...
...
@@ -1119,7 +1113,9 @@ class StreamingListener : public EmptyTestEventListener {
}
explicit
StreamingListener
(
AbstractSocketWriter
*
socket_writer
)
:
socket_writer_
(
socket_writer
)
{
Start
();
}
:
socket_writer_
(
socket_writer
)
{
Start
();
}
void
OnTestProgramStart
(
const
UnitTest
&
/* unit_test */
)
override
{
SendLn
(
"event=TestProgramStart"
);
...
...
@@ -1142,9 +1138,9 @@ class StreamingListener : public EmptyTestEventListener {
void
OnTestIterationEnd
(
const
UnitTest
&
unit_test
,
int
/* iteration */
)
override
{
SendLn
(
"event=TestIterationEnd&passed="
+
FormatBool
(
unit_test
.
Passed
())
+
"&
elapsed_time
="
+
StreamableToString
(
unit_test
.
elapsed_time
())
+
"ms"
);
SendLn
(
"event=TestIterationEnd&passed="
+
FormatBool
(
unit_test
.
Passed
())
+
"&elapsed_time="
+
StreamableToString
(
unit_test
.
elapsed_time
())
+
"ms"
);
}
// Note that "event=TestCaseStart" is a wire format and has to remain
...
...
@@ -1167,8 +1163,7 @@ class StreamingListener : public EmptyTestEventListener {
void
OnTestEnd
(
const
TestInfo
&
test_info
)
override
{
SendLn
(
"event=TestEnd&passed="
+
FormatBool
((
test_info
.
result
())
->
Passed
())
+
"&elapsed_time="
+
FormatBool
((
test_info
.
result
())
->
Passed
())
+
"&elapsed_time="
+
StreamableToString
((
test_info
.
result
())
->
elapsed_time
())
+
"ms"
);
}
...
...
googletest/src/gtest-matchers.cc
View file @
9e712372
...
...
@@ -32,12 +32,13 @@
// This file implements just enough of the matcher interface to allow
// EXPECT_DEATH and friends to accept a matcher argument.
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
#include "gtest/gtest-matchers.h"
#include <string>
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
namespace
testing
{
// Constructs a matcher that matches a const std::string& whose value is
...
...
googletest/src/gtest-port.cc
View file @
9e712372
...
...
@@ -27,61 +27,62 @@
// (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 "gtest/internal/gtest-port.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdint>
#include <fstream>
#include <memory>
#if GTEST_OS_WINDOWS
# include <windows.h>
# include <io.h>
# include <sys/stat.h>
# include <map> // Used in ThreadLocal.
# ifdef _MSC_VER
# include <crtdbg.h>
# endif // _MSC_VER
#include <io.h>
#include <sys/stat.h>
#include <windows.h>
#include <map> // Used in ThreadLocal.
#ifdef _MSC_VER
#include <crtdbg.h>
#endif // _MSC_VER
#else
#
include <unistd.h>
#include <unistd.h>
#endif // GTEST_OS_WINDOWS
#if GTEST_OS_MAC
#
include <mach/mach_init.h>
#
include <mach/task.h>
#
include <mach/vm_map.h>
#include <mach/mach_init.h>
#include <mach/task.h>
#include <mach/vm_map.h>
#endif // GTEST_OS_MAC
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
GTEST_OS_NETBSD || GTEST_OS_OPENBSD
#
include <sys/sysctl.h>
#
if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD
#
include <sys/user.h>
#
endif
#include <sys/sysctl.h>
#if GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD
#include <sys/user.h>
#endif
#endif
#if GTEST_OS_QNX
#
include <devctl.h>
#
include <fcntl.h>
#
include <sys/procfs.h>
#include <devctl.h>
#include <fcntl.h>
#include <sys/procfs.h>
#endif // GTEST_OS_QNX
#if GTEST_OS_AIX
#
include <procinfo.h>
#
include <sys/types.h>
#include <procinfo.h>
#include <sys/types.h>
#endif // GTEST_OS_AIX
#if GTEST_OS_FUCHSIA
#
include <zircon/process.h>
#
include <zircon/syscalls.h>
#include <zircon/process.h>
#include <zircon/syscalls.h>
#endif // GTEST_OS_FUCHSIA
#include "gtest/gtest-spi.h"
#include "gtest/gtest-message.h"
#include "gtest/gtest-spi.h"
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-string.h"
#include "src/gtest-internal-inl.h"
...
...
@@ -131,8 +132,7 @@ size_t GetThreadCount() {
if
(
status
==
KERN_SUCCESS
)
{
// task_threads allocates resources in thread_list and we need to free them
// to avoid leaks.
vm_deallocate
(
task
,
reinterpret_cast
<
vm_address_t
>
(
thread_list
),
vm_deallocate
(
task
,
reinterpret_cast
<
vm_address_t
>
(
thread_list
),
sizeof
(
thread_t
)
*
thread_count
);
return
static_cast
<
size_t
>
(
thread_count
);
}
else
{
...
...
@@ -141,7 +141,7 @@ size_t GetThreadCount() {
}
#elif GTEST_OS_DRAGONFLY || GTEST_OS_FREEBSD || GTEST_OS_GNU_KFREEBSD || \
GTEST_OS_NETBSD
GTEST_OS_NETBSD
#if GTEST_OS_NETBSD
#undef KERN_PROC
...
...
@@ -184,12 +184,12 @@ size_t GetThreadCount() {
// we cannot detect it.
size_t
GetThreadCount
()
{
int
mib
[]
=
{
CTL_KERN
,
KERN_PROC
,
KERN_PROC_PID
|
KERN_PROC_SHOW_THREADS
,
getpid
(),
sizeof
(
struct
kinfo_proc
),
0
,
CTL_KERN
,
KERN_PROC
,
KERN_PROC_PID
|
KERN_PROC_SHOW_THREADS
,
getpid
(),
sizeof
(
struct
kinfo_proc
),
0
,
};
u_int
miblen
=
sizeof
(
mib
)
/
sizeof
(
mib
[
0
]);
...
...
@@ -210,8 +210,7 @@ size_t GetThreadCount() {
// exclude empty members
size_t
nthreads
=
0
;
for
(
size_t
i
=
0
;
i
<
size
/
static_cast
<
size_t
>
(
mib
[
4
]);
i
++
)
{
if
(
info
[
i
].
p_tid
!=
-
1
)
nthreads
++
;
if
(
info
[
i
].
p_tid
!=
-
1
)
nthreads
++
;
}
return
nthreads
;
}
...
...
@@ -254,13 +253,9 @@ size_t GetThreadCount() {
size_t
GetThreadCount
()
{
int
dummy_buffer
;
size_t
avail
;
zx_status_t
status
=
zx_object_get_info
(
zx_process_self
(),
ZX_INFO_PROCESS_THREADS
,
&
dummy_buffer
,
0
,
nullptr
,
&
avail
);
zx_status_t
status
=
zx_object_get_info
(
zx_process_self
(),
ZX_INFO_PROCESS_THREADS
,
&
dummy_buffer
,
0
,
nullptr
,
&
avail
);
if
(
status
==
ZX_OK
)
{
return
avail
;
}
else
{
...
...
@@ -280,23 +275,15 @@ size_t GetThreadCount() {
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
AutoHandle
::
AutoHandle
()
:
handle_
(
INVALID_HANDLE_VALUE
)
{}
AutoHandle
::
AutoHandle
()
:
handle_
(
INVALID_HANDLE_VALUE
)
{}
AutoHandle
::
AutoHandle
(
Handle
handle
)
:
handle_
(
handle
)
{}
AutoHandle
::
AutoHandle
(
Handle
handle
)
:
handle_
(
handle
)
{}
AutoHandle
::~
AutoHandle
()
{
Reset
();
}
AutoHandle
::~
AutoHandle
()
{
Reset
();
}
AutoHandle
::
Handle
AutoHandle
::
Get
()
const
{
return
handle_
;
}
AutoHandle
::
Handle
AutoHandle
::
Get
()
const
{
return
handle_
;
}
void
AutoHandle
::
Reset
()
{
Reset
(
INVALID_HANDLE_VALUE
);
}
void
AutoHandle
::
Reset
()
{
Reset
(
INVALID_HANDLE_VALUE
);
}
void
AutoHandle
::
Reset
(
HANDLE
handle
)
{
// Resetting with the same handle we already own is invalid.
...
...
@@ -308,7 +295,7 @@ void AutoHandle::Reset(HANDLE handle) {
}
else
{
GTEST_CHECK_
(
!
IsCloseable
())
<<
"Resetting a valid handle to itself is likely a programmer error "
"and thus not allowed."
;
"and thus not allowed."
;
}
}
...
...
@@ -370,8 +357,7 @@ namespace {
// MemoryIsNotDeallocated memory_is_not_deallocated;
// critical_section_ = new CRITICAL_SECTION;
//
class
MemoryIsNotDeallocated
{
class
MemoryIsNotDeallocated
{
public:
MemoryIsNotDeallocated
()
:
old_crtdbg_flag_
(
0
)
{
old_crtdbg_flag_
=
_CrtSetDbgFlag
(
_CRTDBG_REPORT_FLAG
);
...
...
@@ -414,15 +400,13 @@ void Mutex::ThreadSafeLazyInit() {
::
InitializeCriticalSection
(
critical_section_
);
// Updates the critical_section_init_phase_ to 2 to signal
// initialization complete.
GTEST_CHECK_
(
::
InterlockedCompareExchange
(
&
critical_section_init_phase_
,
2L
,
1L
)
==
1L
);
GTEST_CHECK_
(
::
InterlockedCompareExchange
(
&
critical_section_init_phase_
,
2L
,
1L
)
==
1L
);
break
;
case
1
:
// Somebody else is already initializing the mutex; spin until they
// are done.
while
(
::
InterlockedCompareExchange
(
&
critical_section_init_phase_
,
2L
,
while
(
::
InterlockedCompareExchange
(
&
critical_section_init_phase_
,
2L
,
2L
)
!=
2L
)
{
// Possibly yields the rest of the thread's time slice to other
// threads.
...
...
@@ -467,9 +451,7 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
private:
struct
ThreadMainParam
{
ThreadMainParam
(
Runnable
*
runnable
,
Notification
*
thread_can_start
)
:
runnable_
(
runnable
),
thread_can_start_
(
thread_can_start
)
{
}
:
runnable_
(
runnable
),
thread_can_start_
(
thread_can_start
)
{}
std
::
unique_ptr
<
Runnable
>
runnable_
;
// Does not own.
Notification
*
thread_can_start_
;
...
...
@@ -492,15 +474,12 @@ class ThreadWithParamSupport : public ThreadWithParamBase {
}
// namespace
ThreadWithParamBase
::
ThreadWithParamBase
(
Runnable
*
runnable
,
ThreadWithParamBase
::
ThreadWithParamBase
(
Runnable
*
runnable
,
Notification
*
thread_can_start
)
:
thread_
(
ThreadWithParamSupport
::
CreateThread
(
runnable
,
thread_can_start
))
{
}
:
thread_
(
ThreadWithParamSupport
::
CreateThread
(
runnable
,
thread_can_start
))
{}
ThreadWithParamBase
::~
ThreadWithParamBase
()
{
Join
();
}
ThreadWithParamBase
::~
ThreadWithParamBase
()
{
Join
();
}
void
ThreadWithParamBase
::
Join
()
{
GTEST_CHECK_
(
::
WaitForSingleObject
(
thread_
.
Get
(),
INFINITE
)
==
WAIT_OBJECT_0
)
...
...
@@ -527,8 +506,10 @@ class ThreadLocalRegistryImpl {
ThreadIdToThreadLocals
::
iterator
thread_local_pos
=
thread_to_thread_locals
->
find
(
current_thread
);
if
(
thread_local_pos
==
thread_to_thread_locals
->
end
())
{
thread_local_pos
=
thread_to_thread_locals
->
insert
(
std
::
make_pair
(
current_thread
,
ThreadLocalValues
())).
first
;
thread_local_pos
=
thread_to_thread_locals
->
insert
(
std
::
make_pair
(
current_thread
,
ThreadLocalValues
()))
.
first
;
StartWatcherThreadFor
(
current_thread
);
}
ThreadLocalValues
&
thread_local_values
=
thread_local_pos
->
second
;
...
...
@@ -556,9 +537,8 @@ class ThreadLocalRegistryImpl {
ThreadIdToThreadLocals
*
const
thread_to_thread_locals
=
GetThreadLocalsMapLocked
();
for
(
ThreadIdToThreadLocals
::
iterator
it
=
thread_to_thread_locals
->
begin
();
it
!=
thread_to_thread_locals
->
end
();
++
it
)
{
thread_to_thread_locals
->
begin
();
it
!=
thread_to_thread_locals
->
end
();
++
it
)
{
ThreadLocalValues
&
thread_local_values
=
it
->
second
;
ThreadLocalValues
::
iterator
value_pos
=
thread_local_values
.
find
(
thread_local_instance
);
...
...
@@ -588,9 +568,8 @@ class ThreadLocalRegistryImpl {
if
(
thread_local_pos
!=
thread_to_thread_locals
->
end
())
{
ThreadLocalValues
&
thread_local_values
=
thread_local_pos
->
second
;
for
(
ThreadLocalValues
::
iterator
value_pos
=
thread_local_values
.
begin
();
value_pos
!=
thread_local_values
.
end
();
++
value_pos
)
{
thread_local_values
.
begin
();
value_pos
!=
thread_local_values
.
end
();
++
value_pos
)
{
value_holders
.
push_back
(
value_pos
->
second
);
}
thread_to_thread_locals
->
erase
(
thread_local_pos
);
...
...
@@ -616,9 +595,8 @@ class ThreadLocalRegistryImpl {
static
void
StartWatcherThreadFor
(
DWORD
thread_id
)
{
// The returned handle will be kept in thread_map and closed by
// watcher_thread in WatcherThreadFunc.
HANDLE
thread
=
::
OpenThread
(
SYNCHRONIZE
|
THREAD_QUERY_INFORMATION
,
FALSE
,
thread_id
);
HANDLE
thread
=
::
OpenThread
(
SYNCHRONIZE
|
THREAD_QUERY_INFORMATION
,
FALSE
,
thread_id
);
GTEST_CHECK_
(
thread
!=
nullptr
);
// We need to pass a valid thread ID pointer into CreateThread for it
// to work correctly under Win98.
...
...
@@ -644,8 +622,7 @@ class ThreadLocalRegistryImpl {
static
DWORD
WINAPI
WatcherThreadFunc
(
LPVOID
param
)
{
const
ThreadIdAndHandle
*
tah
=
reinterpret_cast
<
const
ThreadIdAndHandle
*>
(
param
);
GTEST_CHECK_
(
::
WaitForSingleObject
(
tah
->
second
,
INFINITE
)
==
WAIT_OBJECT_0
);
GTEST_CHECK_
(
::
WaitForSingleObject
(
tah
->
second
,
INFINITE
)
==
WAIT_OBJECT_0
);
OnThreadExit
(
tah
->
first
);
::
CloseHandle
(
tah
->
second
);
delete
tah
;
...
...
@@ -669,16 +646,17 @@ class ThreadLocalRegistryImpl {
};
Mutex
ThreadLocalRegistryImpl
::
mutex_
(
Mutex
::
kStaticMutex
);
// NOLINT
Mutex
ThreadLocalRegistryImpl
::
thread_map_mutex_
(
Mutex
::
kStaticMutex
);
// NOLINT
Mutex
ThreadLocalRegistryImpl
::
thread_map_mutex_
(
Mutex
::
kStaticMutex
);
// NOLINT
ThreadLocalValueHolderBase
*
ThreadLocalRegistry
::
GetValueOnCurrentThread
(
const
ThreadLocalBase
*
thread_local_instance
)
{
const
ThreadLocalBase
*
thread_local_instance
)
{
return
ThreadLocalRegistryImpl
::
GetValueOnCurrentThread
(
thread_local_instance
);
}
void
ThreadLocalRegistry
::
OnThreadLocalDestroyed
(
const
ThreadLocalBase
*
thread_local_instance
)
{
const
ThreadLocalBase
*
thread_local_instance
)
{
ThreadLocalRegistryImpl
::
OnThreadLocalDestroyed
(
thread_local_instance
);
}
...
...
@@ -766,7 +744,7 @@ bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); }
bool
IsAsciiWhiteSpace
(
char
ch
)
{
return
IsInSet
(
ch
,
"
\f\n\r\t\v
"
);
}
bool
IsAsciiWordChar
(
char
ch
)
{
return
(
'a'
<=
ch
&&
ch
<=
'z'
)
||
(
'A'
<=
ch
&&
ch
<=
'Z'
)
||
(
'0'
<=
ch
&&
ch
<=
'9'
)
||
ch
==
'_'
;
(
'0'
<=
ch
&&
ch
<=
'9'
)
||
ch
==
'_'
;
}
// Returns true if and only if "\\c" is a supported escape sequence.
...
...
@@ -779,17 +757,28 @@ bool IsValidEscape(char c) {
bool
AtomMatchesChar
(
bool
escaped
,
char
pattern_char
,
char
ch
)
{
if
(
escaped
)
{
// "\\p" where p is pattern_char.
switch
(
pattern_char
)
{
case
'd'
:
return
IsAsciiDigit
(
ch
);
case
'D'
:
return
!
IsAsciiDigit
(
ch
);
case
'f'
:
return
ch
==
'\f'
;
case
'n'
:
return
ch
==
'\n'
;
case
'r'
:
return
ch
==
'\r'
;
case
's'
:
return
IsAsciiWhiteSpace
(
ch
);
case
'S'
:
return
!
IsAsciiWhiteSpace
(
ch
);
case
't'
:
return
ch
==
'\t'
;
case
'v'
:
return
ch
==
'\v'
;
case
'w'
:
return
IsAsciiWordChar
(
ch
);
case
'W'
:
return
!
IsAsciiWordChar
(
ch
);
case
'd'
:
return
IsAsciiDigit
(
ch
);
case
'D'
:
return
!
IsAsciiDigit
(
ch
);
case
'f'
:
return
ch
==
'\f'
;
case
'n'
:
return
ch
==
'\n'
;
case
'r'
:
return
ch
==
'\r'
;
case
's'
:
return
IsAsciiWhiteSpace
(
ch
);
case
'S'
:
return
!
IsAsciiWhiteSpace
(
ch
);
case
't'
:
return
ch
==
'\t'
;
case
'v'
:
return
ch
==
'\v'
;
case
'w'
:
return
IsAsciiWordChar
(
ch
);
case
'W'
:
return
!
IsAsciiWordChar
(
ch
);
}
return
IsAsciiPunct
(
pattern_char
)
&&
pattern_char
==
ch
;
}
...
...
@@ -800,7 +789,8 @@ bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
// Helper function used by ValidateRegex() to format error messages.
static
std
::
string
FormatRegexSyntaxError
(
const
char
*
regex
,
int
index
)
{
return
(
Message
()
<<
"Syntax error at index "
<<
index
<<
" in simple regular expression
\"
"
<<
regex
<<
"
\"
: "
).
GetString
();
<<
" in simple regular expression
\"
"
<<
regex
<<
"
\"
: "
)
.
GetString
();
}
// Generates non-fatal failures and returns false if regex is invalid;
...
...
@@ -842,12 +832,12 @@ bool ValidateRegex(const char* regex) {
<<
"'$' can only appear at the end."
;
is_valid
=
false
;
}
else
if
(
IsInSet
(
ch
,
"()[]{}|"
))
{
ADD_FAILURE
()
<<
FormatRegexSyntaxError
(
regex
,
i
)
<<
"'"
<<
ch
<<
"' is unsupported."
;
ADD_FAILURE
()
<<
FormatRegexSyntaxError
(
regex
,
i
)
<<
"'"
<<
ch
<<
"' is unsupported."
;
is_valid
=
false
;
}
else
if
(
IsRepeat
(
ch
)
&&
!
prev_repeatable
)
{
ADD_FAILURE
()
<<
FormatRegexSyntaxError
(
regex
,
i
)
<<
"'"
<<
ch
<<
"' can only follow a repeatable token."
;
ADD_FAILURE
()
<<
FormatRegexSyntaxError
(
regex
,
i
)
<<
"'"
<<
ch
<<
"' can only follow a repeatable token."
;
is_valid
=
false
;
}
...
...
@@ -865,12 +855,10 @@ bool ValidateRegex(const char* regex) {
// characters to be indexable by size_t, in which case the test will
// probably time out anyway. We are fine with this limitation as
// std::string has it too.
bool
MatchRepetitionAndRegexAtHead
(
bool
escaped
,
char
c
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
)
{
bool
MatchRepetitionAndRegexAtHead
(
bool
escaped
,
char
c
,
char
repeat
,
const
char
*
regex
,
const
char
*
str
)
{
const
size_t
min_count
=
(
repeat
==
'+'
)
?
1
:
0
;
const
size_t
max_count
=
(
repeat
==
'?'
)
?
1
:
static_cast
<
size_t
>
(
-
1
)
-
1
;
const
size_t
max_count
=
(
repeat
==
'?'
)
?
1
:
static_cast
<
size_t
>
(
-
1
)
-
1
;
// We cannot call numeric_limits::max() as it conflicts with the
// max() macro on Windows.
...
...
@@ -883,8 +871,7 @@ bool MatchRepetitionAndRegexAtHead(
// greedy match.
return
true
;
}
if
(
str
[
i
]
==
'\0'
||
!
AtomMatchesChar
(
escaped
,
c
,
str
[
i
]))
return
false
;
if
(
str
[
i
]
==
'\0'
||
!
AtomMatchesChar
(
escaped
,
c
,
str
[
i
]))
return
false
;
}
return
false
;
}
...
...
@@ -898,25 +885,23 @@ bool MatchRegexAtHead(const char* regex, const char* str) {
// "$" only matches the end of a string. Note that regex being
// valid guarantees that there's nothing after "$" in it.
if
(
*
regex
==
'$'
)
return
*
str
==
'\0'
;
if
(
*
regex
==
'$'
)
return
*
str
==
'\0'
;
// Is the first thing in regex an escape sequence?
const
bool
escaped
=
*
regex
==
'\\'
;
if
(
escaped
)
++
regex
;
if
(
escaped
)
++
regex
;
if
(
IsRepeat
(
regex
[
1
]))
{
// MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so
// here's an indirect recursion. It terminates as the regex gets
// shorter in each recursion.
return
MatchRepetitionAndRegexAtHead
(
escaped
,
regex
[
0
],
regex
[
1
],
regex
+
2
,
str
);
return
MatchRepetitionAndRegexAtHead
(
escaped
,
regex
[
0
],
regex
[
1
],
regex
+
2
,
str
);
}
else
{
// regex isn't empty, isn't "$", and doesn't start with a
// repetition. We match the first atom of regex with the first
// character of str and recurse.
return
(
*
str
!=
'\0'
)
&&
AtomMatchesChar
(
escaped
,
*
regex
,
*
str
)
&&
MatchRegexAtHead
(
regex
+
1
,
str
+
1
);
MatchRegexAtHead
(
regex
+
1
,
str
+
1
);
}
}
...
...
@@ -931,13 +916,11 @@ bool MatchRegexAtHead(const char* regex, const char* str) {
bool
MatchRegexAnywhere
(
const
char
*
regex
,
const
char
*
str
)
{
if
(
regex
==
nullptr
||
str
==
nullptr
)
return
false
;
if
(
*
regex
==
'^'
)
return
MatchRegexAtHead
(
regex
+
1
,
str
);
if
(
*
regex
==
'^'
)
return
MatchRegexAtHead
(
regex
+
1
,
str
);
// A successful match can be anywhere in str.
do
{
if
(
MatchRegexAtHead
(
regex
,
str
))
return
true
;
if
(
MatchRegexAtHead
(
regex
,
str
))
return
true
;
}
while
(
*
str
++
!=
'\0'
);
return
false
;
}
...
...
@@ -1018,8 +1001,8 @@ GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
// FormatFileLocation in order to contrast the two functions.
// Note that FormatCompilerIndependentFileLocation() does NOT append colon
// to the file location it produces, unlike FormatFileLocation().
GTEST_API_
::
std
::
string
FormatCompilerIndependentFileLocation
(
const
char
*
file
,
int
line
)
{
GTEST_API_
::
std
::
string
FormatCompilerIndependentFileLocation
(
const
char
*
file
,
int
line
)
{
const
std
::
string
file_name
(
file
==
nullptr
?
kUnknownFile
:
file
);
if
(
line
<
0
)
...
...
@@ -1030,12 +1013,13 @@ GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
GTestLog
::
GTestLog
(
GTestLogSeverity
severity
,
const
char
*
file
,
int
line
)
:
severity_
(
severity
)
{
const
char
*
const
marker
=
severity
==
GTEST_INFO
?
"[ INFO ]"
:
severity
==
GTEST_WARNING
?
"[WARNING]"
:
severity
==
GTEST_ERROR
?
"[ ERROR ]"
:
"[ FATAL ]"
;
GetStream
()
<<
::
std
::
endl
<<
marker
<<
" "
<<
FormatFileLocation
(
file
,
line
).
c_str
()
<<
": "
;
const
char
*
const
marker
=
severity
==
GTEST_INFO
?
"[ INFO ]"
:
severity
==
GTEST_WARNING
?
"[WARNING]"
:
severity
==
GTEST_ERROR
?
"[ ERROR ]"
:
"[ FATAL ]"
;
GetStream
()
<<
::
std
::
endl
<<
marker
<<
" "
<<
FormatFileLocation
(
file
,
line
).
c_str
()
<<
": "
;
}
// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
...
...
@@ -1058,27 +1042,26 @@ class CapturedStream {
public:
// The ctor redirects the stream to a temporary file.
explicit
CapturedStream
(
int
fd
)
:
fd_
(
fd
),
uncaptured_fd_
(
dup
(
fd
))
{
#
if GTEST_OS_WINDOWS
char
temp_dir_path
[
MAX_PATH
+
1
]
=
{
'\0'
};
// NOLINT
char
temp_file_path
[
MAX_PATH
+
1
]
=
{
'\0'
};
// NOLINT
#if GTEST_OS_WINDOWS
char
temp_dir_path
[
MAX_PATH
+
1
]
=
{
'\0'
};
// NOLINT
char
temp_file_path
[
MAX_PATH
+
1
]
=
{
'\0'
};
// NOLINT
::
GetTempPathA
(
sizeof
(
temp_dir_path
),
temp_dir_path
);
const
UINT
success
=
::
GetTempFileNameA
(
temp_dir_path
,
"gtest_redir"
,
const
UINT
success
=
::
GetTempFileNameA
(
temp_dir_path
,
"gtest_redir"
,
0
,
// Generate unique file name.
temp_file_path
);
GTEST_CHECK_
(
success
!=
0
)
<<
"Unable to create a temporary file in "
<<
temp_dir_path
;
const
int
captured_fd
=
creat
(
temp_file_path
,
_S_IREAD
|
_S_IWRITE
);
GTEST_CHECK_
(
captured_fd
!=
-
1
)
<<
"Unable to open temporary file "
<<
temp_file_path
;
GTEST_CHECK_
(
captured_fd
!=
-
1
)
<<
"Unable to open temporary file "
<<
temp_file_path
;
filename_
=
temp_file_path
;
#
else
#else
// There's no guarantee that a test has write access to the current
// directory, so we create the temporary file in a temporary directory.
std
::
string
name_template
;
#
if GTEST_OS_LINUX_ANDROID
#if GTEST_OS_LINUX_ANDROID
// Note: Android applications are expected to call the framework's
// Context.getExternalStorageDirectory() method through JNI to get
// the location of the world-writable SD Card directory. However,
...
...
@@ -1091,7 +1074,7 @@ class CapturedStream {
// '/sdcard' and other variants cannot be relied on, as they are not
// guaranteed to be mounted, or may have a delay in mounting.
name_template
=
"/data/local/tmp/"
;
#
elif GTEST_OS_IOS
#elif GTEST_OS_IOS
char
user_temp_dir
[
PATH_MAX
+
1
];
// Documented alternative to NSTemporaryDirectory() (for obtaining creating
...
...
@@ -1112,9 +1095,9 @@ class CapturedStream {
name_template
=
user_temp_dir
;
if
(
name_template
.
back
()
!=
GTEST_PATH_SEP_
[
0
])
name_template
.
push_back
(
GTEST_PATH_SEP_
[
0
]);
#
else
#else
name_template
=
"/tmp/"
;
#
endif
#endif
name_template
.
append
(
"gtest_captured_stream.XXXXXX"
);
// mkstemp() modifies the string bytes in place, and does not go beyond the
...
...
@@ -1130,15 +1113,13 @@ class CapturedStream {
<<
" for test; does the test have access to the /tmp directory?"
;
}
filename_
=
std
::
move
(
name_template
);
#
endif // GTEST_OS_WINDOWS
#endif // GTEST_OS_WINDOWS
fflush
(
nullptr
);
dup2
(
captured_fd
,
fd_
);
close
(
captured_fd
);
}
~
CapturedStream
()
{
remove
(
filename_
.
c_str
());
}
~
CapturedStream
()
{
remove
(
filename_
.
c_str
());
}
std
::
string
GetCapturedString
()
{
if
(
uncaptured_fd_
!=
-
1
)
{
...
...
@@ -1215,10 +1196,6 @@ 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
));
...
...
@@ -1236,7 +1213,8 @@ std::string ReadEntireFile(FILE* file) {
// Keeps reading the file until we cannot read further or the
// pre-determined file size is reached.
do
{
bytes_last_read
=
fread
(
buffer
+
bytes_read
,
1
,
file_size
-
bytes_read
,
file
);
bytes_last_read
=
fread
(
buffer
+
bytes_read
,
1
,
file_size
-
bytes_read
,
file
);
bytes_read
+=
bytes_last_read
;
}
while
(
bytes_last_read
>
0
&&
bytes_read
<
file_size
);
...
...
@@ -1324,7 +1302,7 @@ bool ParseInt32(const Message& src_text, const char* str, int32_t* value) {
// LONG_MAX or LONG_MIN when the input overflows.)
result
!=
long_value
// The parsed value overflows as an int32_t.
)
{
)
{
Message
msg
;
msg
<<
"WARNING: "
<<
src_text
<<
" is expected to be a 32-bit integer, but actually"
...
...
@@ -1368,8 +1346,8 @@ int32_t Int32FromGTestEnv(const char* flag, int32_t default_value) {
}
int32_t
result
=
default_value
;
if
(
!
ParseInt32
(
Message
()
<<
"Environment variable "
<<
env_var
,
string_value
,
&
result
))
{
if
(
!
ParseInt32
(
Message
()
<<
"Environment variable "
<<
env_var
,
string_value
,
&
result
))
{
printf
(
"The default value %s is used.
\n
"
,
(
Message
()
<<
default_value
).
GetString
().
c_str
());
fflush
(
stdout
);
...
...
@@ -1388,7 +1366,7 @@ int32_t Int32FromGTestEnv(const char* flag, int32_t default_value) {
// not check that the flag is 'output'
// In essence this checks an env variable called XML_OUTPUT_FILE
// and if it is set we prepend "xml:" to its value, if it not set we return ""
std
::
string
OutputFlagAlsoCheckEnvVar
(){
std
::
string
OutputFlagAlsoCheckEnvVar
()
{
std
::
string
default_value_for_output_flag
=
""
;
const
char
*
xml_output_file_env
=
posix
::
GetEnv
(
"XML_OUTPUT_FILE"
);
if
(
nullptr
!=
xml_output_file_env
)
{
...
...
googletest/src/gtest-printers.cc
View file @
9e712372
...
...
@@ -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.
// Google Test - The Google C++ Testing and Mocking Framework
//
// This file implements a universal value printer that can print a
...
...
@@ -101,7 +100,7 @@ void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
PrintByteSegmentInObjectTo
(
obj_bytes
,
0
,
kChunkSize
,
os
);
*
os
<<
" ... "
;
// Rounds up to 2-byte boundary.
const
size_t
resume_pos
=
(
count
-
kChunkSize
+
1
)
/
2
*
2
;
const
size_t
resume_pos
=
(
count
-
kChunkSize
+
1
)
/
2
*
2
;
PrintByteSegmentInObjectTo
(
obj_bytes
,
resume_pos
,
count
-
resume_pos
,
os
);
}
*
os
<<
">"
;
...
...
@@ -136,11 +135,7 @@ void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hexadecimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
enum
CharFormat
{
kAsIs
,
kHexEscape
,
kSpecialEscape
};
enum
CharFormat
{
kAsIs
,
kHexEscape
,
kSpecialEscape
};
// Returns true if c is a printable ASCII character. We test the
// value of c directly instead of calling isprint(), which is buggy on
...
...
@@ -213,35 +208,21 @@ static CharFormat PrintAsStringLiteralTo(char32_t c, ostream* os) {
}
}
static
const
char
*
GetCharWidthPrefix
(
char
)
{
return
""
;
}
static
const
char
*
GetCharWidthPrefix
(
char
)
{
return
""
;
}
static
const
char
*
GetCharWidthPrefix
(
signed
char
)
{
return
""
;
}
static
const
char
*
GetCharWidthPrefix
(
signed
char
)
{
return
""
;
}
static
const
char
*
GetCharWidthPrefix
(
unsigned
char
)
{
return
""
;
}
static
const
char
*
GetCharWidthPrefix
(
unsigned
char
)
{
return
""
;
}
#ifdef __cpp_char8_t
static
const
char
*
GetCharWidthPrefix
(
char8_t
)
{
return
"u8"
;
}
static
const
char
*
GetCharWidthPrefix
(
char8_t
)
{
return
"u8"
;
}
#endif
static
const
char
*
GetCharWidthPrefix
(
char16_t
)
{
return
"u"
;
}
static
const
char
*
GetCharWidthPrefix
(
char16_t
)
{
return
"u"
;
}
static
const
char
*
GetCharWidthPrefix
(
char32_t
)
{
return
"U"
;
}
static
const
char
*
GetCharWidthPrefix
(
char32_t
)
{
return
"U"
;
}
static
const
char
*
GetCharWidthPrefix
(
wchar_t
)
{
return
"L"
;
}
static
const
char
*
GetCharWidthPrefix
(
wchar_t
)
{
return
"L"
;
}
// Prints a char c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
...
...
@@ -276,8 +257,7 @@ void PrintCharAndCodeTo(Char c, ostream* os) {
// To aid user debugging, we also print c's code in decimal, unless
// it's 0 (in which case c was printed as '\\0', making the code
// obvious).
if
(
c
==
0
)
return
;
if
(
c
==
0
)
return
;
*
os
<<
" ("
<<
static_cast
<
int
>
(
c
);
// For more convenience, we print c's code again in hexadecimal,
...
...
@@ -354,12 +334,10 @@ void PrintTo(__int128_t v, ::std::ostream* os) {
// The array starts at begin, the length is len, it may include '\0' characters
// and may not be NUL-terminated.
template
<
typename
CharType
>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
CharFormat
PrintCharsAsStringTo
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
CharFormat
PrintCharsAsStringTo
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
const
char
*
const
quote_prefix
=
GetCharWidthPrefix
(
*
begin
);
*
os
<<
quote_prefix
<<
"
\"
"
;
bool
is_previous_hex
=
false
;
...
...
@@ -385,12 +363,11 @@ static CharFormat PrintCharsAsStringTo(
// Prints a (const) char/wchar_t array of 'len' elements, starting at address
// 'begin'. CharType must be either char or wchar_t.
template
<
typename
CharType
>
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
void
UniversalPrintCharArray
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_
GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_
GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_
static
void
UniversalPrintCharArray
(
const
CharType
*
begin
,
size_t
len
,
ostream
*
os
)
{
// The code
// const char kFoo[] = "foo";
// generates an array of 4, not 3, elements, with the last one being '\0'.
...
...
@@ -481,28 +458,28 @@ void PrintTo(const wchar_t* s, ostream* os) { PrintCStringTo(s, os); }
namespace
{
bool
ContainsUnprintableControlCodes
(
const
char
*
str
,
size_t
length
)
{
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
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
)
{
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
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
);
const
unsigned
char
*
s
=
reinterpret_cast
<
const
unsigned
char
*>
(
str
);
for
(
size_t
i
=
0
;
i
<
length
;)
{
unsigned
char
lead
=
s
[
i
++
];
...
...
@@ -515,15 +492,13 @@ bool IsValidUTF8(const char* str, size_t length) {
}
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
])
&&
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
])
&&
IsUTF8TrailByte
(
s
[
i
+
1
])
&&
IsUTF8TrailByte
(
s
[
i
+
2
])
&&
// check for non-shortest form
(
lead
!=
0xf0
||
s
[
i
]
>=
0x90
)
&&
...
...
googletest/src/gtest-test-part.cc
View file @
9e712372
...
...
@@ -51,13 +51,11 @@ std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
return
os
<<
internal
::
FormatFileLocation
(
result
.
file_name
(),
result
.
line_number
())
<<
" "
<<
(
result
.
type
()
==
TestPartResult
::
kSuccess
?
"Success"
:
result
.
type
()
==
TestPartResult
::
kSkip
?
"Skipped"
:
result
.
type
()
==
TestPartResult
::
kFatalFailure
?
"Fatal failure"
:
"Non-fatal failure"
)
<<
(
result
.
type
()
==
TestPartResult
::
kSuccess
?
"Success"
:
result
.
type
()
==
TestPartResult
::
kSkip
?
"Skipped"
:
result
.
type
()
==
TestPartResult
::
kFatalFailure
?
"Fatal failure"
:
"Non-fatal failure"
)
<<
":
\n
"
<<
result
.
message
()
<<
std
::
endl
;
}
...
...
@@ -86,8 +84,8 @@ namespace internal {
HasNewFatalFailureHelper
::
HasNewFatalFailureHelper
()
:
has_new_fatal_failure_
(
false
),
original_reporter_
(
GetUnitTestImpl
()
->
GetTestPartResultReporterForCurrentThread
())
{
original_reporter_
(
GetUnitTestImpl
()
->
GetTestPartResultReporterForCurrentThread
())
{
GetUnitTestImpl
()
->
SetTestPartResultReporterForCurrentThread
(
this
);
}
...
...
@@ -98,8 +96,7 @@ HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
void
HasNewFatalFailureHelper
::
ReportTestPartResult
(
const
TestPartResult
&
result
)
{
if
(
result
.
fatally_failed
())
has_new_fatal_failure_
=
true
;
if
(
result
.
fatally_failed
())
has_new_fatal_failure_
=
true
;
original_reporter_
->
ReportTestPartResult
(
result
);
}
...
...
googletest/src/gtest-typed-test.cc
View file @
9e712372
...
...
@@ -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.
#include "gtest/gtest-typed-test.h"
#include "gtest/gtest.h"
...
...
@@ -38,8 +37,7 @@ namespace internal {
// Skips to the first non-space char in str. Returns an empty string if str
// contains only whitespace characters.
static
const
char
*
SkipSpaces
(
const
char
*
str
)
{
while
(
IsSpace
(
*
str
))
str
++
;
while
(
IsSpace
(
*
str
))
str
++
;
return
str
;
}
...
...
@@ -85,8 +83,7 @@ const char* TypedTestSuitePState::VerifyRegisteredTestNames(
}
for
(
RegisteredTestIter
it
=
registered_tests_
.
begin
();
it
!=
registered_tests_
.
end
();
++
it
)
{
it
!=
registered_tests_
.
end
();
++
it
)
{
if
(
tests
.
count
(
it
->
first
)
==
0
)
{
errors
<<
"You forgot to list test "
<<
it
->
first
<<
".
\n
"
;
}
...
...
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