qxmltestlogger.cpp

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

Generated by Squish Coco Non-Commercial