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 static std::vector<std::string> SplitIntoTestNames(const char* src) {
00049   std::vector<std::string> name_vec;
00050   src = SkipSpaces(src);
00051   for (; src != NULL; src = SkipComma(src)) {
00052     name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src)));
00053   }
00054   return name_vec;
00055 }
00056 
00057 // Verifies that registered_tests match the test names in
00058 // defined_test_names_; returns registered_tests if successful, or
00059 // aborts the program otherwise.
00060 const char* TypedTestCasePState::VerifyRegisteredTestNames(
00061     const char* file, int line, const char* registered_tests) {
00062   typedef ::std::set<const char*>::const_iterator DefinedTestIter;
00063   registered_ = true;
00064 
00065   std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
00066 
00067   Message errors;
00068 
00069   std::set<std::string> tests;
00070   for (std::vector<std::string>::const_iterator name_it = name_vec.begin();
00071        name_it != name_vec.end(); ++name_it) {
00072     const std::string& name = *name_it;
00073     if (tests.count(name) != 0) {
00074       errors << "Test " << name << " is listed more than once.\n";
00075       continue;
00076     }
00077 
00078     bool found = false;
00079     for (DefinedTestIter it = defined_test_names_.begin();
00080          it != defined_test_names_.end();
00081          ++it) {
00082       if (name == *it) {
00083         found = true;
00084         break;
00085       }
00086     }
00087 
00088     if (found) {
00089       tests.insert(name);
00090     } else {
00091       errors << "No test named " << name
00092              << " can be found in this test case.\n";
00093     }
00094   }
00095 
00096   for (DefinedTestIter it = defined_test_names_.begin();
00097        it != defined_test_names_.end();
00098        ++it) {
00099     if (tests.count(*it) == 0) {
00100       errors << "You forgot to list test " << *it << ".\n";
00101     }
00102   }
00103 
00104   const std::string& errors_str = errors.GetString();
00105   if (errors_str != "") {
00106     fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
00107             errors_str.c_str());
00108     fflush(stderr);
00109     posix::Abort();
00110   }
00111 
00112   return registered_tests;
00113 }
00114 
00115 #endif  // GTEST_HAS_TYPED_TEST_P
00116 
00117 }  // namespace internal
00118 }  // namespace testing


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:04