qtestxunitstreamer.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/testlib/qtestxunitstreamer.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
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 The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://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 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include <QtTest/private/qtestxunitstreamer_p.h>-
41#include <QtTest/private/qxunittestlogger_p.h>-
42#include <QtTest/private/qtestelement_p.h>-
43#include <QtTest/private/qtestelementattribute_p.h>-
44#include <QtTest/qtestassert.h>-
45#include <QtTest/private/qtestlog_p.h>-
46#include <QtTest/private/qtestresult_p.h>-
47#include <QtTest/private/qxmltestlogger_p.h>-
48-
49QT_BEGIN_NAMESPACE-
50-
51QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)-
52 : testLogger(logger)-
53{-
54 QTEST_ASSERT(testLogger);
never executed: qt_assert("testLogger",__FILE__,54);
!(testLogger)Description
TRUEnever evaluated
FALSEevaluated 215 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-215
55}
executed 215 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
215
56-
57QTestXunitStreamer::~QTestXunitStreamer()-
58{}-
59-
60void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size)-
61{-
62 if (size == 0) return;
never executed: return;
size == 0Description
TRUEnever evaluated
FALSEevaluated 35404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-35404
63-
64 buf[0] = 0;-
65-
66 if (!element) return;
never executed: return;
!elementDescription
TRUEnever evaluated
FALSEevaluated 35404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-35404
67-
68 char* endbuf = buf + size;-
69 element = element->parentElement();-
70 while (element && buf+2 < endbuf) {
elementDescription
TRUEevaluated 66938 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 35404 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
buf+2 < endbufDescription
TRUEevaluated 66938 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
0-66938
71 *(buf++) = ' ';-
72 *(buf++) = ' ';-
73 *buf = 0;-
74 element = element->parentElement();-
75 }
executed 66938 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
66938
76}
executed 35404 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
35404
77-
78void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const-
79{-
80 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-33934
81 return;
never executed: return;
0
82-
83 char indent[20];-
84 indentForElement(element, indent, sizeof(indent));-
85-
86 // Errors are written as CDATA within system-err, comments elsewhere-
87 if (element->elementType() == QTest::LET_Error) {
element->eleme...est::LET_ErrorDescription
TRUEevaluated 30566 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 3368 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
3368-30566
88 if (element->parentElement()->elementType() == QTest::LET_SystemError) {
element->paren...ET_SystemErrorDescription
TRUEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
15283
89 QTest::qt_asprintf(formatted, "<![CDATA[");-
90 } else {
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
91 QTest::qt_asprintf(formatted, "%s<!--", indent);-
92 }
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
93 return;
executed 30566 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
30566
94 }-
95-
96 QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName());-
97}
executed 3368 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
3368
98-
99void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const-
100{-
101 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-33934
102 return;
never executed: return;
0
103-
104 if (!element->childElements()) {
!element->childElements()Description
TRUEevaluated 32464 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1470 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1470-32464
105 formatted->data()[0] = '\0';-
106 return;
executed 32464 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
32464
107 }-
108-
109 char indent[20];-
110 indentForElement(element, indent, sizeof(indent));-
111-
112 QTest::qt_asprintf(formatted, "%s</%s>\n", indent, element->elementName());-
113}
executed 1470 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
1470
114-
115void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const-
116{-
117 if (!attribute || !formatted )
!attributeDescription
TRUEnever evaluated
FALSEevaluated 88028 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 88028 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-88028
118 return;
never executed: return;
0
119-
120 QTest::AttributeIndex attrindex = attribute->index();-
121-
122 // For errors within system-err, we only want to output `message'-
123 if (element && element->elementType() == QTest::LET_Error
elementDescription
TRUEevaluated 88028 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
element->eleme...est::LET_ErrorDescription
TRUEevaluated 77343 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 10685 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-88028
124 && element->parentElement()->elementType() == QTest::LET_SystemError) {
element->paren...ET_SystemErrorDescription
TRUEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 62060 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
15283-62060
125-
126 if (attrindex != QTest::AI_Description) return;
never executed: return;
attrindex != Q...AI_DescriptionDescription
TRUEnever evaluated
FALSEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-15283
127-
128 QXmlTestLogger::xmlCdata(formatted, attribute->value());-
129 return;
executed 15283 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
15283
130 }-
131-
132 char const* key = 0;-
133 if (attrindex == QTest::AI_Description)
attrindex == Q...AI_DescriptionDescription
TRUEevaluated 16036 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 56709 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
16036-56709
134 key = "message";
executed 16036 times by 1 test: key = "message";
Executed by:
  • tst_selftests - unknown status
16036
135 else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
attrindex != QTest::AI_FileDescription
TRUEevaluated 39439 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 17270 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
attrindex != QTest::AI_LineDescription
TRUEevaluated 22169 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 17270 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
17270-39439
136 key = attribute->name();
executed 22169 times by 1 test: key = attribute->name();
Executed by:
  • tst_selftests - unknown status
22169
137-
138 if (key) {
keyDescription
TRUEevaluated 38205 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 34540 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
34540-38205
139 QTestCharBuffer quotedValue;-
140 QXmlTestLogger::xmlQuote(&quotedValue, attribute->value());-
141 QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData());-
142 } else {
executed 38205 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
38205
143 formatted->data()[0] = '\0';-
144 }
executed 34540 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
34540
145}-
146-
147void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const-
148{-
149 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-33934
150 return;
never executed: return;
0
151-
152 // Errors are written as CDATA within system-err, comments elsewhere-
153 if (element->elementType() == QTest::LET_Error) {
element->eleme...est::LET_ErrorDescription
TRUEevaluated 30566 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 3368 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
3368-30566
154 if (element->parentElement()->elementType() == QTest::LET_SystemError) {
element->paren...ET_SystemErrorDescription
TRUEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 15283 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
15283
155 QTest::qt_asprintf(formatted, "]]>\n");-
156 } else {
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
157 QTest::qt_asprintf(formatted, " -->\n");-
158 }
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
159 return;
executed 30566 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
30566
160 }-
161-
162 if (!element->childElements())
!element->childElements()Description
TRUEevaluated 1898 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1470 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1470-1898
163 QTest::qt_asprintf(formatted, "/>\n");
executed 1898 times by 1 test: QTest::qt_asprintf(formatted, "/>\n");
Executed by:
  • tst_selftests - unknown status
1898
164 else-
165 QTest::qt_asprintf(formatted, ">\n");
executed 1470 times by 1 test: QTest::qt_asprintf(formatted, ">\n");
Executed by:
  • tst_selftests - unknown status
1470
166}-
167-
168void QTestXunitStreamer::output(QTestElement *element) const-
169{-
170 QTEST_ASSERT(element);
never executed: qt_assert("element",__FILE__,170);
!(element)Description
TRUEnever evaluated
FALSEevaluated 215 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-215
171-
172 outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");-
173 outputElements(element);-
174}
executed 215 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
215
175-
176void QTestXunitStreamer::outputElements(QTestElement *element, bool) const-
177{-
178 QTestCharBuffer buf;-
179 bool hasChildren;-
180 /*-
181 Elements are in reverse order of occurrence, so start from the end and work-
182 our way backwards.-
183 */-
184 while (element && element->nextElement()) {
elementDescription
TRUEevaluated 34010 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
element->nextElement()Description
TRUEevaluated 32325 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1685 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-34010
185 element = element->nextElement();-
186 }
executed 32325 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
32325
187 while (element) {
elementDescription
TRUEevaluated 34010 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1685 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1685-34010
188 hasChildren = element->childElements();-
189-
190 if (element->elementType() != QTest::LET_Benchmark) {
element->eleme...:LET_BenchmarkDescription
TRUEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
76-33934
191 formatStart(element, &buf);-
192 outputString(buf.data());-
193-
194 outputElementAttributes(element, element->attributes());-
195-
196 formatAfterAttributes(element, &buf);-
197 outputString(buf.data());-
198-
199 if (hasChildren)
hasChildrenDescription
TRUEevaluated 1470 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 32464 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1470-32464
200 outputElements(element->childElements(), true);
executed 1470 times by 1 test: outputElements(element->childElements(), true);
Executed by:
  • tst_selftests - unknown status
1470
201-
202 formatEnd(element, &buf);-
203 outputString(buf.data());-
204 }
executed 33934 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
33934
205 element = element->previousElement();-
206 }
executed 34010 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
34010
207}
executed 1685 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
1685
208-
209void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const-
210{-
211 QTestCharBuffer buf;-
212 while (attribute) {
attributeDescription
TRUEevaluated 88028 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 33934 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
33934-88028
213 formatAttributes(element, attribute, &buf);-
214 outputString(buf.data());-
215 attribute = attribute->nextElement();-
216 }
executed 88028 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
88028
217}
executed 33934 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
33934
218-
219void QTestXunitStreamer::outputString(const char *msg) const-
220{-
221 testLogger->outputString(msg);-
222}
executed 190045 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
190045
223-
224QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9