qplaintestlogger.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9