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