diff options
Diffstat (limited to 'googletest/test/gtest_unittest.cc')
-rw-r--r-- | googletest/test/gtest_unittest.cc | 79 |
1 files changed, 35 insertions, 44 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 57a9913..d4cb0a1 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -60,6 +60,7 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include <string.h> #include <time.h> +#include <cstdint> #include <map> #include <ostream> #include <type_traits> @@ -249,7 +250,6 @@ using testing::internal::GetTestTypeId; using testing::internal::GetTimeInMillis; using testing::internal::GetTypeId; using testing::internal::GetUnitTestImpl; -using testing::internal::Int32; using testing::internal::Int32FromEnvOrDie; using testing::internal::IsAProtocolMessage; using testing::internal::IsContainer; @@ -271,7 +271,6 @@ using testing::internal::StreamableToString; using testing::internal::String; using testing::internal::TestEventListenersAccessor; using testing::internal::TestResultAccessor; -using testing::internal::UInt32; using testing::internal::UnitTestImpl; using testing::internal::WideStringToUtf8; using testing::internal::edit_distance::CalculateOptimalEdits; @@ -788,7 +787,7 @@ TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) { } TEST(RandomTest, GeneratesNumbersWithinRange) { - const UInt32 kRange = 10000; + constexpr uint32_t kRange = 10000; testing::internal::Random random(12345); for (int i = 0; i < 10; i++) { EXPECT_LT(random.Generate(kRange), kRange) << " for iteration " << i; @@ -801,10 +800,10 @@ TEST(RandomTest, GeneratesNumbersWithinRange) { } TEST(RandomTest, RepeatsWhenReseeded) { - const int kSeed = 123; - const int kArraySize = 10; - const UInt32 kRange = 10000; - UInt32 values[kArraySize]; + constexpr int kSeed = 123; + constexpr int kArraySize = 10; + constexpr uint32_t kRange = 10000; + uint32_t values[kArraySize]; testing::internal::Random random(kSeed); for (int i = 0; i < kArraySize; i++) { @@ -1772,7 +1771,7 @@ TEST(Int32FromGTestEnvTest, ParsesAndReturnsValidValue) { // Tests that ParseInt32Flag() returns false and doesn't change the // output value when the flag has wrong format TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) { - Int32 value = 123; + int32_t value = 123; EXPECT_FALSE(ParseInt32Flag("--a=100", "b", &value)); EXPECT_EQ(123, value); @@ -1785,7 +1784,7 @@ TEST(ParseInt32FlagTest, ReturnsFalseForInvalidFlag) { TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) { printf("(expecting 2 warnings)\n"); - Int32 value = 123; + int32_t value = 123; EXPECT_FALSE(ParseInt32Flag("--abc=12345678987654321", "abc", &value)); EXPECT_EQ(123, value); @@ -1799,7 +1798,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueOverflows) { TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) { printf("(expecting 2 warnings)\n"); - Int32 value = 123; + int32_t value = 123; EXPECT_FALSE(ParseInt32Flag("--abc=A1", "abc", &value)); EXPECT_EQ(123, value); @@ -1811,7 +1810,7 @@ TEST(ParseInt32FlagTest, ReturnsDefaultWhenValueIsInvalid) { // returns true when the flag represents a valid decimal integer in // the range of an Int32. TEST(ParseInt32FlagTest, ParsesAndReturnsValidValue) { - Int32 value = 123; + int32_t value = 123; EXPECT_TRUE(ParseInt32Flag("--" GTEST_FLAG_PREFIX_ "abc=456", "abc", &value)); EXPECT_EQ(456, value); @@ -1834,7 +1833,7 @@ TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { #endif // !GTEST_OS_WINDOWS_MOBILE // Tests that Int32FromEnvOrDie() aborts with an error message -// if the variable is not an Int32. +// if the variable is not an int32_t. TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) { SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "xxx"); EXPECT_DEATH_IF_SUPPORTED( @@ -1843,7 +1842,7 @@ TEST(Int32FromEnvOrDieDeathTest, AbortsOnFailure) { } // Tests that Int32FromEnvOrDie() aborts with an error message -// if the variable cannot be represented by an Int32. +// if the variable cannot be represented by an int32_t. TEST(Int32FromEnvOrDieDeathTest, AbortsOnInt32Overflow) { SetEnv(GTEST_FLAG_PREFIX_UPPER_ "VAR", "1234567891234567891234"); EXPECT_DEATH_IF_SUPPORTED( @@ -2924,22 +2923,18 @@ TEST_F(FloatTest, Commutative) { TEST_F(FloatTest, EXPECT_NEAR) { EXPECT_NEAR(-1.0f, -1.1f, 0.2f); EXPECT_NEAR(2.0f, 3.0f, 1.0f); - EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f,1.5f, 0.25f), // NOLINT + EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT "The difference between 1.0f and 1.5f is 0.5, " "which exceeds 0.25f"); - // To work around a bug in gcc 2.95.0, there is intentionally no - // space after the first comma in the previous line. } // Tests ASSERT_NEAR. TEST_F(FloatTest, ASSERT_NEAR) { ASSERT_NEAR(-1.0f, -1.1f, 0.2f); ASSERT_NEAR(2.0f, 3.0f, 1.0f); - EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f,1.5f, 0.25f), // NOLINT + EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0f, 1.5f, 0.25f), // NOLINT "The difference between 1.0f and 1.5f is 0.5, " "which exceeds 0.25f"); - // To work around a bug in gcc 2.95.0, there is intentionally no - // space after the first comma in the previous line. } // Tests the cases where FloatLE() should succeed. @@ -3344,6 +3339,9 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } +void ThrowRuntimeError(const char* what) { + throw std::runtime_error(what); +} // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3819,6 +3817,11 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); + EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowRuntimeError("A description")), + "Expected: ThrowRuntimeError(\"A description\") " + "doesn't throw an exception.\n " + "Actual: it throws std::exception-derived exception " + "with description: \"A description\"."); } // Tests ASSERT_ANY_THROW. @@ -4306,10 +4309,8 @@ TEST(AssertionWithMessageTest, ASSERT_STR) { TEST(AssertionWithMessageTest, ASSERT_FLOATING) { ASSERT_FLOAT_EQ(1, 1) << "This should succeed."; ASSERT_DOUBLE_EQ(1, 1) << "This should succeed."; - EXPECT_FATAL_FAILURE(ASSERT_NEAR(1,1.2, 0.1) << "Expect failure.", // NOLINT + EXPECT_FATAL_FAILURE(ASSERT_NEAR(1, 1.2, 0.1) << "Expect failure.", // NOLINT "Expect failure."); - // To work around a bug in gcc 2.95.0, there is intentionally no - // space after the first comma in the previous statement. } // Tests using ASSERT_FALSE with a streamed message. @@ -4552,6 +4553,11 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); + EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowRuntimeError("A description")), + "Expected: ThrowRuntimeError(\"A description\") " + "doesn't throw an exception.\n " + "Actual: it throws std::exception-derived exception " + "with description: \"A description\"."); } // Tests EXPECT_ANY_THROW. @@ -5572,7 +5578,7 @@ struct Flags { // Creates a Flags struct where the gtest_random_seed flag has the given // value. - static Flags RandomSeed(Int32 random_seed) { + static Flags RandomSeed(int32_t random_seed) { Flags flags; flags.random_seed = random_seed; return flags; @@ -5580,7 +5586,7 @@ struct Flags { // Creates a Flags struct where the gtest_repeat flag has the given // value. - static Flags Repeat(Int32 repeat) { + static Flags Repeat(int32_t repeat) { Flags flags; flags.repeat = repeat; return flags; @@ -5596,7 +5602,7 @@ struct Flags { // Creates a Flags struct where the GTEST_FLAG(stack_trace_depth) flag has // the given value. - static Flags StackTraceDepth(Int32 stack_trace_depth) { + static Flags StackTraceDepth(int32_t stack_trace_depth) { Flags flags; flags.stack_trace_depth = stack_trace_depth; return flags; @@ -5627,10 +5633,10 @@ struct Flags { bool list_tests; const char* output; bool print_time; - Int32 random_seed; - Int32 repeat; + int32_t random_seed; + int32_t repeat; bool shuffle; - Int32 stack_trace_depth; + int32_t stack_trace_depth; const char* stream_result_to; bool throw_on_failure; }; @@ -7422,22 +7428,7 @@ TEST(SkipPrefixTest, DoesNotSkipWhenPrefixDoesNotMatch) { } // Tests ad_hoc_test_result(). - -class AdHocTestResultTest : public testing::Test { - protected: - static void SetUpTestSuite() { - FAIL() << "A failure happened inside SetUpTestSuite()."; - } -}; - -TEST_F(AdHocTestResultTest, AdHocTestResultForTestSuiteShowsFailure) { - const testing::TestResult& test_result = testing::UnitTest::GetInstance() - ->current_test_suite() - ->ad_hoc_test_result(); - EXPECT_TRUE(test_result.Failed()); -} - -TEST_F(AdHocTestResultTest, AdHocTestResultTestForUnitTestDoesNotShowFailure) { +TEST(AdHocTestResultTest, AdHocTestResultForUnitTestDoesNotShowFailure) { const testing::TestResult& test_result = testing::UnitTest::GetInstance()->ad_hoc_test_result(); EXPECT_FALSE(test_result.Failed()); |