11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Copyright 2008 Google Inc. 21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// All Rights Reserved. 31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Redistribution and use in source and binary forms, with or without 51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// modification, are permitted provided that the following conditions are 61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// met: 71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions of source code must retain the above copyright 91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// notice, this list of conditions and the following disclaimer. 101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions in binary form must reproduce the above 111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copyright notice, this list of conditions and the following disclaimer 121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in the documentation and/or other materials provided with the 131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// distribution. 141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Neither the name of Google Inc. nor the names of its 151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// contributors may be used to endorse or promote products derived from 161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this software without specific prior written permission. 171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Author: wan@google.com (Zhanyong Wan) 311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest-typed-test.h" 3341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest.h" 341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 351be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace testing { 361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace internal { 371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#if GTEST_HAS_TYPED_TEST_P 391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 4041d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// Skips to the first non-space char in str. Returns an empty string if str 4141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot// contains only whitespace characters. 4241d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabotstatic const char* SkipSpaces(const char* str) { 4341d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot while (IsSpace(*str)) 4441d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot str++; 4541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot return str; 4641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot} 4741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Verifies that registered_tests match the test names in 491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// defined_test_names_; returns registered_tests if successful, or 501be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// aborts the program otherwise. 511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaconst char* TypedTestCasePState::VerifyRegisteredTestNames( 521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania const char* file, int line, const char* registered_tests) { 531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania typedef ::std::set<const char*>::const_iterator DefinedTestIter; 541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania registered_ = true; 551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 5641d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // Skip initial whitespace in registered_tests since some 5741d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot // preprocessors prefix stringizied literals with whitespace. 5841d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot registered_tests = SkipSpaces(registered_tests); 5941d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot 601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania Message errors; 61fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes ::std::set<std::string> tests; 621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (const char* names = registered_tests; names != NULL; 631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania names = SkipComma(names)) { 64fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes const std::string name = GetPrefixUntilComma(names); 651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (tests.count(name) != 0) { 661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania errors << "Test " << name << " is listed more than once.\n"; 671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania continue; 681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania bool found = false; 711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (DefinedTestIter it = defined_test_names_.begin(); 721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it != defined_test_names_.end(); 731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ++it) { 741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (name == *it) { 751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania found = true; 761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania break; 771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (found) { 811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania tests.insert(name); 821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } else { 831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania errors << "No test named " << name 841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << " can be found in this test case.\n"; 851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania for (DefinedTestIter it = defined_test_names_.begin(); 891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania it != defined_test_names_.end(); 901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania ++it) { 911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (tests.count(*it) == 0) { 921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania errors << "You forgot to list test " << *it << ".\n"; 931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 96fc2de66453b0669c09eaca643b07d34443858b6fElliott Hughes const std::string& errors_str = errors.GetString(); 971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (errors_str != "") { 981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania errors_str.c_str()); 1001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania fflush(stderr); 10141d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot posix::Abort(); 1021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return registered_tests; 1051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 1061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#endif // GTEST_HAS_TYPED_TEST_P 1081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} // namespace internal 1101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} // namespace testing 111