• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

thetic / cpputest / 14350937103

09 Apr 2025 06:30AM UTC coverage: 96.186%. Remained the same
14350937103

push

github

thetic
no WorkingEnvironment

6254 of 6502 relevant lines covered (96.19%)

17609.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/CppUTest/src/TestRegistry.cpp
1
/*
2
 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *     * Redistributions of source code must retain the above copyright
8
 *       notice, this list of conditions and the following disclaimer.
9
 *     * Redistributions in binary form must reproduce the above copyright
10
 *       notice, this list of conditions and the following disclaimer in the
11
 *       documentation and/or other materials provided with the distribution.
12
 *     * Neither the name of the <organization> nor the
13
 *       names of its contributors may be used to endorse or promote products
14
 *       derived from this software without specific prior written permission.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ''AS IS'' AND ANY
17
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
20
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 */
27

28
#include "CppUTest/TestHarness.h"
29
#include "CppUTest/TestRegistry.h"
30

31
TestRegistry::TestRegistry() :
423✔
32
    tests_(nullptr), nameFilters_(nullptr), groupFilters_(nullptr), firstPlugin_(NullTestPlugin::instance()), runInSeperateProcess_(false), currentRepetition_(0), runIgnored_(false)
423✔
33
{
34
}
423✔
35

36
TestRegistry::~TestRegistry()
750✔
37
{
38
}
750✔
39

40
void TestRegistry::addTest(UtestShell *test)
52,920✔
41
{
42
    tests_ = test->addTest(tests_);
52,920✔
43
}
52,920✔
44

45
void TestRegistry::runAllTests(TestResult& result)
289✔
46
{
47
    bool groupStart = true;
289✔
48

49
    result.testsStarted();
289✔
50
    for (UtestShell *test = tests_; test != nullptr; test = test->getNext()) {
52,137✔
51
        if (runIgnored_) test->setRunIgnored();
51,850✔
52

53
        if (groupStart) {
51,850✔
54
            result.currentGroupStarted(test);
3,134✔
55
            groupStart = false;
3,134✔
56
        }
57

58
        result.countTest();
51,850✔
59
        if (testShouldRun(test, result)) {
51,850✔
60
            result.currentTestStarted(test);
1,572✔
61
            test->runOneTest(firstPlugin_, result);
1,572✔
62
            result.currentTestEnded(test);
1,570✔
63
        }
64

65
        if (endOfGroup(test)) {
51,848✔
66
            groupStart = true;
3,132✔
67
            result.currentGroupEnded(test);
3,132✔
68
        }
69
    }
70
    result.testsEnded();
287✔
71
    currentRepetition_++;
287✔
72
}
287✔
73

74
void TestRegistry::listTestGroupNames(TestResult& result)
4✔
75
{
76
    SimpleString groupList;
4✔
77

78
    for (UtestShell *test = tests_; test != nullptr; test = test->getNext()) {
1,347✔
79
        SimpleString gname;
1,343✔
80
        gname += "#";
1,343✔
81
        gname += test->getGroup();
1,343✔
82
        gname += "#";
1,343✔
83

84
        if (!groupList.contains(gname)) {
1,343✔
85
            groupList += gname;
77✔
86
            groupList += " ";
77✔
87
        }
88
    }
1,343✔
89

90
    groupList.replace("#", "");
4✔
91

92
    if (groupList.endsWith(" "))
4✔
93
        groupList = groupList.subString(0, groupList.size() - 1);
4✔
94
    result.print(groupList.asCharString());
4✔
95
}
4✔
96

97
void TestRegistry::listTestGroupAndCaseNames(TestResult& result)
2✔
98
{
99
    SimpleString groupAndNameList;
2✔
100

101
    for (UtestShell *test = tests_; test != nullptr; test = test->getNext()) {
6✔
102
        if (testShouldRun(test, result)) {
4✔
103
            SimpleString groupAndName;
4✔
104
            groupAndName += "#";
4✔
105
            groupAndName += test->getGroup();
4✔
106
            groupAndName += ".";
4✔
107
            groupAndName += test->getName();
4✔
108
            groupAndName += "#";
4✔
109

110
            if (!groupAndNameList.contains(groupAndName)) {
4✔
111
                groupAndNameList += groupAndName;
4✔
112
                groupAndNameList += " ";
4✔
113
            }
114
        }
4✔
115
    }
116

117
    groupAndNameList.replace("#", "");
2✔
118

119
    if (groupAndNameList.endsWith(" "))
2✔
120
        groupAndNameList = groupAndNameList.subString(0, groupAndNameList.size() - 1);
2✔
121
    result.print(groupAndNameList.asCharString());
2✔
122
}
2✔
123

124
void TestRegistry::listTestLocations(TestResult& result)
2✔
125
{
126
    SimpleString testLocations;
2✔
127

128
    for (UtestShell *test = tests_; test != nullptr; test = test->getNext()) {
6✔
129
            SimpleString testLocation;
4✔
130
            testLocation += test->getGroup();
4✔
131
            testLocation += ".";
4✔
132
            testLocation += test->getName();
4✔
133
            testLocation += ".";
4✔
134
            testLocation += test->getFile();
4✔
135
            testLocation += ".";
4✔
136
            testLocation += StringFromFormat("%d\n",(int) test->getLineNumber());
4✔
137

138
            testLocations += testLocation;
4✔
139
    }
4✔
140

141
    result.print(testLocations.asCharString());
2✔
142
}
2✔
143

144
bool TestRegistry::endOfGroup(UtestShell* test)
51,848✔
145
{
146
    return (!test || !test->getNext() || test->getGroup() != test->getNext()->getGroup());
51,848✔
147
}
148

149
size_t TestRegistry::countTests()
9✔
150
{
151
    return tests_ ? tests_->countTests() : 0;
9✔
152
}
153

154
TestRegistry* TestRegistry::currentRegistry_ = nullptr;
155

156
TestRegistry* TestRegistry::getCurrentRegistry()
52,870✔
157
{
158
    static TestRegistry registry;
52,870✔
159
    return (currentRegistry_ == nullptr) ? &registry : currentRegistry_;
52,870✔
160
}
161

162
void TestRegistry::setCurrentRegistry(TestRegistry* registry)
654✔
163
{
164
    currentRegistry_ = registry;
654✔
165
}
654✔
166

167
void TestRegistry::unDoLastAddTest()
11✔
168
{
169
    tests_ = tests_ ? tests_->getNext() : nullptr;
11✔
170

171
}
11✔
172

173
void TestRegistry::setNameFilters(const TestFilter* filters)
94✔
174
{
175
    nameFilters_ = filters;
94✔
176
}
94✔
177

178
void TestRegistry::setGroupFilters(const TestFilter* filters)
94✔
179
{
180
    groupFilters_ = filters;
94✔
181
}
94✔
182

183
void TestRegistry::setRunIgnored()
1✔
184
{
185
    runIgnored_ = true;
1✔
186
}
1✔
187

188
void TestRegistry::setRunTestsInSeperateProcess()
×
189
{
190
    runInSeperateProcess_ = true;
×
191
}
×
192

193
int TestRegistry::getCurrentRepetition()
18✔
194
{
195
    return currentRepetition_;
18✔
196
}
197

198
bool TestRegistry::testShouldRun(UtestShell* test, TestResult& result)
51,854✔
199
{
200
    if (test->shouldRun(groupFilters_, nameFilters_)) return true;
51,854✔
201
    else {
202
        result.countFilteredOut();
50,278✔
203
        return false;
50,278✔
204
    }
205
}
206

207
void TestRegistry::resetPlugins()
1✔
208
{
209
    firstPlugin_ = NullTestPlugin::instance();
1✔
210
}
1✔
211

212
void TestRegistry::installPlugin(TestPlugin* plugin)
238✔
213
{
214
    firstPlugin_ = plugin->addPlugin(firstPlugin_);
238✔
215
}
238✔
216

217
TestPlugin* TestRegistry::getFirstPlugin()
99✔
218
{
219
    return firstPlugin_;
99✔
220
}
221

222
TestPlugin* TestRegistry::getPluginByName(const SimpleString& name)
4✔
223
{
224
    return firstPlugin_->getPluginByName(name);
4✔
225
}
226

227
void TestRegistry::removePluginByName(const SimpleString& name)
174✔
228
{
229
    if (firstPlugin_->removePluginByName(name) == firstPlugin_) firstPlugin_ = firstPlugin_->getNext();
174✔
230
    if (firstPlugin_->getName() == name) firstPlugin_ = firstPlugin_->getNext();
174✔
231
    firstPlugin_->removePluginByName(name);
174✔
232
}
174✔
233

234
int TestRegistry::countPlugins()
9✔
235
{
236
    int count = 0;
9✔
237
    for (TestPlugin* plugin = firstPlugin_; plugin != NullTestPlugin::instance(); plugin = plugin->getNext())
21✔
238
        count++;
12✔
239
    return count;
9✔
240
}
241

242

243
UtestShell* TestRegistry::getFirstTest()
148✔
244
{
245
    return tests_;
148✔
246
}
247

248
void TestRegistry::shuffleTests(size_t seed)
4✔
249
{
250
    UtestShellPointerArray array(getFirstTest());
4✔
251
    array.shuffle(seed);
4✔
252
    tests_ = array.getFirstTest();
4✔
253
}
4✔
254

255
void TestRegistry::reverseTests()
3✔
256
{
257
    UtestShellPointerArray array(getFirstTest());
3✔
258
    array.reverse();
3✔
259
    tests_ = array.getFirstTest();
3✔
260
}
3✔
261

262
UtestShell* TestRegistry::getTestWithNext(UtestShell* test)
58✔
263
{
264
    UtestShell* current = tests_;
58✔
265
    while (current && current->getNext() != test)
10,642✔
266
        current = current->getNext();
10,584✔
267
    return current;
58✔
268
}
269

270
UtestShell* TestRegistry::findTestWithName(const SimpleString& name)
2✔
271
{
272
    UtestShell* current = tests_;
2✔
273
    while (current) {
3✔
274
        if (current->getName() == name)
2✔
275
            return current;
1✔
276
        current = current->getNext();
1✔
277
    }
278
    return nullptr;
1✔
279
}
280

281
UtestShell* TestRegistry::findTestWithGroup(const SimpleString& group)
2✔
282
{
283
    UtestShell* current = tests_;
2✔
284
    while (current) {
3✔
285
        if (current->getGroup() == group)
2✔
286
            return current;
1✔
287
        current = current->getNext();
1✔
288
    }
289
    return nullptr;
1✔
290
}
291

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc