duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

gtest-typed-test.cc (4038B)


      1 // Copyright 2008 Google Inc.
      2 // All Rights Reserved.
      3 //
      4 // Redistribution and use in source and binary forms, with or without
      5 // modification, are permitted provided that the following conditions are
      6 // met:
      7 //
      8 //     * Redistributions of source code must retain the above copyright
      9 // notice, this list of conditions and the following disclaimer.
     10 //     * Redistributions in binary form must reproduce the above
     11 // copyright notice, this list of conditions and the following disclaimer
     12 // in the documentation and/or other materials provided with the
     13 // distribution.
     14 //     * Neither the name of Google Inc. nor the names of its
     15 // contributors may be used to endorse or promote products derived from
     16 // this software without specific prior written permission.
     17 //
     18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 
     31 #include "gtest/gtest-typed-test.h"
     32 
     33 #include "gtest/gtest.h"
     34 
     35 namespace testing {
     36 namespace internal {
     37 
     38 #if GTEST_HAS_TYPED_TEST_P
     39 
     40 // Skips to the first non-space char in str. Returns an empty string if str
     41 // contains only whitespace characters.
     42 static const char* SkipSpaces(const char* str) {
     43   while (IsSpace(*str))
     44     str++;
     45   return str;
     46 }
     47 
     48 static std::vector<std::string> SplitIntoTestNames(const char* src) {
     49   std::vector<std::string> name_vec;
     50   src = SkipSpaces(src);
     51   for (; src != nullptr; src = SkipComma(src)) {
     52     name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src)));
     53   }
     54   return name_vec;
     55 }
     56 
     57 // Verifies that registered_tests match the test names in
     58 // registered_tests_; returns registered_tests if successful, or
     59 // aborts the program otherwise.
     60 const char* TypedTestSuitePState::VerifyRegisteredTestNames(
     61     const char* test_suite_name, const char* file, int line,
     62     const char* registered_tests) {
     63   RegisterTypeParameterizedTestSuite(test_suite_name, CodeLocation(file, line));
     64 
     65   typedef RegisteredTestsMap::const_iterator RegisteredTestIter;
     66   registered_ = true;
     67 
     68   std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests);
     69 
     70   Message errors;
     71 
     72   std::set<std::string> tests;
     73   for (std::vector<std::string>::const_iterator name_it = name_vec.begin();
     74        name_it != name_vec.end(); ++name_it) {
     75     const std::string& name = *name_it;
     76     if (tests.count(name) != 0) {
     77       errors << "Test " << name << " is listed more than once.\n";
     78       continue;
     79     }
     80 
     81     bool found = false;
     82     for (RegisteredTestIter it = registered_tests_.begin();
     83          it != registered_tests_.end();
     84          ++it) {
     85       if (name == it->first) {
     86         found = true;
     87         break;
     88       }
     89     }
     90 
     91     if (found) {
     92       tests.insert(name);
     93     } else {
     94       errors << "No test named " << name
     95              << " can be found in this test suite.\n";
     96     }
     97   }
     98 
     99   for (RegisteredTestIter it = registered_tests_.begin();
    100        it != registered_tests_.end();
    101        ++it) {
    102     if (tests.count(it->first) == 0) {
    103       errors << "You forgot to list test " << it->first << ".\n";
    104     }
    105   }
    106 
    107   const std::string& errors_str = errors.GetString();
    108   if (errors_str != "") {
    109     fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
    110             errors_str.c_str());
    111     fflush(stderr);
    112     posix::Abort();
    113   }
    114 
    115   return registered_tests;
    116 }
    117 
    118 #endif  // GTEST_HAS_TYPED_TEST_P
    119 
    120 }  // namespace internal
    121 }  // namespace testing