diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-06-02 22:02:11 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-06-02 22:02:11 +0000 |
commit | 190f8ee25a6977ac6eb71b816498df42f17ad9a7 (patch) | |
tree | 658b8c02fce43448931b29c311631a0fda983ed6 /utils/unittest/googletest/include/gtest/internal/gtest-internal.h | |
parent | e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0 (diff) |
Merge gtest-1.4.0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105353 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/unittest/googletest/include/gtest/internal/gtest-internal.h')
-rw-r--r-- | utils/unittest/googletest/include/gtest/internal/gtest-internal.h | 98 |
1 files changed, 61 insertions, 37 deletions
diff --git a/utils/unittest/googletest/include/gtest/internal/gtest-internal.h b/utils/unittest/googletest/include/gtest/internal/gtest-internal.h index def4b5970a..20c32340d7 100644 --- a/utils/unittest/googletest/include/gtest/internal/gtest-internal.h +++ b/utils/unittest/googletest/include/gtest/internal/gtest-internal.h @@ -121,25 +121,20 @@ namespace testing { // Forward declaration of classes. +class AssertionResult; // Result of an assertion. class Message; // Represents a failure message. class Test; // Represents a test. -class TestCase; // A collection of related tests. -class TestPartResult; // Result of a test part. class TestInfo; // Information about a test. +class TestPartResult; // Result of a test part. class UnitTest; // A collection of test cases. -class UnitTestEventListenerInterface; // Listens to Google Test events. -class AssertionResult; // Result of an assertion. namespace internal { struct TraceInfo; // Information about a trace point. class ScopedTrace; // Implements scoped trace. class TestInfoImpl; // Opaque implementation of TestInfo -class TestResult; // Result of a single Test. class UnitTestImpl; // Opaque implementation of UnitTest - -template <typename E> class List; // A generic list. -template <typename E> class ListNode; // A node in a generic list. +template <typename E> class Vector; // A generic vector. // How many times InitGoogleTest() has been called. extern int g_init_gtest_count; @@ -231,13 +226,13 @@ String StreamableToString(const T& streamable); // This overload makes sure that all pointers (including // those to char or wchar_t) are printed as raw pointers. template <typename T> -inline String FormatValueForFailureMessage(internal::true_type dummy, +inline String FormatValueForFailureMessage(internal::true_type /*dummy*/, T* pointer) { return StreamableToString(static_cast<const void*>(pointer)); } template <typename T> -inline String FormatValueForFailureMessage(internal::false_type dummy, +inline String FormatValueForFailureMessage(internal::false_type /*dummy*/, const T& value) { return StreamableToString(value); } @@ -403,7 +398,7 @@ class FloatingPoint { // around may change its bits, although the new value is guaranteed // to be also a NAN. Therefore, don't expect this constructor to // preserve the bits in x when x is a NAN. - explicit FloatingPoint(const RawType& x) : value_(x) {} + explicit FloatingPoint(const RawType& x) { u_.value_ = x; } // Static methods @@ -412,8 +407,8 @@ class FloatingPoint { // This function is needed to test the AlmostEquals() method. static RawType ReinterpretBits(const Bits bits) { FloatingPoint fp(0); - fp.bits_ = bits; - return fp.value_; + fp.u_.bits_ = bits; + return fp.u_.value_; } // Returns the floating-point number that represent positive infinity. @@ -424,16 +419,16 @@ class FloatingPoint { // Non-static methods // Returns the bits that represents this number. - const Bits &bits() const { return bits_; } + const Bits &bits() const { return u_.bits_; } // Returns the exponent bits of this number. - Bits exponent_bits() const { return kExponentBitMask & bits_; } + Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } // Returns the fraction bits of this number. - Bits fraction_bits() const { return kFractionBitMask & bits_; } + Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } // Returns the sign bit of this number. - Bits sign_bit() const { return kSignBitMask & bits_; } + Bits sign_bit() const { return kSignBitMask & u_.bits_; } // Returns true iff this is NAN (not a number). bool is_nan() const { @@ -453,10 +448,17 @@ class FloatingPoint { // a NAN must return false. if (is_nan() || rhs.is_nan()) return false; - return DistanceBetweenSignAndMagnitudeNumbers(bits_, rhs.bits_) <= kMaxUlps; + return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) + <= kMaxUlps; } private: + // The data type used to store the actual floating-point number. + union FloatingPointUnion { + RawType value_; // The raw floating-point number. + Bits bits_; // The bits that represent the number. + }; + // Converts an integer from the sign-and-magnitude representation to // the biased representation. More precisely, let N be 2 to the // power of (kBitCount - 1), an integer x is represented by the @@ -491,10 +493,7 @@ class FloatingPoint { return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); } - union { - RawType value_; // The raw floating-point number. - Bits bits_; // The bits that represent the number. - }; + FloatingPointUnion u_; }; // Typedefs the instances of the FloatingPoint template class that we @@ -637,7 +636,7 @@ class TypedTestCasePState { "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", FormatFileLocation(file, line).c_str(), test_name, case_name); fflush(stderr); - abort(); + posix::Abort(); } defined_test_names_.insert(test_name); return true; @@ -746,8 +745,8 @@ class TypeParameterizedTestCase { template <GTEST_TEMPLATE_ Fixture, typename Types> class TypeParameterizedTestCase<Fixture, Templates0, Types> { public: - static bool Register(const char* prefix, const char* case_name, - const char* test_names) { + static bool Register(const char* /*prefix*/, const char* /*case_name*/, + const char* /*test_names*/) { return true; } }; @@ -766,12 +765,37 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> { // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); -// Returns the number of failed test parts in the given test result object. -int GetFailedPartCount(const TestResult* result); +// Helpers for suppressing warnings on unreachable code or constant +// condition. -// A helper for suppressing warnings on unreachable code in some macros. +// Always returns true. bool AlwaysTrue(); +// Always returns false. +inline bool AlwaysFalse() { return !AlwaysTrue(); } + +// A simple Linear Congruential Generator for generating random +// numbers with a uniform distribution. Unlike rand() and srand(), it +// doesn't use global state (and therefore can't interfere with user +// code). Unlike rand_r(), it's portable. An LCG isn't very random, +// but it's good enough for our purposes. +class Random { + public: + static const UInt32 kMaxRange = 1u << 31; + + explicit Random(UInt32 seed) : state_(seed) {} + + void Reseed(UInt32 seed) { state_ = seed; } + + // Generates a random number from [0, range). Crashes if 'range' is + // 0 or greater than kMaxRange. + UInt32 Generate(UInt32 range); + + private: + UInt32 state_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); +}; + } // namespace internal } // namespace testing @@ -780,18 +804,18 @@ bool AlwaysTrue(); = ::testing::Message() #define GTEST_FATAL_FAILURE_(message) \ - return GTEST_MESSAGE_(message, ::testing::TPRT_FATAL_FAILURE) + return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) #define GTEST_NONFATAL_FAILURE_(message) \ - GTEST_MESSAGE_(message, ::testing::TPRT_NONFATAL_FAILURE) + GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) #define GTEST_SUCCESS_(message) \ - GTEST_MESSAGE_(message, ::testing::TPRT_SUCCESS) + GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) // Suppresses MSVC warnings 4072 (unreachable code) for the code following // statement if it returns or throws (or doesn't return or throw in some // situations). -#define GTEST_HIDE_UNREACHABLE_CODE_(statement) \ +#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ if (::testing::internal::AlwaysTrue()) { statement; } #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ @@ -799,7 +823,7 @@ bool AlwaysTrue(); if (const char* gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (expected_exception const&) { \ gtest_caught_expected = true; \ @@ -823,7 +847,7 @@ bool AlwaysTrue(); GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (...) { \ gtest_msg = "Expected: " #statement " doesn't throw an exception.\n" \ @@ -839,7 +863,7 @@ bool AlwaysTrue(); if (const char* gtest_msg = "") { \ bool gtest_caught_any = false; \ try { \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (...) { \ gtest_caught_any = true; \ @@ -856,7 +880,7 @@ bool AlwaysTrue(); #define GTEST_TEST_BOOLEAN_(boolexpr, booltext, actual, expected, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (boolexpr) \ + if (::testing::internal::IsTrue(boolexpr)) \ ; \ else \ fail("Value of: " booltext "\n Actual: " #actual "\nExpected: " #expected) @@ -865,7 +889,7 @@ bool AlwaysTrue(); GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ if (const char* gtest_msg = "") { \ ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ gtest_msg = "Expected: " #statement " doesn't generate new fatal " \ "failures in the current thread.\n" \ |