Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | | - |
8 | namespace QTest | - |
9 | { | - |
10 | static QTestData *currentTestData = 0; | - |
11 | static QTestData *currentGlobalTestData = 0; | - |
12 | static const char *currentTestFunc = 0; | - |
13 | static const char *currentTestObjectName = 0; | - |
14 | static bool failed = false; | - |
15 | static bool skipCurrentTest = false; | - |
16 | | - |
17 | static const char *expectFailComment = 0; | - |
18 | static int expectFailMode = 0; | - |
19 | | - |
20 | static const char *currentAppname = 0; | - |
21 | } | - |
22 | | - |
23 | void QTestResult::reset() | - |
24 | { | - |
25 | QTest::currentTestData = 0; | - |
26 | QTest::currentGlobalTestData = 0; | - |
27 | QTest::currentTestFunc = 0; | - |
28 | QTest::currentTestObjectName = 0; | - |
29 | QTest::failed = false; | - |
30 | | - |
31 | QTest::expectFailComment = 0; | - |
32 | QTest::expectFailMode = 0; | - |
33 | | - |
34 | QTestLog::resetCounters(); | - |
35 | } | 0 |
36 | | - |
37 | bool QTestResult::currentTestFailed() | - |
38 | { | - |
39 | return QTest::failed; executed: return QTest::failed; Execution Count:133604 | 133604 |
40 | } | - |
41 | | - |
42 | QTestData *QTestResult::currentGlobalTestData() | - |
43 | { | - |
44 | return QTest::currentGlobalTestData; executed: return QTest::currentGlobalTestData; Execution Count:1463 | 1463 |
45 | } | - |
46 | | - |
47 | QTestData *QTestResult::currentTestData() | - |
48 | { | - |
49 | return QTest::currentTestData; executed: return QTest::currentTestData; Execution Count:178658 | 178658 |
50 | } | - |
51 | | - |
52 | void QTestResult::setCurrentGlobalTestData(QTestData *data) | - |
53 | { | - |
54 | QTest::currentGlobalTestData = data; | - |
55 | } executed: } Execution Count:7016 | 7016 |
56 | | - |
57 | void QTestResult::setCurrentTestData(QTestData *data) | - |
58 | { | - |
59 | QTest::currentTestData = data; | - |
60 | QTest::failed = false; | - |
61 | } executed: } Execution Count:139683 | 139683 |
62 | | - |
63 | void QTestResult::setCurrentTestFunction(const char *func) | - |
64 | { | - |
65 | QTest::currentTestFunc = func; | - |
66 | QTest::failed = false; | - |
67 | if (func) evaluated: func yes Evaluation Count:7610 | yes Evaluation Count:391 |
| 391-7610 |
68 | QTestLog::enterTestFunction(func); executed: QTestLog::enterTestFunction(func); Execution Count:7610 | 7610 |
69 | } executed: } Execution Count:8001 | 8001 |
70 | | - |
71 | static void clearExpectFail() | - |
72 | { | - |
73 | QTest::expectFailMode = 0; | - |
74 | delete [] const_cast<char *>(QTest::expectFailComment); | - |
75 | QTest::expectFailComment = 0; | - |
76 | } executed: } Execution Count:68120 | 68120 |
77 | | - |
78 | void QTestResult::finishedCurrentTestData() | - |
79 | { | - |
80 | if (QTest::expectFailMode) partially evaluated: QTest::expectFailMode no Evaluation Count:0 | yes Evaluation Count:67229 |
| 0-67229 |
81 | 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 |
82 | clearExpectFail(); | - |
83 | | - |
84 | if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) { evaluated: !QTest::failed yes Evaluation Count:66997 | yes Evaluation Count:232 |
partially evaluated: QTestLog::unhandledIgnoreMessages() no Evaluation Count:0 | yes Evaluation Count:66997 |
| 0-66997 |
85 | QTestLog::printUnhandledIgnoreMessages(); | - |
86 | addFailure("Not all expected messages were received", 0, 0); | - |
87 | } | 0 |
88 | QTestLog::clearIgnoreMessages(); | - |
89 | } executed: } Execution Count:67229 | 67229 |
90 | | - |
91 | void QTestResult::finishedCurrentTestDataCleanup() | - |
92 | { | - |
93 | | - |
94 | if (!QTest::failed && !QTest::skipCurrentTest) { evaluated: !QTest::failed yes Evaluation Count:66989 | yes Evaluation Count:232 |
evaluated: !QTest::skipCurrentTest yes Evaluation Count:66746 | yes Evaluation Count:243 |
| 232-66989 |
95 | QTestLog::addPass(""); | - |
96 | } executed: } Execution Count:66746 | 66746 |
97 | | - |
98 | QTest::failed = false; | - |
99 | } executed: } Execution Count:67221 | 67221 |
100 | | - |
101 | void QTestResult::finishedCurrentTestFunction() | - |
102 | { | - |
103 | QTest::currentTestFunc = 0; | - |
104 | QTest::failed = false; | - |
105 | | - |
106 | QTestLog::leaveTestFunction(); | - |
107 | } executed: } Execution Count:7602 | 7602 |
108 | | - |
109 | const char *QTestResult::currentTestFunction() | - |
110 | { | - |
111 | return QTest::currentTestFunc; executed: return QTest::currentTestFunc; Execution Count:138699 | 138699 |
112 | } | - |
113 | | - |
114 | const char *QTestResult::currentDataTag() | - |
115 | { | - |
116 | return QTest::currentTestData ? QTest::currentTestData->dataTag() | 263182 |
117 | : static_cast<const char *>(0); executed: return QTest::currentTestData ? QTest::currentTestData->dataTag() : static_cast<const char *>(0); Execution Count:263182 | 263182 |
118 | } | - |
119 | | - |
120 | const char *QTestResult::currentGlobalDataTag() | - |
121 | { | - |
122 | return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() | 69975 |
123 | : static_cast<const char *>(0); executed: return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() : static_cast<const char *>(0); Execution Count:69975 | 69975 |
124 | } | - |
125 | | - |
126 | static bool isExpectFailData(const char *dataIndex) | - |
127 | { | - |
128 | if (!dataIndex || dataIndex[0] == '\0') evaluated: !dataIndex yes Evaluation Count:3 | yes Evaluation Count:10960 |
evaluated: dataIndex[0] == '\0' yes Evaluation Count:59 | yes Evaluation Count:10901 |
| 3-10960 |
129 | return true; executed: return true; Execution Count:62 | 62 |
130 | if (!QTest::currentTestData) partially evaluated: !QTest::currentTestData no Evaluation Count:0 | yes Evaluation Count:10901 |
| 0-10901 |
131 | return false; never executed: return false; | 0 |
132 | if (strcmp(dataIndex, QTest::currentTestData->dataTag()) == 0) evaluated: strcmp(dataIndex, QTest::currentTestData->dataTag()) == 0 yes Evaluation Count:277 | yes Evaluation Count:10624 |
| 277-10624 |
133 | return true; executed: return true; Execution Count:277 | 277 |
134 | return false; executed: return false; Execution Count:10624 | 10624 |
135 | } | - |
136 | | - |
137 | bool QTestResult::expectFail(const char *dataIndex, const char *comment, | - |
138 | QTest::TestFailMode mode, const char *file, int line) | - |
139 | { | - |
140 | do { if (!(comment)) qt_assert("comment","qtestresult.cpp",186); } while (0); never executed: qt_assert("comment","qtestresult.cpp",186); executed: } Execution Count:10963 partially evaluated: !(comment) no Evaluation Count:0 | yes Evaluation Count:10963 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:10963 |
| 0-10963 |
141 | do { if (!(mode > 0)) qt_assert("mode > 0","qtestresult.cpp",187); } while (0); never executed: qt_assert("mode > 0","qtestresult.cpp",187); executed: } Execution Count:10963 partially evaluated: !(mode > 0) no Evaluation Count:0 | yes Evaluation Count:10963 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:10963 |
| 0-10963 |
142 | | - |
143 | if (!isExpectFailData(dataIndex)) { evaluated: !isExpectFailData(dataIndex) yes Evaluation Count:10624 | yes Evaluation Count:339 |
| 339-10624 |
144 | delete[] comment; | - |
145 | return true; executed: return true; Execution Count:10624 | 10624 |
146 | } | - |
147 | | - |
148 | if (QTest::expectFailMode) { partially evaluated: QTest::expectFailMode no Evaluation Count:0 | yes Evaluation Count:339 |
| 0-339 |
149 | delete[] comment; | - |
150 | clearExpectFail(); | - |
151 | addFailure("Already expecting a fail", file, line); | - |
152 | return false; never executed: return false; | 0 |
153 | } | - |
154 | | - |
155 | QTest::expectFailMode = mode; | - |
156 | QTest::expectFailComment = comment; | - |
157 | return true; executed: return true; Execution Count:339 | 339 |
158 | } | - |
159 | | - |
160 | static bool checkStatement(bool statement, const char *msg, const char *file, int line) | - |
161 | { | - |
162 | if (statement) { evaluated: statement yes Evaluation Count:36939626 | yes Evaluation Count:492 |
| 492-36939626 |
163 | if (QTest::expectFailMode) { partially evaluated: QTest::expectFailMode no Evaluation Count:0 | yes Evaluation Count:36957509 |
| 0-36957509 |
164 | QTestLog::addXPass(msg, file, line); | - |
165 | bool doContinue = (QTest::expectFailMode == QTest::Continue); | - |
166 | clearExpectFail(); | - |
167 | QTest::failed = true; | - |
168 | return doContinue; never executed: return doContinue; | 0 |
169 | } | - |
170 | return true; executed: return true; Execution Count:36961204 | 36961204 |
171 | } | - |
172 | | - |
173 | if (QTest::expectFailMode) { evaluated: QTest::expectFailMode yes Evaluation Count:339 | yes Evaluation Count:153 |
| 153-339 |
174 | QTestLog::addXFail(QTest::expectFailComment, file, line); | - |
175 | bool doContinue = (QTest::expectFailMode == QTest::Continue); | - |
176 | clearExpectFail(); | - |
177 | return doContinue; executed: return doContinue; Execution Count:339 | 339 |
178 | } | - |
179 | | - |
180 | QTestResult::addFailure(msg, file, line); | - |
181 | return false; executed: return false; Execution Count:153 | 153 |
182 | } | - |
183 | | - |
184 | bool QTestResult::verify(bool statement, const char *statementStr, | - |
185 | const char *description, const char *file, int line) | - |
186 | { | - |
187 | do { if (!(statementStr)) qt_assert("statementStr","qtestresult.cpp",233); } while (0); never executed: qt_assert("statementStr","qtestresult.cpp",233); executed: } Execution Count:12563018 partially evaluated: !(statementStr) no Evaluation Count:0 | yes Evaluation Count:12563019 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:12563014 |
| 0-12563019 |
188 | | - |
189 | char msg[1024]; | - |
190 | | - |
191 | if (QTestLog::verboseLevel() >= 2) { partially evaluated: QTestLog::verboseLevel() >= 2 no Evaluation Count:0 | yes Evaluation Count:12563030 |
| 0-12563030 |
192 | qsnprintf(msg, 1024, "QVERIFY(%s)", statementStr); | - |
193 | QTestLog::info(msg, file, line); | - |
194 | } | 0 |
195 | | - |
196 | const char * format = QTest::expectFailMode evaluated: QTest::expectFailMode yes Evaluation Count:163 | yes Evaluation Count:12562875 |
| 163-12562875 |
197 | ? "'%s' returned TRUE unexpectedly. (%s)" | - |
198 | : "'%s' returned FALSE. (%s)"; | - |
199 | qsnprintf(msg, 1024, format, statementStr, description ? description : ""); | - |
200 | | - |
201 | return checkStatement(statement, msg, file, line); executed: return checkStatement(statement, msg, file, line); Execution Count:12563090 | 12563090 |
202 | } | - |
203 | | - |
204 | bool QTestResult::compare(bool success, const char *failureMsg, | - |
205 | char *val1, char *val2, | - |
206 | const char *actual, const char *expected, | - |
207 | const char *file, int line) | - |
208 | { | - |
209 | do { if (!(expected)) qt_assert("expected","qtestresult.cpp",255); } while (0); never executed: qt_assert("expected","qtestresult.cpp",255); executed: } Execution Count:24359921 partially evaluated: !(expected) no Evaluation Count:0 | yes Evaluation Count:24366651 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:24358163 |
| 0-24366651 |
210 | do { if (!(actual)) qt_assert("actual","qtestresult.cpp",256); } while (0); never executed: qt_assert("actual","qtestresult.cpp",256); executed: } Execution Count:24361801 partially evaluated: !(actual) no Evaluation Count:0 | yes Evaluation Count:24365173 |
partially evaluated: 0 no Evaluation Count:0 | yes Evaluation Count:24370641 |
| 0-24370641 |
211 | | - |
212 | char msg[1024]; | - |
213 | | - |
214 | if (QTestLog::verboseLevel() >= 2) { partially evaluated: QTestLog::verboseLevel() >= 2 no Evaluation Count:0 | yes Evaluation Count:24374088 |
| 0-24374088 |
215 | qsnprintf(msg, 1024, "QCOMPARE(%s, %s)", actual, expected); | - |
216 | QTestLog::info(msg, file, line); | - |
217 | } | 0 |
218 | | - |
219 | if (!failureMsg) evaluated: !failureMsg yes Evaluation Count:16 | yes Evaluation Count:24390218 |
| 16-24390218 |
220 | failureMsg = "Compared values are not the same"; executed: failureMsg = "Compared values are not the same"; Execution Count:16 | 16 |
221 | | - |
222 | if (success && QTest::expectFailMode) { evaluated: success yes Evaluation Count:24390291 | yes Evaluation Count:182 |
partially evaluated: QTest::expectFailMode no Evaluation Count:0 | yes Evaluation Count:24396938 |
| 0-24396938 |
223 | qsnprintf(msg, 1024, "QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected); | - |
224 | } else if (val1 || val2) { evaluated: val1 yes Evaluation Count:22598818 | yes Evaluation Count:1816305 |
partially evaluated: val2 no Evaluation Count:0 | yes Evaluation Count:1816902 |
| 0-22598818 |
225 | qsnprintf(msg, 1024, "%s\n Actual (%s): %s\n Expected (%s): %s", | - |
226 | failureMsg, | - |
227 | actual, val1 ? val1 : "<null>", | - |
228 | expected, val2 ? val2 : "<null>"); | - |
229 | } else executed: } Execution Count:22581842 | 22581842 |
230 | qsnprintf(msg, 1024, "%s", failureMsg); executed: qsnprintf(msg, 1024, "%s", failureMsg); Execution Count:1808580 | 1808580 |
231 | | - |
232 | delete [] val1; | - |
233 | delete [] val2; | - |
234 | | - |
235 | return checkStatement(success, msg, file, line); executed: return checkStatement(success, msg, file, line); Execution Count:24389115 | 24389115 |
236 | } | - |
237 | | - |
238 | void QTestResult::addFailure(const char *message, const char *file, int line) | - |
239 | { | - |
240 | clearExpectFail(); | - |
241 | | - |
242 | QTestLog::addFail(message, file, line); | - |
243 | QTest::failed = true; | - |
244 | } executed: } Execution Count:237 | 237 |
245 | | - |
246 | void QTestResult::addSkip(const char *message, const char *file, int line) | - |
247 | { | - |
248 | clearExpectFail(); | - |
249 | | - |
250 | QTestLog::addSkip(message, file, line); | - |
251 | } executed: } Execution Count:315 | 315 |
252 | | - |
253 | void QTestResult::setCurrentTestObject(const char *name) | - |
254 | { | - |
255 | QTest::currentTestObjectName = name; | - |
256 | } | 0 |
257 | | - |
258 | const char *QTestResult::currentTestObjectName() | - |
259 | { | - |
260 | return QTest::currentTestObjectName ? QTest::currentTestObjectName : ""; executed: return QTest::currentTestObjectName ? QTest::currentTestObjectName : ""; Execution Count:70062 | 70062 |
261 | } | - |
262 | | - |
263 | void QTestResult::setSkipCurrentTest(bool value) | - |
264 | { | - |
265 | QTest::skipCurrentTest = value; | - |
266 | } executed: } Execution Count:73958 | 73958 |
267 | | - |
268 | bool QTestResult::skipCurrentTest() | - |
269 | { | - |
270 | return QTest::skipCurrentTest; executed: return QTest::skipCurrentTest; Execution Count:140578 | 140578 |
271 | } | - |
272 | | - |
273 | void QTestResult::setCurrentAppname(const char *appname) | - |
274 | { | - |
275 | QTest::currentAppname = appname; | - |
276 | } | 0 |
277 | | - |
278 | const char *QTestResult::currentAppname() | - |
279 | { | - |
280 | return QTest::currentAppname; executed: return QTest::currentAppname; Execution Count:396 | 396 |
281 | } | - |
282 | | - |
283 | | - |
284 | | - |
| | |