aboutsummaryrefslogtreecommitdiff
path: root/lib/gtest/test/gtest-death-test_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gtest/test/gtest-death-test_test.cc')
-rw-r--r--lib/gtest/test/gtest-death-test_test.cc83
1 files changed, 40 insertions, 43 deletions
diff --git a/lib/gtest/test/gtest-death-test_test.cc b/lib/gtest/test/gtest-death-test_test.cc
index b389e73b80..c2d26df993 100644
--- a/lib/gtest/test/gtest-death-test_test.cc
+++ b/lib/gtest/test/gtest-death-test_test.cc
@@ -45,7 +45,6 @@ using testing::internal::AlwaysTrue;
# else
# include <unistd.h>
# include <sys/wait.h> // For waitpid.
-# include <limits> // For std::numeric_limits.
# endif // GTEST_OS_WINDOWS
# include <limits.h>
@@ -77,7 +76,6 @@ using testing::internal::GetLastErrnoDescription;
using testing::internal::GetUnitTestImpl;
using testing::internal::InDeathTestChild;
using testing::internal::ParseNaturalNumber;
-using testing::internal::String;
namespace testing {
namespace internal {
@@ -466,6 +464,8 @@ TEST_F(TestForDeathTest, MixedStyles) {
EXPECT_DEATH(_exit(1), "");
}
+# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
+
namespace {
bool pthread_flag;
@@ -476,8 +476,6 @@ void SetPthreadFlag() {
} // namespace
-# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
-
TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
if (!testing::GTEST_FLAG(death_test_use_fork)) {
testing::GTEST_FLAG(death_test_style) = "threadsafe";
@@ -1124,41 +1122,40 @@ TEST(AutoHandleTest, AutoHandleWorks) {
# if GTEST_OS_WINDOWS
typedef unsigned __int64 BiggestParsable;
typedef signed __int64 BiggestSignedParsable;
-const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
-const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
# else
typedef unsigned long long BiggestParsable;
typedef signed long long BiggestSignedParsable;
-const BiggestParsable kBiggestParsableMax =
- ::std::numeric_limits<BiggestParsable>::max();
-const BiggestSignedParsable kBiggestSignedParsableMax =
- ::std::numeric_limits<BiggestSignedParsable>::max();
# endif // GTEST_OS_WINDOWS
+// We cannot use std::numeric_limits<T>::max() as it clashes with the
+// max() macro defined by <windows.h>.
+const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
+const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
+
TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
BiggestParsable result = 0;
// Rejects non-numbers.
- EXPECT_FALSE(ParseNaturalNumber(String("non-number string"), &result));
+ EXPECT_FALSE(ParseNaturalNumber("non-number string", &result));
// Rejects numbers with whitespace prefix.
- EXPECT_FALSE(ParseNaturalNumber(String(" 123"), &result));
+ EXPECT_FALSE(ParseNaturalNumber(" 123", &result));
// Rejects negative numbers.
- EXPECT_FALSE(ParseNaturalNumber(String("-123"), &result));
+ EXPECT_FALSE(ParseNaturalNumber("-123", &result));
// Rejects numbers starting with a plus sign.
- EXPECT_FALSE(ParseNaturalNumber(String("+123"), &result));
+ EXPECT_FALSE(ParseNaturalNumber("+123", &result));
errno = 0;
}
TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
BiggestParsable result = 0;
- EXPECT_FALSE(ParseNaturalNumber(String("99999999999999999999999"), &result));
+ EXPECT_FALSE(ParseNaturalNumber("99999999999999999999999", &result));
signed char char_result = 0;
- EXPECT_FALSE(ParseNaturalNumber(String("200"), &char_result));
+ EXPECT_FALSE(ParseNaturalNumber("200", &char_result));
errno = 0;
}
@@ -1166,16 +1163,16 @@ TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
BiggestParsable result = 0;
result = 0;
- ASSERT_TRUE(ParseNaturalNumber(String("123"), &result));
+ ASSERT_TRUE(ParseNaturalNumber("123", &result));
EXPECT_EQ(123U, result);
// Check 0 as an edge case.
result = 1;
- ASSERT_TRUE(ParseNaturalNumber(String("0"), &result));
+ ASSERT_TRUE(ParseNaturalNumber("0", &result));
EXPECT_EQ(0U, result);
result = 1;
- ASSERT_TRUE(ParseNaturalNumber(String("00000"), &result));
+ ASSERT_TRUE(ParseNaturalNumber("00000", &result));
EXPECT_EQ(0U, result);
}
@@ -1211,11 +1208,11 @@ TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
short short_result = 0;
- ASSERT_TRUE(ParseNaturalNumber(String("123"), &short_result));
+ ASSERT_TRUE(ParseNaturalNumber("123", &short_result));
EXPECT_EQ(123, short_result);
signed char char_result = 0;
- ASSERT_TRUE(ParseNaturalNumber(String("123"), &char_result));
+ ASSERT_TRUE(ParseNaturalNumber("123", &char_result));
EXPECT_EQ(123, char_result);
}
@@ -1245,7 +1242,6 @@ TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
using testing::internal::CaptureStderr;
using testing::internal::GetCapturedStderr;
-using testing::internal::String;
// Tests that EXPECT_DEATH_IF_SUPPORTED/ASSERT_DEATH_IF_SUPPORTED are still
// defined but do not trigger failures when death tests are not available on
@@ -1255,7 +1251,7 @@ TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
// when death tests are not supported.
CaptureStderr();
EXPECT_DEATH_IF_SUPPORTED(;, "");
- String output = GetCapturedStderr();
+ std::string output = GetCapturedStderr();
ASSERT_TRUE(NULL != strstr(output.c_str(),
"Death tests are not supported on this platform"));
ASSERT_TRUE(NULL != strstr(output.c_str(), ";"));
@@ -1291,6 +1287,27 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
FuncWithAssert(&n);
EXPECT_EQ(1, n);
}
+
+TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
+ testing::GTEST_FLAG(death_test_style) = "fast";
+ EXPECT_FALSE(InDeathTestChild());
+ EXPECT_DEATH({
+ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
+ fflush(stderr);
+ _exit(1);
+ }, "Inside");
+}
+
+TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
+ testing::GTEST_FLAG(death_test_style) = "threadsafe";
+ EXPECT_FALSE(InDeathTestChild());
+ EXPECT_DEATH({
+ fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
+ fflush(stderr);
+ _exit(1);
+ }, "Inside");
+}
+
#endif // GTEST_HAS_DEATH_TEST
// Tests that the death test macros expand to code which may or may not
@@ -1343,26 +1360,6 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
#endif // _MSC_VER
}
-TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
- testing::GTEST_FLAG(death_test_style) = "fast";
- EXPECT_FALSE(InDeathTestChild());
- EXPECT_DEATH({
- fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
- fflush(stderr);
- _exit(1);
- }, "Inside");
-}
-
-TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
- testing::GTEST_FLAG(death_test_style) = "threadsafe";
- EXPECT_FALSE(InDeathTestChild());
- EXPECT_DEATH({
- fprintf(stderr, InDeathTestChild() ? "Inside" : "Outside");
- fflush(stderr);
- _exit(1);
- }, "Inside");
-}
-
// Tests that a test case whose name ends with "DeathTest" works fine
// on Windows.
TEST(NotADeathTest, Test) {