Many changes:

- appends "_" to internal macro names (by Markus Heule).
- makes Google Test work with newer versions of tools on Symbian and Windows CE (by Mika Raento).
- adds the (ASSERT|EXPECT)_NO_FATAL_FAILURE macros (by Markus Heule).
- changes EXPECT_(NON|)FATAL_FAILURE to catch failures in the current thread only (by Markus Heule).
- adds the EXPECT_(NON|)FATAL_FAILURE_ON_ALL_THREADS macros (by Markus Heule).
- adds GTEST_HAS_PTHREAD and GTEST_IS_THREADSAFE to indicate the availability of <pthread.h> and Google Test's thread-safety (by Zhanyong Wan).
- adds scons/SConscript for building with scons (by Joi Sigurdsson).
- adds src/gtest-all.cc for building Google Test from a single file (by Markus Heule).
- updates the xcode project to include new tests (by Preston Jackson).
This commit is contained in:
shiqian
2008-10-11 07:20:02 +00:00
parent 0cbe322d37
commit e0865dd919
34 changed files with 2317 additions and 731 deletions

View File

@@ -115,7 +115,7 @@ class MayDie {
// A member function that may die.
void MemberFunction() const {
if (should_die_) {
GTEST_LOG(FATAL, "death inside MayDie::MemberFunction().");
GTEST_LOG_(FATAL, "death inside MayDie::MemberFunction().");
}
}
@@ -126,26 +126,26 @@ class MayDie {
// A global function that's expected to die.
void GlobalFunction() {
GTEST_LOG(FATAL, "death inside GlobalFunction().");
GTEST_LOG_(FATAL, "death inside GlobalFunction().");
}
// A non-void function that's expected to die.
int NonVoidFunction() {
GTEST_LOG(FATAL, "death inside NonVoidFunction().");
GTEST_LOG_(FATAL, "death inside NonVoidFunction().");
return 1;
}
// A unary function that may die.
void DieIf(bool should_die) {
if (should_die) {
GTEST_LOG(FATAL, "death inside DieIf().");
GTEST_LOG_(FATAL, "death inside DieIf().");
}
}
// A binary function that may die.
bool DieIfLessThan(int x, int y) {
if (x < y) {
GTEST_LOG(FATAL, "death inside DieIfLessThan().");
GTEST_LOG_(FATAL, "death inside DieIfLessThan().");
}
return true;
}
@@ -160,7 +160,7 @@ void DeathTestSubroutine() {
int DieInDebugElse12(int* sideeffect) {
if (sideeffect) *sideeffect = 12;
#ifndef NDEBUG
GTEST_LOG(FATAL, "debug death inside DieInDebugElse12()");
GTEST_LOG_(FATAL, "debug death inside DieInDebugElse12()");
#endif // NDEBUG
return 12;
}
@@ -717,7 +717,7 @@ bool MockDeathTestFactory::Create(const char* statement,
return true;
}
// A test fixture for testing the logic of the GTEST_DEATH_TEST macro.
// A test fixture for testing the logic of the GTEST_DEATH_TEST_ macro.
// It installs a MockDeathTestFactory that is used for the duration
// of the test case.
class MacroLogicDeathTest : public testing::Test {

View File

@@ -286,9 +286,12 @@ TEST(DirectoryTest, RootOfWrongDriveDoesNotExists) {
}
#endif // GTEST_OS_WINDOWS
#ifndef _WIN32_WCE
// Windows CE _does_ consider an empty directory to exist.
TEST(DirectoryTest, EmptyPathDirectoryDoesNotExist) {
EXPECT_FALSE(FilePath("").DirectoryExists());
}
#endif // ! _WIN32_WCE
TEST(DirectoryTest, CurrentDirectoryExists) {
#ifdef GTEST_OS_WINDOWS // We are on Windows.

View File

@@ -0,0 +1,138 @@
// Copyright 2008 Google Inc. All Rights Reserved.
// Author: mheule@google.com (Markus Heule)
#include <gtest/gtest-test-part.h>
#include <gtest/gtest.h>
using testing::Test;
using testing::TestPartResult;
using testing::TestPartResultArray;
using testing::TPRT_FATAL_FAILURE;
using testing::TPRT_NONFATAL_FAILURE;
using testing::TPRT_SUCCESS;
namespace {
// Tests the TestPartResult class.
// The test fixture for testing TestPartResult.
class TestPartResultTest : public Test {
protected:
TestPartResultTest()
: r1_(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!"),
r2_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure!"),
r3_(TPRT_FATAL_FAILURE, NULL, -1, "Failure!") {}
TestPartResult r1_, r2_, r3_;
};
// Tests TestPartResult::type().
TEST_F(TestPartResultTest, type) {
EXPECT_EQ(TPRT_SUCCESS, r1_.type());
EXPECT_EQ(TPRT_NONFATAL_FAILURE, r2_.type());
EXPECT_EQ(TPRT_FATAL_FAILURE, r3_.type());
}
// Tests TestPartResult::file_name().
TEST_F(TestPartResultTest, file_name) {
EXPECT_STREQ("foo/bar.cc", r1_.file_name());
EXPECT_STREQ(NULL, r3_.file_name());
}
// Tests TestPartResult::line_number().
TEST_F(TestPartResultTest, line_number) {
EXPECT_EQ(10, r1_.line_number());
EXPECT_EQ(-1, r2_.line_number());
}
// Tests TestPartResult::message().
TEST_F(TestPartResultTest, message) {
EXPECT_STREQ("Success!", r1_.message());
}
// Tests TestPartResult::passed().
TEST_F(TestPartResultTest, Passed) {
EXPECT_TRUE(r1_.passed());
EXPECT_FALSE(r2_.passed());
EXPECT_FALSE(r3_.passed());
}
// Tests TestPartResult::failed().
TEST_F(TestPartResultTest, Failed) {
EXPECT_FALSE(r1_.failed());
EXPECT_TRUE(r2_.failed());
EXPECT_TRUE(r3_.failed());
}
// Tests TestPartResult::fatally_failed().
TEST_F(TestPartResultTest, FatallyFailed) {
EXPECT_FALSE(r1_.fatally_failed());
EXPECT_FALSE(r2_.fatally_failed());
EXPECT_TRUE(r3_.fatally_failed());
}
// Tests TestPartResult::nonfatally_failed().
TEST_F(TestPartResultTest, NonfatallyFailed) {
EXPECT_FALSE(r1_.nonfatally_failed());
EXPECT_TRUE(r2_.nonfatally_failed());
EXPECT_FALSE(r3_.nonfatally_failed());
}
// Tests the TestPartResultArray class.
class TestPartResultArrayTest : public Test {
protected:
TestPartResultArrayTest()
: r1_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure 1"),
r2_(TPRT_FATAL_FAILURE, "foo/bar.cc", -1, "Failure 2") {}
const TestPartResult r1_, r2_;
};
// Tests that TestPartResultArray initially has size 0.
TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
TestPartResultArray results;
EXPECT_EQ(0, results.size());
}
// Tests that TestPartResultArray contains the given TestPartResult
// after one Append() operation.
TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
TestPartResultArray results;
results.Append(r1_);
EXPECT_EQ(1, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
}
// Tests that TestPartResultArray contains the given TestPartResults
// after two Append() operations.
TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
TestPartResultArray results;
results.Append(r1_);
results.Append(r2_);
EXPECT_EQ(2, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
}
#ifdef GTEST_HAS_DEATH_TEST
typedef TestPartResultArrayTest TestPartResultArrayDeathTest;
// Tests that the program dies when GetTestPartResult() is called with
// an invalid index.
TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) {
TestPartResultArray results;
results.Append(r1_);
EXPECT_DEATH(results.GetTestPartResult(-1), "");
EXPECT_DEATH(results.GetTestPartResult(1), "");
}
#endif // GTEST_HAS_DEATH_TEST
// TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper.
} // namespace

View File

@@ -36,7 +36,7 @@
#include <gtest/gtest.h>
namespace testing {
GTEST_DECLARE_string(filter);
GTEST_DECLARE_string_(filter);
}
namespace {

View File

@@ -46,14 +46,20 @@
#include <stdlib.h>
#if GTEST_HAS_PTHREAD
#include <pthread.h>
#endif // GTEST_HAS_PTHREAD
#ifdef GTEST_OS_LINUX
#include <string.h>
#include <signal.h>
#include <pthread.h>
#include <string>
#include <vector>
#endif // GTEST_OS_LINUX
using testing::ScopedFakeTestPartResultReporter;
using testing::TestPartResultArray;
// Tests catching fatal failures.
// A subroutine used by the following test.
@@ -790,6 +796,134 @@ INSTANTIATE_TYPED_TEST_CASE_P(My, ATypeParamDeathTest, NumericTypes);
#endif // GTEST_HAS_DEATH_TEST
// Tests various failure conditions of
// EXPECT_{,NON}FATAL_FAILURE{,_ON_ALL_THREADS}.
class ExpectFailureTest : public testing::Test {
protected:
enum FailureMode {
FATAL_FAILURE,
NONFATAL_FAILURE
};
static void AddFailure(FailureMode failure) {
if (failure == FATAL_FAILURE) {
FAIL() << "Expected fatal failure.";
} else {
ADD_FAILURE() << "Expected non-fatal failure.";
}
}
};
TEST_F(ExpectFailureTest, ExpectFatalFailure) {
// Expected fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(SUCCEED(), "Expected fatal failure.");
// Expected fatal failure, but got a non-fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Expected non-fatal "
"failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE(AddFailure(FATAL_FAILURE), "Some other fatal failure "
"expected.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
// Expected non-fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(SUCCEED(), "Expected non-fatal failure.");
// Expected non-fatal failure, but got a fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(AddFailure(FATAL_FAILURE), "Expected fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Some other non-fatal "
"failure.");
}
#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
class ExpectFailureWithThreadsTest : public ExpectFailureTest {
protected:
static void AddFailureInOtherThread(FailureMode failure) {
pthread_t tid;
pthread_create(&tid,
NULL,
ExpectFailureWithThreadsTest::FailureThread,
&failure);
pthread_join(tid, NULL);
}
private:
static void* FailureThread(void* attr) {
FailureMode* failure = static_cast<FailureMode*>(attr);
AddFailure(*failure);
return NULL;
}
};
TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailure) {
// We only intercept the current thread.
printf("(expecting 2 failures)\n");
EXPECT_FATAL_FAILURE(AddFailureInOtherThread(FATAL_FAILURE),
"Expected fatal failure.");
}
TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailure) {
// We only intercept the current thread.
printf("(expecting 2 failures)\n");
EXPECT_NONFATAL_FAILURE(AddFailureInOtherThread(NONFATAL_FAILURE),
"Expected non-fatal failure.");
}
typedef ExpectFailureWithThreadsTest ScopedFakeTestPartResultReporterTest;
// Tests that the ScopedFakeTestPartResultReporter only catches failures from
// the current thread if it is instantiated with INTERCEPT_ONLY_CURRENT_THREAD.
TEST_F(ScopedFakeTestPartResultReporterTest, InterceptOnlyCurrentThread) {
printf("(expecting 2 failures)\n");
TestPartResultArray results;
{
ScopedFakeTestPartResultReporter reporter(
ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
&results);
AddFailureInOtherThread(FATAL_FAILURE);
AddFailureInOtherThread(NONFATAL_FAILURE);
}
// The two failures should not have been intercepted.
EXPECT_EQ(0, results.size()) << "This shouldn't fail.";
}
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
TEST_F(ExpectFailureTest, ExpectFatalFailureOnAllThreads) {
// Expected fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected fatal failure.");
// Expected fatal failure, but got a non-fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
"Expected non-fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
"Some other fatal failure expected.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
// Expected non-fatal failure, but succeeds.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected non-fatal "
"failure.");
// Expected non-fatal failure, but got a fatal failure.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
"Expected fatal failure.");
// Wrong message.
printf("(expecting 1 failure)\n");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
"Some other non-fatal failure.");
}
// Two test environments for testing testing::AddGlobalTestEnvironment().
class FooEnvironment : public testing::Environment {

View File

@@ -7,7 +7,7 @@ Expected: true
gtest_output_test_.cc:#: Failure
Value of: 3
Expected: 2
[==========] Running 48 tests from 21 test cases.
[==========] Running 52 tests from 22 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
@@ -386,6 +386,107 @@ Value of: TypeParam()
Expected: 1
Expected failure
[ FAILED ] Unsigned/TypedTestP/1.Failure
[----------] 4 tests from ExpectFailureTest
[ RUN ] ExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ RUN ] ExpectFailureTest.ExpectNonFatalFailure
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ RUN ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ RUN ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: Failure
Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
@@ -395,9 +496,9 @@ FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: Failure
Failed
Expected fatal failure.
[==========] 48 tests from 21 test cases ran.
[==========] 52 tests from 22 test cases ran.
[ PASSED ] 19 tests.
[ FAILED ] 29 tests, listed below:
[ FAILED ] 33 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
@@ -427,8 +528,12 @@ Expected fatal failure.
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
29 FAILED TESTS
33 FAILED TESTS
The non-test part of the code is expected to have 2 failures.
gtest_output_test_.cc:#: Failure

View File

@@ -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 46 tests from 19 test cases.
[==========] Running 50 tests from 20 test cases.
[----------] Global test environment set-up.
FooEnvironment::SetUp() called.
BarEnvironment::SetUp() called.
@@ -344,6 +344,95 @@ gtest_output_test_.cc:#: error: Value of: TypeParam()
Expected: 1
Expected failure
[ FAILED ] Unsigned/TypedTestP/1.Failure
[----------] 4 tests from ExpectFailureTest
[ RUN ] ExpectFailureTest.ExpectFatalFailure
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ RUN ] ExpectFailureTest.ExpectNonFatalFailure
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ RUN ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 fatal failure containing "Some other fatal failure expected."
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ RUN ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Success:
Succeeded
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure
Actual:
gtest_output_test_.cc:#: Fatal failure:
Failed
Expected fatal failure.
(expecting 1 failure)
gtest.cc:#: error: Expected: 1 non-fatal failure containing "Some other non-fatal failure."
Actual:
gtest_output_test_.cc:#: Non-fatal failure:
Failed
Expected non-fatal failure.
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
[----------] Global test environment tear-down
BarEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
@@ -351,9 +440,9 @@ Expected non-fatal failure.
FooEnvironment::TearDown() called.
gtest_output_test_.cc:#: error: Failed
Expected fatal failure.
[==========] 46 tests from 19 test cases ran.
[==========] 50 tests from 20 test cases ran.
[ PASSED ] 14 tests.
[ FAILED ] 32 tests, listed below:
[ FAILED ] 36 tests, listed below:
[ FAILED ] FatalFailureTest.FatalFailureInSubroutine
[ FAILED ] FatalFailureTest.FatalFailureInNestedSubroutine
[ FAILED ] FatalFailureTest.NonfatalFailureInSubroutine
@@ -386,8 +475,12 @@ Expected fatal failure.
[ FAILED ] TypedTest/0.Failure, where TypeParam = int
[ FAILED ] Unsigned/TypedTestP/0.Failure, where TypeParam = unsigned char
[ FAILED ] Unsigned/TypedTestP/1.Failure, where TypeParam = unsigned int
[ FAILED ] ExpectFailureTest.ExpectFatalFailure
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailure
[ FAILED ] ExpectFailureTest.ExpectFatalFailureOnAllThreads
[ FAILED ] ExpectFailureTest.ExpectNonFatalFailureOnAllThreads
32 FAILED TESTS
36 FAILED TESTS
The non-test part of the code is expected to have 2 failures.
gtest_output_test_.cc:#: error: Value of: false

View File

@@ -27,7 +27,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// This file is AUTOMATICALLY GENERATED on 06/11/2008 by command
// This file is AUTOMATICALLY GENERATED on 10/02/2008 by command
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
// Regression test for gtest_pred_impl.h

View File

@@ -46,9 +46,9 @@
namespace testing {
GTEST_DECLARE_string(death_test_style);
GTEST_DECLARE_string(filter);
GTEST_DECLARE_int32(repeat);
GTEST_DECLARE_string_(death_test_style);
GTEST_DECLARE_string_(filter);
GTEST_DECLARE_int32_(repeat);
} // namespace testing

View File

@@ -0,0 +1,57 @@
// Copyright 2008, 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: mheule@google.com (Markus Heule)
//
// This test verifies that it's possible to use Google Test by including
// the gtest.h header file alone.
#include <gtest/gtest.h>
namespace {
void Subroutine() {
EXPECT_EQ(42, 42);
}
TEST(NoFatalFailureTest, ExpectNoFatalFailure) {
EXPECT_NO_FATAL_FAILURE(;);
EXPECT_NO_FATAL_FAILURE(SUCCEED());
EXPECT_NO_FATAL_FAILURE(Subroutine());
EXPECT_NO_FATAL_FAILURE({ SUCCEED(); });
}
TEST(NoFatalFailureTest, AssertNoFatalFailure) {
ASSERT_NO_FATAL_FAILURE(;);
ASSERT_NO_FATAL_FAILURE(SUCCEED());
ASSERT_NO_FATAL_FAILURE(Subroutine());
ASSERT_NO_FATAL_FAILURE({ SUCCEED(); });
}
} // namespace

View File

@@ -112,6 +112,36 @@ TEST(StressTest, CanUseScopedTraceAndAssertionsInManyThreads) {
// ManyAsserts() in many threads here.
}
TEST(NoFatalFailureTest, ExpectNoFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(NoFatalFailureTest, AssertNoFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(FatalFailureTest, ExpectFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(FatalFailureOnAllThreadsTest, ExpectFatalFailureOnAllThreads) {
// TODO(wan@google.com): Test this works correctly when Google Test
// is made thread-safe.
}
TEST(NonFatalFailureTest, ExpectNonFatalFailureIgnoresFailuresInOtherThreads) {
// TODO(mheule@google.com): Test this works correctly when Google
// Test is made thread-safe.
}
TEST(NonFatalFailureOnAllThreadsTest, ExpectNonFatalFailureOnAllThreads) {
// TODO(wan@google.com): Test this works correctly when Google Test
// is made thread-safe.
}
} // namespace
} // namespace testing

View File

@@ -46,11 +46,14 @@
#include <stdlib.h>
#if GTEST_HAS_PTHREAD
#include <pthread.h>
#endif // GTEST_HAS_PTHREAD
#ifdef GTEST_OS_LINUX
#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include <pthread.h>
#include <unistd.h>
#include <string>
#include <vector>
@@ -68,8 +71,8 @@ using testing::internal::ParseInt32Flag;
namespace testing {
GTEST_DECLARE_string(output);
GTEST_DECLARE_string(color);
GTEST_DECLARE_string_(output);
GTEST_DECLARE_string_(color);
namespace internal {
bool ShouldUseColor(bool stdout_is_tty);
@@ -114,6 +117,7 @@ using testing::internal::StreamableToString;
using testing::internal::String;
using testing::internal::TestProperty;
using testing::internal::TestResult;
using testing::internal::ThreadLocal;
using testing::internal::UnitTestImpl;
using testing::internal::WideStringToUtf8;
@@ -142,31 +146,31 @@ TEST(FormatTimeInMillisAsSecondsTest, FormatsNegativeNumber) {
EXPECT_STREQ("-3", FormatTimeInMillisAsSeconds(-3000));
}
#ifndef __SYMBIAN32__
#ifndef GTEST_OS_SYMBIAN
// NULL testing does not work with Symbian compilers.
// Tests that GTEST_IS_NULL_LITERAL(x) is true when x is a null
// Tests that GTEST_IS_NULL_LITERAL_(x) is true when x is a null
// pointer literal.
TEST(NullLiteralTest, IsTrueForNullLiterals) {
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(NULL));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(0));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(1 - 1));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(0U));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(0L));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(false));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL(true && false));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(NULL));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(1 - 1));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0U));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(0L));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(false));
EXPECT_TRUE(GTEST_IS_NULL_LITERAL_(true && false));
}
// Tests that GTEST_IS_NULL_LITERAL(x) is false when x is not a null
// Tests that GTEST_IS_NULL_LITERAL_(x) is false when x is not a null
// pointer literal.
TEST(NullLiteralTest, IsFalseForNonNullLiterals) {
EXPECT_FALSE(GTEST_IS_NULL_LITERAL(1));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL(0.0));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL('a'));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL(static_cast<void*>(NULL)));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(1));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(0.0));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_('a'));
EXPECT_FALSE(GTEST_IS_NULL_LITERAL_(static_cast<void*>(NULL)));
}
#endif // __SYMBIAN32__
#endif // GTEST_OS_SYMBIAN
//
// Tests CodePointToUtf8().
@@ -662,120 +666,31 @@ TEST(TestPropertyTest, ReplaceStringValue) {
EXPECT_STREQ("2", property.value());
}
// Tests the TestPartResult class.
// The test fixture for testing TestPartResult.
class TestPartResultTest : public Test {
class ScopedFakeTestPartResultReporterTest : public Test {
protected:
TestPartResultTest()
: r1_(TPRT_SUCCESS, "foo/bar.cc", 10, "Success!"),
r2_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure!"),
r3_(TPRT_FATAL_FAILURE, NULL, -1, "Failure!") {}
TestPartResult r1_, r2_, r3_;
enum FailureMode {
FATAL_FAILURE,
NONFATAL_FAILURE
};
static void AddFailure(FailureMode failure) {
if (failure == FATAL_FAILURE) {
FAIL() << "Expected fatal failure.";
} else {
ADD_FAILURE() << "Expected non-fatal failure.";
}
}
};
// Tests TestPartResult::type()
TEST_F(TestPartResultTest, type) {
EXPECT_EQ(TPRT_SUCCESS, r1_.type());
EXPECT_EQ(TPRT_NONFATAL_FAILURE, r2_.type());
EXPECT_EQ(TPRT_FATAL_FAILURE, r3_.type());
}
// Tests TestPartResult::file_name()
TEST_F(TestPartResultTest, file_name) {
EXPECT_STREQ("foo/bar.cc", r1_.file_name());
EXPECT_STREQ(NULL, r3_.file_name());
}
// Tests TestPartResult::line_number()
TEST_F(TestPartResultTest, line_number) {
EXPECT_EQ(10, r1_.line_number());
EXPECT_EQ(-1, r2_.line_number());
}
// Tests TestPartResult::message()
TEST_F(TestPartResultTest, message) {
EXPECT_STREQ("Success!", r1_.message());
}
// Tests TestPartResult::passed()
TEST_F(TestPartResultTest, Passed) {
EXPECT_TRUE(r1_.passed());
EXPECT_FALSE(r2_.passed());
EXPECT_FALSE(r3_.passed());
}
// Tests TestPartResult::failed()
TEST_F(TestPartResultTest, Failed) {
EXPECT_FALSE(r1_.failed());
EXPECT_TRUE(r2_.failed());
EXPECT_TRUE(r3_.failed());
}
// Tests TestPartResult::fatally_failed()
TEST_F(TestPartResultTest, FatallyFailed) {
EXPECT_FALSE(r1_.fatally_failed());
EXPECT_FALSE(r2_.fatally_failed());
EXPECT_TRUE(r3_.fatally_failed());
}
// Tests TestPartResult::nonfatally_failed()
TEST_F(TestPartResultTest, NonfatallyFailed) {
EXPECT_FALSE(r1_.nonfatally_failed());
EXPECT_TRUE(r2_.nonfatally_failed());
EXPECT_FALSE(r3_.nonfatally_failed());
}
// Tests the TestPartResultArray class.
class TestPartResultArrayTest : public Test {
protected:
TestPartResultArrayTest()
: r1_(TPRT_NONFATAL_FAILURE, "foo/bar.cc", -1, "Failure 1"),
r2_(TPRT_FATAL_FAILURE, "foo/bar.cc", -1, "Failure 2") {}
const TestPartResult r1_, r2_;
};
// Tests that TestPartResultArray initially has size 0.
TEST_F(TestPartResultArrayTest, InitialSizeIsZero) {
TestPartResultArray results;
EXPECT_EQ(0, results.size());
}
// Tests that TestPartResultArray contains the given TestPartResult
// after one Append() operation.
TEST_F(TestPartResultArrayTest, ContainsGivenResultAfterAppend) {
TestPartResultArray results;
results.Append(r1_);
EXPECT_EQ(1, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
}
// Tests that TestPartResultArray contains the given TestPartResults
// after two Append() operations.
TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) {
TestPartResultArray results;
results.Append(r1_);
results.Append(r2_);
EXPECT_EQ(2, results.size());
EXPECT_STREQ("Failure 1", results.GetTestPartResult(0).message());
EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message());
}
void ScopedFakeTestPartResultReporterTestHelper() {
FAIL() << "Expected fatal failure.";
}
// Tests that ScopedFakeTestPartResultReporter intercepts test
// failures.
TEST(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
TEST_F(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
TestPartResultArray results;
{
ScopedFakeTestPartResultReporter reporter(&results);
ADD_FAILURE() << "Expected non-fatal failure.";
ScopedFakeTestPartResultReporterTestHelper();
ScopedFakeTestPartResultReporter reporter(
ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
&results);
AddFailure(NONFATAL_FAILURE);
AddFailure(FATAL_FAILURE);
}
EXPECT_EQ(2, results.size());
@@ -783,6 +698,128 @@ TEST(ScopedFakeTestPartResultReporterTest, InterceptsTestFailures) {
EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
}
TEST_F(ScopedFakeTestPartResultReporterTest, DeprecatedConstructor) {
TestPartResultArray results;
{
// Tests, that the deprecated constructor still works.
ScopedFakeTestPartResultReporter reporter(&results);
AddFailure(NONFATAL_FAILURE);
}
EXPECT_EQ(1, results.size());
}
#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
class ScopedFakeTestPartResultReporterWithThreadsTest
: public ScopedFakeTestPartResultReporterTest {
protected:
static void AddFailureInOtherThread(FailureMode failure) {
pthread_t tid;
pthread_create(&tid,
NULL,
ScopedFakeTestPartResultReporterWithThreadsTest::
FailureThread,
&failure);
pthread_join(tid, NULL);
}
private:
static void* FailureThread(void* attr) {
FailureMode* failure = static_cast<FailureMode*>(attr);
AddFailure(*failure);
return NULL;
}
};
TEST_F(ScopedFakeTestPartResultReporterWithThreadsTest,
InterceptsTestFailuresInAllThreads) {
TestPartResultArray results;
{
ScopedFakeTestPartResultReporter reporter(
ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS, &results);
AddFailure(NONFATAL_FAILURE);
AddFailure(FATAL_FAILURE);
AddFailureInOtherThread(NONFATAL_FAILURE);
AddFailureInOtherThread(FATAL_FAILURE);
}
EXPECT_EQ(4, results.size());
EXPECT_TRUE(results.GetTestPartResult(0).nonfatally_failed());
EXPECT_TRUE(results.GetTestPartResult(1).fatally_failed());
EXPECT_TRUE(results.GetTestPartResult(2).nonfatally_failed());
EXPECT_TRUE(results.GetTestPartResult(3).fatally_failed());
}
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
// Tests EXPECT_{,NON}FATAL_FAILURE{,ON_ALL_THREADS}.
typedef ScopedFakeTestPartResultReporterTest ExpectFailureTest;
TEST_F(ExpectFailureTest, ExpectFatalFaliure) {
EXPECT_FATAL_FAILURE(AddFailure(FATAL_FAILURE), "Expected fatal failure.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailure) {
EXPECT_NONFATAL_FAILURE(AddFailure(NONFATAL_FAILURE),
"Expected non-fatal failure.");
}
TEST_F(ExpectFailureTest, ExpectFatalFailureOnAllThreads) {
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
"Expected fatal failure.");
}
TEST_F(ExpectFailureTest, ExpectNonFatalFailureOnAllThreads) {
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
"Expected non-fatal failure.");
}
// Tests that the EXPECT_{,NON}FATAL_FAILURE{,_ON_ALL_THREADS} accepts
// a statement that contains a macro which expands to code containing
// an unprotected comma.
static int global_var = 0;
#define GTEST_USE_UNPROTECTED_COMMA_ global_var++, global_var++
TEST_F(ExpectFailureTest, AcceptsMacroThatExpandsToUnprotectedComma) {
EXPECT_FATAL_FAILURE({
GTEST_USE_UNPROTECTED_COMMA_;
AddFailure(FATAL_FAILURE);
}, "");
EXPECT_FATAL_FAILURE_ON_ALL_THREADS({
GTEST_USE_UNPROTECTED_COMMA_;
AddFailure(FATAL_FAILURE);
}, "");
EXPECT_NONFATAL_FAILURE({
GTEST_USE_UNPROTECTED_COMMA_;
AddFailure(NONFATAL_FAILURE);
}, "");
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS({
GTEST_USE_UNPROTECTED_COMMA_;
AddFailure(NONFATAL_FAILURE);
}, "");
}
#if GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
typedef ScopedFakeTestPartResultReporterWithThreadsTest
ExpectFailureWithThreadsTest;
TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailureOnAllThreads) {
EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailureInOtherThread(FATAL_FAILURE),
"Expected fatal failure.");
}
TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailureOnAllThreads) {
EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(
AddFailureInOtherThread(NONFATAL_FAILURE), "Expected non-fatal failure.");
}
#endif // GTEST_IS_THREADSAFE && GTEST_HAS_PTHREAD
// Tests the TestResult class
// The test fixture for testing TestResult.
@@ -1875,6 +1912,8 @@ TEST_F(FloatTest, LargeDiff) {
TEST_F(FloatTest, Infinity) {
EXPECT_FLOAT_EQ(infinity_, close_to_infinity_);
EXPECT_FLOAT_EQ(-infinity_, -close_to_infinity_);
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(infinity_, -infinity_),
"-infinity_");
@@ -1882,10 +1921,13 @@ TEST_F(FloatTest, Infinity) {
// are only 1 DLP apart.
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(infinity_, nan1_),
"nan1_");
#endif // ! GTEST_OS_SYMBIAN
}
// Tests that comparing with NAN always returns false.
TEST_F(FloatTest, NaN) {
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(nan1_, nan1_),
"nan1_");
EXPECT_NONFATAL_FAILURE(EXPECT_FLOAT_EQ(nan1_, nan2_),
@@ -1895,6 +1937,7 @@ TEST_F(FloatTest, NaN) {
EXPECT_FATAL_FAILURE(ASSERT_FLOAT_EQ(nan1_, infinity_),
"infinity_");
#endif // ! GTEST_OS_SYMBIAN
}
// Tests that *_FLOAT_EQ are reflexive.
@@ -1956,6 +1999,8 @@ TEST_F(FloatTest, FloatLEFails) {
EXPECT_PRED_FORMAT2(FloatLE, further_from_one_, 1.0f);
}, "(further_from_one_) <= (1.0f)");
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
// or when either val1 or val2 is NaN.
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_PRED_FORMAT2(FloatLE, nan1_, infinity_);
@@ -1967,6 +2012,7 @@ TEST_F(FloatTest, FloatLEFails) {
EXPECT_FATAL_FAILURE({ // NOLINT
ASSERT_PRED_FORMAT2(FloatLE, nan1_, nan1_);
}, "(nan1_) <= (nan1_)");
#endif // ! GTEST_OS_SYMBIAN
}
// Instantiates FloatingPointTest for testing *_DOUBLE_EQ.
@@ -2021,6 +2067,8 @@ TEST_F(DoubleTest, LargeDiff) {
TEST_F(DoubleTest, Infinity) {
EXPECT_DOUBLE_EQ(infinity_, close_to_infinity_);
EXPECT_DOUBLE_EQ(-infinity_, -close_to_infinity_);
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(infinity_, -infinity_),
"-infinity_");
@@ -2028,22 +2076,29 @@ TEST_F(DoubleTest, Infinity) {
// are only 1 DLP apart.
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(infinity_, nan1_),
"nan1_");
#endif // ! GTEST_OS_SYMBIAN
}
// Tests that comparing with NAN always returns false.
TEST_F(DoubleTest, NaN) {
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(nan1_, nan1_),
"nan1_");
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(nan1_, nan2_), "nan2_");
EXPECT_NONFATAL_FAILURE(EXPECT_DOUBLE_EQ(1.0, nan1_), "nan1_");
EXPECT_FATAL_FAILURE(ASSERT_DOUBLE_EQ(nan1_, infinity_), "infinity_");
#endif // ! GTEST_OS_SYMBIAN
}
// Tests that *_DOUBLE_EQ are reflexive.
TEST_F(DoubleTest, Reflexive) {
EXPECT_DOUBLE_EQ(0.0, 0.0);
EXPECT_DOUBLE_EQ(1.0, 1.0);
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
ASSERT_DOUBLE_EQ(infinity_, infinity_);
#endif // ! GTEST_OS_SYMBIAN
}
// Tests that *_DOUBLE_EQ are commutative.
@@ -2059,38 +2114,22 @@ TEST_F(DoubleTest, Commutative) {
TEST_F(DoubleTest, EXPECT_NEAR) {
EXPECT_NEAR(-1.0, -1.1, 0.2);
EXPECT_NEAR(2.0, 3.0, 1.0);
#ifdef __SYMBIAN32__
// Symbian STLport has currently a buggy floating point output.
// TODO(mikie): fix STLport.
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0, 1.2, 0.1), // NOLINT
"The difference between 1.0 and 1.2 is 0.19999:, "
"which exceeds 0.1");
#else // !__SYMBIAN32__
EXPECT_NONFATAL_FAILURE(EXPECT_NEAR(1.0, 1.2, 0.1), // NOLINT
"The difference between 1.0 and 1.2 is 0.2, "
"which exceeds 0.1");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
#endif // __SYMBIAN32__
}
// Tests ASSERT_NEAR.
TEST_F(DoubleTest, ASSERT_NEAR) {
ASSERT_NEAR(-1.0, -1.1, 0.2);
ASSERT_NEAR(2.0, 3.0, 1.0);
#ifdef __SYMBIAN32__
// Symbian STLport has currently a buggy floating point output.
// TODO(mikie): fix STLport.
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0, 1.2, 0.1), // NOLINT
"The difference between 1.0 and 1.2 is 0.19999:, "
"which exceeds 0.1");
#else // ! __SYMBIAN32__
EXPECT_FATAL_FAILURE(ASSERT_NEAR(1.0, 1.2, 0.1), // NOLINT
"The difference between 1.0 and 1.2 is 0.2, "
"which exceeds 0.1");
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
#endif // __SYMBIAN32__
}
// Tests the cases where DoubleLE() should succeed.
@@ -2113,6 +2152,8 @@ TEST_F(DoubleTest, DoubleLEFails) {
EXPECT_PRED_FORMAT2(DoubleLE, further_from_one_, 1.0);
}, "(further_from_one_) <= (1.0)");
#ifndef GTEST_OS_SYMBIAN
// Nokia's STLport crashes if we try to output infinity or NaN.
// or when either val1 or val2 is NaN.
EXPECT_NONFATAL_FAILURE({ // NOLINT
EXPECT_PRED_FORMAT2(DoubleLE, nan1_, infinity_);
@@ -2123,6 +2164,7 @@ TEST_F(DoubleTest, DoubleLEFails) {
EXPECT_FATAL_FAILURE({ // NOLINT
ASSERT_PRED_FORMAT2(DoubleLE, nan1_, nan1_);
}, "(nan1_) <= (nan1_)");
#endif // ! GTEST_OS_SYMBIAN
}
@@ -2389,6 +2431,97 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
#endif // GTEST_HAS_EXCEPTIONS
// Tests {ASSERT|EXPECT}_NO_FATAL_FAILURE.
class NoFatalFailureTest : public Test {
protected:
void Succeeds() {}
void FailsNonFatal() {
ADD_FAILURE() << "some non-fatal failure";
}
void Fails() {
FAIL() << "some fatal failure";
}
void DoAssertNoFatalFailureOnFails() {
ASSERT_NO_FATAL_FAILURE(Fails());
ADD_FAILURE() << "shold not reach here.";
}
void DoExpectNoFatalFailureOnFails() {
EXPECT_NO_FATAL_FAILURE(Fails());
ADD_FAILURE() << "other failure";
}
};
TEST_F(NoFatalFailureTest, NoFailure) {
EXPECT_NO_FATAL_FAILURE(Succeeds());
ASSERT_NO_FATAL_FAILURE(Succeeds());
}
TEST_F(NoFatalFailureTest, NonFatalIsNoFailure) {
EXPECT_NONFATAL_FAILURE(
EXPECT_NO_FATAL_FAILURE(FailsNonFatal()),
"some non-fatal failure");
EXPECT_NONFATAL_FAILURE(
ASSERT_NO_FATAL_FAILURE(FailsNonFatal()),
"some non-fatal failure");
}
TEST_F(NoFatalFailureTest, AssertNoFatalFailureOnFatalFailure) {
TestPartResultArray gtest_failures;
{
ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
DoAssertNoFatalFailureOnFails();
}
ASSERT_EQ(2, gtest_failures.size());
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
gtest_failures.GetTestPartResult(0).type());
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
gtest_failures.GetTestPartResult(1).type());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
gtest_failures.GetTestPartResult(0).message());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "it does",
gtest_failures.GetTestPartResult(1).message());
}
TEST_F(NoFatalFailureTest, ExpectNoFatalFailureOnFatalFailure) {
TestPartResultArray gtest_failures;
{
ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
DoExpectNoFatalFailureOnFails();
}
ASSERT_EQ(3, gtest_failures.size());
EXPECT_EQ(testing::TPRT_FATAL_FAILURE,
gtest_failures.GetTestPartResult(0).type());
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
gtest_failures.GetTestPartResult(1).type());
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
gtest_failures.GetTestPartResult(2).type());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "some fatal failure",
gtest_failures.GetTestPartResult(0).message());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "it does",
gtest_failures.GetTestPartResult(1).message());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "other failure",
gtest_failures.GetTestPartResult(2).message());
}
TEST_F(NoFatalFailureTest, MessageIsStreamable) {
TestPartResultArray gtest_failures;
{
ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message";
}
ASSERT_EQ(2, gtest_failures.size());
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
gtest_failures.GetTestPartResult(0).type());
EXPECT_EQ(testing::TPRT_NONFATAL_FAILURE,
gtest_failures.GetTestPartResult(1).type());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "foo",
gtest_failures.GetTestPartResult(0).message());
EXPECT_PRED_FORMAT2(testing::IsSubstring, "my message",
gtest_failures.GetTestPartResult(1).message());
}
// Tests non-string assertions.
// Tests EqFailure(), used for implementing *EQ* assertions.
@@ -2492,7 +2625,7 @@ TEST(AssertionTest, ASSERT_EQ) {
}
// Tests ASSERT_EQ(NULL, pointer).
#ifndef __SYMBIAN32__
#ifndef GTEST_OS_SYMBIAN
// The NULL-detection template magic fails to compile with
// the Nokia compiler and crashes the ARM compiler, hence
// not testing on Symbian.
@@ -2506,7 +2639,7 @@ TEST(AssertionTest, ASSERT_EQ_NULL) {
EXPECT_FATAL_FAILURE(ASSERT_EQ(NULL, &n),
"Value of: &n\n");
}
#endif // __SYMBIAN32__
#endif // GTEST_OS_SYMBIAN
// Tests ASSERT_EQ(0, non_pointer). Since the literal 0 can be
// treated as a null pointer by the compiler, we need to make sure
@@ -2807,7 +2940,7 @@ TEST(HRESULTAssertionTest, Streaming) {
#endif // defined(GTEST_OS_WINDOWS)
// Tests that the assertion macros behave like single statements.
TEST(AssertionSyntaxTest, BehavesLikeSingleStatement) {
TEST(AssertionSyntaxTest, BasicAssertionsBehavesLikeSingleStatement) {
if (false)
ASSERT_TRUE(false) << "This should never be executed; "
"It's a compilation test only.";
@@ -2824,8 +2957,10 @@ TEST(AssertionSyntaxTest, BehavesLikeSingleStatement) {
;
else
EXPECT_GT(3, 2) << "";
}
#if GTEST_HAS_EXCEPTIONS
TEST(AssertionSyntaxTest, ExceptionAssertionsBehavesLikeSingleStatement) {
if (false)
EXPECT_THROW(1, bool);
@@ -2849,7 +2984,30 @@ TEST(AssertionSyntaxTest, BehavesLikeSingleStatement) {
EXPECT_ANY_THROW(ThrowAnInteger());
else
;
}
#endif // GTEST_HAS_EXCEPTIONS
TEST(AssertionSyntaxTest, NoFatalFailureAssertionsBehavesLikeSingleStatement) {
if (false)
EXPECT_NO_FATAL_FAILURE(FAIL()) << "This should never be executed. "
<< "It's a compilation test only.";
else
;
if (false)
ASSERT_NO_FATAL_FAILURE(FAIL()) << "";
else
;
if (true)
EXPECT_NO_FATAL_FAILURE(SUCCEED());
else
;
if (false)
;
else
ASSERT_NO_FATAL_FAILURE(SUCCEED());
}
// Tests that the assertion macros work well with switch statements.
@@ -2984,7 +3142,7 @@ TEST(ExpectTest, EXPECT_EQ_Double) {
"5.1");
}
#ifndef __SYMBIAN32__
#ifndef GTEST_OS_SYMBIAN
// Tests EXPECT_EQ(NULL, pointer).
TEST(ExpectTest, EXPECT_EQ_NULL) {
// A success.
@@ -2996,7 +3154,7 @@ TEST(ExpectTest, EXPECT_EQ_NULL) {
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(NULL, &n),
"Value of: &n\n");
}
#endif // __SYMBIAN32__
#endif // GTEST_OS_SYMBIAN
// Tests EXPECT_EQ(0, non_pointer). Since the literal 0 can be
// treated as a null pointer by the compiler, we need to make sure
@@ -4739,7 +4897,24 @@ TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) {
#endif // GTEST_OS_WINDOWS
}
#ifndef __SYMBIAN32__
TEST(ThreadLocalTest, DefaultConstructor) {
ThreadLocal<int> t1;
EXPECT_EQ(0, t1.get());
ThreadLocal<void*> t2;
EXPECT_TRUE(t2.get() == NULL);
}
TEST(ThreadLocalTest, Init) {
ThreadLocal<int> t1(123);
EXPECT_EQ(123, t1.get());
int i = 0;
ThreadLocal<int*> t2(&i);
EXPECT_EQ(&i, t2.get());
}
#ifndef GTEST_OS_SYMBIAN
// We will want to integrate running the unittests to a different
// main application on Symbian.
int main(int argc, char** argv) {
@@ -4756,4 +4931,4 @@ int main(int argc, char** argv) {
// Runs all tests using Google Test.
return RUN_ALL_TESTS();
}
#endif // __SYMBIAN32_
#endif // GTEST_OS_SYMBIAN