qxmltestlogger.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5namespace QTest { -
6 -
7 static const char* xmlMessageType2String(QAbstractTestLogger::MessageTypes type) -
8 { -
9 switch (type) { -
10 case QAbstractTestLogger::Warn: -
11 return "warn";
never executed: return "warn";
0
12 case QAbstractTestLogger::QSystem: -
13 return "system";
never executed: return "system";
0
14 case QAbstractTestLogger::QDebug: -
15 return "qdebug";
never executed: return "qdebug";
0
16 case QAbstractTestLogger::QWarning: -
17 return "qwarn";
never executed: return "qwarn";
0
18 case QAbstractTestLogger::QFatal: -
19 return "qfatal";
never executed: return "qfatal";
0
20 case QAbstractTestLogger::Skip: -
21 return "skip";
never executed: return "skip";
0
22 case QAbstractTestLogger::Info: -
23 return "info";
never executed: return "info";
0
24 } -
25 return "??????";
never executed: return "??????";
0
26 } -
27 -
28 static const char* xmlIncidentType2String(QAbstractTestLogger::IncidentTypes type) -
29 { -
30 switch (type) { -
31 case QAbstractTestLogger::Pass: -
32 return "pass";
never executed: return "pass";
0
33 case QAbstractTestLogger::XFail: -
34 return "xfail";
never executed: return "xfail";
0
35 case QAbstractTestLogger::Fail: -
36 return "fail";
never executed: return "fail";
0
37 case QAbstractTestLogger::XPass: -
38 return "xpass";
never executed: return "xpass";
0
39 } -
40 return "??????";
never executed: return "??????";
0
41 } -
42 -
43} -
44 -
45 -
46QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename) -
47 : QAbstractTestLogger(filename), xmlmode(mode) -
48{ -
49}
never executed: }
0
50 -
51QXmlTestLogger::~QXmlTestLogger() -
52{ -
53} -
54 -
55void QXmlTestLogger::startLogging() -
56{ -
57 QAbstractTestLogger::startLogging(); -
58 QTestCharBuffer buf; -
59 -
60 if (xmlmode == QXmlTestLogger::Complete) {
never evaluated: xmlmode == QXmlTestLogger::Complete
0
61 QTestCharBuffer quotedTc; -
62 xmlQuote(&quotedTc, QTestResult::currentTestObjectName()); -
63 QTest::qt_asprintf(&buf, -
64 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" -
65 "<TestCase name=\"%s\">\n", quotedTc.constData()); -
66 outputString(buf.constData()); -
67 }
never executed: }
0
68 -
69 QTest::qt_asprintf(&buf, -
70 "<Environment>\n" -
71 " <QtVersion>%s</QtVersion>\n" -
72 " <QTestVersion>" "5.0.2" "</QTestVersion>\n" -
73 "</Environment>\n", qVersion()); -
74 outputString(buf.constData()); -
75}
never executed: }
0
76 -
77void QXmlTestLogger::stopLogging() -
78{ -
79 if (xmlmode == QXmlTestLogger::Complete) {
never evaluated: xmlmode == QXmlTestLogger::Complete
0
80 outputString("</TestCase>\n"); -
81 }
never executed: }
0
82 -
83 QAbstractTestLogger::stopLogging(); -
84}
never executed: }
0
85 -
86void QXmlTestLogger::enterTestFunction(const char *function) -
87{ -
88 QTestCharBuffer buf; -
89 QTestCharBuffer quotedFunction; -
90 xmlQuote(&quotedFunction, function); -
91 QTest::qt_asprintf(&buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData()); -
92 outputString(buf.constData()); -
93}
never executed: }
0
94 -
95void QXmlTestLogger::leaveTestFunction() -
96{ -
97 outputString("</TestFunction>\n"); -
98}
never executed: }
0
99 -
100namespace QTest -
101{ -
102 -
103inline static bool isEmpty(const char *str) -
104{ -
105 return !str || !str[0];
never executed: return !str || !str[0];
0
106} -
107 -
108static const char *incidentFormatString(bool noDescription, bool noTag) -
109{ -
110 if (noDescription) {
never evaluated: noDescription
0
111 if (noTag)
never evaluated: noTag
0
112 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
never executed: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
0
113 else -
114 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
115 " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" 0
116 "</Incident>\n";
never executed: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";
0
117 } else { -
118 if (noTag)
never evaluated: noTag
0
119 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
120 " <Description><![CDATA[%s%s%s%s]]></Description>\n" 0
121 "</Incident>\n";
never executed: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";
0
122 else -
123 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
124 " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" 0
125 " <Description><![CDATA[%s]]></Description>\n" 0
126 "</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
127 } -
128} -
129 -
130static const char *benchmarkResultFormatString() -
131{ -
132 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
133} -
134 -
135static const char *messageFormatString(bool noDescription, bool noTag) -
136{ -
137 if (noDescription) {
never evaluated: noDescription
0
138 if (noTag)
never evaluated: noTag
0
139 return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n";
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n";
0
140 else -
141 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
142 " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" 0
143 "</Message>\n";
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n";
0
144 } else { -
145 if (noTag)
never evaluated: noTag
0
146 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
147 " <Description><![CDATA[%s%s%s%s]]></Description>\n" 0
148 "</Message>\n";
never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";
0
149 else -
150 return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" 0
151 " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" 0
152 " <Description><![CDATA[%s]]></Description>\n" 0
153 "</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
154 } -
155} -
156 -
157} -
158 -
159void QXmlTestLogger::addIncident(IncidentTypes type, const char *description, -
160 const char *file, int line) -
161{ -
162 QTestCharBuffer buf; -
163 const char *tag = QTestResult::currentDataTag(); -
164 const char *gtag = QTestResult::currentGlobalDataTag(); -
165 const char *filler = (tag && gtag) ? ":" : "";
never evaluated: tag
never evaluated: gtag
0
166 const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
never evaluated: QTest::isEmpty(tag)
never evaluated: QTest::isEmpty(gtag)
0
167 -
168 QTestCharBuffer quotedFile; -
169 QTestCharBuffer cdataGtag; -
170 QTestCharBuffer cdataTag; -
171 QTestCharBuffer cdataDescription; -
172 -
173 xmlQuote(&quotedFile, file); -
174 xmlCdata(&cdataGtag, gtag); -
175 xmlCdata(&cdataTag, tag); -
176 xmlCdata(&cdataDescription, description); -
177 -
178 QTest::qt_asprintf(&buf, -
179 QTest::incidentFormatString(QTest::isEmpty(description), notag), -
180 QTest::xmlIncidentType2String(type), -
181 quotedFile.constData(), line, -
182 cdataGtag.constData(), -
183 filler, -
184 cdataTag.constData(), -
185 cdataDescription.constData()); -
186 -
187 outputString(buf.constData()); -
188}
never executed: }
0
189 -
190void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result) -
191{ -
192 QTestCharBuffer buf; -
193 QTestCharBuffer quotedMetric; -
194 QTestCharBuffer quotedTag; -
195 -
196 xmlQuote(&quotedMetric, -
197 benchmarkMetricName(result.metric)); -
198 xmlQuote(&quotedTag, result.context.tag.toUtf8().constData()); -
199 -
200 QTest::qt_asprintf( -
201 &buf, -
202 QTest::benchmarkResultFormatString(), -
203 quotedMetric.constData(), -
204 quotedTag.constData(), -
205 QByteArray::number(result.value).constData(), -
206 result.iterations); -
207 outputString(buf.constData()); -
208}
never executed: }
0
209 -
210void QXmlTestLogger::addMessage(MessageTypes type, const char *message, -
211 const char *file, int line) -
212{ -
213 QTestCharBuffer buf; -
214 const char *tag = QTestResult::currentDataTag(); -
215 const char *gtag = QTestResult::currentGlobalDataTag(); -
216 const char *filler = (tag && gtag) ? ":" : "";
never evaluated: tag
never evaluated: gtag
0
217 const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
never evaluated: QTest::isEmpty(tag)
never evaluated: QTest::isEmpty(gtag)
0
218 -
219 QTestCharBuffer quotedFile; -
220 QTestCharBuffer cdataGtag; -
221 QTestCharBuffer cdataTag; -
222 QTestCharBuffer cdataDescription; -
223 -
224 xmlQuote(&quotedFile, file); -
225 xmlCdata(&cdataGtag, gtag); -
226 xmlCdata(&cdataTag, tag); -
227 xmlCdata(&cdataDescription, message); -
228 -
229 QTest::qt_asprintf(&buf, -
230 QTest::messageFormatString(QTest::isEmpty(message), notag), -
231 QTest::xmlMessageType2String(type), -
232 quotedFile.constData(), line, -
233 cdataGtag.constData(), -
234 filler, -
235 cdataTag.constData(), -
236 cdataDescription.constData()); -
237 -
238 outputString(buf.constData()); -
239}
never executed: }
0
240 -
241 -
242 -
243 -
244 -
245 -
246int QXmlTestLogger::xmlQuote(QTestCharBuffer* destBuf, char const* src, size_t n) -
247{ -
248 if (n == 0) return 0;
never executed: return 0;
never evaluated: n == 0
0
249 -
250 char *dest = destBuf->data(); -
251 *dest = 0; -
252 if (!src) return 0;
never executed: return 0;
never evaluated: !src
0
253 -
254 char* begin = dest; -
255 char* end = dest + n; -
256 -
257 while (dest < end) {
never evaluated: dest < end
0
258 switch (*src) { -
259 case '>': if (dest + sizeof("&gt;") < end) { strcpy(dest, "&gt;"); dest += sizeof("&gt;") - 1; } else { *dest = 0; return (dest+sizeof("&gt;")-begin); } ++src; break;;
never executed: }
never executed: return (dest+sizeof("&gt;")-begin);
never executed: break;
never evaluated: dest + sizeof("&gt;") < end
0
260 case '<': if (dest + sizeof("&lt;") < end) { strcpy(dest, "&lt;"); dest += sizeof("&lt;") - 1; } else { *dest = 0; return (dest+sizeof("&lt;")-begin); } ++src; break;;
never executed: }
never executed: return (dest+sizeof("&lt;")-begin);
never executed: break;
never evaluated: dest + sizeof("&lt;") < end
0
261 case '\'': if (dest + sizeof("&apos;") < end) { strcpy(dest, "&apos;"); dest += sizeof("&apos;") - 1; } else { *dest = 0; return (dest+sizeof("&apos;")-begin); } ++src; break;;
never executed: }
never executed: return (dest+sizeof("&apos;")-begin);
never executed: break;
never evaluated: dest + sizeof("&apos;") < end
0
262 case '"': if (dest + sizeof("&quot;") < end) { strcpy(dest, "&quot;"); dest += sizeof("&quot;") - 1; } else { *dest = 0; return (dest+sizeof("&quot;")-begin); } ++src; break;;
never executed: }
never executed: return (dest+sizeof("&quot;")-begin);
never executed: break;
never evaluated: dest + sizeof("&quot;") < end
0
263 case '&': if (dest + sizeof("&amp;") < end) { strcpy(dest, "&amp;"); dest += sizeof("&amp;") - 1; } else { *dest = 0; return (dest+sizeof("&amp;")-begin); } ++src; break;;
never executed: }
never executed: return (dest+sizeof("&amp;")-begin);
never executed: break;
never evaluated: dest + sizeof("&amp;") < end
0
264 -
265 -
266 -
267 case '-': if (dest + sizeof("&#x002D;") < end) { strcpy(dest, "&#x002D;"); dest += sizeof("&#x002D;") - 1; } else { *dest = 0; return (dest+sizeof("&#x002D;")-begin); } ++src; break;;
never evaluated: dest + sizeof("&#x002D;") < end
never executed: }
never executed: return (dest+sizeof("&#x002D;")-begin);
never executed: break;
0
268 -
269 -
270 -
271 case 0: -
272 *dest = 0; -
273 return (dest-begin);
never executed: return (dest-begin);
0
274 -
275 default: -
276 *dest = *src; -
277 ++dest; -
278 ++src; -
279 break;
never executed: break;
0
280 } -
281 }
never executed: }
0
282 -
283 -
284 *(dest-1) = 0; -
285 return (dest-begin);
never executed: return (dest-begin);
0
286} -
287 -
288 -
289 -
290 -
291 -
292int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n) -
293{ -
294 if (!n) return 0;
never executed: return 0;
never evaluated: !n
0
295 -
296 char *dest = destBuf->data(); -
297 -
298 if (!src || n == 1) {
never evaluated: !src
never evaluated: n == 1
0
299 *dest = 0; -
300 return 0;
never executed: return 0;
0
301 } -
302 -
303 static char const CDATA_END[] = "]]>"; -
304 static char const CDATA_END_ESCAPED[] = "]]]><![CDATA[]>"; -
305 -
306 char* begin = dest; -
307 char* end = dest + n; -
308 while (dest < end) {
never evaluated: dest < end
0
309 if (!*src) {
never evaluated: !*src
0
310 *dest = 0; -
311 return (dest-begin);
never executed: return (dest-begin);
0
312 } -
313 -
314 if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
never evaluated: !strncmp(src, CDATA_END, sizeof(CDATA_END)-1)
0
315 if (dest + sizeof(CDATA_END_ESCAPED) < end) {
never evaluated: dest + sizeof(CDATA_END_ESCAPED) < end
0
316 strcpy(dest, CDATA_END_ESCAPED); -
317 src += sizeof(CDATA_END)-1; -
318 dest += sizeof(CDATA_END_ESCAPED) - 1; -
319 }
never executed: }
0
320 else { -
321 *dest = 0; -
322 return (dest+sizeof(CDATA_END_ESCAPED)-begin);
never executed: return (dest+sizeof(CDATA_END_ESCAPED)-begin);
0
323 } -
324 continue;
never executed: continue;
0
325 } -
326 -
327 *dest = *src; -
328 ++src; -
329 ++dest; -
330 }
never executed: }
0
331 -
332 -
333 *(dest-1) = 0; -
334 return (dest-begin);
never executed: return (dest-begin);
0
335} -
336 -
337typedef int (*StringFormatFunction)(QTestCharBuffer*,char const*,size_t); -
338 -
339 -
340 -
341 -
342 -
343int allocateStringFn(QTestCharBuffer* str, char const* src, StringFormatFunction func) -
344{ -
345 static const int MAXSIZE = 1024*1024*2; -
346 -
347 int size = str->size(); -
348 -
349 int res = 0; -
350 -
351 for (;;) { -
352 res = func(str, src, size); -
353 str->data()[size - 1] = '\0'; -
354 if (res < size) {
never evaluated: res < size
0
355 -
356 break;
never executed: break;
0
357 } -
358 -
359 size *= 2; -
360 if (size > MAXSIZE) {
never evaluated: size > MAXSIZE
0
361 break;
never executed: break;
0
362 } -
363 if (!str->reset(size))
never evaluated: !str->reset(size)
0
364 break;
never executed: break;
0
365 }
never executed: }
0
366 -
367 return res;
never executed: return res;
0
368} -
369 -
370int QXmlTestLogger::xmlQuote(QTestCharBuffer* str, char const* src) -
371{ -
372 return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
never executed: return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
0
373} -
374 -
375int QXmlTestLogger::xmlCdata(QTestCharBuffer* str, char const* src) -
376{ -
377 return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
never executed: return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
0
378} -
379 -
380 -
381 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial