Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00041
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
00058
00059
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 }
00118 }