gtest-typed-test.cc
Go to the documentation of this file.
00001 // Copyright 2008 Google Inc.
00002 // All Rights Reserved.
00003 //
00004 // Redistribution and use in source and binary forms, with or without
00005 // modification, are permitted provided that the following conditions are
00006 // met:
00007 //
00008 //     * Redistributions of source code must retain the above copyright
00009 // notice, this list of conditions and the following disclaimer.
00010 //     * Redistributions in binary form must reproduce the above
00011 // copyright notice, this list of conditions and the following disclaimer
00012 // in the documentation and/or other materials provided with the
00013 // distribution.
00014 //     * Neither the name of Google Inc. nor the names of its
00015 // contributors may be used to endorse or promote products derived from
00016 // this software without specific prior written permission.
00017 //
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // Author: wan@google.com (Zhanyong Wan)
00031 
00032 #include "gtest/gtest-typed-test.h"
00033 #include "gtest/gtest.h"
00034 
00035 namespace testing {
00036 namespace internal {
00037 
00038 #if GTEST_HAS_TYPED_TEST_P
00039 
00040 // Skips to the first non-space char in str. Returns an empty string if str
00041 // contains only whitespace characters.
00042 static const char* SkipSpaces(const char* str) {
00043   while (IsSpace(*str))
00044     str++;
00045   return str;
00046 }
00047 
00048 // Verifies that registered_tests match the test names in
00049 // defined_test_names_; returns registered_tests if successful, or
00050 // aborts the program otherwise.
00051 const char* TypedTestCasePState::VerifyRegisteredTestNames(
00052     const char* file, int line, const char* registered_tests) {
00053   typedef ::std::set<const char*>::const_iterator DefinedTestIter;
00054   registered_ = true;
00055 
00056   // Skip initial whitespace in registered_tests since some
00057   // preprocessors prefix stringizied literals with whitespace.
00058   registered_tests = SkipSpaces(registered_tests);
00059 
00060   Message errors;
00061   ::std::set<String> tests;
00062   for (const char* names = registered_tests; names != NULL;
00063        names = SkipComma(names)) {
00064     const String name = GetPrefixUntilComma(names);
00065     if (tests.count(name) != 0) {
00066       errors << "Test " << name << " is listed more than once.\n";
00067       continue;
00068     }
00069 
00070     bool found = false;
00071     for (DefinedTestIter it = defined_test_names_.begin();
00072          it != defined_test_names_.end();
00073          ++it) {
00074       if (name == *it) {
00075         found = true;
00076         break;
00077       }
00078     }
00079 
00080     if (found) {
00081       tests.insert(name);
00082     } else {
00083       errors << "No test named " << name
00084              << " can be found in this test case.\n";
00085     }
00086   }
00087 
00088   for (DefinedTestIter it = defined_test_names_.begin();
00089        it != defined_test_names_.end();
00090        ++it) {
00091     if (tests.count(*it) == 0) {
00092       errors << "You forgot to list test " << *it << ".\n";
00093     }
00094   }
00095 
00096   const String& errors_str = errors.GetString();
00097   if (errors_str != "") {
00098     fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
00099             errors_str.c_str());
00100     fflush(stderr);
00101     posix::Abort();
00102   }
00103 
00104   return registered_tests;
00105 }
00106 
00107 #endif  // GTEST_HAS_TYPED_TEST_P
00108 
00109 }  // namespace internal
00110 }  // namespace testing


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:24:39