qplaintestlogger.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4namespace QTest { -
5 -
6 static const char *incidentType2String(QAbstractTestLogger::IncidentTypes type) -
7 { -
8 switch (type) { -
9 case QAbstractTestLogger::Pass: -
10 return "PASS ";
executed: return "PASS ";
Execution Count:66746
66746
11 case QAbstractTestLogger::XFail: -
12 return "XFAIL ";
executed: return "XFAIL ";
Execution Count:339
339
13 case QAbstractTestLogger::Fail: -
14 return "FAIL! ";
executed: return "FAIL! ";
Execution Count:237
237
15 case QAbstractTestLogger::XPass: -
16 return "XPASS ";
never executed: return "XPASS ";
0
17 } -
18 return "??????";
never executed: return "??????";
0
19 } -
20 -
21 static const char *benchmarkResult2String() -
22 { -
23 return "RESULT ";
executed: return "RESULT ";
Execution Count:8
8
24 } -
25 -
26 static const char *messageType2String(QAbstractTestLogger::MessageTypes type) -
27 { -
28 switch (type) { -
29 case QAbstractTestLogger::Skip: -
30 return "SKIP ";
executed: return "SKIP ";
Execution Count:315
315
31 case QAbstractTestLogger::Warn: -
32 return "WARNING";
executed: return "WARNING";
Execution Count:8
8
33 case QAbstractTestLogger::QWarning: -
34 return "QWARN ";
executed: return "QWARN ";
Execution Count:445
445
35 case QAbstractTestLogger::QDebug: -
36 return "QDEBUG ";
executed: return "QDEBUG ";
Execution Count:1076
1076
37 case QAbstractTestLogger::QSystem: -
38 return "QSYSTEM";
never executed: return "QSYSTEM";
0
39 case QAbstractTestLogger::QFatal: -
40 return "QFATAL ";
executed: return "QFATAL ";
Execution Count:5
5
41 case QAbstractTestLogger::Info: -
42 return "INFO ";
never executed: return "INFO ";
0
43 } -
44 return "??????";
never executed: return "??????";
0
45 } -
46 -
47 template <typename T> -
48 static int countSignificantDigits(T num) -
49 { -
50 if (num <= 0)
evaluated: num <= 0
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:6
6-10
51 return 0;
executed: return 0;
Execution Count:10
10
52 -
53 int digits = 0; -
54 qreal divisor = 1; -
55 -
56 while (num / divisor >= 1) {
evaluated: num / divisor >= 1
TRUEFALSE
yes
Evaluation Count:6
yes
Evaluation Count:6
6
57 divisor *= 10; -
58 ++digits; -
59 }
executed: }
Execution Count:6
6
60 -
61 return digits;
executed: return digits;
Execution Count:6
6
62 } -
63 -
64 -
65 template <typename T> QString formatResult(T number, int significantDigits) -
66 { -
67 if (number < T(0))
partially evaluated: number < T(0)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
68 return QLatin1String("NAN");
never executed: return QLatin1String("NAN");
0
69 if (number == T(0))
evaluated: number == T(0)
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:6
6-10
70 return QLatin1String("0");
executed: return QLatin1String("0");
Execution Count:10
10
71 -
72 QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0); -
73 QString afterDecimalPoint = QString::number(number, 'f', 20); -
74 afterDecimalPoint.remove(0, beforeDecimalPoint.count() + 1); -
75 -
76 int beforeUse = qMin(beforeDecimalPoint.count(), significantDigits); -
77 int beforeRemove = beforeDecimalPoint.count() - beforeUse; -
78 -
79 -
80 beforeDecimalPoint.chop(beforeRemove); -
81 for (int i = 0; i < beforeRemove; ++i) {
partially evaluated: i < beforeRemove
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
82 beforeDecimalPoint.append(QLatin1Char('0')); -
83 }
never executed: }
0
84 -
85 int afterUse = significantDigits - beforeUse; -
86 -
87 -
88 if (beforeDecimalPoint == QLatin1String("0") && afterDecimalPoint.isEmpty() == false) {
partially evaluated: beforeDecimalPoint == QLatin1String("0")
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
never evaluated: afterDecimalPoint.isEmpty() == false
0-6
89 ++afterUse; -
90 -
91 int i = 0; -
92 while (i < afterDecimalPoint.count() && afterDecimalPoint.at(i) == QLatin1Char('0')) {
never evaluated: i < afterDecimalPoint.count()
never evaluated: afterDecimalPoint.at(i) == QLatin1Char('0')
0
93 ++i; -
94 }
never executed: }
0
95 -
96 afterUse += i; -
97 }
never executed: }
0
98 -
99 int afterRemove = afterDecimalPoint.count() - afterUse; -
100 afterDecimalPoint.chop(afterRemove); -
101 -
102 QChar separator = QLatin1Char(','); -
103 QChar decimalPoint = QLatin1Char('.'); -
104 -
105 -
106 int length = beforeDecimalPoint.length(); -
107 for (int i = beforeDecimalPoint.length() -1; i >= 1; --i) {
partially evaluated: i >= 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
108 if ((length - i) % 3 == 0)
never evaluated: (length - i) % 3 == 0
0
109 beforeDecimalPoint.insert(i, separator);
never executed: beforeDecimalPoint.insert(i, separator);
0
110 }
never executed: }
0
111 -
112 QString print; -
113 print = beforeDecimalPoint; -
114 if (afterUse > 0)
partially evaluated: afterUse > 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
115 print.append(decimalPoint);
never executed: print.append(decimalPoint);
0
116 -
117 print += afterDecimalPoint; -
118 -
119 -
120 return print;
executed: return print;
Execution Count:6
6
121 } -
122 -
123 template <typename T> -
124 int formatResult(char * buffer, int bufferSize, T number, int significantDigits) -
125 { -
126 QString result = formatResult(number, significantDigits); -
127 qstrncpy(buffer, result.toLatin1().constData(), bufferSize); -
128 int size = result.count(); -
129 return size;
executed: return size;
Execution Count:16
16
130 } -
131} -
132 -
133void QPlainTestLogger::outputMessage(const char *str) -
134{ -
135 outputString(str); -
136}
executed: }
Execution Count:69974
69974
137 -
138void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line) -
139{ -
140 do { if (!(type)) qt_assert("type","qplaintestlogger.cpp",215); } while (0);
never executed: qt_assert("type","qplaintestlogger.cpp",215);
executed: }
Execution Count:69171
partially evaluated: !(type)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69171
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69171
0-69171
141 do { if (!(msg)) qt_assert("msg","qplaintestlogger.cpp",216); } while (0);
never executed: qt_assert("msg","qplaintestlogger.cpp",216);
executed: }
Execution Count:69171
partially evaluated: !(msg)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69171
partially evaluated: 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:69171
0-69171
142 -
143 QTestCharBuffer buf; -
144 -
145 const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction()
partially evaluated: QTestResult::currentTestFunction()
TRUEFALSE
yes
Evaluation Count:69171
no
Evaluation Count:0
0-69171
146 : "UnknownTestFunc"; -
147 const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : "";
evaluated: QTestResult::currentDataTag()
TRUEFALSE
yes
Evaluation Count:62195
yes
Evaluation Count:6976
6976-62195
148 const char *gtag = QTestResult::currentGlobalDataTag()
evaluated: QTestResult::currentGlobalDataTag()
TRUEFALSE
yes
Evaluation Count:804
yes
Evaluation Count:68367
804-68367
149 ? QTestResult::currentGlobalDataTag() -
150 : ""; -
151 const char *filler = (tag[0] && gtag[0]) ? ":" : "";
evaluated: tag[0]
TRUEFALSE
yes
Evaluation Count:62180
yes
Evaluation Count:6991
evaluated: gtag[0]
TRUEFALSE
yes
Evaluation Count:700
yes
Evaluation Count:61480
700-62180
152 if (file) {
evaluated: file
TRUEFALSE
yes
Evaluation Count:895
yes
Evaluation Count:68276
895-68276
153 QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" -
154 -
155 -
156 -
157 " Loc: [%s(%d)]\n" -
158 -
159 , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, -
160 msg[0] ? " " : "", msg, file, line); -
161 } else {
executed: }
Execution Count:895
895
162 QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", -
163 type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, -
164 msg[0] ? " " : "", msg); -
165 }
executed: }
Execution Count:68276
68276
166 -
167 -
168 memcpy(buf.data(), type, strlen(type)); -
169 outputMessage(buf.data()); -
170}
executed: }
Execution Count:69171
69171
171 -
172void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) -
173{ -
174 const char *bmtag = QTest::benchmarkResult2String(); -
175 -
176 char buf1[1024]; -
177 qsnprintf( -
178 buf1, sizeof(buf1), "%s: %s::%s", -
179 bmtag, -
180 QTestResult::currentTestObjectName(), -
181 result.context.slotName.toLatin1().data()); -
182 -
183 char bufTag[1024]; -
184 bufTag[0] = 0; -
185 QByteArray tag = result.context.tag.toLocal8Bit(); -
186 if (tag.isEmpty() == false) {
partially evaluated: tag.isEmpty() == false
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
187 qsnprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); -
188 }
executed: }
Execution Count:8
8
189 -
190 -
191 char fillFormat[8]; -
192 int fillLength = 5; -
193 qsnprintf(fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); -
194 char fill[1024]; -
195 qsnprintf(fill, sizeof(fill), fillFormat, ""); -
196 -
197 const char * unitText = QTest::benchmarkMetricUnit(result.metric); -
198 -
199 qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); -
200 char resultBuffer[100] = ""; -
201 QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value)); -
202 -
203 char buf2[1024]; -
204 qsnprintf(buf2, sizeof(buf2), "%s %s", resultBuffer, unitText); -
205 -
206 char buf2_[1024]; -
207 QByteArray iterationText = " per iteration"; -
208 qt_noop(); -
209 qsnprintf(buf2_, sizeof(buf2_), "%s", iterationText.data()); -
210 -
211 char buf3[1024]; -
212 qt_noop(); -
213 QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value)); -
214 qsnprintf(buf3, sizeof(buf3), " (total: %s, iterations: %d)", resultBuffer, result.iterations); -
215 -
216 char buf[1024]; -
217 -
218 if (result.setByMacro) {
partially evaluated: result.setByMacro
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-8
219 qsnprintf(buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); -
220 } else {
executed: }
Execution Count:8
8
221 qsnprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); -
222 }
never executed: }
0
223 -
224 memcpy(buf, bmtag, strlen(bmtag)); -
225 outputMessage(buf); -
226}
executed: }
Execution Count:8
8
227 -
228QPlainTestLogger::QPlainTestLogger(const char *filename) -
229 : QAbstractTestLogger(filename) -
230{ -
231}
executed: }
Execution Count:399
399
232 -
233QPlainTestLogger::~QPlainTestLogger() -
234{ -
235} -
236 -
237void QPlainTestLogger::startLogging() -
238{ -
239 QAbstractTestLogger::startLogging(); -
240 -
241 char buf[1024]; -
242 if (QTestLog::verboseLevel() < 0) {
partially evaluated: QTestLog::verboseLevel() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:399
0-399
243 qsnprintf(buf, sizeof(buf), "Testing %s\n", QTestResult::currentTestObjectName()); -
244 } else {
never executed: }
0
245 qsnprintf(buf, sizeof(buf), -
246 "********* Start testing of %s *********\n" -
247 "Config: Using QTest library " "5.0.2" -
248 ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion()); -
249 }
executed: }
Execution Count:399
399
250 outputMessage(buf); -
251}
executed: }
Execution Count:399
399
252 -
253void QPlainTestLogger::stopLogging() -
254{ -
255 char buf[1024]; -
256 if (QTestLog::verboseLevel() < 0) {
partially evaluated: QTestLog::verboseLevel() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:396
0-396
257 qsnprintf(buf, sizeof(buf), "Totals: %d passed, %d failed, %d skipped\n", -
258 QTestLog::passCount(), QTestLog::failCount(), -
259 QTestLog::skipCount()); -
260 } else {
never executed: }
0
261 qsnprintf(buf, sizeof(buf), -
262 "Totals: %d passed, %d failed, %d skipped\n" -
263 "********* Finished testing of %s *********\n", -
264 QTestLog::passCount(), QTestLog::failCount(), -
265 QTestLog::skipCount(), QTestResult::currentTestObjectName()); -
266 }
executed: }
Execution Count:396
396
267 outputMessage(buf); -
268 -
269 QAbstractTestLogger::stopLogging(); -
270}
executed: }
Execution Count:396
396
271 -
272 -
273void QPlainTestLogger::enterTestFunction(const char * ) -
274{ -
275 if (QTestLog::verboseLevel() >= 1)
partially evaluated: QTestLog::verboseLevel() >= 1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7610
0-7610
276 printMessage(QTest::messageType2String(Info), "entering");
never executed: printMessage(QTest::messageType2String(Info), "entering");
0
277}
executed: }
Execution Count:7610
7610
278 -
279void QPlainTestLogger::leaveTestFunction() -
280{ -
281} -
282 -
283void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, -
284 const char *file, int line) -
285{ -
286 -
287 if ((type == QAbstractTestLogger::Pass || type == QAbstractTestLogger::XFail)
evaluated: type == QAbstractTestLogger::Pass
TRUEFALSE
yes
Evaluation Count:66746
yes
Evaluation Count:576
evaluated: type == QAbstractTestLogger::XFail
TRUEFALSE
yes
Evaluation Count:339
yes
Evaluation Count:237
237-66746
288 && QTestLog::verboseLevel() < 0)
partially evaluated: QTestLog::verboseLevel() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67085
0-67085
289 return;
never executed: return;
0
290 -
291 printMessage(QTest::incidentType2String(type), description, file, line); -
292}
executed: }
Execution Count:67322
67322
293 -
294void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) -
295{ -
296 -
297 if (QTestLog::verboseLevel() < 0)
partially evaluated: QTestLog::verboseLevel() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
0-8
298 return;
never executed: return;
0
299 -
300 printBenchmarkResult(result); -
301}
executed: }
Execution Count:8
8
302 -
303void QPlainTestLogger::addMessage(MessageTypes type, const char *message, -
304 const char *file, int line) -
305{ -
306 -
307 if (type != QAbstractTestLogger::QFatal && QTestLog::verboseLevel() < 0)
evaluated: type != QAbstractTestLogger::QFatal
TRUEFALSE
yes
Evaluation Count:1844
yes
Evaluation Count:5
partially evaluated: QTestLog::verboseLevel() < 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1844
0-1844
308 return;
never executed: return;
0
309 -
310 printMessage(QTest::messageType2String(type), message, file, line); -
311}
executed: }
Execution Count:1849
1849
312 -
313 -
314 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial