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) 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-
43QT_BEGIN_NAMESPACE-
44-
45QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)-
46 : testLogger(logger)-
47{-
48 QTEST_ASSERT(testLogger);
never executed: qt_assert("testLogger",__FILE__,48);
!(testLogger)Description
TRUEnever evaluated
FALSEevaluated 215 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-215
49}
executed 215 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
215
50-
51QTestXunitStreamer::~QTestXunitStreamer()-
52{}-
53-
54void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size)-
55{-
56 if (size == 0) return;
never executed: return;
size == 0Description
TRUEnever evaluated
FALSEevaluated 35334 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-35334
57-
58 buf[0] = 0;-
59-
60 if (!element) return;
never executed: return;
!elementDescription
TRUEnever evaluated
FALSEevaluated 35334 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-35334
61-
62 char* endbuf = buf + size;-
63 element = element->parentElement();-
64 while (element && buf+2 < endbuf) {
elementDescription
TRUEevaluated 66840 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 35334 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
buf+2 < endbufDescription
TRUEevaluated 66840 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
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:
  • tst_selftests - unknown status
66840
70}
executed 35334 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
35334
71-
72void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const-
73{-
74 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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) {
element->eleme...est::LET_ErrorDescription
TRUEevaluated 30566 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
3319-30566
82 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
83 QTest::qt_asprintf(formatted, "<![CDATA[");-
84 } else {
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
85 QTest::qt_asprintf(formatted, "%s<!--", indent);-
86 }
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
87 return;
executed 30566 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
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:
  • tst_selftests - unknown status
3319
92-
93void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const-
94{-
95 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-33885
96 return;
never executed: return;
0
97-
98 if (!element->childElements()) {
!element->childElements()Description
TRUEevaluated 32436 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1449 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1449-32436
99 formatted->data()[0] = '\0';-
100 return;
executed 32436 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
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:
  • tst_selftests - unknown status
1449
108-
109void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const-
110{-
111 if (!attribute || !formatted )
!attributeDescription
TRUEnever evaluated
FALSEevaluated 87818 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 87818 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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
elementDescription
TRUEevaluated 87818 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 10475 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-87818
118 && 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
119-
120 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
121-
122 QXmlTestLogger::xmlCdata(formatted, attribute->value());-
123 return;
executed 15283 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
15283
124 }-
125-
126 char const* key = 0;-
127 if (attrindex == QTest::AI_Description)
attrindex == Q...AI_DescriptionDescription
TRUEevaluated 16008 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 56527 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
16008-56527
128 key = "message";
executed 16008 times by 1 test: key = "message";
Executed by:
  • tst_selftests - unknown status
16008
129 else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
attrindex != QTest::AI_FileDescription
TRUEevaluated 39306 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 17221 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
attrindex != QTest::AI_LineDescription
TRUEevaluated 22085 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 17221 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
17221-39306
130 key = attribute->name();
executed 22085 times by 1 test: key = attribute->name();
Executed by:
  • tst_selftests - unknown status
22085
131-
132 if (key) {
keyDescription
TRUEevaluated 38093 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 34442 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
34442-38093
133 QTestCharBuffer quotedValue;-
134 QXmlTestLogger::xmlQuote(&quotedValue, 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:
  • tst_selftests - unknown status
38093
137 formatted->data()[0] = '\0';-
138 }
executed 34442 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
34442
139}-
140-
141void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const-
142{-
143 if (!element || !formatted )
!elementDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
!formattedDescription
TRUEnever evaluated
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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) {
element->eleme...est::LET_ErrorDescription
TRUEevaluated 30566 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 3319 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
3319-30566
148 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
149 QTest::qt_asprintf(formatted, "]]>\n");-
150 } else {
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
151 QTest::qt_asprintf(formatted, " -->\n");-
152 }
executed 15283 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
15283
153 return;
executed 30566 times by 1 test: return;
Executed by:
  • tst_selftests - unknown status
30566
154 }-
155-
156 if (!element->childElements())
!element->childElements()Description
TRUEevaluated 1870 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1449 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1449-1870
157 QTest::qt_asprintf(formatted, "/>\n");
executed 1870 times by 1 test: QTest::qt_asprintf(formatted, "/>\n");
Executed by:
  • tst_selftests - unknown status
1870
158 else-
159 QTest::qt_asprintf(formatted, ">\n");
executed 1449 times by 1 test: QTest::qt_asprintf(formatted, ">\n");
Executed by:
  • tst_selftests - unknown status
1449
160}-
161-
162void QTestXunitStreamer::output(QTestElement *element) const-
163{-
164 QTEST_ASSERT(element);
never executed: qt_assert("element",__FILE__,164);
!(element)Description
TRUEnever evaluated
FALSEevaluated 215 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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:
  • tst_selftests - unknown status
215
169-
170void 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()) {
elementDescription
TRUEevaluated 33961 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEnever evaluated
element->nextElement()Description
TRUEevaluated 32297 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1664 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
0-33961
179 element = element->nextElement();-
180 }
executed 32297 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
32297
181 while (element) {
elementDescription
TRUEevaluated 33961 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 1664 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1664-33961
182 hasChildren = element->childElements();-
183-
184 if (element->elementType() != QTest::LET_Benchmark) {
element->eleme...:LET_BenchmarkDescription
TRUEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 76 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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)
hasChildrenDescription
TRUEevaluated 1449 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 32436 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
1449-32436
194 outputElements(element->childElements(), true);
executed 1449 times by 1 test: outputElements(element->childElements(), true);
Executed by:
  • tst_selftests - unknown status
1449
195-
196 formatEnd(element, &buf);-
197 outputString(buf.data());-
198 }
executed 33885 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
33885
199 element = element->previousElement();-
200 }
executed 33961 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
33961
201}
executed 1664 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
1664
202-
203void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const-
204{-
205 QTestCharBuffer buf;-
206 while (attribute) {
attributeDescription
TRUEevaluated 87818 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
FALSEevaluated 33885 times by 1 test
Evaluated by:
  • tst_selftests - unknown status
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:
  • tst_selftests - unknown status
87818
211}
executed 33885 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
33885
212-
213void QTestXunitStreamer::outputString(const char *msg) const-
214{-
215 testLogger->outputString(msg);-
216}
executed 189688 times by 1 test: end of block
Executed by:
  • tst_selftests - unknown status
189688
217-
218QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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