qtestresult.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtTest module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <QtTest/private/qtestresult_p.h> -
43#include <QtCore/qglobal.h> -
44 -
45#include <QtTest/private/qtestlog_p.h> -
46#include <QtTest/qtestdata.h> -
47#include <QtTest/qtestassert.h> -
48 -
49#include <stdio.h> -
50#include <string.h> -
51 -
52QT_BEGIN_NAMESPACE -
53 -
54namespace QTest -
55{ -
56 static QTestData *currentTestData = 0; -
57 static QTestData *currentGlobalTestData = 0; -
58 static const char *currentTestFunc = 0; -
59 static const char *currentTestObjectName = 0; -
60 static bool failed = false; -
61 static bool skipCurrentTest = false; -
62 -
63 static const char *expectFailComment = 0; -
64 static int expectFailMode = 0; -
65 -
66 static const char *currentAppname = 0; -
67} -
68 -
69void QTestResult::reset() -
70{ -
71 QTest::currentTestData = 0;
never executed (the execution status of this line is deduced): QTest::currentTestData = 0;
-
72 QTest::currentGlobalTestData = 0;
never executed (the execution status of this line is deduced): QTest::currentGlobalTestData = 0;
-
73 QTest::currentTestFunc = 0;
never executed (the execution status of this line is deduced): QTest::currentTestFunc = 0;
-
74 QTest::currentTestObjectName = 0;
never executed (the execution status of this line is deduced): QTest::currentTestObjectName = 0;
-
75 QTest::failed = false;
never executed (the execution status of this line is deduced): QTest::failed = false;
-
76 -
77 QTest::expectFailComment = 0;
never executed (the execution status of this line is deduced): QTest::expectFailComment = 0;
-
78 QTest::expectFailMode = 0;
never executed (the execution status of this line is deduced): QTest::expectFailMode = 0;
-
79 -
80 QTestLog::resetCounters();
never executed (the execution status of this line is deduced): QTestLog::resetCounters();
-
81}
never executed: }
0
82 -
83bool QTestResult::currentTestFailed() -
84{ -
85 return QTest::failed;
executed: return QTest::failed;
Execution Count:133604
133604
86} -
87 -
88QTestData *QTestResult::currentGlobalTestData() -
89{ -
90 return QTest::currentGlobalTestData;
executed: return QTest::currentGlobalTestData;
Execution Count:1463
1463
91} -
92 -
93QTestData *QTestResult::currentTestData() -
94{ -
95 return QTest::currentTestData;
executed: return QTest::currentTestData;
Execution Count:178658
178658
96} -
97 -
98void QTestResult::setCurrentGlobalTestData(QTestData *data) -
99{ -
100 QTest::currentGlobalTestData = data;
executed (the execution status of this line is deduced): QTest::currentGlobalTestData = data;
-
101}
executed: }
Execution Count:7016
7016
102 -
103void QTestResult::setCurrentTestData(QTestData *data) -
104{ -
105 QTest::currentTestData = data;
executed (the execution status of this line is deduced): QTest::currentTestData = data;
-
106 QTest::failed = false;
executed (the execution status of this line is deduced): QTest::failed = false;
-
107}
executed: }
Execution Count:139683
139683
108 -
109void QTestResult::setCurrentTestFunction(const char *func) -
110{ -
111 QTest::currentTestFunc = func;
executed (the execution status of this line is deduced): QTest::currentTestFunc = func;
-
112 QTest::failed = false;
executed (the execution status of this line is deduced): QTest::failed = false;
-
113 if (func)
evaluated: func
TRUEFALSE
yes
Evaluation Count:7610
yes
Evaluation Count:391
391-7610
114 QTestLog::enterTestFunction(func);
executed: QTestLog::enterTestFunction(func);
Execution Count:7610
7610
115}
executed: }
Execution Count:8001
8001
116 -
117static void clearExpectFail() -
118{ -
119 QTest::expectFailMode = 0;
executed (the execution status of this line is deduced): QTest::expectFailMode = 0;
-
120 delete [] const_cast<char *>(QTest::expectFailComment);
executed (the execution status of this line is deduced): delete [] const_cast<char *>(QTest::expectFailComment);
-
121 QTest::expectFailComment = 0;
executed (the execution status of this line is deduced): QTest::expectFailComment = 0;
-
122}
executed: }
Execution Count:68120
68120
123 -
124void QTestResult::finishedCurrentTestData() -
125{ -
126 if (QTest::expectFailMode)
partially evaluated: QTest::expectFailMode
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67229
0-67229
127 addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0);
never executed: addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0);
0
128 clearExpectFail();
executed (the execution status of this line is deduced): clearExpectFail();
-
129 -
130 if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) {
evaluated: !QTest::failed
TRUEFALSE
yes
Evaluation Count:66997
yes
Evaluation Count:232
partially evaluated: QTestLog::unhandledIgnoreMessages()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:66997
0-66997
131 QTestLog::printUnhandledIgnoreMessages();
never executed (the execution status of this line is deduced): QTestLog::printUnhandledIgnoreMessages();
-
132 addFailure("Not all expected messages were received", 0, 0);
never executed (the execution status of this line is deduced): addFailure("Not all expected messages were received", 0, 0);
-
133 }
never executed: }
0
134 QTestLog::clearIgnoreMessages();
executed (the execution status of this line is deduced): QTestLog::clearIgnoreMessages();
-
135}
executed: }
Execution Count:67229
67229
136 -
137void QTestResult::finishedCurrentTestDataCleanup() -
138{ -
139 // If the current test hasn't failed or been skipped, then it passes. -
140 if (!QTest::failed && !QTest::skipCurrentTest) {
evaluated: !QTest::failed
TRUEFALSE
yes
Evaluation Count:66989
yes
Evaluation Count:232
evaluated: !QTest::skipCurrentTest
TRUEFALSE
yes
Evaluation Count:66746
yes
Evaluation Count:243
232-66989
141 QTestLog::addPass("");
executed (the execution status of this line is deduced): QTestLog::addPass("");
-
142 }
executed: }
Execution Count:66746
66746
143 -
144 QTest::failed = false;
executed (the execution status of this line is deduced): QTest::failed = false;
-
145}
executed: }
Execution Count:67221
67221
146 -
147void QTestResult::finishedCurrentTestFunction() -
148{ -
149 QTest::currentTestFunc = 0;
executed (the execution status of this line is deduced): QTest::currentTestFunc = 0;
-
150 QTest::failed = false;
executed (the execution status of this line is deduced): QTest::failed = false;
-
151 -
152 QTestLog::leaveTestFunction();
executed (the execution status of this line is deduced): QTestLog::leaveTestFunction();
-
153}
executed: }
Execution Count:7602
7602
154 -
155const char *QTestResult::currentTestFunction() -
156{ -
157 return QTest::currentTestFunc;
executed: return QTest::currentTestFunc;
Execution Count:138699
138699
158} -
159 -
160const char *QTestResult::currentDataTag() -
161{ -
162 return QTest::currentTestData ? QTest::currentTestData->dataTag()
executed: return QTest::currentTestData ? QTest::currentTestData->dataTag() : static_cast<const char *>(0);
Execution Count:263182
263182
163 : static_cast<const char *>(0);
executed: return QTest::currentTestData ? QTest::currentTestData->dataTag() : static_cast<const char *>(0);
Execution Count:263182
263182
164} -
165 -
166const char *QTestResult::currentGlobalDataTag() -
167{ -
168 return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag()
executed: return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() : static_cast<const char *>(0);
Execution Count:69975
69975
169 : static_cast<const char *>(0);
executed: return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() : static_cast<const char *>(0);
Execution Count:69975
69975
170} -
171 -
172static bool isExpectFailData(const char *dataIndex) -
173{ -
174 if (!dataIndex || dataIndex[0] == '\0')
evaluated: !dataIndex
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:10960
evaluated: dataIndex[0] == '\0'
TRUEFALSE
yes
Evaluation Count:59
yes
Evaluation Count:10901
3-10960
175 return true;
executed: return true;
Execution Count:62
62
176 if (!QTest::currentTestData)
partially evaluated: !QTest::currentTestData
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10901
0-10901
177 return false;
never executed: return false;
0
178 if (strcmp(dataIndex, QTest::currentTestData->dataTag()) == 0)
evaluated: strcmp(dataIndex, QTest::currentTestData->dataTag()) == 0
TRUEFALSE
yes
Evaluation Count:277
yes
Evaluation Count:10624
277-10624
179 return true;
executed: return true;
Execution Count:277
277
180 return false;
executed: return false;
Execution Count:10624
10624
181} -
182 -
183bool QTestResult::expectFail(const char *dataIndex, const char *comment, -
184 QTest::TestFailMode mode, const char *file, int line) -
185{ -
186 QTEST_ASSERT(comment);
never executed: qt_assert("comment","qtestresult.cpp",186);
executed: }
Execution Count:10963
partially evaluated: !(comment)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10963
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10963
0-10963
187 QTEST_ASSERT(mode > 0);
never executed: qt_assert("mode > 0","qtestresult.cpp",187);
executed: }
Execution Count:10963
partially evaluated: !(mode > 0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10963
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10963
0-10963
188 -
189 if (!isExpectFailData(dataIndex)) {
evaluated: !isExpectFailData(dataIndex)
TRUEFALSE
yes
Evaluation Count:10624
yes
Evaluation Count:339
339-10624
190 delete[] comment;
executed (the execution status of this line is deduced): delete[] comment;
-
191 return true; // we don't care
executed: return true;
Execution Count:10624
10624
192 } -
193 -
194 if (QTest::expectFailMode) {
partially evaluated: QTest::expectFailMode
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:339
0-339
195 delete[] comment;
never executed (the execution status of this line is deduced): delete[] comment;
-
196 clearExpectFail();
never executed (the execution status of this line is deduced): clearExpectFail();
-
197 addFailure("Already expecting a fail", file, line);
never executed (the execution status of this line is deduced): addFailure("Already expecting a fail", file, line);
-
198 return false;
never executed: return false;
0
199 } -
200 -
201 QTest::expectFailMode = mode;
executed (the execution status of this line is deduced): QTest::expectFailMode = mode;
-
202 QTest::expectFailComment = comment;
executed (the execution status of this line is deduced): QTest::expectFailComment = comment;
-
203 return true;
executed: return true;
Execution Count:339
339
204} -
205 -
206static bool checkStatement(bool statement, const char *msg, const char *file, int line) -
207{ -
208 if (statement) {
evaluated: statement
TRUEFALSE
yes
Evaluation Count:36939626
yes
Evaluation Count:492
492-36939626
209 if (QTest::expectFailMode) {
partially evaluated: QTest::expectFailMode
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:36957509
0-36957509
210 QTestLog::addXPass(msg, file, line);
never executed (the execution status of this line is deduced): QTestLog::addXPass(msg, file, line);
-
211 bool doContinue = (QTest::expectFailMode == QTest::Continue);
never executed (the execution status of this line is deduced): bool doContinue = (QTest::expectFailMode == QTest::Continue);
-
212 clearExpectFail();
never executed (the execution status of this line is deduced): clearExpectFail();
-
213 QTest::failed = true;
never executed (the execution status of this line is deduced): QTest::failed = true;
-
214 return doContinue;
never executed: return doContinue;
0
215 } -
216 return true;
executed: return true;
Execution Count:36961204
36961204
217 } -
218 -
219 if (QTest::expectFailMode) {
evaluated: QTest::expectFailMode
TRUEFALSE
yes
Evaluation Count:339
yes
Evaluation Count:153
153-339
220 QTestLog::addXFail(QTest::expectFailComment, file, line);
executed (the execution status of this line is deduced): QTestLog::addXFail(QTest::expectFailComment, file, line);
-
221 bool doContinue = (QTest::expectFailMode == QTest::Continue);
executed (the execution status of this line is deduced): bool doContinue = (QTest::expectFailMode == QTest::Continue);
-
222 clearExpectFail();
executed (the execution status of this line is deduced): clearExpectFail();
-
223 return doContinue;
executed: return doContinue;
Execution Count:339
339
224 } -
225 -
226 QTestResult::addFailure(msg, file, line);
executed (the execution status of this line is deduced): QTestResult::addFailure(msg, file, line);
-
227 return false;
executed: return false;
Execution Count:153
153
228} -
229 -
230bool QTestResult::verify(bool statement, const char *statementStr, -
231 const char *description, const char *file, int line) -
232{ -
233 QTEST_ASSERT(statementStr);
never executed: qt_assert("statementStr","qtestresult.cpp",233);
executed: }
Execution Count:12563018
partially evaluated: !(statementStr)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12563019
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12563014
0-12563019
234 -
235 char msg[1024];
executed (the execution status of this line is deduced): char msg[1024];
-
236 -
237 if (QTestLog::verboseLevel() >= 2) {
partially evaluated: QTestLog::verboseLevel() >= 2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12563030
0-12563030
238 qsnprintf(msg, 1024, "QVERIFY(%s)", statementStr);
never executed (the execution status of this line is deduced): qsnprintf(msg, 1024, "QVERIFY(%s)", statementStr);
-
239 QTestLog::info(msg, file, line);
never executed (the execution status of this line is deduced): QTestLog::info(msg, file, line);
-
240 }
never executed: }
0
241 -
242 const char * format = QTest::expectFailMode
evaluated: QTest::expectFailMode
TRUEFALSE
yes
Evaluation Count:163
yes
Evaluation Count:12562875
163-12562875
243 ? "'%s' returned TRUE unexpectedly. (%s)"
executed (the execution status of this line is deduced): ? "'%s' returned TRUE unexpectedly. (%s)"
-
244 : "'%s' returned FALSE. (%s)";
executed (the execution status of this line is deduced): : "'%s' returned FALSE. (%s)";
-
245 qsnprintf(msg, 1024, format, statementStr, description ? description : "");
executed (the execution status of this line is deduced): qsnprintf(msg, 1024, format, statementStr, description ? description : "");
-
246 -
247 return checkStatement(statement, msg, file, line);
executed: return checkStatement(statement, msg, file, line);
Execution Count:12563090
12563090
248} -
249 -
250bool QTestResult::compare(bool success, const char *failureMsg, -
251 char *val1, char *val2, -
252 const char *actual, const char *expected, -
253 const char *file, int line) -
254{ -
255 QTEST_ASSERT(expected);
never executed: qt_assert("expected","qtestresult.cpp",255);
executed: }
Execution Count:24359921
partially evaluated: !(expected)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24366651
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24358163
0-24366651
256 QTEST_ASSERT(actual);
never executed: qt_assert("actual","qtestresult.cpp",256);
executed: }
Execution Count:24361801
partially evaluated: !(actual)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24365173
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24370641
0-24370641
257 -
258 char msg[1024];
executed (the execution status of this line is deduced): char msg[1024];
-
259 -
260 if (QTestLog::verboseLevel() >= 2) {
partially evaluated: QTestLog::verboseLevel() >= 2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24374088
0-24374088
261 qsnprintf(msg, 1024, "QCOMPARE(%s, %s)", actual, expected);
never executed (the execution status of this line is deduced): qsnprintf(msg, 1024, "QCOMPARE(%s, %s)", actual, expected);
-
262 QTestLog::info(msg, file, line);
never executed (the execution status of this line is deduced): QTestLog::info(msg, file, line);
-
263 }
never executed: }
0
264 -
265 if (!failureMsg)
evaluated: !failureMsg
TRUEFALSE
yes
Evaluation Count:16
yes
Evaluation Count:24390218
16-24390218
266 failureMsg = "Compared values are not the same";
executed: failureMsg = "Compared values are not the same";
Execution Count:16
16
267 -
268 if (success && QTest::expectFailMode) {
evaluated: success
TRUEFALSE
yes
Evaluation Count:24390291
yes
Evaluation Count:182
partially evaluated: QTest::expectFailMode
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:24396938
0-24396938
269 qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
never executed (the execution status of this line is deduced): qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
-
270 } else if (val1 || val2) {
never executed: }
evaluated: val1
TRUEFALSE
yes
Evaluation Count:22598818
yes
Evaluation Count:1816305
partially evaluated: val2
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1816902
0-22598818
271 qsnprintf(msg, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s",
executed (the execution status of this line is deduced): qsnprintf(msg, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s",
-
272 failureMsg,
executed (the execution status of this line is deduced): failureMsg,
-
273 actual, val1 ? val1 : "<null>",
executed (the execution status of this line is deduced): actual, val1 ? val1 : "<null>",
-
274 expected, val2 ? val2 : "<null>");
executed (the execution status of this line is deduced): expected, val2 ? val2 : "<null>");
-
275 } else
executed: }
Execution Count:22581842
22581842
276 qsnprintf(msg, 1024, "%s", failureMsg);
executed: qsnprintf(msg, 1024, "%s", failureMsg);
Execution Count:1808580
1808580
277 -
278 delete [] val1;
executed (the execution status of this line is deduced): delete [] val1;
-
279 delete [] val2;
executed (the execution status of this line is deduced): delete [] val2;
-
280 -
281 return checkStatement(success, msg, file, line);
executed: return checkStatement(success, msg, file, line);
Execution Count:24389115
24389115
282} -
283 -
284void QTestResult::addFailure(const char *message, const char *file, int line) -
285{ -
286 clearExpectFail();
executed (the execution status of this line is deduced): clearExpectFail();
-
287 -
288 QTestLog::addFail(message, file, line);
executed (the execution status of this line is deduced): QTestLog::addFail(message, file, line);
-
289 QTest::failed = true;
executed (the execution status of this line is deduced): QTest::failed = true;
-
290}
executed: }
Execution Count:237
237
291 -
292void QTestResult::addSkip(const char *message, const char *file, int line) -
293{ -
294 clearExpectFail();
executed (the execution status of this line is deduced): clearExpectFail();
-
295 -
296 QTestLog::addSkip(message, file, line);
executed (the execution status of this line is deduced): QTestLog::addSkip(message, file, line);
-
297}
executed: }
Execution Count:315
315
298 -
299void QTestResult::setCurrentTestObject(const char *name) -
300{ -
301 QTest::currentTestObjectName = name;
never executed (the execution status of this line is deduced): QTest::currentTestObjectName = name;
-
302}
never executed: }
0
303 -
304const char *QTestResult::currentTestObjectName() -
305{ -
306 return QTest::currentTestObjectName ? QTest::currentTestObjectName : "";
executed: return QTest::currentTestObjectName ? QTest::currentTestObjectName : "";
Execution Count:70062
70062
307} -
308 -
309void QTestResult::setSkipCurrentTest(bool value) -
310{ -
311 QTest::skipCurrentTest = value;
executed (the execution status of this line is deduced): QTest::skipCurrentTest = value;
-
312}
executed: }
Execution Count:73958
73958
313 -
314bool QTestResult::skipCurrentTest() -
315{ -
316 return QTest::skipCurrentTest;
executed: return QTest::skipCurrentTest;
Execution Count:140578
140578
317} -
318 -
319void QTestResult::setCurrentAppname(const char *appname) -
320{ -
321 QTest::currentAppname = appname;
never executed (the execution status of this line is deduced): QTest::currentAppname = appname;
-
322}
never executed: }
0
323 -
324const char *QTestResult::currentAppname() -
325{ -
326 return QTest::currentAppname;
executed: return QTest::currentAppname;
Execution Count:396
396
327} -
328 -
329QT_END_NAMESPACE -
330 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial