Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qxmltestlogger.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | - | |||||||||||||
46 | QT_BEGIN_NAMESPACE | - | ||||||||||||
47 | - | |||||||||||||
48 | namespace 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:
| 24 | ||||||||||||
54 | return "warn"; executed 24 times by 1 test: return "warn"; Executed by:
| 24 | ||||||||||||
55 | case QAbstractTestLogger::QSystem: executed 12 times by 1 test: case QAbstractTestLogger::QSystem: Executed by:
| 12 | ||||||||||||
56 | return "system"; executed 12 times by 1 test: return "system"; Executed by:
| 12 | ||||||||||||
57 | case QAbstractTestLogger::QDebug: executed 1077 times by 1 test: case QAbstractTestLogger::QDebug: Executed by:
| 1077 | ||||||||||||
58 | return "qdebug"; executed 1077 times by 1 test: return "qdebug"; Executed by:
| 1077 | ||||||||||||
59 | case QAbstractTestLogger::QInfo: executed 24 times by 1 test: case QAbstractTestLogger::QInfo: Executed by:
| 24 | ||||||||||||
60 | return "qinfo"; executed 24 times by 1 test: return "qinfo"; Executed by:
| 24 | ||||||||||||
61 | case QAbstractTestLogger::QWarning: executed 24048 times by 1 test: case QAbstractTestLogger::QWarning: Executed by:
| 24048 | ||||||||||||
62 | return "qwarn"; executed 24048 times by 1 test: return "qwarn"; Executed by:
| 24048 | ||||||||||||
63 | case QAbstractTestLogger::QFatal: executed 24 times by 1 test: case QAbstractTestLogger::QFatal: Executed by:
| 24 | ||||||||||||
64 | return "qfatal"; executed 24 times by 1 test: return "qfatal"; Executed by:
| 24 | ||||||||||||
65 | case QAbstractTestLogger::Skip: executed 444 times by 1 test: case QAbstractTestLogger::Skip: Executed by:
| 444 | ||||||||||||
66 | return "skip"; executed 444 times by 1 test: return "skip"; Executed by:
| 444 | ||||||||||||
67 | case QAbstractTestLogger::Info: executed 372 times by 1 test: case QAbstractTestLogger::Info: Executed by:
| 372 | ||||||||||||
68 | return "info"; executed 372 times by 1 test: return "info"; Executed by:
| 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:
| 2223 | ||||||||||||
77 | return "pass"; executed 2223 times by 1 test: return "pass"; Executed by:
| 2223 | ||||||||||||
78 | case QAbstractTestLogger::XFail: executed 180 times by 1 test: case QAbstractTestLogger::XFail: Executed by:
| 180 | ||||||||||||
79 | return "xfail"; executed 180 times by 1 test: return "xfail"; Executed by:
| 180 | ||||||||||||
80 | case QAbstractTestLogger::Fail: executed 1197 times by 1 test: case QAbstractTestLogger::Fail: Executed by:
| 1197 | ||||||||||||
81 | return "fail"; executed 1197 times by 1 test: return "fail"; Executed by:
| 1197 | ||||||||||||
82 | case QAbstractTestLogger::XPass: executed 48 times by 1 test: case QAbstractTestLogger::XPass: Executed by:
| 48 | ||||||||||||
83 | return "xpass"; executed 48 times by 1 test: return "xpass"; Executed by:
| 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 | - | |||||||||||||
95 | QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename) | - | ||||||||||||
96 | : QAbstractTestLogger(filename), xmlmode(mode) | - | ||||||||||||
97 | { | - | ||||||||||||
98 | } executed 369 times by 1 test: end of block Executed by:
| 369 | ||||||||||||
99 | - | |||||||||||||
100 | QXmlTestLogger::~QXmlTestLogger() | - | ||||||||||||
101 | { | - | ||||||||||||
102 | } | - | ||||||||||||
103 | - | |||||||||||||
104 | void QXmlTestLogger::startLogging() | - | ||||||||||||
105 | { | - | ||||||||||||
106 | QAbstractTestLogger::startLogging(); | - | ||||||||||||
107 | QTestCharBuffer buf; | - | ||||||||||||
108 | - | |||||||||||||
109 | if (xmlmode == QXmlTestLogger::Complete) {
| 184-185 | ||||||||||||
110 | QTestCharBuffer quotedTc; | - | ||||||||||||
111 | xmlQuote("edTc, 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:
| 184 | ||||||||||||
117 | - | |||||||||||||
118 | QTestCharBuffer quotedBuild; | - | ||||||||||||
119 | xmlQuote("edBuild, 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:
| 369 | ||||||||||||
129 | - | |||||||||||||
130 | void 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) {
| 184-185 | ||||||||||||
137 | outputString("</TestCase>\n"); | - | ||||||||||||
138 | } executed 184 times by 1 test: end of block Executed by:
| 184 | ||||||||||||
139 | - | |||||||||||||
140 | QAbstractTestLogger::stopLogging(); | - | ||||||||||||
141 | } executed 369 times by 1 test: end of block Executed by:
| 369 | ||||||||||||
142 | - | |||||||||||||
143 | void QXmlTestLogger::enterTestFunction(const char *function) | - | ||||||||||||
144 | { | - | ||||||||||||
145 | QTestCharBuffer buf; | - | ||||||||||||
146 | QTestCharBuffer quotedFunction; | - | ||||||||||||
147 | xmlQuote("edFunction, 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:
| 2238 | ||||||||||||
151 | - | |||||||||||||
152 | void 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:
| 2238 | ||||||||||||
162 | - | |||||||||||||
163 | namespace QTest | - | ||||||||||||
164 | { | - | ||||||||||||
165 | - | |||||||||||||
166 | inline static bool isEmpty(const char *str) | - | ||||||||||||
167 | { | - | ||||||||||||
168 | return !str || !str[0]; executed 59238 times by 1 test: return !str || !str[0]; Executed by:
| 2223-59238 | ||||||||||||
169 | } | - | ||||||||||||
170 | - | |||||||||||||
171 | static const char *incidentFormatString(bool noDescription, bool noTag) | - | ||||||||||||
172 | { | - | ||||||||||||
173 | if (noDescription) {
| 1425-2223 | ||||||||||||
174 | if (noTag)
| 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:
| 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:
| 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:
| 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:
| 1344 | ||||||||||||
180 | } else { | - | ||||||||||||
181 | if (noTag)
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 900 | ||||||||||||
190 | } | - | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | static 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:
| 132 | ||||||||||||
196 | } | - | ||||||||||||
197 | - | |||||||||||||
198 | static const char *messageFormatString(bool noDescription, bool noTag) | - | ||||||||||||
199 | { | - | ||||||||||||
200 | if (noDescription) {
| 0-26025 | ||||||||||||
201 | if (noTag)
| 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)
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 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:
| 1524 | ||||||||||||
217 | } | - | ||||||||||||
218 | } | - | ||||||||||||
219 | - | |||||||||||||
220 | } // namespace | - | ||||||||||||
221 | - | |||||||||||||
222 | void 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) ? ":" : "";
| 84-2244 | ||||||||||||
229 | const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
| 0-2244 | ||||||||||||
230 | - | |||||||||||||
231 | QTestCharBuffer quotedFile; | - | ||||||||||||
232 | QTestCharBuffer cdataGtag; | - | ||||||||||||
233 | QTestCharBuffer cdataTag; | - | ||||||||||||
234 | QTestCharBuffer cdataDescription; | - | ||||||||||||
235 | - | |||||||||||||
236 | xmlQuote("edFile, 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:
| 3648 | ||||||||||||
252 | - | |||||||||||||
253 | void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result) | - | ||||||||||||
254 | { | - | ||||||||||||
255 | QTestCharBuffer buf; | - | ||||||||||||
256 | QTestCharBuffer quotedMetric; | - | ||||||||||||
257 | QTestCharBuffer quotedTag; | - | ||||||||||||
258 | - | |||||||||||||
259 | xmlQuote("edMetric, | - | ||||||||||||
260 | benchmarkMetricName(result.metric)); | - | ||||||||||||
261 | xmlQuote("edTag, 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:
| 132 | ||||||||||||
273 | - | |||||||||||||
274 | void 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) ? ":" : "";
| 408-24513 | ||||||||||||
281 | const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
| 12-24513 | ||||||||||||
282 | - | |||||||||||||
283 | QTestCharBuffer quotedFile; | - | ||||||||||||
284 | QTestCharBuffer cdataGtag; | - | ||||||||||||
285 | QTestCharBuffer cdataTag; | - | ||||||||||||
286 | QTestCharBuffer cdataDescription; | - | ||||||||||||
287 | - | |||||||||||||
288 | xmlQuote("edFile, 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:
| 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 | */ | - | ||||||||||||
310 | int QXmlTestLogger::xmlQuote(QTestCharBuffer* destBuf, char const* src, size_t n) | - | ||||||||||||
311 | { | - | ||||||||||||
312 | if (n == 0) return 0; never executed: return 0;
| 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:
| 27573-43276 | ||||||||||||
317 | - | |||||||||||||
318 | char* begin = dest; | - | ||||||||||||
319 | char* end = dest + n; | - | ||||||||||||
320 | - | |||||||||||||
321 | while (dest < end) {
| 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('>', ">"); executed 253 times by 1 test: end of block Executed by:
never executed: return (dest+sizeof(">")-begin); executed 253 times by 1 test: break; Executed by:
executed 253 times by 1 test: case '>': Executed by:
| 0-253 | ||||||||||||
338 | MAP_ENTITY('<', "<"); executed 187 times by 1 test: end of block Executed by:
never executed: return (dest+sizeof("<")-begin); executed 187 times by 1 test: break; Executed by:
executed 187 times by 1 test: case '<': Executed by:
| 0-187 | ||||||||||||
339 | MAP_ENTITY('\'', "'"); executed 588 times by 1 test: end of block Executed by:
never executed: return (dest+sizeof("'")-begin); executed 588 times by 1 test: break; Executed by:
executed 588 times by 1 test: case '\'': Executed by:
| 0-588 | ||||||||||||
340 | MAP_ENTITY('"', """); executed 666 times by 1 test: end of block Executed by:
never executed: return (dest+sizeof(""")-begin); executed 666 times by 1 test: break; Executed by:
executed 666 times by 1 test: case '"': Executed by:
| 0-666 | ||||||||||||
341 | MAP_ENTITY('&', "&"); never executed: end of block never executed: return (dest+sizeof("&")-begin); never executed: break;
never executed: case '&': | 0 | ||||||||||||
342 | - | |||||||||||||
343 | // not strictly necessary, but allows handling of comments without | - | ||||||||||||
344 | // having to explicitly look for `--' | - | ||||||||||||
345 | MAP_ENTITY('-', "-"); executed 1210 times by 1 test: end of block Executed by:
never executed: return (dest+sizeof("-")-begin); executed 1210 times by 1 test: break; Executed by:
executed 1210 times by 1 test: case '-': Executed by:
| 0-1210 | ||||||||||||
346 | - | |||||||||||||
347 | #undef MAP_ENTITY | - | ||||||||||||
348 | - | |||||||||||||
349 | case 0: executed 43248 times by 1 test: case 0: Executed by:
| 43248 | ||||||||||||
350 | *dest = 0; | - | ||||||||||||
351 | return (dest-begin); executed 43248 times by 1 test: return (dest-begin); Executed by:
| 43248 | ||||||||||||
352 | - | |||||||||||||
353 | default: executed 419251 times by 1 test: default: Executed by:
| 419251 | ||||||||||||
354 | *dest = *src; | - | ||||||||||||
355 | ++dest; | - | ||||||||||||
356 | ++src; | - | ||||||||||||
357 | break; executed 419251 times by 1 test: break; Executed by:
| 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:
| 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 | */ | - | ||||||||||||
370 | int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n) | - | ||||||||||||
371 | { | - | ||||||||||||
372 | if (!n) return 0; never executed: return 0;
| 0-104350 | ||||||||||||
373 | - | |||||||||||||
374 | char *dest = destBuf->data(); | - | ||||||||||||
375 | - | |||||||||||||
376 | if (!src || n == 1) {
| 0-55086 | ||||||||||||
377 | *dest = 0; | - | ||||||||||||
378 | return 0; executed 55086 times by 1 test: return 0; Executed by:
| 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) {
| 48-451388 | ||||||||||||
387 | if (!*src) {
| 49216-402172 | ||||||||||||
388 | *dest = 0; | - | ||||||||||||
389 | return (dest-begin); executed 49216 times by 1 test: return (dest-begin); Executed by:
| 49216 | ||||||||||||
390 | } | - | ||||||||||||
391 | - | |||||||||||||
392 | if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
| 250-401922 | ||||||||||||
393 | if (dest + sizeof(CDATA_END_ESCAPED) < end) {
| 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:
| 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:
| 250 | ||||||||||||
403 | } | - | ||||||||||||
404 | - | |||||||||||||
405 | *dest = *src; | - | ||||||||||||
406 | ++src; | - | ||||||||||||
407 | ++dest; | - | ||||||||||||
408 | } executed 401922 times by 1 test: end of block Executed by:
| 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:
| 48 | ||||||||||||
413 | } | - | ||||||||||||
414 | - | |||||||||||||
415 | typedef 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 | */ | - | ||||||||||||
421 | int 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) {
| 76-175123 | ||||||||||||
433 | // We succeeded or fatally failed | - | ||||||||||||
434 | break; executed 175123 times by 1 test: break; Executed by:
| 175123 | ||||||||||||
435 | } | - | ||||||||||||
436 | // buffer wasn't big enough, try again | - | ||||||||||||
437 | size *= 2; | - | ||||||||||||
438 | if (size > MAXSIZE) {
| 0-76 | ||||||||||||
439 | break; never executed: break; | 0 | ||||||||||||
440 | } | - | ||||||||||||
441 | if (!str->reset(size))
| 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:
| 76 | ||||||||||||
444 | - | |||||||||||||
445 | return res; executed 175123 times by 1 test: return res; Executed by:
| 175123 | ||||||||||||
446 | } | - | ||||||||||||
447 | - | |||||||||||||
448 | int 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:
| 70821 | ||||||||||||
451 | } | - | ||||||||||||
452 | - | |||||||||||||
453 | int 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:
| 104302 | ||||||||||||
456 | } | - | ||||||||||||
457 | - | |||||||||||||
458 | QT_END_NAMESPACE | - | ||||||||||||
Source code | Switch to Preprocessed file |