diff options
Diffstat (limited to 'include/gtest')
-rw-r--r-- | include/gtest/gtest-death-test.h | 4 | ||||
-rw-r--r-- | include/gtest/gtest-spi.h | 25 | ||||
-rw-r--r-- | include/gtest/gtest.h | 18 | ||||
-rw-r--r-- | include/gtest/internal/gtest-death-test-internal.h | 4 | ||||
-rw-r--r-- | include/gtest/internal/gtest-internal.h | 10 | ||||
-rw-r--r-- | include/gtest/internal/gtest-port.h | 8 |
6 files changed, 44 insertions, 25 deletions
diff --git a/include/gtest/gtest-death-test.h b/include/gtest/gtest-death-test.h index b72745c..fdb497f 100644 --- a/include/gtest/gtest-death-test.h +++ b/include/gtest/gtest-death-test.h @@ -245,10 +245,10 @@ class KilledBySignal { #ifdef NDEBUG #define EXPECT_DEBUG_DEATH(statement, regex) \ - do { statement; } while (false) + do { statement; } while (::testing::internal::AlwaysFalse()) #define ASSERT_DEBUG_DEATH(statement, regex) \ - do { statement; } while (false) + do { statement; } while (::testing::internal::AlwaysFalse()) #else diff --git a/include/gtest/gtest-spi.h b/include/gtest/gtest-spi.h index db0100f..2953411 100644 --- a/include/gtest/gtest-spi.h +++ b/include/gtest/gtest-spi.h @@ -150,7 +150,7 @@ class SingleFailureChecker { INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ GTestExpectFatalFailureHelper::Execute();\ }\ - } while (false) + } while (::testing::internal::AlwaysFalse()) #define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ do { \ @@ -167,7 +167,7 @@ class SingleFailureChecker { INTERCEPT_ALL_THREADS, >est_failures);\ GTestExpectFatalFailureHelper::Execute();\ }\ - } while (false) + } while (::testing::internal::AlwaysFalse()) // A macro for testing Google Test assertions or code that's expected to // generate Google Test non-fatal failures. It asserts that the given @@ -190,8 +190,17 @@ class SingleFailureChecker { // Note that even though the implementations of the following two // macros are much alike, we cannot refactor them to use a common // helper macro, due to some peculiarity in how the preprocessor -// works. The AcceptsMacroThatExpandsToUnprotectedComma test in -// gtest_unittest.cc will fail to compile if we do that. +// works. If we do that, the code won't compile when the user gives +// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that +// expands to code containing an unprotected comma. The +// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc +// catches that. +// +// For the same reason, we have to write +// if (::testing::internal::AlwaysTrue()) { statement; } +// instead of +// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) +// to avoid an MSVC warning on unreachable code. #define EXPECT_NONFATAL_FAILURE(statement, substr) \ do {\ ::testing::TestPartResultArray gtest_failures;\ @@ -202,9 +211,9 @@ class SingleFailureChecker { ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter:: \ INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\ - statement;\ + if (::testing::internal::AlwaysTrue()) { statement; }\ }\ - } while (false) + } while (::testing::internal::AlwaysFalse()) #define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \ do {\ @@ -216,8 +225,8 @@ class SingleFailureChecker { ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\ >est_failures);\ - statement;\ + if (::testing::internal::AlwaysTrue()) { statement; }\ }\ - } while (false) + } while (::testing::internal::AlwaysFalse()) #endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_ diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 2f15fa3..6fc5ac5 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -146,13 +146,13 @@ namespace internal { class AssertHelper; class DefaultGlobalTestPartResultReporter; -class EventListenersAccessor; class ExecDeathTest; class NoExecDeathTest; class FinalSuccessChecker; class GTestFlagSaver; class TestInfoImpl; class TestResultAccessor; +class TestEventListenersAccessor; class TestEventRepeater; class WindowsDeathTest; class UnitTestImpl* GetUnitTestImpl(); @@ -832,11 +832,11 @@ class EmptyTestEventListener : public TestEventListener { virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} }; -// EventListeners lets users add listeners to track events in Google Test. -class EventListeners { +// TestEventListeners lets users add listeners to track events in Google Test. +class TestEventListeners { public: - EventListeners(); - ~EventListeners(); + TestEventListeners(); + ~TestEventListeners(); // Appends an event listener to the end of the list. Google Test assumes // the ownership of the listener (i.e. it will delete the listener when @@ -871,8 +871,8 @@ class EventListeners { private: friend class TestCase; friend class internal::DefaultGlobalTestPartResultReporter; - friend class internal::EventListenersAccessor; friend class internal::NoExecDeathTest; + friend class internal::TestEventListenersAccessor; friend class internal::TestInfoImpl; friend class internal::UnitTestImpl; @@ -906,8 +906,8 @@ class EventListeners { // Listener responsible for the creation of the XML output file. TestEventListener* default_xml_generator_; - // We disallow copying EventListeners. - GTEST_DISALLOW_COPY_AND_ASSIGN_(EventListeners); + // We disallow copying TestEventListeners. + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventListeners); }; // A UnitTest consists of a vector of TestCases. @@ -1002,7 +1002,7 @@ class UnitTest { // Returns the list of event listeners that can be used to track events // inside Google Test. - EventListeners& listeners(); + TestEventListeners& listeners(); private: // Registers and returns a global test environment. When a test diff --git a/include/gtest/internal/gtest-death-test-internal.h b/include/gtest/internal/gtest-death-test-internal.h index 78fbae9..5aba1a0 100644 --- a/include/gtest/internal/gtest-death-test-internal.h +++ b/include/gtest/internal/gtest-death-test-internal.h @@ -153,7 +153,7 @@ bool ExitedUnsuccessfully(int exit_status); // ASSERT_EXIT*, and EXPECT_EXIT*. #define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (true) { \ + if (::testing::internal::AlwaysTrue()) { \ const ::testing::internal::RE& gtest_regex = (regex); \ ::testing::internal::DeathTest* gtest_dt; \ if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ @@ -259,7 +259,7 @@ InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); GTEST_LOG_(WARNING) \ << "Death tests are not supported on this platform.\n" \ << "Statement '" #statement "' cannot be verified."; \ - } else if (!::testing::internal::AlwaysTrue()) { \ + } else if (::testing::internal::AlwaysFalse()) { \ ::testing::internal::RE::PartialMatch(".*", (regex)); \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ terminator; \ diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index f5c30fb..7033b0c 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -745,9 +745,15 @@ class TypeParameterizedTestCase<Fixture, Templates0, Types> { // the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count); -// A helper for suppressing warnings on unreachable code in some macros. +// Helpers for suppressing warnings on unreachable code or constant +// condition. + +// 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 @@ -854,7 +860,7 @@ class Random { #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) diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 9afbd47..ac460ee 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -577,6 +577,10 @@ typedef ::std::stringstream StrStream; typedef ::std::strstream StrStream; #endif // GTEST_HAS_STD_STRING +// A helper for suppressing warnings on constant condition. It just +// returns 'condition'. +bool IsTrue(bool condition); + // Defines scoped_ptr. // This implementation of scoped_ptr is PARTIAL - it only contains @@ -599,7 +603,7 @@ class scoped_ptr { void reset(T* p = NULL) { if (p != ptr_) { - if (sizeof(T) > 0) { // Makes sure T is a complete type. + if (IsTrue(sizeof(T) > 0)) { // Makes sure T is a complete type. delete ptr_; } ptr_ = p; @@ -1037,7 +1041,7 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds. // whether it is built in the debug mode or not. #define GTEST_CHECK_(condition) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (condition) \ + if (::testing::internal::IsTrue(condition)) \ ; \ else \ GTEST_LOG_(FATAL) << "Condition " #condition " failed. " |