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).

This commit is contained in:
zhanyong.wan
2010-08-09 18:19:15 +00:00
parent 7c598c4f1a
commit 5c4b472bbf
13 changed files with 936 additions and 589 deletions

View File

@@ -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.