1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright 2009 Google Inc. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Redistribution and use in source and binary forms, with or without 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// modification, are permitted provided that the following conditions are 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// met: 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// * Redistributions of source code must retain the above copyright 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// notice, this list of conditions and the following disclaimer. 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// * Redistributions in binary form must reproduce the above 10c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// copyright notice, this list of conditions and the following disclaimer 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// in the documentation and/or other materials provided with the 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// distribution. 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// * Neither the name of Google Inc. nor the names of its 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// contributors may be used to endorse or promote products derived from 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// this software without specific prior written permission. 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Author: vladl@google.com (Vlad Losev) 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// The Google C++ Testing Framework (Google Test) 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This file contains tests verifying correctness of data provided via 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// UnitTest's public methods. 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 36731df977c0511bca2206b5f333555b1205ff1f43Iain Merrick#include "gtest/gtest.h" 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string.h> // For strcmp. 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <algorithm> 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochusing ::testing::InitGoogleTest; 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace testing { 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochnamespace internal { 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochtemplate <typename T> 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct LessByName { 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool operator()(const T* a, const T* b) { 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return strcmp(a->name(), b->name()) < 0; 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass UnitTestHelper { 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns the array of pointers to all test cases sorted by the test case 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // name. The caller is responsible for deleting the array. 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static TestCase const** const GetSortedTestCases() { 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnitTest& unit_test = *UnitTest::GetInstance(); 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch TestCase const** const test_cases = 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch new const TestCase*[unit_test.total_test_case_count()]; 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch for (int i = 0; i < unit_test.total_test_case_count(); ++i) 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch test_cases[i] = unit_test.GetTestCase(i); 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch std::sort(test_cases, 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch test_cases + unit_test.total_test_case_count(), 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch LessByName<TestCase>()); 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return test_cases; 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns the test case by its name. The caller doesn't own the returned 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // pointer. 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const TestCase* FindTestCase(const char* name) { 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnitTest& unit_test = *UnitTest::GetInstance(); 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch for (int i = 0; i < unit_test.total_test_case_count(); ++i) { 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase* test_case = unit_test.GetTestCase(i); 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch if (0 == strcmp(test_case->name(), name)) 78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return test_case; 79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return NULL; 81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Returns the array of pointers to all tests in a particular test case 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // sorted by the test name. The caller is responsible for deleting the 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // array. 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static TestInfo const** const GetSortedTests(const TestCase* test_case) { 87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch TestInfo const** const tests = 88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch new const TestInfo*[test_case->total_test_count()]; 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch for (int i = 0; i < test_case->total_test_count(); ++i) 91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch tests[i] = test_case->GetTestInfo(i); 92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch std::sort(tests, tests + test_case->total_test_count(), 94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch LessByName<TestInfo>()); 95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return tests; 96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if GTEST_HAS_TYPED_TEST 100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochtemplate <typename T> class TestCaseWithCommentTest : public Test {}; 101c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTYPED_TEST_CASE(TestCaseWithCommentTest, Types<int>); 102c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTYPED_TEST(TestCaseWithCommentTest, Dummy) {} 103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst int kTypedTestCases = 1; 105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst int kTypedTests = 1; 106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#else 107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst int kTypedTestCases = 0; 108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochconst int kTypedTests = 0; 109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // GTEST_HAS_TYPED_TEST 110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// We can only test the accessors that do not change value while tests run. 112c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Since tests can be run in any order, the values the accessors that track 113c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// test execution (such as failed_test_count) can not be predicted. 114c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTEST(ApiTest, UnitTestImmutableAccessorsWork) { 115c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnitTest* unit_test = UnitTest::GetInstance(); 116c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 117c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); 118c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1 + kTypedTestCases, unit_test->test_case_to_run_count()); 119c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(2, unit_test->disabled_test_count()); 120c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(5 + kTypedTests, unit_test->total_test_count()); 121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(3 + kTypedTests, unit_test->test_to_run_count()); 122c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 123c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); 124c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 125c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", test_cases[0]->name()); 126c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); 127c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if GTEST_HAS_TYPED_TEST 128c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); 129c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // GTEST_HAS_TYPED_TEST 130c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 131c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] test_cases; 132c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 133c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The following lines initiate actions to verify certain methods in 134c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // FinalSuccessChecker::TearDown. 135c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 136c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Records a test property to verify TestResult::GetTestProperty(). 137c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RecordProperty("key", "value"); 138c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 139c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 140dc0f95d653279beabeb9817299e2902918ba123eKristian MonsenAssertionResult IsNull(const char* str) { 141dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen if (str != NULL) { 142dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen return testing::AssertionFailure() << "argument is " << str; 143dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen } 144dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen return AssertionSuccess(); 145dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen} 146dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen 147c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTEST(ApiTest, TestCaseImmutableAccessorsWork) { 148c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); 149c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_TRUE(test_case != NULL); 150c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 151c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", test_case->name()); 152dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_case->type_param())); 153c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_case->should_run()); 154c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_case->disabled_test_count()); 155c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(3, test_case->test_to_run_count()); 156c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(4, test_case->total_test_count()); 157c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 158c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); 159c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 160c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); 161c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); 162dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[0]->value_param())); 163dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[0]->type_param())); 164c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(tests[0]->should_run()); 165c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 166c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); 167c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); 168dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[1]->value_param())); 169dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[1]->type_param())); 170c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[1]->should_run()); 171c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 172c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); 173c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); 174dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[2]->value_param())); 175dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[2]->type_param())); 176c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[2]->should_run()); 177c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 178c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); 179c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); 180dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[3]->value_param())); 181dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[3]->type_param())); 182c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[3]->should_run()); 183c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 184c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] tests; 185c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch tests = NULL; 186c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 187c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if GTEST_HAS_TYPED_TEST 188c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); 189c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_TRUE(test_case != NULL); 190c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 191c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); 192dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_STREQ(GetTypeName<int>().c_str(), test_case->type_param()); 193c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_case->should_run()); 194c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_case->disabled_test_count()); 195c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_case->test_to_run_count()); 196c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(1, test_case->total_test_count()); 197c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 198c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch tests = UnitTestHelper::GetSortedTests(test_case); 199c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 200c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("Dummy", tests[0]->name()); 201c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); 202dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[0]->value_param())); 203dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param()); 204c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[0]->should_run()); 205c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 206c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] tests; 207c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // GTEST_HAS_TYPED_TEST 208c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 209c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 210c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTEST(ApiTest, TestCaseDisabledAccessorsWork) { 211c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase* test_case = UnitTestHelper::FindTestCase("DISABLED_Test"); 212c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_TRUE(test_case != NULL); 213c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 214c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Test", test_case->name()); 215dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_case->type_param())); 216c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(test_case->should_run()); 217c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_case->disabled_test_count()); 218c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_case->test_to_run_count()); 219c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(1, test_case->total_test_count()); 220c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 221c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestInfo* const test_info = test_case->GetTestInfo(0); 222c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("Dummy2", test_info->name()); 223c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Test", test_info->test_case_name()); 224dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_info->value_param())); 225dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_info->type_param())); 226c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(test_info->should_run()); 227c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 228c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 229c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// These two tests are here to provide support for testing 230c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// test_case_to_run_count, disabled_test_count, and test_to_run_count. 231c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTEST(ApiTest, DISABLED_Dummy1) {} 232c407dc5cd9bdc5668497f21b26b09d988ab439deBen MurdochTEST(DISABLED_Test, Dummy2) {} 233c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 234c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass FinalSuccessChecker : public Environment { 235c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch protected: 236c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void TearDown() { 237c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch UnitTest* unit_test = UnitTest::GetInstance(); 238c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 239c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1 + kTypedTestCases, unit_test->successful_test_case_count()); 240c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(3 + kTypedTests, unit_test->successful_test_count()); 241c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, unit_test->failed_test_case_count()); 242c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, unit_test->failed_test_count()); 243c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(unit_test->Passed()); 244c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(unit_test->Failed()); 245c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(2 + kTypedTestCases, unit_test->total_test_case_count()); 246c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 247c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); 248c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 249c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", test_cases[0]->name()); 250dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_cases[0]->type_param())); 251c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_cases[0]->should_run()); 252c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_cases[0]->disabled_test_count()); 253c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(4, test_cases[0]->total_test_count()); 254c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(3, test_cases[0]->successful_test_count()); 255c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_cases[0]->failed_test_count()); 256c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_cases[0]->Passed()); 257c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(test_cases[0]->Failed()); 258c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 259c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); 260dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(test_cases[1]->type_param())); 261c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(test_cases[1]->should_run()); 262c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_cases[1]->disabled_test_count()); 263c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(1, test_cases[1]->total_test_count()); 264c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_cases[1]->successful_test_count()); 265c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_cases[1]->failed_test_count()); 266c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 267c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if GTEST_HAS_TYPED_TEST 268c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); 269dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_STREQ(GetTypeName<int>().c_str(), test_cases[2]->type_param()); 270c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_cases[2]->should_run()); 271c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_cases[2]->disabled_test_count()); 272c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch ASSERT_EQ(1, test_cases[2]->total_test_count()); 273c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, test_cases[2]->successful_test_count()); 274c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, test_cases[2]->failed_test_count()); 275c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(test_cases[2]->Passed()); 276c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(test_cases[2]->Failed()); 277c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // GTEST_HAS_TYPED_TEST 278c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 279c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); 280c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestInfo** tests = UnitTestHelper::GetSortedTests(test_case); 281c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); 282c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); 283c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_FALSE(tests[0]->should_run()); 284c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 285c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); 286c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); 287dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[1]->value_param())); 288dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[1]->type_param())); 289c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[1]->should_run()); 290c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[1]->result()->Passed()); 291c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, tests[1]->result()->test_property_count()); 292c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 293c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); 294c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); 295dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[2]->value_param())); 296dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[2]->type_param())); 297c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[2]->should_run()); 298c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[2]->result()->Passed()); 299c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, tests[2]->result()->test_property_count()); 300c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 301c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); 302c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); 303dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[3]->value_param())); 304dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[3]->type_param())); 305c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[3]->should_run()); 306c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[3]->result()->Passed()); 307c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(1, tests[3]->result()->test_property_count()); 308c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const TestProperty& property = tests[3]->result()->GetTestProperty(0); 309c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("key", property.key()); 310c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("value", property.value()); 311c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 312c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] tests; 313c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 314c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#if GTEST_HAS_TYPED_TEST 315c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch test_case = UnitTestHelper::FindTestCase("TestCaseWithCommentTest/0"); 316c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch tests = UnitTestHelper::GetSortedTests(test_case); 317c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 318c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("Dummy", tests[0]->name()); 319c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); 320dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_TRUE(IsNull(tests[0]->value_param())); 321dc0f95d653279beabeb9817299e2902918ba123eKristian Monsen EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param()); 322c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[0]->should_run()); 323c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_TRUE(tests[0]->result()->Passed()); 324c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch EXPECT_EQ(0, tests[0]->result()->test_property_count()); 325c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 326c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] tests; 327c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // GTEST_HAS_TYPED_TEST 328c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch delete[] test_cases; 329c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } 330c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 331c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 332c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} // namespace internal 333c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} // namespace testing 334c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 335c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochint main(int argc, char **argv) { 336c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch InitGoogleTest(&argc, argv); 337c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 338c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch AddGlobalTestEnvironment(new testing::internal::FinalSuccessChecker()); 339c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 340c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch return RUN_ALL_TESTS(); 341c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch} 342