qtestxunitstreamer.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 <QtTest/private/qtestxunitstreamer_p.h> -
43#include <QtTest/private/qxunittestlogger_p.h> -
44#include <QtTest/private/qtestelement_p.h> -
45#include <QtTest/private/qtestelementattribute_p.h> -
46#include <QtTest/qtestassert.h> -
47#include <QtTest/private/qtestlog_p.h> -
48#include <QtTest/private/qtestresult_p.h> -
49#include <QtTest/private/qxmltestlogger_p.h> -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger) -
54 : testLogger(logger) -
55{ -
56 QTEST_ASSERT(testLogger);
never executed: qt_assert("testLogger","qtestxunitstreamer.cpp",56);
never executed: }
never evaluated: !(testLogger)
never evaluated: 0
0
57}
never executed: }
0
58 -
59QTestXunitStreamer::~QTestXunitStreamer() -
60{} -
61 -
62void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size) -
63{ -
64 if (size == 0) return;
never executed: return;
never evaluated: size == 0
0
65 -
66 buf[0] = 0;
never executed (the execution status of this line is deduced): buf[0] = 0;
-
67 -
68 if (!element) return;
never executed: return;
never evaluated: !element
0
69 -
70 char* endbuf = buf + size;
never executed (the execution status of this line is deduced): char* endbuf = buf + size;
-
71 element = element->parentElement();
never executed (the execution status of this line is deduced): element = element->parentElement();
-
72 while (element && buf+2 < endbuf) {
never evaluated: element
never evaluated: buf+2 < endbuf
0
73 *(buf++) = ' ';
never executed (the execution status of this line is deduced): *(buf++) = ' ';
-
74 *(buf++) = ' ';
never executed (the execution status of this line is deduced): *(buf++) = ' ';
-
75 *buf = 0;
never executed (the execution status of this line is deduced): *buf = 0;
-
76 element = element->parentElement();
never executed (the execution status of this line is deduced): element = element->parentElement();
-
77 }
never executed: }
0
78}
never executed: }
0
79 -
80void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const -
81{ -
82 if (!element || !formatted )
never evaluated: !element
never evaluated: !formatted
0
83 return;
never executed: return;
0
84 -
85 char indent[20];
never executed (the execution status of this line is deduced): char indent[20];
-
86 indentForElement(element, indent, sizeof(indent));
never executed (the execution status of this line is deduced): indentForElement(element, indent, sizeof(indent));
-
87 -
88 // Errors are written as CDATA within system-err, comments elsewhere -
89 if (element->elementType() == QTest::LET_Error) {
never evaluated: element->elementType() == QTest::LET_Error
0
90 if (element->parentElement()->elementType() == QTest::LET_SystemError) {
never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError
0
91 QTest::qt_asprintf(formatted, "<![CDATA[");
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, "<![CDATA[");
-
92 } else {
never executed: }
0
93 QTest::qt_asprintf(formatted, "%s<!--", indent);
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, "%s<!--", indent);
-
94 }
never executed: }
0
95 return;
never executed: return;
0
96 } -
97 -
98 QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName());
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName());
-
99}
never executed: }
0
100 -
101void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const -
102{ -
103 if (!element || !formatted )
never evaluated: !element
never evaluated: !formatted
0
104 return;
never executed: return;
0
105 -
106 if (!element->childElements()) {
never evaluated: !element->childElements()
0
107 formatted->data()[0] = '\0';
never executed (the execution status of this line is deduced): formatted->data()[0] = '\0';
-
108 return;
never executed: return;
0
109 } -
110 -
111 char indent[20];
never executed (the execution status of this line is deduced): char indent[20];
-
112 indentForElement(element, indent, sizeof(indent));
never executed (the execution status of this line is deduced): indentForElement(element, indent, sizeof(indent));
-
113 -
114 QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName());
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName());
-
115}
never executed: }
0
116 -
117void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const -
118{ -
119 if (!attribute || !formatted )
never evaluated: !attribute
never evaluated: !formatted
0
120 return;
never executed: return;
0
121 -
122 QTest::AttributeIndex attrindex = attribute->index();
never executed (the execution status of this line is deduced): QTest::AttributeIndex attrindex = attribute->index();
-
123 -
124 // For errors within system-err, we only want to output `message' -
125 if (element && element->elementType() == QTest::LET_Error
never evaluated: element
never evaluated: element->elementType() == QTest::LET_Error
0
126 && element->parentElement()->elementType() == QTest::LET_SystemError) {
never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError
0
127 -
128 if (attrindex != QTest::AI_Description) return;
never executed: return;
never evaluated: attrindex != QTest::AI_Description
0
129 -
130 QXmlTestLogger::xmlCdata(formatted, attribute->value());
never executed (the execution status of this line is deduced): QXmlTestLogger::xmlCdata(formatted, attribute->value());
-
131 return;
never executed: return;
0
132 } -
133 -
134 char const* key = 0;
never executed (the execution status of this line is deduced): char const* key = 0;
-
135 if (attrindex == QTest::AI_Description)
never evaluated: attrindex == QTest::AI_Description
0
136 key = "message";
never executed: key = "message";
0
137 else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
never evaluated: attrindex != QTest::AI_File
never evaluated: attrindex != QTest::AI_Line
0
138 key = attribute->name();
never executed: key = attribute->name();
0
139 -
140 if (key) {
never evaluated: key
0
141 QTestCharBuffer quotedValue;
never executed (the execution status of this line is deduced): QTestCharBuffer quotedValue;
-
142 QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
never executed (the execution status of this line is deduced): QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());
-
143 QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());
-
144 } else {
never executed: }
0
145 formatted->data()[0] = '\0';
never executed (the execution status of this line is deduced): formatted->data()[0] = '\0';
-
146 }
never executed: }
0
147} -
148 -
149void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const -
150{ -
151 if (!element || !formatted )
never evaluated: !element
never evaluated: !formatted
0
152 return;
never executed: return;
0
153 -
154 // Errors are written as CDATA within system-err, comments elsewhere -
155 if (element->elementType() == QTest::LET_Error) {
never evaluated: element->elementType() == QTest::LET_Error
0
156 if (element->parentElement()->elementType() == QTest::LET_SystemError) {
never evaluated: element->parentElement()->elementType() == QTest::LET_SystemError
0
157 QTest::qt_asprintf(formatted, "]]>\n");
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, "]]>\n");
-
158 } else {
never executed: }
0
159 QTest::qt_asprintf(formatted, " -->\n");
never executed (the execution status of this line is deduced): QTest::qt_asprintf(formatted, " -->\n");
-
160 }
never executed: }
0
161 return;
never executed: return;
0
162 } -
163 -
164 if (!element->childElements())
never evaluated: !element->childElements()
0
165 QTest::qt_asprintf(formatted, "/>\n");
never executed: QTest::qt_asprintf(formatted, "/>\n");
0
166 else -
167 QTest::qt_asprintf(formatted, ">\n");
never executed: QTest::qt_asprintf(formatted, ">\n");
0
168} -
169 -
170void QTestXunitStreamer::output(QTestElement *element) const -
171{ -
172 QTEST_ASSERT(element);
never executed: qt_assert("element","qtestxunitstreamer.cpp",172);
never executed: }
never evaluated: !(element)
never evaluated: 0
0
173 -
174 outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
never executed (the execution status of this line is deduced): outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
-
175 outputElements(element);
never executed (the execution status of this line is deduced): outputElements(element);
-
176}
never executed: }
0
177 -
178void QTestXunitStreamer::outputElements(QTestElement *element, bool) const -
179{ -
180 QTestCharBuffer buf;
never executed (the execution status of this line is deduced): QTestCharBuffer buf;
-
181 bool hasChildren;
never executed (the execution status of this line is deduced): bool hasChildren;
-
182 /* -
183 Elements are in reverse order of occurrence, so start from the end and work -
184 our way backwards. -
185 */ -
186 while (element && element->nextElement()) {
never evaluated: element
never evaluated: element->nextElement()
0
187 element = element->nextElement();
never executed (the execution status of this line is deduced): element = element->nextElement();
-
188 }
never executed: }
0
189 while (element) {
never evaluated: element
0
190 hasChildren = element->childElements();
never executed (the execution status of this line is deduced): hasChildren = element->childElements();
-
191 -
192 if (element->elementType() != QTest::LET_Benchmark) {
never evaluated: element->elementType() != QTest::LET_Benchmark
0
193 formatStart(element, &buf);
never executed (the execution status of this line is deduced): formatStart(element, &buf);
-
194 outputString(buf.data());
never executed (the execution status of this line is deduced): outputString(buf.data());
-
195 -
196 outputElementAttributes(element, element->attributes());
never executed (the execution status of this line is deduced): outputElementAttributes(element, element->attributes());
-
197 -
198 formatAfterAttributes(element, &buf);
never executed (the execution status of this line is deduced): formatAfterAttributes(element, &buf);
-
199 outputString(buf.data());
never executed (the execution status of this line is deduced): outputString(buf.data());
-
200 -
201 if (hasChildren)
never evaluated: hasChildren
0
202 outputElements(element->childElements(), true);
never executed: outputElements(element->childElements(), true);
0
203 -
204 formatEnd(element, &buf);
never executed (the execution status of this line is deduced): formatEnd(element, &buf);
-
205 outputString(buf.data());
never executed (the execution status of this line is deduced): outputString(buf.data());
-
206 }
never executed: }
0
207 element = element->previousElement();
never executed (the execution status of this line is deduced): element = element->previousElement();
-
208 }
never executed: }
0
209}
never executed: }
0
210 -
211void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const -
212{ -
213 QTestCharBuffer buf;
never executed (the execution status of this line is deduced): QTestCharBuffer buf;
-
214 while (attribute) {
never evaluated: attribute
0
215 formatAttributes(element, attribute, &buf);
never executed (the execution status of this line is deduced): formatAttributes(element, attribute, &buf);
-
216 outputString(buf.data());
never executed (the execution status of this line is deduced): outputString(buf.data());
-
217 attribute = attribute->nextElement();
never executed (the execution status of this line is deduced): attribute = attribute->nextElement();
-
218 }
never executed: }
0
219}
never executed: }
0
220 -
221void QTestXunitStreamer::outputString(const char *msg) const -
222{ -
223 testLogger->outputString(msg);
never executed (the execution status of this line is deduced): testLogger->outputString(msg);
-
224}
never executed: }
0
225 -
226QT_END_NAMESPACE -
227 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial