/home/arjun/llvm-project/llvm/utils/unittest/googletest/src/gtest-typed-test.cc
Line | Count | Source (jump to first uncovered line) |
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 | | // Author: wan@google.com (Zhanyong Wan) |
31 | | |
32 | | #include "gtest/gtest-typed-test.h" |
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 | 0 | static const char* SkipSpaces(const char* str) { |
43 | 0 | while (IsSpace(*str)) |
44 | 0 | str++; |
45 | 0 | return str; |
46 | 0 | } |
47 | | |
48 | 0 | static std::vector<std::string> SplitIntoTestNames(const char* src) { |
49 | 0 | std::vector<std::string> name_vec; |
50 | 0 | src = SkipSpaces(src); |
51 | 0 | for (; src != NULL; src = SkipComma(src)) { |
52 | 0 | name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); |
53 | 0 | } |
54 | 0 | return name_vec; |
55 | 0 | } |
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* TypedTestCasePState::VerifyRegisteredTestNames( |
61 | 0 | const char* file, int line, const char* registered_tests) { |
62 | 0 | typedef RegisteredTestsMap::const_iterator RegisteredTestIter; |
63 | 0 | registered_ = true; |
64 | 0 |
|
65 | 0 | std::vector<std::string> name_vec = SplitIntoTestNames(registered_tests); |
66 | 0 |
|
67 | 0 | Message errors; |
68 | 0 |
|
69 | 0 | std::set<std::string> tests; |
70 | 0 | for (std::vector<std::string>::const_iterator name_it = name_vec.begin(); |
71 | 0 | name_it != name_vec.end(); ++name_it) { |
72 | 0 | const std::string& name = *name_it; |
73 | 0 | if (tests.count(name) != 0) { |
74 | 0 | errors << "Test " << name << " is listed more than once.\n"; |
75 | 0 | continue; |
76 | 0 | } |
77 | 0 | |
78 | 0 | bool found = false; |
79 | 0 | for (RegisteredTestIter it = registered_tests_.begin(); |
80 | 0 | it != registered_tests_.end(); |
81 | 0 | ++it) { |
82 | 0 | if (name == it->first) { |
83 | 0 | found = true; |
84 | 0 | break; |
85 | 0 | } |
86 | 0 | } |
87 | 0 |
|
88 | 0 | if (found) { |
89 | 0 | tests.insert(name); |
90 | 0 | } else { |
91 | 0 | errors << "No test named " << name |
92 | 0 | << " can be found in this test case.\n"; |
93 | 0 | } |
94 | 0 | } |
95 | 0 |
|
96 | 0 | for (RegisteredTestIter it = registered_tests_.begin(); |
97 | 0 | it != registered_tests_.end(); |
98 | 0 | ++it) { |
99 | 0 | if (tests.count(it->first) == 0) { |
100 | 0 | errors << "You forgot to list test " << it->first << ".\n"; |
101 | 0 | } |
102 | 0 | } |
103 | 0 |
|
104 | 0 | const std::string& errors_str = errors.GetString(); |
105 | 0 | if (errors_str != "") { |
106 | 0 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), |
107 | 0 | errors_str.c_str()); |
108 | 0 | fflush(stderr); |
109 | 0 | posix::Abort(); |
110 | 0 | } |
111 | 0 |
|
112 | 0 | return registered_tests; |
113 | 0 | } |
114 | | |
115 | | #endif // GTEST_HAS_TYPED_TEST_P |
116 | | |
117 | | } // namespace internal |
118 | | } // namespace testing |