From e0865dd9199e8fffd5c2f95a68de6c1851f77c15 Mon Sep 17 00:00:00 2001 From: shiqian Date: Sat, 11 Oct 2008 07:20:02 +0000 Subject: 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 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). --- test/gtest-test-part_test.cc | 138 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/gtest-test-part_test.cc (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc new file mode 100644 index 00000000..f4f0d1d5 --- /dev/null +++ b/test/gtest-test-part_test.cc @@ -0,0 +1,138 @@ +// Copyright 2008 Google Inc. All Rights Reserved. +// Author: mheule@google.com (Markus Heule) + +#include + +#include + +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 -- cgit v1.2.3 From 0af0709b02899f9177db55eba7929e65e5834b29 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Mon, 23 Feb 2009 23:21:55 +0000 Subject: Cleans up macro definitions. --- test/gtest-test-part_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index f4f0d1d5..f9e2e5d3 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -117,7 +117,7 @@ TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) { EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message()); } -#ifdef GTEST_HAS_DEATH_TEST +#if GTEST_HAS_DEATH_TEST typedef TestPartResultArrayTest TestPartResultArrayDeathTest; -- cgit v1.2.3 From 1bd424d9608d85fc6b705a2370ed86db3118dcf6 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 29 May 2009 19:46:51 +0000 Subject: Adds missing copyright in test/gtest-test-part_test.cc (by Markus Heule). Minor format adjustments. --- test/gtest-test-part_test.cc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index f9e2e5d3..93fe156e 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -1,5 +1,34 @@ -// Copyright 2008 Google Inc. All Rights Reserved. +// 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) +// #include -- cgit v1.2.3 From b2ee82ebf9b8f1be859d08611b768ae6c0700090 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 11 Sep 2009 06:59:42 +0000 Subject: Improves EXPECT_DEATH_IF_SUPPORTED to allow streaming of messages and enforcing the validity of arguments (by Vlad Losev); adds samples for the event listener API (by Vlad Losev); simplifies the tests using EXPECT_DEATH_IF_SUPPORTED (by Zhanyong Wan). --- test/gtest-test-part_test.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index 93fe156e..fc94f92b 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -146,8 +146,6 @@ TEST_F(TestPartResultArrayTest, ContainsGivenResultsAfterTwoAppends) { EXPECT_STREQ("Failure 2", results.GetTestPartResult(1).message()); } -#if GTEST_HAS_DEATH_TEST - typedef TestPartResultArrayTest TestPartResultArrayDeathTest; // Tests that the program dies when GetTestPartResult() is called with @@ -156,12 +154,10 @@ TEST_F(TestPartResultArrayDeathTest, DiesWhenIndexIsOutOfBound) { TestPartResultArray results; results.Append(r1_); - EXPECT_DEATH(results.GetTestPartResult(-1), ""); - EXPECT_DEATH(results.GetTestPartResult(1), ""); + EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(-1), ""); + EXPECT_DEATH_IF_SUPPORTED(results.GetTestPartResult(1), ""); } -#endif // GTEST_HAS_DEATH_TEST - // TODO(mheule@google.com): Add a test for the class HasNewFatalFailureHelper. } // namespace -- cgit v1.2.3 From e5373af0cb9cae249e7bc618cae3483397332895 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 18 Sep 2009 18:16:20 +0000 Subject: Renames the TestPartResult type enums and adjusts the order of methods in the event listener interface (by Vlad Losev). --- test/gtest-test-part_test.cc | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index fc94f92b..403c1845 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -38,10 +38,6 @@ 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. @@ -50,18 +46,18 @@ namespace { 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!") {} + : r1_(TestPartResult::kSuccess, "foo/bar.cc", 10, "Success!"), + r2_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure!"), + r3_(TestPartResult::kFatalFailure, 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()); + EXPECT_EQ(TestPartResult::kSuccess, r1_.type()); + EXPECT_EQ(TestPartResult::kNonFatalFailure, r2_.type()); + EXPECT_EQ(TestPartResult::kFatalFailure, r3_.type()); } // Tests TestPartResult::file_name(). @@ -114,8 +110,8 @@ TEST_F(TestPartResultTest, NonfatallyFailed) { 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") {} + : r1_(TestPartResult::kNonFatalFailure, "foo/bar.cc", -1, "Failure 1"), + r2_(TestPartResult::kFatalFailure, "foo/bar.cc", -1, "Failure 2") {} const TestPartResult r1_, r2_; }; -- cgit v1.2.3 From cca227fe7548171869021bafc31ffd33515f1fcc Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 16 Dec 2009 20:21:27 +0000 Subject: Moves mis-placed tests. --- test/gtest-test-part_test.cc | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index 403c1845..5a3e9196 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -34,6 +34,7 @@ #include +using testing::Message; using testing::Test; using testing::TestPartResult; using testing::TestPartResultArray; @@ -53,6 +54,54 @@ class TestPartResultTest : public Test { TestPartResult r1_, r2_, r3_; }; + +TEST_F(TestPartResultTest, ConstructorWorks) { + Message message; + message << "something is terribly wrong"; + message << static_cast(testing::internal::kStackTraceMarker); + message << "some unimportant stack trace"; + + const TestPartResult result(TestPartResult::kNonFatalFailure, + "some_file.cc", + 42, + message.GetString().c_str()); + + EXPECT_EQ(TestPartResult::kNonFatalFailure, result.type()); + EXPECT_STREQ("some_file.cc", result.file_name()); + EXPECT_EQ(42, result.line_number()); + EXPECT_STREQ(message.GetString().c_str(), result.message()); + EXPECT_STREQ("something is terribly wrong", result.summary()); +} + +TEST_F(TestPartResultTest, ResultAccessorsWork) { + const TestPartResult success(TestPartResult::kSuccess, + "file.cc", + 42, + "message"); + EXPECT_TRUE(success.passed()); + EXPECT_FALSE(success.failed()); + EXPECT_FALSE(success.nonfatally_failed()); + EXPECT_FALSE(success.fatally_failed()); + + const TestPartResult nonfatal_failure(TestPartResult::kNonFatalFailure, + "file.cc", + 42, + "message"); + EXPECT_FALSE(nonfatal_failure.passed()); + EXPECT_TRUE(nonfatal_failure.failed()); + EXPECT_TRUE(nonfatal_failure.nonfatally_failed()); + EXPECT_FALSE(nonfatal_failure.fatally_failed()); + + const TestPartResult fatal_failure(TestPartResult::kFatalFailure, + "file.cc", + 42, + "message"); + EXPECT_FALSE(fatal_failure.passed()); + EXPECT_TRUE(fatal_failure.failed()); + EXPECT_FALSE(fatal_failure.nonfatally_failed()); + EXPECT_TRUE(fatal_failure.fatally_failed()); +} + // Tests TestPartResult::type(). TEST_F(TestPartResultTest, type) { EXPECT_EQ(TestPartResult::kSuccess, r1_.type()); -- cgit v1.2.3 From dac3e879c56a50696a36f53e1e5e353e48fa665f Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 14 Sep 2010 05:35:59 +0000 Subject: Include gtest headers as user headers instead of system headers. --- test/gtest-test-part_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/gtest-test-part_test.cc') diff --git a/test/gtest-test-part_test.cc b/test/gtest-test-part_test.cc index 5a3e9196..ca8ba933 100644 --- a/test/gtest-test-part_test.cc +++ b/test/gtest-test-part_test.cc @@ -30,9 +30,9 @@ // Author: mheule@google.com (Markus Heule) // -#include +#include "gtest/gtest-test-part.h" -#include +#include "gtest/gtest.h" using testing::Message; using testing::Test; -- cgit v1.2.3