qxmltestlogger.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/testlib/qxmltestlogger.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2015 The Qt Company Ltd.-
4** Contact: http://www.qt.io/licensing/-
5**-
6** This file is part of the QtTest module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL21$-
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 The Qt Company. For licensing terms-
14** and conditions see http://www.qt.io/terms-conditions. For further-
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free-
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and-
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the-
22** following information to ensure the GNU Lesser General Public License-
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and-
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.-
25**-
26** As a special exception, The Qt Company gives you certain additional-
27** rights. These rights are described in The Qt Company LGPL Exception-
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.-
29**-
30** $QT_END_LICENSE$-
31**-
32****************************************************************************/-
33-
34#include <stdio.h>-
35#include <string.h>-
36#include <QtCore/qglobal.h>-
37#include <QtCore/qlibraryinfo.h>-
38-
39#include <QtTest/private/qtestlog_p.h>-
40#include <QtTest/private/qxmltestlogger_p.h>-
41#include <QtTest/private/qtestresult_p.h>-
42#include <QtTest/private/qbenchmark_p.h>-
43#include <QtTest/private/qbenchmarkmetric_p.h>-
44#include <QtTest/qtestcase.h>-
45-
46QT_BEGIN_NAMESPACE-
47-
48namespace QTest {-
49-
50 static const char* xmlMessageType2String(QAbstractTestLogger::MessageTypes type)-
51 {-
52 switch (type) {-
53 case QAbstractTestLogger::Warn:
executed 24 times by 1 test: case QAbstractTestLogger::Warn:
Executed by:
  • tst_selftests - unknown status
24
54 return "warn";
executed 24 times by 1 test: return "warn";
Executed by:
  • tst_selftests - unknown status
24
55 case QAbstractTestLogger::QSystem:
executed 12 times by 1 test: case QAbstractTestLogger::QSystem:
Executed by:
  • tst_selftests - unknown status
12
56 return "system";
executed 12 times by 1 test: return "system";
Executed by:
  • tst_selftests - unknown status
12
57 case QAbstractTestLogger::QDebug:
executed 1077 times by 1 test: case QAbstractTestLogger::QDebug:
Executed by:
  • tst_selftests - unknown status
1077
58 return "qdebug";
executed 1077 times by 1 test: return "qdebug";
Executed by:
  • tst_selftests - unknown status
1077
59 case QAbstractTestLogger::QInfo:
executed 24 times by 1 test: case QAbstractTestLogger::QInfo:
Executed by:
  • tst_selftests - unknown status
24
60 return "qinfo";
executed 24 times by 1 test: return "qinfo";
Executed by:
  • tst_selftests - unknown status
24
61 case QAbstractTestLogger::QWarning:
executed 24048 times by 1 test: case QAbstractTestLogger::QWarning:
Executed by:
  • tst_selftests - unknown status
24048
62 return "qwarn";
executed 24048 times by 1 test: return "qwarn";
Executed by:
  • tst_selftests - unknown status
24048
63 case QAbstractTestLogger::QFatal:
executed 24 times by 1 test: case QAbstractTestLogger::QFatal:
Executed by:
  • tst_selftests - unknown status
24
64 return "qfatal";
executed 24 times by 1 test: return "qfatal";
Executed by:
  • tst_selftests - unknown status
24
65 case QAbstractTestLogger::Skip:
executed 444 times by 1 test: case QAbstractTestLogger::Skip:
Executed by:
  • tst_selftests - unknown status
444
66 return "skip";
executed 444 times by 1 test: return "skip";
Executed by:
  • tst_selftests - unknown status
444
67 case QAbstractTestLogger::Info:
executed 372 times by 1 test: case QAbstractTestLogger::Info:
Executed by:
  • tst_selftests - unknown status
372
68 return "info";
executed 372 times by 1 test: return "info";
Executed by:
  • tst_selftests - unknown status
372
69 }-
70 return "??????";
never executed: return "??????";
0
71 }-
72-
73 static const char* xmlIncidentType2String(QAbstractTestLogger::IncidentTypes type)-
74 {-
75 switch (type) {-
76 case QAbstractTestLogger::Pass:
executed 2223 times by 1 test: case QAbstractTestLogger::Pass:
Executed by:
  • tst_selftests - unknown status
2223
77 return "pass";
executed 2223 times by 1 test: return "pass";
Executed by:
  • tst_selftests - unknown status
2223
78 case QAbstractTestLogger::XFail:
executed 180 times by 1 test: case QAbstractTestLogger::XFail:
Executed by:
  • tst_selftests - unknown status
180
79 return "xfail";
executed 180 times by 1 test: return "xfail";
Executed by:
  • tst_selftests - unknown status
180
80 case QAbstractTestLogger::Fail:
executed 1197 times by 1 test: case QAbstractTestLogger::Fail:
Executed by:
  • tst_selftests - unknown status
1197
81 return "fail";
executed 1197 times by 1 test: return "fail";
Executed by:
  • tst_selftests - unknown status
1197
82 case QAbstractTestLogger::XPass:
executed 48 times by 1 test: case QAbstractTestLogger::XPass:
Executed by:
  • tst_selftests - unknown status
48
83 return "xpass";
executed 48 times by 1 test: return "xpass";
Executed by:
  • tst_selftests - unknown status
48
84 case QAbstractTestLogger::BlacklistedPass:
never executed: case QAbstractTestLogger::BlacklistedPass:
0
85 return "bpass";
never executed: return "bpass";
0
86 case QAbstractTestLogger::BlacklistedFail:
never executed: case QAbstractTestLogger::BlacklistedFail:
0
87 return "bfail";
never executed: return "bfail";
0
88 }-
89 return "??????";
never executed: return "??????";
0
90 }-
91-
92}-
93-
94-
95QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename)-
96 : QAbstractTestLogger(filename), xmlmode(mode)-
97{-
98}
executed 369 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
369
99-
100QXmlTestLogger::~QXmlTestLogger()-
101{-
102}-
103-
104void QXmlTestLogger::startLogging()-
105{-
106 QAbstractTestLogger::startLogging();-
107 QTestCharBuffer buf;-
108-
109 if (xmlmode == QXmlTestLogger::Complete) {
xmlmode == QXm...gger::CompleteDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 185 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
184-185
110 QTestCharBuffer quotedTc;-
111 xmlQuote(&quotedTc, QTestResult::currentTestObjectName());-
112 QTest::qt_asprintf(&buf,-
113 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"-
114 "<TestCase name=\"%s\">\n", quotedTc.constData());-
115 outputString(buf.constData());-
116 }
executed 184 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
184
117-
118 QTestCharBuffer quotedBuild;-
119 xmlQuote(&quotedBuild, QLibraryInfo::build());-
120-
121 QTest::qt_asprintf(&buf,-
122 "<Environment>\n"-
123 " <QtVersion>%s</QtVersion>\n"-
124 " <QtBuild>%s</QtBuild>\n"-
125 " <QTestVersion>" QTEST_VERSION_STR "</QTestVersion>\n"-
126 "</Environment>\n", qVersion(), quotedBuild.constData());-
127 outputString(buf.constData());-
128}
executed 369 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
369
129-
130void QXmlTestLogger::stopLogging()-
131{-
132 QTestCharBuffer buf;-
133 QTest::qt_asprintf(&buf,-
134 "<Duration msecs=\"%f\"/>\n", QTestLog::msecsTotalTime());-
135 outputString(buf.constData());-
136 if (xmlmode == QXmlTestLogger::Complete) {
xmlmode == QXm...gger::CompleteDescription
TRUEevaluated 184 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 185 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
184-185
137 outputString("</TestCase>\n");-
138 }
executed 184 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
184
139-
140 QAbstractTestLogger::stopLogging();-
141}
executed 369 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
369
142-
143void QXmlTestLogger::enterTestFunction(const char *function)-
144{-
145 QTestCharBuffer buf;-
146 QTestCharBuffer quotedFunction;-
147 xmlQuote(&quotedFunction, function);-
148 QTest::qt_asprintf(&buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData());-
149 outputString(buf.constData());-
150}
executed 2238 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
2238
151-
152void QXmlTestLogger::leaveTestFunction()-
153{-
154 QTestCharBuffer buf;-
155 QTest::qt_asprintf(&buf,-
156 " <Duration msecs=\"%f\"/>\n"-
157 "</TestFunction>\n",-
158 QTestLog::msecsFunctionTime());-
159-
160 outputString(buf.constData());-
161}
executed 2238 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
2238
162-
163namespace QTest-
164{-
165-
166inline static bool isEmpty(const char *str)-
167{-
168 return !str || !str[0];
executed 59238 times by 1 test: return !str || !str[0];
Executed by:
  • tst_selftests - unknown status
!strDescription
TRUEevaluated 51822 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 7416 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!str[0]Description
TRUEevaluated 2223 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 5193 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
2223-59238
169}-
170-
171static const char *incidentFormatString(bool noDescription, bool noTag)-
172{-
173 if (noDescription) {
noDescriptionDescription
TRUEevaluated 2223 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1425 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1425-2223
174 if (noTag)
noTagDescription
TRUEevaluated 879 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1344 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
879-1344
175 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
executed 879 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
Executed by:
  • tst_selftests - unknown status
879
176 else-
177 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
executed 1344 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
1344
178 " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
executed 1344 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
1344
179 "</Incident>\n";
executed 1344 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
1344
180 } else {-
181 if (noTag)
noTagDescription
TRUEevaluated 525 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 900 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
525-900
182 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
executed 525 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
525
183 " <Description><![CDATA[%s%s%s%s]]></Description>\n"
executed 525 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
525
184 "</Incident>\n";
executed 525 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
525
185 else-
186 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
executed 900 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
900
187 " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
executed 900 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
900
188 " <Description><![CDATA[%s]]></Description>\n"
executed 900 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
900
189 "</Incident>\n";
executed 900 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";
Executed by:
  • tst_selftests - unknown status
900
190 }-
191}-
192-
193static const char *benchmarkResultFormatString()-
194{-
195 return "<BenchmarkResult metric=\"%s\" tag=\"%s\" value=\"%s\" iterations=\"%d\" />\n";
executed 132 times by 1 test: return "<BenchmarkResult metric=\"%s\" tag=\"%s\" value=\"%s\" iterations=\"%d\" />\n";
Executed by:
  • tst_selftests - unknown status
132
196}-
197-
198static const char *messageFormatString(bool noDescription, bool noTag)-
199{-
200 if (noDescription) {
noDescriptionDescription
TRUEnever evaluated
FALSEevaluated 26025 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-26025
201 if (noTag)
noTagDescription
TRUEnever evaluated
FALSEnever evaluated
0
202 return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n";
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n";
0
203 else-
204 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n";
0
205 " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n";
0
206 "</Message>\n";
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n";
0
207 } else {-
208 if (noTag)
noTagDescription
TRUEevaluated 24501 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1524 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1524-24501
209 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
24501
210 " <Description><![CDATA[%s%s%s%s]]></Description>\n"
executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
24501
211 "</Message>\n";
executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
24501
212 else-
213 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
1524
214 " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
1524
215 " <Description><![CDATA[%s]]></Description>\n"
executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
1524
216 "</Message>\n";
executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";
Executed by:
  • tst_selftests - unknown status
1524
217 }-
218}-
219-
220} // namespace-
221-
222void QXmlTestLogger::addIncident(IncidentTypes type, const char *description,-
223 const char *file, int line)-
224{-
225 QTestCharBuffer buf;-
226 const char *tag = QTestResult::currentDataTag();-
227 const char *gtag = QTestResult::currentGlobalDataTag();-
228 const char *filler = (tag && gtag) ? ":" : "";
tagDescription
TRUEevaluated 2244 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
gtagDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 2160 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
84-2244
229 const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
QTest::isEmpty(tag)Description
TRUEevaluated 1404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 2244 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
QTest::isEmpty(gtag)Description
TRUEevaluated 1404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
0-2244
230-
231 QTestCharBuffer quotedFile;-
232 QTestCharBuffer cdataGtag;-
233 QTestCharBuffer cdataTag;-
234 QTestCharBuffer cdataDescription;-
235-
236 xmlQuote(&quotedFile, file);-
237 xmlCdata(&cdataGtag, gtag);-
238 xmlCdata(&cdataTag, tag);-
239 xmlCdata(&cdataDescription, description);-
240-
241 QTest::qt_asprintf(&buf,-
242 QTest::incidentFormatString(QTest::isEmpty(description), notag),-
243 QTest::xmlIncidentType2String(type),-
244 quotedFile.constData(), line,-
245 cdataGtag.constData(),-
246 filler,-
247 cdataTag.constData(),-
248 cdataDescription.constData());-
249-
250 outputString(buf.constData());-
251}
executed 3648 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
3648
252-
253void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)-
254{-
255 QTestCharBuffer buf;-
256 QTestCharBuffer quotedMetric;-
257 QTestCharBuffer quotedTag;-
258-
259 xmlQuote(&quotedMetric,-
260 benchmarkMetricName(result.metric));-
261 xmlQuote(&quotedTag, result.context.tag.toUtf8().constData());-
262-
263 const qreal valuePerIteration = qreal(result.value) / qreal(result.iterations);-
264 QTest::qt_asprintf(-
265 &buf,-
266 QTest::benchmarkResultFormatString(),-
267 quotedMetric.constData(),-
268 quotedTag.constData(),-
269 QByteArray::number(valuePerIteration).constData(), //no 64-bit qsnprintf support-
270 result.iterations);-
271 outputString(buf.constData());-
272}
executed 132 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
132
273-
274void QXmlTestLogger::addMessage(MessageTypes type, const QString &message,-
275 const char *file, int line)-
276{-
277 QTestCharBuffer buf;-
278 const char *tag = QTestResult::currentDataTag();-
279 const char *gtag = QTestResult::currentGlobalDataTag();-
280 const char *filler = (tag && gtag) ? ":" : "";
tagDescription
TRUEevaluated 1512 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 24513 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
gtagDescription
TRUEevaluated 408 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1104 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
408-24513
281 const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
QTest::isEmpty(tag)Description
TRUEevaluated 24513 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1512 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
QTest::isEmpty(gtag)Description
TRUEevaluated 24501 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
12-24513
282-
283 QTestCharBuffer quotedFile;-
284 QTestCharBuffer cdataGtag;-
285 QTestCharBuffer cdataTag;-
286 QTestCharBuffer cdataDescription;-
287-
288 xmlQuote(&quotedFile, file);-
289 xmlCdata(&cdataGtag, gtag);-
290 xmlCdata(&cdataTag, tag);-
291 xmlCdata(&cdataDescription, message.toUtf8().constData());-
292-
293 QTest::qt_asprintf(&buf,-
294 QTest::messageFormatString(message.isEmpty(), notag),-
295 QTest::xmlMessageType2String(type),-
296 quotedFile.constData(), line,-
297 cdataGtag.constData(),-
298 filler,-
299 cdataTag.constData(),-
300 cdataDescription.constData());-
301-
302 outputString(buf.constData());-
303}
executed 26025 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
26025
304-
305/*-
306 Copy up to n characters from the src string into dest, escaping any special-
307 XML characters as necessary so that dest is suitable for use in an XML-
308 quoted attribute string.-
309*/-
310int QXmlTestLogger::xmlQuote(QTestCharBuffer* destBuf, char const* src, size_t n)-
311{-
312 if (n == 0) return 0;
never executed: return 0;
n == 0Description
TRUEnever evaluated
FALSEevaluated 70849 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-70849
313-
314 char *dest = destBuf->data();-
315 *dest = 0;-
316 if (!src) return 0;
executed 27573 times by 1 test: return 0;
Executed by:
  • tst_selftests - unknown status
!srcDescription
TRUEevaluated 27573 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 43276 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
27573-43276
317-
318 char* begin = dest;-
319 char* end = dest + n;-
320-
321 while (dest < end) {
dest < endDescription
TRUEevaluated 465403 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 28 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
28-465403
322 switch (*src) {-
323-
324#define MAP_ENTITY(chr, ent) \-
325 case chr: \-
326 if (dest + sizeof(ent) < end) { \-
327 strcpy(dest, ent); \-
328 dest += sizeof(ent) - 1; \-
329 } \-
330 else { \-
331 *dest = 0; \-
332 return (dest+sizeof(ent)-begin); \-
333 } \-
334 ++src; \-
335 break;-
336-
337 MAP_ENTITY('>', "&gt;");
executed 253 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
never executed: return (dest+sizeof("&gt;")-begin);
executed 253 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
dest + sizeof("&gt;") < endDescription
TRUEevaluated 253 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
executed 253 times by 1 test: case '>':
Executed by:
  • tst_selftests - unknown status
0-253
338 MAP_ENTITY('<', "&lt;");
executed 187 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
never executed: return (dest+sizeof("&lt;")-begin);
executed 187 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
dest + sizeof("&lt;") < endDescription
TRUEevaluated 187 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
executed 187 times by 1 test: case '<':
Executed by:
  • tst_selftests - unknown status
0-187
339 MAP_ENTITY('\'', "&apos;");
executed 588 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
never executed: return (dest+sizeof("&apos;")-begin);
executed 588 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
dest + sizeof("&apos;") < endDescription
TRUEevaluated 588 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
executed 588 times by 1 test: case '\'':
Executed by:
  • tst_selftests - unknown status
0-588
340 MAP_ENTITY('"', "&quot;");
executed 666 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
never executed: return (dest+sizeof("&quot;")-begin);
executed 666 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
dest + sizeof("&quot;") < endDescription
TRUEevaluated 666 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
executed 666 times by 1 test: case '"':
Executed by:
  • tst_selftests - unknown status
0-666
341 MAP_ENTITY('&', "&amp;");
never executed: end of block
never executed: return (dest+sizeof("&amp;")-begin);
never executed: break;
dest + sizeof("&amp;") < endDescription
TRUEnever evaluated
FALSEnever evaluated
never executed: case '&':
0
342-
343 // not strictly necessary, but allows handling of comments without-
344 // having to explicitly look for `--'-
345 MAP_ENTITY('-', "&#x002D;");
executed 1210 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
never executed: return (dest+sizeof("&#x002D;")-begin);
executed 1210 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
dest + sizeof(...x002D;") < endDescription
TRUEevaluated 1210 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
executed 1210 times by 1 test: case '-':
Executed by:
  • tst_selftests - unknown status
0-1210
346-
347#undef MAP_ENTITY-
348-
349 case 0:
executed 43248 times by 1 test: case 0:
Executed by:
  • tst_selftests - unknown status
43248
350 *dest = 0;-
351 return (dest-begin);
executed 43248 times by 1 test: return (dest-begin);
Executed by:
  • tst_selftests - unknown status
43248
352-
353 default:
executed 419251 times by 1 test: default:
Executed by:
  • tst_selftests - unknown status
419251
354 *dest = *src;-
355 ++dest;-
356 ++src;-
357 break;
executed 419251 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
419251
358 }-
359 }-
360-
361 // If we get here, dest was completely filled (dest == end)-
362 *(dest-1) = 0;-
363 return (dest-begin);
executed 28 times by 1 test: return (dest-begin);
Executed by:
  • tst_selftests - unknown status
28
364}-
365-
366/*-
367 Copy up to n characters from the src string into dest, escaping any-
368 special strings such that dest is suitable for use in an XML CDATA section.-
369*/-
370int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n)-
371{-
372 if (!n) return 0;
never executed: return 0;
!nDescription
TRUEnever evaluated
FALSEevaluated 104350 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-104350
373-
374 char *dest = destBuf->data();-
375-
376 if (!src || n == 1) {
!srcDescription
TRUEevaluated 55086 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 49264 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
n == 1Description
TRUEnever evaluated
FALSEevaluated 49264 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-55086
377 *dest = 0;-
378 return 0;
executed 55086 times by 1 test: return 0;
Executed by:
  • tst_selftests - unknown status
55086
379 }-
380-
381 static char const CDATA_END[] = "]]>";-
382 static char const CDATA_END_ESCAPED[] = "]]]><![CDATA[]>";-
383-
384 char* begin = dest;-
385 char* end = dest + n;-
386 while (dest < end) {
dest < endDescription
TRUEevaluated 451388 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 48 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
48-451388
387 if (!*src) {
!*srcDescription
TRUEevaluated 49216 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 402172 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
49216-402172
388 *dest = 0;-
389 return (dest-begin);
executed 49216 times by 1 test: return (dest-begin);
Executed by:
  • tst_selftests - unknown status
49216
390 }-
391-
392 if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
!strncmp(src, ...(CDATA_END)-1)Description
TRUEevaluated 250 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 401922 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
250-401922
393 if (dest + sizeof(CDATA_END_ESCAPED) < end) {
dest + sizeof(...ESCAPED) < endDescription
TRUEevaluated 250 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
0-250
394 strcpy(dest, CDATA_END_ESCAPED);-
395 src += sizeof(CDATA_END)-1;-
396 dest += sizeof(CDATA_END_ESCAPED) - 1;-
397 }
executed 250 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
250
398 else {-
399 *dest = 0;-
400 return (dest+sizeof(CDATA_END_ESCAPED)-begin);
never executed: return (dest+sizeof(CDATA_END_ESCAPED)-begin);
0
401 }-
402 continue;
executed 250 times by 1 test: continue;
Executed by:
  • tst_selftests - unknown status
250
403 }-
404-
405 *dest = *src;-
406 ++src;-
407 ++dest;-
408 }
executed 401922 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
401922
409-
410 // If we get here, dest was completely filled (dest == end)-
411 *(dest-1) = 0;-
412 return (dest-begin);
executed 48 times by 1 test: return (dest-begin);
Executed by:
  • tst_selftests - unknown status
48
413}-
414-
415typedef int (*StringFormatFunction)(QTestCharBuffer*,char const*,size_t);-
416-
417/*-
418 A wrapper for string functions written to work with a fixed size buffer so they can be called-
419 with a dynamically allocated buffer.-
420*/-
421int allocateStringFn(QTestCharBuffer* str, char const* src, StringFormatFunction func)-
422{-
423 static const int MAXSIZE = 1024*1024*2;-
424-
425 int size = str->size();-
426-
427 int res = 0;-
428-
429 for (;;) {-
430 res = func(str, src, size);-
431 str->data()[size - 1] = '\0';-
432 if (res < size) {
res < sizeDescription
TRUEevaluated 175123 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
76-175123
433 // We succeeded or fatally failed-
434 break;
executed 175123 times by 1 test: break;
Executed by:
  • tst_selftests - unknown status
175123
435 }-
436 // buffer wasn't big enough, try again-
437 size *= 2;-
438 if (size > MAXSIZE) {
size > MAXSIZEDescription
TRUEnever evaluated
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-76
439 break;
never executed: break;
0
440 }-
441 if (!str->reset(size))
!str->reset(size)Description
TRUEnever evaluated
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-76
442 break; // ran out of memory - bye
never executed: break;
0
443 }
executed 76 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
76
444-
445 return res;
executed 175123 times by 1 test: return res;
Executed by:
  • tst_selftests - unknown status
175123
446}-
447-
448int QXmlTestLogger::xmlQuote(QTestCharBuffer* str, char const* src)-
449{-
450 return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
executed 70821 times by 1 test: return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
Executed by:
  • tst_selftests - unknown status
70821
451}-
452-
453int QXmlTestLogger::xmlCdata(QTestCharBuffer* str, char const* src)-
454{-
455 return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
executed 104302 times by 1 test: return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
Executed by:
  • tst_selftests - unknown status
104302
456}-
457-
458QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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