From c214ebc830aa918d54e535c6caa2da6317877e12 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 16 Jul 2009 00:36:55 +0000 Subject: More refactoring for the event listener API, by Vlad Losev. --- test/gtest-unittest-api_test.cc | 363 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 test/gtest-unittest-api_test.cc (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc new file mode 100644 index 00000000..658e2985 --- /dev/null +++ b/test/gtest-unittest-api_test.cc @@ -0,0 +1,363 @@ +// Copyright 2009 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) +// +// The Google C++ Testing Framework (Google Test) +// +// This file contains tests verifying correctness of data provided via +// UnitTest's public methods. + +#include + +#include // For strcmp. +#include + +using ::testing::AddGlobalTestEnvironment; +using ::testing::Environment; +using ::testing::InitGoogleTest; +using ::testing::Test; +using ::testing::TestInfo; +using ::testing::TestPartResult; +using ::testing::UnitTest; +using ::testing::internal::TestCase; +using ::testing::internal::TestProperty; + +#if GTEST_HAS_TYPED_TEST +using ::testing::Types; +using ::testing::internal::GetTypeName; +using ::testing::internal::String; +#endif // GTEST_HAS_TYPED_TEST + +namespace testing { +namespace internal { + +template +struct LessByName { + bool operator()(const T* a, const T* b) { + return strcmp(a->name(), b->name()) < 0; + } +}; + +class UnitTestAccessor { + public: + // Returns the array of pointers to all test cases sorted by the test case + // name. The caller is responsible for deleting the array. + static TestCase const** const GetSortedTestCases() { + UnitTest* unit_test = UnitTest::GetInstance(); + TestCase const** const test_cases = + new const TestCase*[unit_test->total_test_case_count()]; + + for (int i = 0; i < unit_test->total_test_case_count(); ++i) + test_cases[i] = unit_test->GetTestCase(i); + + std::sort(test_cases, + test_cases + unit_test->total_test_case_count(), + LessByName()); + return test_cases; + } + + // Returns the test case by its name. The caller doesn't own the returned + // pointer. + static const TestCase* FindTestCase(const char* name) { + UnitTest* unit_test = UnitTest::GetInstance(); + for (int i = 0; i < unit_test->total_test_case_count(); ++i) { + const TestCase* test_case = unit_test->GetTestCase(i); + if (0 == strcmp(test_case->name(), name)) + return test_case; + } + return NULL; + } + + // Returns the array of pointers to all tests in a particular test case + // sorted by the test name. The caller is responsible for deleting the + // array. + static TestInfo const** const GetSortedTests(const TestCase* test_case) { + TestInfo const** const tests = + new const TestInfo*[test_case->total_test_count()]; + + for (int i = 0; i < test_case->total_test_count(); ++i) + tests[i] = test_case->GetTestInfo(i); + + std::sort(tests, + tests + test_case->total_test_count(), + LessByName()); + return tests; + } +}; + +// TODO(vladl@google.com): Put tests into the internal namespace after +// UnitTest methods are published. +} // namespace internal + +using internal::UnitTestAccessor; + +#if GTEST_HAS_TYPED_TEST +template class TestCaseWithCommentTest : public Test {}; +TYPED_TEST_CASE(TestCaseWithCommentTest, Types); +TYPED_TEST(TestCaseWithCommentTest, Dummy) {} + +const int kTypedTestCases = 1; +const int kTypedTests = 1; + +String GetExpectedTestCaseComment() { + Message comment; + comment << "TypeParam = " << GetTypeName().c_str(); + return comment.GetString(); +} +#else +const int kTypedTestCases = 0; +const int kTypedTests = 0; +#endif // GTEST_HAS_TYPED_TEST + +// We can only test the accessors that do not change value while tests run. +// Since tests can be run in any order, the values the accessors that track +// test execution (such as failed_test_count) can not be predicted. +TEST(ApiTest, UnitTestImmutableAccessorsWork) { + UnitTest* unit_test = UnitTest::GetInstance(); + + ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); + EXPECT_EQ(1 + kTypedTestCases, unit_test->test_case_to_run_count()); + EXPECT_EQ(2, unit_test->disabled_test_count()); + EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count()); + EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_count()); + + const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + + EXPECT_STREQ("ApiTest", test_cases[0]->name()); + EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); +#if GTEST_HAS_TYPED_TEST + EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); +#endif // GTEST_HAS_TYPED_TEST + + delete[] test_cases; + + // The following lines initiate actions to verify certain methods in + // FinalSuccessChecker::TearDown. + + // Records a test property to verify TestResult::GetTestProperty(). + RecordProperty("key", "value"); +} + +TEST(ApiTest, TestCaseImmutableAccessorsWork) { + const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); + ASSERT_TRUE(test_case != NULL); + + EXPECT_STREQ("ApiTest", test_case->name()); + EXPECT_STREQ("", test_case->comment()); + EXPECT_TRUE(test_case->should_run()); + EXPECT_EQ(1, test_case->disabled_test_count()); + EXPECT_EQ(3, test_case->test_to_run_count()); + ASSERT_EQ(4, test_case->total_test_count()); + + const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + + EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); + EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); + EXPECT_STREQ("", tests[0]->comment()); + EXPECT_STREQ("", tests[0]->test_case_comment()); + EXPECT_FALSE(tests[0]->should_run()); + + EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); + EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); + EXPECT_STREQ("", tests[1]->comment()); + EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(tests[1]->should_run()); + + EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); + EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); + EXPECT_STREQ("", tests[2]->comment()); + EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(tests[2]->should_run()); + + EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); + EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); + EXPECT_STREQ("", tests[3]->comment()); + EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(tests[3]->should_run()); + + delete[] tests; + tests = NULL; + +#if GTEST_HAS_TYPED_TEST + test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); + ASSERT_TRUE(test_case != NULL); + + EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); + EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), test_case->comment()); + EXPECT_TRUE(test_case->should_run()); + EXPECT_EQ(0, test_case->disabled_test_count()); + EXPECT_EQ(1, test_case->test_to_run_count()); + ASSERT_EQ(1, test_case->total_test_count()); + + tests = UnitTestAccessor::GetSortedTests(test_case); + + EXPECT_STREQ("Dummy", tests[0]->name()); + EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); + EXPECT_STREQ("", tests[0]->comment()); + EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), + tests[0]->test_case_comment()); + EXPECT_TRUE(tests[0]->should_run()); + + delete[] tests; +#endif // GTEST_HAS_TYPED_TEST +} + +TEST(ApiTest, TestCaseDisabledAccessorsWork) { + const TestCase* test_case = UnitTestAccessor::FindTestCase("DISABLED_Test"); + ASSERT_TRUE(test_case != NULL); + + EXPECT_STREQ("DISABLED_Test", test_case->name()); + EXPECT_STREQ("", test_case->comment()); + EXPECT_FALSE(test_case->should_run()); + EXPECT_EQ(1, test_case->disabled_test_count()); + EXPECT_EQ(0, test_case->test_to_run_count()); + ASSERT_EQ(1, test_case->total_test_count()); + + const TestInfo* const test_info = test_case->GetTestInfo(0); + EXPECT_STREQ("Dummy2", test_info->name()); + EXPECT_STREQ("DISABLED_Test", test_info->test_case_name()); + EXPECT_STREQ("", test_info->comment()); + EXPECT_STREQ("", test_info->test_case_comment()); + EXPECT_FALSE(test_info->should_run()); +} + +// These two tests are here to provide support for testing +// test_case_to_run_count, disabled_test_count, and test_to_run_count. +TEST(ApiTest, DISABLED_Dummy1) {} +TEST(DISABLED_Test, Dummy2) {} + +class FinalSuccessChecker : public Environment { + protected: + virtual void TearDown() { + UnitTest* unit_test = UnitTest::GetInstance(); + + EXPECT_EQ(1 + kTypedTestCases, unit_test->successful_test_case_count()); + EXPECT_EQ(3 + kTypedTests, unit_test->successful_test_count()); + EXPECT_EQ(0, unit_test->failed_test_case_count()); + EXPECT_EQ(0, unit_test->failed_test_count()); + EXPECT_TRUE(unit_test->Passed()); + EXPECT_FALSE(unit_test->Failed()); + ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); + + const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + + EXPECT_STREQ("ApiTest", test_cases[0]->name()); + EXPECT_STREQ("", test_cases[0]->comment()); + EXPECT_TRUE(test_cases[0]->should_run()); + EXPECT_EQ(1, test_cases[0]->disabled_test_count()); + ASSERT_EQ(4, test_cases[0]->total_test_count()); + EXPECT_EQ(3, test_cases[0]->successful_test_count()); + EXPECT_EQ(0, test_cases[0]->failed_test_count()); + EXPECT_TRUE(test_cases[0]->Passed()); + EXPECT_FALSE(test_cases[0]->Failed()); + + EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); + EXPECT_STREQ("", test_cases[1]->comment()); + EXPECT_FALSE(test_cases[1]->should_run()); + EXPECT_EQ(1, test_cases[1]->disabled_test_count()); + ASSERT_EQ(1, test_cases[1]->total_test_count()); + EXPECT_EQ(0, test_cases[1]->successful_test_count()); + EXPECT_EQ(0, test_cases[1]->failed_test_count()); + +#if GTEST_HAS_TYPED_TEST + EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); + EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), + test_cases[2]->comment()); + EXPECT_TRUE(test_cases[2]->should_run()); + EXPECT_EQ(0, test_cases[2]->disabled_test_count()); + ASSERT_EQ(1, test_cases[2]->total_test_count()); + EXPECT_EQ(1, test_cases[2]->successful_test_count()); + EXPECT_EQ(0, test_cases[2]->failed_test_count()); + EXPECT_TRUE(test_cases[2]->Passed()); + EXPECT_FALSE(test_cases[2]->Failed()); +#endif // GTEST_HAS_TYPED_TEST + + const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); + const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); + EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); + EXPECT_FALSE(tests[0]->should_run()); + + EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); + EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); + EXPECT_STREQ("", tests[1]->comment()); + EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(tests[1]->should_run()); + EXPECT_TRUE(tests[1]->result()->Passed()); + EXPECT_EQ(0, tests[1]->result()->test_property_count()); + + EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); + EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); + EXPECT_STREQ("", tests[2]->comment()); + EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(tests[2]->should_run()); + EXPECT_TRUE(tests[2]->result()->Passed()); + EXPECT_EQ(0, tests[2]->result()->test_property_count()); + + EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); + EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); + EXPECT_STREQ("", tests[3]->comment()); + EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(tests[3]->should_run()); + EXPECT_TRUE(tests[3]->result()->Passed()); + EXPECT_EQ(1, tests[3]->result()->test_property_count()); + const TestProperty& property = tests[3]->result()->GetTestProperty(0); + EXPECT_STREQ("key", property.key()); + EXPECT_STREQ("value", property.value()); + + delete[] tests; + +#if GTEST_HAS_TYPED_TEST + test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); + tests = UnitTestAccessor::GetSortedTests(test_case); + + EXPECT_STREQ("Dummy", tests[0]->name()); + EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); + EXPECT_STREQ("", tests[0]->comment()); + EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), + tests[0]->test_case_comment()); + EXPECT_TRUE(tests[0]->should_run()); + EXPECT_TRUE(tests[0]->result()->Passed()); + EXPECT_EQ(0, tests[0]->result()->test_property_count()); + + delete[] tests; +#endif // GTEST_HAS_TYPED_TEST + delete[] test_cases; + } +}; + +} // namespace testing + +int main(int argc, char **argv) { + InitGoogleTest(&argc, argv); + + AddGlobalTestEnvironment(new testing::FinalSuccessChecker()); + + return RUN_ALL_TESTS(); +} -- cgit v1.2.3 From b50ef44a3527d958270ff1f08cb99e3ac633bd17 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 24 Sep 2009 21:15:59 +0000 Subject: Publishes the even listener API (by Vlad Losev); adds OS-indicating macros to simplify gtest code (by Zhanyong Wan). --- test/gtest-unittest-api_test.cc | 66 ++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index 658e2985..7e0f8f80 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -38,21 +38,7 @@ #include // For strcmp. #include -using ::testing::AddGlobalTestEnvironment; -using ::testing::Environment; using ::testing::InitGoogleTest; -using ::testing::Test; -using ::testing::TestInfo; -using ::testing::TestPartResult; -using ::testing::UnitTest; -using ::testing::internal::TestCase; -using ::testing::internal::TestProperty; - -#if GTEST_HAS_TYPED_TEST -using ::testing::Types; -using ::testing::internal::GetTypeName; -using ::testing::internal::String; -#endif // GTEST_HAS_TYPED_TEST namespace testing { namespace internal { @@ -64,20 +50,20 @@ struct LessByName { } }; -class UnitTestAccessor { +class UnitTestHelper { public: // Returns the array of pointers to all test cases sorted by the test case // name. The caller is responsible for deleting the array. static TestCase const** const GetSortedTestCases() { - UnitTest* unit_test = UnitTest::GetInstance(); + UnitTest& unit_test = *UnitTest::GetInstance(); TestCase const** const test_cases = - new const TestCase*[unit_test->total_test_case_count()]; + new const TestCase*[unit_test.total_test_case_count()]; - for (int i = 0; i < unit_test->total_test_case_count(); ++i) - test_cases[i] = unit_test->GetTestCase(i); + for (int i = 0; i < unit_test.total_test_case_count(); ++i) + test_cases[i] = unit_test.GetTestCase(i); std::sort(test_cases, - test_cases + unit_test->total_test_case_count(), + test_cases + unit_test.total_test_case_count(), LessByName()); return test_cases; } @@ -85,9 +71,9 @@ class UnitTestAccessor { // Returns the test case by its name. The caller doesn't own the returned // pointer. static const TestCase* FindTestCase(const char* name) { - UnitTest* unit_test = UnitTest::GetInstance(); - for (int i = 0; i < unit_test->total_test_case_count(); ++i) { - const TestCase* test_case = unit_test->GetTestCase(i); + UnitTest& unit_test = *UnitTest::GetInstance(); + for (int i = 0; i < unit_test.total_test_case_count(); ++i) { + const TestCase* test_case = unit_test.GetTestCase(i); if (0 == strcmp(test_case->name(), name)) return test_case; } @@ -104,19 +90,12 @@ class UnitTestAccessor { for (int i = 0; i < test_case->total_test_count(); ++i) tests[i] = test_case->GetTestInfo(i); - std::sort(tests, - tests + test_case->total_test_count(), + std::sort(tests, tests + test_case->total_test_count(), LessByName()); return tests; } }; -// TODO(vladl@google.com): Put tests into the internal namespace after -// UnitTest methods are published. -} // namespace internal - -using internal::UnitTestAccessor; - #if GTEST_HAS_TYPED_TEST template class TestCaseWithCommentTest : public Test {}; TYPED_TEST_CASE(TestCaseWithCommentTest, Types); @@ -147,7 +126,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count()); EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_count()); - const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); @@ -165,7 +144,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { } TEST(ApiTest, TestCaseImmutableAccessorsWork) { - const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); + const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("ApiTest", test_case->name()); @@ -175,7 +154,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_EQ(3, test_case->test_to_run_count()); ASSERT_EQ(4, test_case->total_test_count()); - const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); @@ -205,7 +184,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { tests = NULL; #if GTEST_HAS_TYPED_TEST - test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); + test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); @@ -215,7 +194,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_EQ(1, test_case->test_to_run_count()); ASSERT_EQ(1, test_case->total_test_count()); - tests = UnitTestAccessor::GetSortedTests(test_case); + tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); @@ -229,7 +208,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { } TEST(ApiTest, TestCaseDisabledAccessorsWork) { - const TestCase* test_case = UnitTestAccessor::FindTestCase("DISABLED_Test"); + const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("DISABLED_Test", test_case->name()); @@ -265,7 +244,7 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(unit_test->Failed()); ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); - const TestCase** const test_cases = UnitTestAccessor::GetSortedTestCases(); + const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); EXPECT_STREQ("", test_cases[0]->comment()); @@ -298,8 +277,8 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(test_cases[2]->Failed()); #endif // GTEST_HAS_TYPED_TEST - const TestCase* test_case = UnitTestAccessor::FindTestCase("ApiTest"); - const TestInfo** tests = UnitTestAccessor::GetSortedTests(test_case); + const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); + const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); EXPECT_FALSE(tests[0]->should_run()); @@ -334,8 +313,8 @@ class FinalSuccessChecker : public Environment { delete[] tests; #if GTEST_HAS_TYPED_TEST - test_case = UnitTestAccessor::FindTestCase("TestCaseWithCommentTest/0"); - tests = UnitTestAccessor::GetSortedTests(test_case); + test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); + tests = UnitTestHelper::GetSortedTests(test_case); EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); @@ -352,12 +331,13 @@ class FinalSuccessChecker : public Environment { } }; +} // namespace internal } // namespace testing int main(int argc, char **argv) { InitGoogleTest(&argc, argv); - AddGlobalTestEnvironment(new testing::FinalSuccessChecker()); + AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker()); return RUN_ALL_TESTS(); } -- 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-unittest-api_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index 7e0f8f80..ed5dea83 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -33,7 +33,7 @@ // This file contains tests verifying correctness of data provided via // UnitTest's public methods. -#include +#include "gtest/gtest.h" #include // For strcmp. #include -- cgit v1.2.3 From 9bcf4d0a654b27732e2fa901fe98c09aba71773a Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 2 Feb 2011 00:49:33 +0000 Subject: Adds type_param and value_param as attributes to the XML report; also removes the comment() and test_case_comment() fields of TestInfo. Proposed and initally implemented by Joey Oravec. Re-implemented by Vlad Losev. --- test/gtest-unittest-api_test.cc | 69 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index ed5dea83..f53e2744 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -37,6 +37,7 @@ #include // For strcmp. #include +#include using ::testing::InitGoogleTest; @@ -103,12 +104,6 @@ TYPED_TEST(TestCaseWithCommentTest, Dummy) {} const int kTypedTestCases = 1; const int kTypedTests = 1; - -String GetExpectedTestCaseComment() { - Message comment; - comment << "TypeParam = " << GetTypeName().c_str(); - return comment.GetString(); -} #else const int kTypedTestCases = 0; const int kTypedTests = 0; @@ -143,12 +138,19 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { RecordProperty("key", "value"); } +AssertionResult IsNull(const char* str) { + if (str != NULL) { + return testing::AssertionFailure() << "argument is " << str; + } + return AssertionSuccess(); +} + TEST(ApiTest, TestCaseImmutableAccessorsWork) { const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("ApiTest", test_case->name()); - EXPECT_STREQ("", test_case->comment()); + EXPECT_TRUE(IsNull(test_case->type_param())); EXPECT_TRUE(test_case->should_run()); EXPECT_EQ(1, test_case->disabled_test_count()); EXPECT_EQ(3, test_case->test_to_run_count()); @@ -158,26 +160,26 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ("", tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_TRUE(IsNull(tests[0]->type_param())); EXPECT_FALSE(tests[0]->should_run()); EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); - EXPECT_STREQ("", tests[1]->comment()); - EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[1]->value_param())); + EXPECT_TRUE(IsNull(tests[1]->type_param())); EXPECT_TRUE(tests[1]->should_run()); EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); - EXPECT_STREQ("", tests[2]->comment()); - EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[2]->value_param())); + EXPECT_TRUE(IsNull(tests[2]->type_param())); EXPECT_TRUE(tests[2]->should_run()); EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); - EXPECT_STREQ("", tests[3]->comment()); - EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[3]->value_param())); + EXPECT_TRUE(IsNull(tests[3]->type_param())); EXPECT_TRUE(tests[3]->should_run()); delete[] tests; @@ -188,7 +190,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), test_case->comment()); + EXPECT_STREQ(GetTypeName().c_str(), test_case->type_param()); EXPECT_TRUE(test_case->should_run()); EXPECT_EQ(0, test_case->disabled_test_count()); EXPECT_EQ(1, test_case->test_to_run_count()); @@ -198,9 +200,8 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_STREQ(GetTypeName().c_str(), tests[0]->type_param()); EXPECT_TRUE(tests[0]->should_run()); delete[] tests; @@ -212,7 +213,7 @@ TEST(ApiTest, TestCaseDisabledAccessorsWork) { ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("DISABLED_Test", test_case->name()); - EXPECT_STREQ("", test_case->comment()); + EXPECT_TRUE(IsNull(test_case->type_param())); EXPECT_FALSE(test_case->should_run()); EXPECT_EQ(1, test_case->disabled_test_count()); EXPECT_EQ(0, test_case->test_to_run_count()); @@ -221,8 +222,8 @@ TEST(ApiTest, TestCaseDisabledAccessorsWork) { const TestInfo* const test_info = test_case->GetTestInfo(0); EXPECT_STREQ("Dummy2", test_info->name()); EXPECT_STREQ("DISABLED_Test", test_info->test_case_name()); - EXPECT_STREQ("", test_info->comment()); - EXPECT_STREQ("", test_info->test_case_comment()); + EXPECT_TRUE(IsNull(test_info->value_param())); + EXPECT_TRUE(IsNull(test_info->type_param())); EXPECT_FALSE(test_info->should_run()); } @@ -247,7 +248,7 @@ class FinalSuccessChecker : public Environment { const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); - EXPECT_STREQ("", test_cases[0]->comment()); + EXPECT_TRUE(IsNull(test_cases[0]->type_param())); EXPECT_TRUE(test_cases[0]->should_run()); EXPECT_EQ(1, test_cases[0]->disabled_test_count()); ASSERT_EQ(4, test_cases[0]->total_test_count()); @@ -257,7 +258,7 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(test_cases[0]->Failed()); EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); - EXPECT_STREQ("", test_cases[1]->comment()); + EXPECT_TRUE(IsNull(test_cases[1]->type_param())); EXPECT_FALSE(test_cases[1]->should_run()); EXPECT_EQ(1, test_cases[1]->disabled_test_count()); ASSERT_EQ(1, test_cases[1]->total_test_count()); @@ -266,8 +267,7 @@ class FinalSuccessChecker : public Environment { #if GTEST_HAS_TYPED_TEST EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - test_cases[2]->comment()); + EXPECT_STREQ(GetTypeName().c_str(), test_cases[2]->type_param()); EXPECT_TRUE(test_cases[2]->should_run()); EXPECT_EQ(0, test_cases[2]->disabled_test_count()); ASSERT_EQ(1, test_cases[2]->total_test_count()); @@ -285,24 +285,24 @@ class FinalSuccessChecker : public Environment { EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); - EXPECT_STREQ("", tests[1]->comment()); - EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[1]->value_param())); + EXPECT_TRUE(IsNull(tests[1]->type_param())); EXPECT_TRUE(tests[1]->should_run()); EXPECT_TRUE(tests[1]->result()->Passed()); EXPECT_EQ(0, tests[1]->result()->test_property_count()); EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); - EXPECT_STREQ("", tests[2]->comment()); - EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[2]->value_param())); + EXPECT_TRUE(IsNull(tests[2]->type_param())); EXPECT_TRUE(tests[2]->should_run()); EXPECT_TRUE(tests[2]->result()->Passed()); EXPECT_EQ(0, tests[2]->result()->test_property_count()); EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); - EXPECT_STREQ("", tests[3]->comment()); - EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[3]->value_param())); + EXPECT_TRUE(IsNull(tests[3]->type_param())); EXPECT_TRUE(tests[3]->should_run()); EXPECT_TRUE(tests[3]->result()->Passed()); EXPECT_EQ(1, tests[3]->result()->test_property_count()); @@ -318,9 +318,8 @@ class FinalSuccessChecker : public Environment { EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_STREQ(GetTypeName().c_str(), tests[0]->type_param()); EXPECT_TRUE(tests[0]->should_run()); EXPECT_TRUE(tests[0]->result()->Passed()); EXPECT_EQ(0, tests[0]->result()->test_property_count()); -- cgit v1.2.3 From b147ec394bc024dc63860f0a982ecd82106b8e40 Mon Sep 17 00:00:00 2001 From: vladlosev Date: Wed, 2 Feb 2011 01:18:50 +0000 Subject: Removes unused include directive. --- test/gtest-unittest-api_test.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index f53e2744..07083e51 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -37,7 +37,6 @@ #include // For strcmp. #include -#include using ::testing::InitGoogleTest; -- cgit v1.2.3 From 5d83ee08dff5775b3bc59d144bc3ea3d4fe9dfb9 Mon Sep 17 00:00:00 2001 From: kosak Date: Tue, 3 Dec 2013 23:15:40 +0000 Subject: Fix warnings encountered with clang -Wall. --- test/gtest-unittest-api_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/gtest-unittest-api_test.cc') diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index 07083e51..b1f51688 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -54,7 +54,7 @@ class UnitTestHelper { public: // Returns the array of pointers to all test cases sorted by the test case // name. The caller is responsible for deleting the array. - static TestCase const** const GetSortedTestCases() { + static TestCase const** GetSortedTestCases() { UnitTest& unit_test = *UnitTest::GetInstance(); TestCase const** const test_cases = new const TestCase*[unit_test.total_test_case_count()]; @@ -83,7 +83,7 @@ class UnitTestHelper { // Returns the array of pointers to all tests in a particular test case // sorted by the test name. The caller is responsible for deleting the // array. - static TestInfo const** const GetSortedTests(const TestCase* test_case) { + static TestInfo const** GetSortedTests(const TestCase* test_case) { TestInfo const** const tests = new const TestInfo*[test_case->total_test_count()]; -- cgit v1.2.3