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