aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-08-09 18:19:15 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2010-08-09 18:19:15 +0000
commit5c4b472bbf8c81fc3d52fc69a92f174821a96280 (patch)
treecb61bdc699ce42b01ae571b3021d7c3a66188311 /test
parent7c598c4f1a44fdda5f97587484c85bef9e93fa98 (diff)
downloadgoogletest-5c4b472bbf8c81fc3d52fc69a92f174821a96280.tar.gz
googletest-5c4b472bbf8c81fc3d52fc69a92f174821a96280.tar.bz2
googletest-5c4b472bbf8c81fc3d52fc69a92f174821a96280.zip
Makes gtest print enums as integers instead of hex dumps (by Zhanyong Wan); improves the hex dump format (by Zhanyong Wan); gets rid of class TestInfoImpl (by Zhanyong Wan); adds exception handling (by Vlad Losev).
Diffstat (limited to 'test')
-rw-r--r--test/gtest-death-test_test.cc11
-rw-r--r--test/gtest-printers_test.cc82
-rwxr-xr-xtest/gtest_catch_exceptions_test.py203
-rw-r--r--test/gtest_catch_exceptions_test_.cc299
-rw-r--r--test/gtest_output_test_.cc131
-rw-r--r--test/gtest_output_test_golden_win.txt49
-rw-r--r--test/gtest_unittest.cc62
7 files changed, 619 insertions, 218 deletions
diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc
index ed5b53b7..d33cfeb7 100644
--- a/test/gtest-death-test_test.cc
+++ b/test/gtest-death-test_test.cc
@@ -614,17 +614,6 @@ TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
abort();
}, "");
}
-
-TEST(PopUpDeathTest, DoesNotShowPopUpOnThrow) {
- printf("This test should be considered failing if it shows "
- "any pop-up dialogs.\n");
- fflush(stdout);
-
- EXPECT_DEATH({
- testing::GTEST_FLAG(catch_exceptions) = false;
- throw 1;
- }, "");
-}
#endif // GTEST_OS_WINDOWS
// Tests that EXPECT_DEBUG_DEATH in debug mode does not abort
diff --git a/test/gtest-printers_test.cc b/test/gtest-printers_test.cc
index 11f6625b..5dec871c 100644
--- a/test/gtest-printers_test.cc
+++ b/test/gtest-printers_test.cc
@@ -60,6 +60,42 @@
// Some user-defined types for testing the universal value printer.
+// An anonymous enum type.
+enum AnonymousEnum {
+ kAE1 = -1,
+ kAE2 = 1
+};
+
+// An enum without a user-defined printer.
+enum EnumWithoutPrinter {
+ kEWP1 = -2,
+ kEWP2 = 42
+};
+
+// An enum with a << operator.
+enum EnumWithStreaming {
+ kEWS1 = 10,
+};
+
+std::ostream& operator<<(std::ostream& os, EnumWithStreaming e) {
+ return os << (e == kEWS1 ? "kEWS1" : "invalid");
+}
+
+// An enum with a PrintTo() function.
+enum EnumWithPrintTo {
+ kEWPT1 = 1,
+};
+
+void PrintTo(EnumWithPrintTo e, std::ostream* os) {
+ *os << (e == kEWPT1 ? "kEWPT1" : "invalid");
+}
+
+// A class implicitly convertible to BiggestInt.
+class BiggestIntConvertible {
+ public:
+ operator ::testing::internal::BiggestInt() const { return 42; }
+};
+
// A user-defined unprintable class template in the global namespace.
template <typename T>
class UnprintableTemplateInGlobal {
@@ -207,6 +243,34 @@ string PrintByRef(const T& value) {
return ss.str();
}
+// Tests printing various enum types.
+
+TEST(PrintEnumTest, AnonymousEnum) {
+ EXPECT_EQ("-1", Print(kAE1));
+ EXPECT_EQ("1", Print(kAE2));
+}
+
+TEST(PrintEnumTest, EnumWithoutPrinter) {
+ EXPECT_EQ("-2", Print(kEWP1));
+ EXPECT_EQ("42", Print(kEWP2));
+}
+
+TEST(PrintEnumTest, EnumWithStreaming) {
+ EXPECT_EQ("kEWS1", Print(kEWS1));
+ EXPECT_EQ("invalid", Print(static_cast<EnumWithStreaming>(0)));
+}
+
+TEST(PrintEnumTest, EnumWithPrintTo) {
+ EXPECT_EQ("kEWPT1", Print(kEWPT1));
+ EXPECT_EQ("invalid", Print(static_cast<EnumWithPrintTo>(0)));
+}
+
+// Tests printing a class implicitly convertible to BiggestInt.
+
+TEST(PrintClassTest, BiggestIntConvertible) {
+ EXPECT_EQ("42", Print(BiggestIntConvertible()));
+}
+
// Tests printing various char types.
// char.
@@ -913,7 +977,7 @@ TEST(PrintUnprintableTypeTest, InGlobalNamespace) {
// Unprintable types in a user namespace.
TEST(PrintUnprintableTypeTest, InUserNamespace) {
- EXPECT_EQ("16-byte object <EF12 0000 34AB 0000 0000 0000 0000 0000>",
+ EXPECT_EQ("16-byte object <EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
Print(::foo::UnprintableInFoo()));
}
@@ -925,13 +989,13 @@ struct Big {
};
TEST(PrintUnpritableTypeTest, BigObject) {
- EXPECT_EQ("257-byte object <0000 0000 0000 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 ... 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 "
- "0000 0000 0000 0000 0000 0000 0000 0000 00>",
+ EXPECT_EQ("257-byte object <00-00 00-00 00-00 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 ... 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 "
+ "00-00 00-00 00-00 00-00 00-00 00-00 00-00 00-00 00>",
Print(Big()));
}
@@ -1022,7 +1086,7 @@ TEST(PrintReferenceTest, PrintsAddressAndValue) {
const ::foo::UnprintableInFoo x;
EXPECT_EQ("@" + PrintPointer(&x) + " 16-byte object "
- "<EF12 0000 34AB 0000 0000 0000 0000 0000>",
+ "<EF-12 00-00 34-AB 00-00 00-00 00-00 00-00 00-00>",
PrintByRef(x));
}
diff --git a/test/gtest_catch_exceptions_test.py b/test/gtest_catch_exceptions_test.py
new file mode 100755
index 00000000..c4d1756d
--- /dev/null
+++ b/test/gtest_catch_exceptions_test.py
@@ -0,0 +1,203 @@
+#!/usr/bin/env python
+#
+# Copyright 2010 Google Inc. All Rights Reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+"""Tests Google Test's exception catching behavior.
+
+This script invokes gtest_catch_exceptions_test_ and
+gtest_catch_exceptions_ex_test_ (programs written with
+Google Test) and verifies their output.
+"""
+
+__author__ = 'vladl@google.com (Vlad Losev)'
+
+import os
+
+import gtest_test_utils
+
+# Constants.
+LIST_TESTS_FLAG = '--gtest_list_tests'
+
+# Path to the gtest_catch_exceptions_ex_test_ binary, compiled with
+# exceptions enabled.
+EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath(
+ 'gtest_catch_exceptions_ex_test_')
+
+# Path to the gtest_catch_exceptions_test_ binary, compiled with
+# exceptions disabled.
+EXE_PATH = gtest_test_utils.GetTestExecutablePath(
+ 'gtest_catch_exceptions_no_ex_test_')
+
+TEST_LIST = gtest_test_utils.Subprocess([EXE_PATH, LIST_TESTS_FLAG]).output
+
+SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST
+
+if SUPPORTS_SEH_EXCEPTIONS:
+ BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
+
+EX_BINARY_OUTPUT = gtest_test_utils.Subprocess([EX_EXE_PATH]).output
+
+
+# The tests.
+if SUPPORTS_SEH_EXCEPTIONS:
+ # pylint:disable-msg=C6302
+ class CatchSehExceptionsTest(gtest_test_utils.TestCase):
+ """Tests exception-catching behavior."""
+
+
+ def TestSehExceptions(self, test_output):
+ self.assert_('SEH exception with code 0x2a thrown '
+ 'in the test fixture\'s constructor'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown '
+ 'in the test fixture\'s destructor'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown in SetUp()'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown in TearDown()'
+ in test_output)
+ self.assert_('SEH exception with code 0x2a thrown in the test body'
+ in test_output)
+
+ def testCatchesSehExceptionsWithCxxExceptionsEnabled(self):
+ self.TestSehExceptions(EX_BINARY_OUTPUT)
+
+ def testCatchesSehExceptionsWithCxxExceptionsDisabled(self):
+ self.TestSehExceptions(BINARY_OUTPUT)
+
+
+class CatchCxxExceptionsTest(gtest_test_utils.TestCase):
+ """Tests C++ exception-catching behavior.
+
+ Tests in this test case verify that:
+ * C++ exceptions are caught and logged as C++ (not SEH) exceptions
+ * Exception thrown affect the remainder of the test work flow in the
+ expected manner.
+ """
+
+ def testCatchesCxxExceptionsInFixtureConstructor(self):
+ self.assert_('C++ exception with description '
+ '"Standard C++ exception" thrown '
+ 'in the test fixture\'s constructor'
+ in EX_BINARY_OUTPUT)
+ self.assert_('unexpected' not in EX_BINARY_OUTPUT,
+ 'This failure belongs in this test only if '
+ '"CxxExceptionInConstructorTest" (no quotes) '
+ 'appears on the same line as words "called unexpectedly"')
+
+ def testCatchesCxxExceptionsInFixtureDestructor(self):
+ self.assert_('C++ exception with description '
+ '"Standard C++ exception" thrown '
+ 'in the test fixture\'s destructor'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+
+ def testCatchesCxxExceptionsInSetUpTestCase(self):
+ self.assert_('C++ exception with description "Standard C++ exception"'
+ ' thrown in SetUpTestCase()'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTestCaseTest constructor '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTestCaseTest destructor '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTestCaseTest test body '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+
+ def testCatchesCxxExceptionsInTearDownTestCase(self):
+ self.assert_('C++ exception with description "Standard C++ exception"'
+ ' thrown in TearDownTestCase()'
+ in EX_BINARY_OUTPUT)
+
+ def testCatchesCxxExceptionsInSetUp(self):
+ self.assert_('C++ exception with description "Standard C++ exception"'
+ ' thrown in SetUp()'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTest destructor '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInSetUpTest::TearDown() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('unexpected' not in EX_BINARY_OUTPUT,
+ 'This failure belongs in this test only if '
+ '"CxxExceptionInSetUpTest" (no quotes) '
+ 'appears on the same line as words "called unexpectedly"')
+
+ def testCatchesCxxExceptionsInTearDown(self):
+ self.assert_('C++ exception with description "Standard C++ exception"'
+ ' thrown in TearDown()'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInTearDownTest destructor '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+
+ def testCatchesCxxExceptionsInTestBody(self):
+ self.assert_('C++ exception with description "Standard C++ exception"'
+ ' thrown in the test body'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInTestBodyTest destructor '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+ self.assert_('CxxExceptionInTestBodyTest::TearDown() '
+ 'called as expected.'
+ in EX_BINARY_OUTPUT)
+
+ def testCatchesNonStdCxxExceptions(self):
+ self.assert_('Unknown C++ exception thrown in the test body'
+ in EX_BINARY_OUTPUT)
+
+if __name__ == '__main__':
+ gtest_test_utils.Main()
diff --git a/test/gtest_catch_exceptions_test_.cc b/test/gtest_catch_exceptions_test_.cc
new file mode 100644
index 00000000..86736811
--- /dev/null
+++ b/test/gtest_catch_exceptions_test_.cc
@@ -0,0 +1,299 @@
+// Copyright 2010, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Author: vladl@google.com (Vlad Losev)
+//
+// Tests for Google Test itself. Tests in this file throw C++ or SEH
+// exceptions, and the output is verified by gtest_catch_exceptions_test.py.
+
+#include <gtest/gtest.h>
+
+#include <stdio.h> // NOLINT
+
+#if GTEST_HAS_SEH
+#include <windows.h>
+#endif
+
+#if GTEST_HAS_EXCEPTIONS
+#include <stdexcept>
+#endif
+
+using testing::Test;
+using testing::GTEST_FLAG(catch_exceptions);
+
+#if GTEST_HAS_SEH
+
+class SehExceptionInConstructorTest : public Test {
+ public:
+ SehExceptionInConstructorTest() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInConstructorTest, ThrowsExceptionInConstructor) {}
+
+class SehExceptionInDestructorTest : public Test {
+ public:
+ ~SehExceptionInDestructorTest() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
+
+class SehExceptionInSetUpTestCaseTest : public Test {
+ public:
+ static void SetUpTestCase() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) {}
+
+class SehExceptionInTearDownTestCaseTest : public Test {
+ public:
+ static void TearDownTestCase() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {}
+
+class SehExceptionInSetUpTest : public Test {
+ protected:
+ virtual void SetUp() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInSetUpTest, ThrowsExceptionInSetUp) {}
+
+class SehExceptionInTearDownTest : public Test {
+ protected:
+ virtual void TearDown() { RaiseException(42, 0, 0, NULL); }
+};
+
+TEST_F(SehExceptionInTearDownTest, ThrowsExceptionInTearDown) {}
+
+TEST(SehExceptionTest, ThrowsSehException) {
+ RaiseException(42, 0, 0, NULL);
+}
+
+#endif // GTEST_HAS_SEH
+
+#if GTEST_HAS_EXCEPTIONS
+
+class CxxExceptionInConstructorTest : public Test {
+ public:
+ CxxExceptionInConstructorTest() {
+ // Without this macro VC++ complains about unreachable code at the end of
+ // the constructor.
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
+ throw std::runtime_error("Standard C++ exception"));
+ }
+
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInConstructorTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInConstructorTest() {
+ ADD_FAILURE() << "CxxExceptionInConstructorTest destructor "
+ << "called unexpectedly.";
+ }
+
+ virtual void SetUp() {
+ ADD_FAILURE() << "CxxExceptionInConstructorTest::SetUp() "
+ << "called unexpectedly.";
+ }
+
+ virtual void TearDown() {
+ ADD_FAILURE() << "CxxExceptionInConstructorTest::TearDown() "
+ << "called unexpectedly.";
+ }
+};
+
+TEST_F(CxxExceptionInConstructorTest, ThrowsExceptionInConstructor) {
+ ADD_FAILURE() << "CxxExceptionInConstructorTest test body "
+ << "called unexpectedly.";
+}
+
+class CxxExceptionInDestructorTest : public Test {
+ public:
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInDestructorTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInDestructorTest() {
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
+ throw std::runtime_error("Standard C++ exception"));
+ }
+};
+
+TEST_F(CxxExceptionInDestructorTest, ThrowsExceptionInDestructor) {}
+
+class CxxExceptionInSetUpTestCaseTest : public Test {
+ public:
+ CxxExceptionInSetUpTestCaseTest() {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest constructor "
+ "called as expected.\n");
+ }
+
+ static void SetUpTestCase() {
+ throw std::runtime_error("Standard C++ exception");
+ }
+
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInSetUpTestCaseTest() {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest destructor "
+ "called as expected.\n");
+ }
+
+ virtual void SetUp() {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest::SetUp() "
+ "called as expected.\n");
+ }
+
+ virtual void TearDown() {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest::TearDown() "
+ "called as expected.\n");
+ }
+};
+
+TEST_F(CxxExceptionInSetUpTestCaseTest, ThrowsExceptionInSetUpTestCase) {
+ printf("%s",
+ "CxxExceptionInSetUpTestCaseTest test body "
+ "called as expected.\n");
+}
+
+class CxxExceptionInTearDownTestCaseTest : public Test {
+ public:
+ static void TearDownTestCase() {
+ throw std::runtime_error("Standard C++ exception");
+ }
+};
+
+TEST_F(CxxExceptionInTearDownTestCaseTest, ThrowsExceptionInTearDownTestCase) {}
+
+class CxxExceptionInSetUpTest : public Test {
+ public:
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInSetUpTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInSetUpTest() {
+ printf("%s",
+ "CxxExceptionInSetUpTest destructor "
+ "called as expected.\n");
+ }
+
+ virtual void SetUp() { throw std::runtime_error("Standard C++ exception"); }
+
+ virtual void TearDown() {
+ printf("%s",
+ "CxxExceptionInSetUpTest::TearDown() "
+ "called as expected.\n");
+ }
+};
+
+TEST_F(CxxExceptionInSetUpTest, ThrowsExceptionInSetUp) {
+ ADD_FAILURE() << "CxxExceptionInSetUpTest test body "
+ << "called unexpectedly.";
+}
+
+class CxxExceptionInTearDownTest : public Test {
+ public:
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInTearDownTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInTearDownTest() {
+ printf("%s",
+ "CxxExceptionInTearDownTest destructor "
+ "called as expected.\n");
+ }
+
+ virtual void TearDown() {
+ throw std::runtime_error("Standard C++ exception");
+ }
+};
+
+TEST_F(CxxExceptionInTearDownTest, ThrowsExceptionInTearDown) {}
+
+class CxxExceptionInTestBodyTest : public Test {
+ public:
+ static void TearDownTestCase() {
+ printf("%s",
+ "CxxExceptionInTestBodyTest::TearDownTestCase() "
+ "called as expected.\n");
+ }
+
+ protected:
+ ~CxxExceptionInTestBodyTest() {
+ printf("%s",
+ "CxxExceptionInTestBodyTest destructor "
+ "called as expected.\n");
+ }
+
+ virtual void TearDown() {
+ printf("%s",
+ "CxxExceptionInTestBodyTest::TearDown() "
+ "called as expected.\n");
+ }
+};
+
+TEST_F(CxxExceptionInTestBodyTest, ThrowsStdCxxException) {
+ throw std::runtime_error("Standard C++ exception");
+}
+
+TEST(CxxExceptionTest, ThrowsNonStdCxxException) {
+ throw "C-string";
+}
+
+#endif // GTEST_HAS_EXCEPTIONS
+
+int main(int argc, char** argv) {
+#if GTEST_HAS_SEH
+ // Tells Google Test to catch SEH-style exceptions on Windows.
+ GTEST_FLAG(catch_exceptions) = true;
+#endif
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/gtest_output_test_.cc b/test/gtest_output_test_.cc
index 454e1bad..fc80fac3 100644
--- a/test/gtest_output_test_.cc
+++ b/test/gtest_output_test_.cc
@@ -445,137 +445,6 @@ TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
ADD_FAILURE_AT("foo.cc", 42) << "Expected failure in foo.cc";
}
-#if GTEST_OS_WINDOWS
-
-// This group of tests verifies that Google Test handles SEH and C++
-// exceptions correctly.
-
-// A function that throws an SEH exception.
-static void ThrowSEH() {
- int* p = NULL;
- *p = 0; // Raises an access violation.
-}
-
-// Tests exceptions thrown in the test fixture constructor.
-class ExceptionInFixtureCtorTest : public testing::Test {
- protected:
- ExceptionInFixtureCtorTest() {
- printf("(expecting a failure on thrown exception "
- "in the test fixture's constructor)\n");
-
- ThrowSEH();
- }
-
- virtual ~ExceptionInFixtureCtorTest() {
- Deinit();
- }
-
- virtual void SetUp() {
- FAIL() << "UNEXPECTED failure in SetUp(). "
- << "We should never get here, as the test fixture c'tor threw.";
- }
-
- virtual void TearDown() {
- FAIL() << "UNEXPECTED failure in TearDown(). "
- << "We should never get here, as the test fixture c'tor threw.";
- }
- private:
- void Deinit() {
- FAIL() << "UNEXPECTED failure in the d'tor. "
- << "We should never get here, as the test fixture c'tor threw.";
- }
-};
-
-TEST_F(ExceptionInFixtureCtorTest, ExceptionInFixtureCtor) {
- FAIL() << "UNEXPECTED failure in the test function. "
- << "We should never get here, as the test fixture c'tor threw.";
-}
-
-// Tests exceptions thrown in SetUp().
-class ExceptionInSetUpTest : public testing::Test {
- protected:
- virtual ~ExceptionInSetUpTest() {
- Deinit();
- }
-
- virtual void SetUp() {
- printf("(expecting 3 failures)\n");
-
- ThrowSEH();
- }
-
- virtual void TearDown() {
- FAIL() << "Expected failure #2, in TearDown().";
- }
- private:
- void Deinit() {
- FAIL() << "Expected failure #3, in the test fixture d'tor.";
- }
-};
-
-TEST_F(ExceptionInSetUpTest, ExceptionInSetUp) {
- FAIL() << "UNEXPECTED failure in the test function. "
- << "We should never get here, as SetUp() threw.";
-}
-
-// Tests that TearDown() and the test fixture d'tor are always called,
-// even when the test function throws an exception.
-class ExceptionInTestFunctionTest : public testing::Test {
- protected:
- virtual ~ExceptionInTestFunctionTest() {
- Deinit();
- }
-
- virtual void TearDown() {
- FAIL() << "Expected failure #2, in TearDown().";
- }
- private:
- void Deinit() {
- FAIL() << "Expected failure #3, in the test fixture d'tor.";
- }
-};
-
-// Tests that the test fixture d'tor is always called, even when the
-// test function throws an SEH exception.
-TEST_F(ExceptionInTestFunctionTest, SEH) {
- printf("(expecting 3 failures)\n");
-
- ThrowSEH();
-}
-
-#if GTEST_HAS_EXCEPTIONS
-
-// Tests that the test fixture d'tor is always called, even when the
-// test function throws a C++ exception. We do this only when
-// GTEST_HAS_EXCEPTIONS is non-zero, i.e. C++ exceptions are enabled.
-TEST_F(ExceptionInTestFunctionTest, CppException) {
- throw 1;
-}
-
-// Tests exceptions thrown in TearDown().
-class ExceptionInTearDownTest : public testing::Test {
- protected:
- virtual ~ExceptionInTearDownTest() {
- Deinit();
- }
-
- virtual void TearDown() {
- throw 1;
- }
- private:
- void Deinit() {
- FAIL() << "Expected failure #2, in the test fixture d'tor.";
- }
-};
-
-TEST_F(ExceptionInTearDownTest, ExceptionInTearDown) {
- printf("(expecting 2 failures)\n");
-}
-
-#endif // GTEST_HAS_EXCEPTIONS
-
-#endif // GTEST_OS_WINDOWS
-
#if GTEST_IS_THREADSAFE
// A unary function that may die.
diff --git a/test/gtest_output_test_golden_win.txt b/test/gtest_output_test_golden_win.txt
index 135f39e3..8251c23d 100644
--- a/test/gtest_output_test_golden_win.txt
+++ b/test/gtest_output_test_golden_win.txt
@@ -5,7 +5,7 @@ gtest_output_test_.cc:#: error: Value of: false
Expected: true
gtest_output_test_.cc:#: error: Value of: 3
Expected: 2
-[==========] Running 63 tests from 29 test cases.
+[==========] Running 58 tests from 25 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
@@ -178,42 +178,6 @@ Expected failure #3, in the test fixture d'tor.
foo.cc(42): error: Failed
Expected failure in foo.cc
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
-[----------] 1 test from ExceptionInFixtureCtorTest
-[ RUN ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
-(expecting a failure on thrown exception in the test fixture's constructor)
-unknown file: error: Exception thrown with code 0xc0000005 in the test fixture's constructor.
-[----------] 1 test from ExceptionInSetUpTest
-[ RUN ] ExceptionInSetUpTest.ExceptionInSetUp
-(expecting 3 failures)
-unknown file: error: Exception thrown with code 0xc0000005 in SetUp().
-gtest_output_test_.cc:#: error: Failed
-Expected failure #2, in TearDown().
-gtest_output_test_.cc:#: error: Failed
-Expected failure #3, in the test fixture d'tor.
-[ FAILED ] ExceptionInSetUpTest.ExceptionInSetUp
-[----------] 2 tests from ExceptionInTestFunctionTest
-[ RUN ] ExceptionInTestFunctionTest.SEH
-(expecting 3 failures)
-unknown file: error: Exception thrown with code 0xc0000005 in the test body.
-gtest_output_test_.cc:#: error: Failed
-Expected failure #2, in TearDown().
-gtest_output_test_.cc:#: error: Failed
-Expected failure #3, in the test fixture d'tor.
-[ FAILED ] ExceptionInTestFunctionTest.SEH
-[ RUN ] ExceptionInTestFunctionTest.CppException
-unknown file: error: Exception thrown with code 0xe06d7363 in the test body.
-gtest_output_test_.cc:#: error: Failed
-Expected failure #2, in TearDown().
-gtest_output_test_.cc:#: error: Failed
-Expected failure #3, in the test fixture d'tor.
-[ FAILED ] ExceptionInTestFunctionTest.CppException
-[----------] 1 test from ExceptionInTearDownTest
-[ RUN ] ExceptionInTearDownTest.ExceptionInTearDown
-(expecting 2 failures)
-unknown file: error: Exception thrown with code 0xe06d7363 in TearDown().
-gtest_output_test_.cc:#: error: Failed
-Expected failure #2, in the test fixture d'tor.
-[ FAILED ] ExceptionInTearDownTest.ExceptionInTearDown
[----------] 4 tests from MixedUpTestCaseTest
[ RUN ] MixedUpTestCaseTest.FirstTestFromNamespaceFoo
[ OK ] MixedUpTestCaseTest.FirstTestFromNamespaceFoo
@@ -497,9 +461,9 @@ Expected non-fatal failure.
FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
Expected fatal failure.
-[==========] 63 tests from 29 test cases ran.
+[==========] 58 tests from 25 test cases ran.
[ PASSED ] 21 tests.
-[ FAILED ] 42 tests, listed below:
+[ FAILED ] 37 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
@@ -514,11 +478,6 @@ Expected fatal failure.
[ FAILED ] NonFatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] FatalFailureInSetUpTest.FailureInSetUp
[ FAILED ] AddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
-[ FAILED ] ExceptionInFixtureCtorTest.ExceptionInFixtureCtor
-[ FAILED ] ExceptionInSetUpTest.ExceptionInSetUp
-[ FAILED ] ExceptionInTestFunctionTest.SEH
-[ FAILED ] ExceptionInTestFunctionTest.CppException
-[ FAILED ] ExceptionInTearDownTest.ExceptionInTearDown
[ FAILED ] MixedUpTestCaseTest.ThisShouldFail
[ FAILED ] MixedUpTestCaseTest.ThisShouldFailToo
[ FAILED ] MixedUpTestCaseWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
@@ -543,7 +502,7 @@ Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
-42 FAILED TESTS
+37 FAILED TESTS
YOU HAVE 1 DISABLED TEST
Note: Google Test filter = FatalFailureTest.*:LoggingTest.*
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index 910d4e20..9b95b138 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -3767,6 +3767,17 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
"Value of: y\n Actual: -1\nExpected: x\nWhich is: 5");
}
+enum NamedEnum {
+ kE1 = 0,
+ kE2 = 1,
+};
+
+TEST(AssertionTest, NamedEnum) {
+ EXPECT_EQ(kE1, kE1);
+ EXPECT_LT(kE1, kE2);
+ EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Which is: 0");
+ EXPECT_NONFATAL_FAILURE(EXPECT_EQ(kE1, kE2), "Actual: 1");
+}
// The version of gcc used in XCode 2.2 has a bug and doesn't allow
// anonymous enums in assertions. Therefore the following test is not
@@ -3776,7 +3787,7 @@ TEST(AssertionTest, ExpectWorksWithUncopyableObject) {
// Tests using assertions with anonymous enums.
enum {
- CASE_A = -1,
+ kCaseA = -1,
#if GTEST_OS_LINUX
// We want to test the case where the size of the anonymous enum is
// larger than sizeof(int), to make sure our implementation of the
@@ -3784,37 +3795,44 @@ enum {
// (incorrectly) doesn't allow an enum value to exceed the range of
// an int, so this has to be conditionally compiled.
//
- // On Linux, CASE_B and CASE_A have the same value when truncated to
+ // On Linux, kCaseB and kCaseA have the same value when truncated to
// int size. We want to test whether this will confuse the
// assertions.
- CASE_B = testing::internal::kMaxBiggestInt,
+ kCaseB = testing::internal::kMaxBiggestInt,
#else
- CASE_B = INT_MAX,
+ kCaseB = INT_MAX,
#endif // GTEST_OS_LINUX
+ kCaseC = 42,
};
TEST(AssertionTest, AnonymousEnum) {
#if GTEST_OS_LINUX
- EXPECT_EQ(static_cast<int>(CASE_A), static_cast<int>(CASE_B));
+ EXPECT_EQ(static_cast<int>(kCaseA), static_cast<int>(kCaseB));
#endif // GTEST_OS_LINUX
- EXPECT_EQ(CASE_A, CASE_A);
- EXPECT_NE(CASE_A, CASE_B);
- EXPECT_LT(CASE_A, CASE_B);
- EXPECT_LE(CASE_A, CASE_B);
- EXPECT_GT(CASE_B, CASE_A);
- EXPECT_GE(CASE_A, CASE_A);
- EXPECT_NONFATAL_FAILURE(EXPECT_GE(CASE_A, CASE_B),
- "(CASE_A) >= (CASE_B)");
-
- ASSERT_EQ(CASE_A, CASE_A);
- ASSERT_NE(CASE_A, CASE_B);
- ASSERT_LT(CASE_A, CASE_B);
- ASSERT_LE(CASE_A, CASE_B);
- ASSERT_GT(CASE_B, CASE_A);
- ASSERT_GE(CASE_A, CASE_A);
- EXPECT_FATAL_FAILURE(ASSERT_EQ(CASE_A, CASE_B),
- "Value of: CASE_B");
+ EXPECT_EQ(kCaseA, kCaseA);
+ EXPECT_NE(kCaseA, kCaseB);
+ EXPECT_LT(kCaseA, kCaseB);
+ EXPECT_LE(kCaseA, kCaseB);
+ EXPECT_GT(kCaseB, kCaseA);
+ EXPECT_GE(kCaseA, kCaseA);
+ EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseB),
+ "(kCaseA) >= (kCaseB)");
+ EXPECT_NONFATAL_FAILURE(EXPECT_GE(kCaseA, kCaseC),
+ "-1 vs 42");
+
+ ASSERT_EQ(kCaseA, kCaseA);
+ ASSERT_NE(kCaseA, kCaseB);
+ ASSERT_LT(kCaseA, kCaseB);
+ ASSERT_LE(kCaseA, kCaseB);
+ ASSERT_GT(kCaseB, kCaseA);
+ ASSERT_GE(kCaseA, kCaseA);
+ EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseB),
+ "Value of: kCaseB");
+ EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
+ "Actual: 42");
+ EXPECT_FATAL_FAILURE(ASSERT_EQ(kCaseA, kCaseC),
+ "Which is: -1");
}
#endif // !GTEST_OS_MAC && !defined(__SUNPRO_CC)