diff options
Diffstat (limited to 'include/gtest')
-rw-r--r-- | include/gtest/gtest-spi.h | 14 | ||||
-rw-r--r-- | include/gtest/gtest-test-part.h | 33 | ||||
-rw-r--r-- | include/gtest/gtest.h | 74 | ||||
-rw-r--r-- | include/gtest/internal/gtest-internal.h | 6 |
4 files changed, 63 insertions, 64 deletions
diff --git a/include/gtest/gtest-spi.h b/include/gtest/gtest-spi.h index a4e387a3..db0100ff 100644 --- a/include/gtest/gtest-spi.h +++ b/include/gtest/gtest-spi.h @@ -97,12 +97,12 @@ class SingleFailureChecker { public: // The constructor remembers the arguments. SingleFailureChecker(const TestPartResultArray* results, - TestPartResultType type, + TestPartResult::Type type, const char* substr); ~SingleFailureChecker(); private: const TestPartResultArray* const results_; - const TestPartResultType type_; + const TestPartResult::Type type_; const String substr_; GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker); @@ -143,7 +143,7 @@ class SingleFailureChecker { };\ ::testing::TestPartResultArray gtest_failures;\ ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ {\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter:: \ @@ -160,7 +160,7 @@ class SingleFailureChecker { };\ ::testing::TestPartResultArray gtest_failures;\ ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TPRT_FATAL_FAILURE, (substr));\ + >est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\ {\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter:: \ @@ -196,7 +196,8 @@ class SingleFailureChecker { do {\ ::testing::TestPartResultArray gtest_failures;\ ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TPRT_NONFATAL_FAILURE, (substr));\ + >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ + (substr));\ {\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter:: \ @@ -209,7 +210,8 @@ class SingleFailureChecker { do {\ ::testing::TestPartResultArray gtest_failures;\ ::testing::internal::SingleFailureChecker gtest_checker(\ - >est_failures, ::testing::TPRT_NONFATAL_FAILURE, (substr));\ + >est_failures, ::testing::TestPartResult::kNonFatalFailure, \ + (substr));\ {\ ::testing::ScopedFakeTestPartResultReporter gtest_reporter(\ ::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\ diff --git a/include/gtest/gtest-test-part.h b/include/gtest/gtest-test-part.h index 14d8e7b6..58e7df9e 100644 --- a/include/gtest/gtest-test-part.h +++ b/include/gtest/gtest-test-part.h @@ -39,27 +39,24 @@ namespace testing { -// The possible outcomes of a test part (i.e. an assertion or an -// explicit SUCCEED(), FAIL(), or ADD_FAILURE()). -// TODO(vladl@google.com): Rename the enum values to kSuccess, -// kNonFatalFailure, and kFatalFailure before publishing the event listener -// API (see issue http://code.google.com/p/googletest/issues/detail?id=165). -enum TestPartResultType { - TPRT_SUCCESS, // Succeeded. - TPRT_NONFATAL_FAILURE, // Failed but the test can continue. - TPRT_FATAL_FAILURE // Failed and the test should be terminated. -}; - // A copyable object representing the result of a test part (i.e. an // assertion or an explicit FAIL(), ADD_FAILURE(), or SUCCESS()). // // Don't inherit from TestPartResult as its destructor is not virtual. class TestPartResult { public: + // The possible outcomes of a test part (i.e. an assertion or an + // explicit SUCCEED(), FAIL(), or ADD_FAILURE()). + enum Type { + kSuccess, // Succeeded. + kNonFatalFailure, // Failed but the test can continue. + kFatalFailure // Failed and the test should be terminated. + }; + // C'tor. TestPartResult does NOT have a default constructor. // Always use this constructor (with parameters) to create a // TestPartResult object. - TestPartResult(TestPartResultType type, + TestPartResult(Type type, const char* file_name, int line_number, const char* message) @@ -71,7 +68,7 @@ class TestPartResult { } // Gets the outcome of the test part. - TestPartResultType type() const { return type_; } + Type type() const { return type_; } // Gets the name of the source file where the test part took place, or // NULL if it's unknown. @@ -88,18 +85,18 @@ class TestPartResult { const char* message() const { return message_.c_str(); } // Returns true iff the test part passed. - bool passed() const { return type_ == TPRT_SUCCESS; } + bool passed() const { return type_ == kSuccess; } // Returns true iff the test part failed. - bool failed() const { return type_ != TPRT_SUCCESS; } + bool failed() const { return type_ != kSuccess; } // Returns true iff the test part non-fatally failed. - bool nonfatally_failed() const { return type_ == TPRT_NONFATAL_FAILURE; } + bool nonfatally_failed() const { return type_ == kNonFatalFailure; } // Returns true iff the test part fatally failed. - bool fatally_failed() const { return type_ == TPRT_FATAL_FAILURE; } + bool fatally_failed() const { return type_ == kFatalFailure; } private: - TestPartResultType type_; + Type type_; // Gets the summary of the failure message by omitting the stack // trace in it. diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index ecbbf9be..5c928767 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -161,7 +161,7 @@ class UnitTestAccessor; class TestEventRepeater; class WindowsDeathTest; class UnitTestImpl* GetUnitTestImpl(); -void ReportFailureInUnknownLocation(TestPartResultType result_type, +void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const String& message); class PrettyUnitTestResultPrinter; class XmlUnitTestResultPrinter; @@ -773,58 +773,54 @@ class Environment { namespace internal { -// TODO(vladl@google.com): Order the methods the way they are invoked by -// Google Test. -// The interface for tracing execution of tests. +// The interface for tracing execution of tests. The methods are organized in +// the order the corresponding events are fired. class UnitTestEventListenerInterface { public: virtual ~UnitTestEventListenerInterface() {} - // TODO(vladl@google.com): Add tests for OnTestIterationStart and - // OnTestIterationEnd. - // Fired before any test activity starts. virtual void OnTestProgramStart(const UnitTest& unit_test) = 0; - // Fired after all test activities have ended. - virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; - // Fired before each iteration of tests starts. There may be more than // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration // index, starting from 0. virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration) = 0; - // Fired after each iteration of tests finishes. - virtual void OnTestIterationEnd(const UnitTest& unit_test, - int iteration) = 0; - // Fired before environment set-up for each iteration of tests starts. virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0; // Fired after environment set-up for each iteration of tests ends. virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0; - // Fired before environment tear-down for each iteration of tests starts. - virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; - - // Fired after environment tear-down for each iteration of tests ends. - virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; - // Fired before the test case starts. virtual void OnTestCaseStart(const TestCase& test_case) = 0; - // Fired after the test case ends. - virtual void OnTestCaseEnd(const TestCase& test_case) = 0; - // Fired before the test starts. virtual void OnTestStart(const TestInfo& test_info) = 0; + // Fired after a failed assertion or a SUCCESS(). + virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; + // Fired after the test ends. virtual void OnTestEnd(const TestInfo& test_info) = 0; - // Fired after a failed assertion or a SUCCESS(). - virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0; + // Fired after the test case ends. + virtual void OnTestCaseEnd(const TestCase& test_case) = 0; + + // Fired before environment tear-down for each iteration of tests starts. + virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0; + + // Fired after environment tear-down for each iteration of tests ends. + virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0; + + // Fired after each iteration of tests finishes. + virtual void OnTestIterationEnd(const UnitTest& unit_test, + int iteration) = 0; + + // Fired after all test activities have ended. + virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0; }; // The convenience class for users who need to override just one or two @@ -835,20 +831,20 @@ class UnitTestEventListenerInterface { class EmptyTestEventListener : public UnitTestEventListenerInterface { public: virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {} - virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} virtual void OnTestIterationStart(const UnitTest& /*unit_test*/, int /*iteration*/) {} - virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/, - int /*iteration*/) {} virtual void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) {} virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {} - virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {} - virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {} virtual void OnTestCaseStart(const TestCase& /*test_case*/) {} - virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} virtual void OnTestStart(const TestInfo& /*test_info*/) {} - virtual void OnTestEnd(const TestInfo& /*test_info*/) {} virtual void OnTestPartResult(const TestPartResult& /*test_part_result*/) {} + virtual void OnTestEnd(const TestInfo& /*test_info*/) {} + virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {} + virtual void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) {} + virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {} + virtual void OnTestIterationEnd(const UnitTest& /*unit_test*/, + int /*iteration*/) {} + virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {} }; // EventListeners lets users add listeners to track events in Google Test. @@ -996,7 +992,7 @@ class UnitTest { // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) // eventually call this to report their results. The user code // should use the assertion macros instead of calling this directly. - void AddTestPartResult(TestPartResultType result_type, + void AddTestPartResult(TestPartResult::Type result_type, const char* file_name, int line_number, const internal::String& message, @@ -1066,7 +1062,7 @@ class UnitTest { friend class internal::AssertHelper; friend class Test; friend void internal::ReportFailureInUnknownLocation( - TestPartResultType result_type, + TestPartResult::Type result_type, const internal::String& message); // TODO(vladl@google.com): Remove these when publishing the new accessors. friend class internal::PrettyUnitTestResultPrinter; @@ -1470,7 +1466,9 @@ AssertionResult DoubleNearPredFormat(const char* expr1, class AssertHelper { public: // Constructor. - AssertHelper(TestPartResultType type, const char* file, int line, + AssertHelper(TestPartResult::Type type, + const char* file, + int line, const char* message); ~AssertHelper(); @@ -1484,11 +1482,13 @@ class AssertHelper { // re-using stack space even for temporary variables, so every EXPECT_EQ // reserves stack space for another AssertHelper. struct AssertHelperData { - AssertHelperData(TestPartResultType t, const char* srcfile, int line_num, + AssertHelperData(TestPartResult::Type t, + const char* srcfile, + int line_num, const char* msg) : type(t), file(srcfile), line(line_num), message(msg) { } - TestPartResultType const type; + TestPartResult::Type const type; const char* const file; int const line; String const message; diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 49e104af..47755243 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -756,13 +756,13 @@ 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 |