| 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) 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 | - | |||||||||||||
| 49 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 50 | - | |||||||||||||
| 51 | QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger) | - | ||||||||||||
| 52 | : testLogger(logger) | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | QTEST_ASSERT(testLogger); never executed: qt_assert("testLogger",__FILE__,54);
| 0-215 | ||||||||||||
| 55 | } executed 215 times by 1 test: end of blockExecuted by:
| 215 | ||||||||||||
| 56 | - | |||||||||||||
| 57 | QTestXunitStreamer::~QTestXunitStreamer() | - | ||||||||||||
| 58 | {} | - | ||||||||||||
| 59 | - | |||||||||||||
| 60 | void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size) | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | if (size == 0) return; never executed: return;
| 0-35404 | ||||||||||||
| 63 | - | |||||||||||||
| 64 | buf[0] = 0; | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | if (!element) return; never executed: return;
| 0-35404 | ||||||||||||
| 67 | - | |||||||||||||
| 68 | char* endbuf = buf + size; | - | ||||||||||||
| 69 | element = element->parentElement(); | - | ||||||||||||
| 70 | while (element && buf+2 < endbuf) {
| 0-66938 | ||||||||||||
| 71 | *(buf++) = ' '; | - | ||||||||||||
| 72 | *(buf++) = ' '; | - | ||||||||||||
| 73 | *buf = 0; | - | ||||||||||||
| 74 | element = element->parentElement(); | - | ||||||||||||
| 75 | } executed 66938 times by 1 test: end of blockExecuted by:
| 66938 | ||||||||||||
| 76 | } executed 35404 times by 1 test: end of blockExecuted by:
| 35404 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | if (!element || !formatted )
| 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) {
| 3368-30566 | ||||||||||||
| 88 | if (element->parentElement()->elementType() == QTest::LET_SystemError) {
| 15283 | ||||||||||||
| 89 | QTest::qt_asprintf(formatted, "<![CDATA["); | - | ||||||||||||
| 90 | } else { executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||
| 91 | QTest::qt_asprintf(formatted, "%s<!--", indent); | - | ||||||||||||
| 92 | } executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||
| 93 | return; executed 30566 times by 1 test: return;Executed by:
| 30566 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QTest::qt_asprintf(formatted, "%s<%s", indent, element->elementName()); | - | ||||||||||||
| 97 | } executed 3368 times by 1 test: end of blockExecuted by:
| 3368 | ||||||||||||
| 98 | - | |||||||||||||
| 99 | void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const | - | ||||||||||||
| 100 | { | - | ||||||||||||
| 101 | if (!element || !formatted )
| 0-33934 | ||||||||||||
| 102 | return; never executed: return; | 0 | ||||||||||||
| 103 | - | |||||||||||||
| 104 | if (!element->childElements()) {
| 1470-32464 | ||||||||||||
| 105 | formatted->data()[0] = '\0'; | - | ||||||||||||
| 106 | return; executed 32464 times by 1 test: return;Executed by:
| 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 blockExecuted by:
| 1470 | ||||||||||||
| 114 | - | |||||||||||||
| 115 | void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const | - | ||||||||||||
| 116 | { | - | ||||||||||||
| 117 | if (!attribute || !formatted )
| 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
| 0-88028 | ||||||||||||
| 124 | && element->parentElement()->elementType() == QTest::LET_SystemError) {
| 15283-62060 | ||||||||||||
| 125 | - | |||||||||||||
| 126 | if (attrindex != QTest::AI_Description) return; never executed: return;
| 0-15283 | ||||||||||||
| 127 | - | |||||||||||||
| 128 | QXmlTestLogger::xmlCdata(formatted, attribute->value()); | - | ||||||||||||
| 129 | return; executed 15283 times by 1 test: return;Executed by:
| 15283 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | char const* key = 0; | - | ||||||||||||
| 133 | if (attrindex == QTest::AI_Description)
| 16036-56709 | ||||||||||||
| 134 | key = "message"; executed 16036 times by 1 test: key = "message";Executed by:
| 16036 | ||||||||||||
| 135 | else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
| 17270-39439 | ||||||||||||
| 136 | key = attribute->name(); executed 22169 times by 1 test: key = attribute->name();Executed by:
| 22169 | ||||||||||||
| 137 | - | |||||||||||||
| 138 | if (key) {
| 34540-38205 | ||||||||||||
| 139 | QTestCharBuffer quotedValue; | - | ||||||||||||
| 140 | QXmlTestLogger::xmlQuote("edValue, attribute->value()); | - | ||||||||||||
| 141 | QTest::qt_asprintf(formatted, " %s=\"%s\"", key, quotedValue.constData()); | - | ||||||||||||
| 142 | } else { executed 38205 times by 1 test: end of blockExecuted by:
| 38205 | ||||||||||||
| 143 | formatted->data()[0] = '\0'; | - | ||||||||||||
| 144 | } executed 34540 times by 1 test: end of blockExecuted by:
| 34540 | ||||||||||||
| 145 | } | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const | - | ||||||||||||
| 148 | { | - | ||||||||||||
| 149 | if (!element || !formatted )
| 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) {
| 3368-30566 | ||||||||||||
| 154 | if (element->parentElement()->elementType() == QTest::LET_SystemError) {
| 15283 | ||||||||||||
| 155 | QTest::qt_asprintf(formatted, "]]>\n"); | - | ||||||||||||
| 156 | } else { executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||
| 157 | QTest::qt_asprintf(formatted, " -->\n"); | - | ||||||||||||
| 158 | } executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||
| 159 | return; executed 30566 times by 1 test: return;Executed by:
| 30566 | ||||||||||||
| 160 | } | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | if (!element->childElements())
| 1470-1898 | ||||||||||||
| 163 | QTest::qt_asprintf(formatted, "/>\n"); executed 1898 times by 1 test: QTest::qt_asprintf(formatted, "/>\n");Executed by:
| 1898 | ||||||||||||
| 164 | else | - | ||||||||||||
| 165 | QTest::qt_asprintf(formatted, ">\n"); executed 1470 times by 1 test: QTest::qt_asprintf(formatted, ">\n");Executed by:
| 1470 | ||||||||||||
| 166 | } | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | void QTestXunitStreamer::output(QTestElement *element) const | - | ||||||||||||
| 169 | { | - | ||||||||||||
| 170 | QTEST_ASSERT(element); never executed: qt_assert("element",__FILE__,170);
| 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 blockExecuted by:
| 215 | ||||||||||||
| 175 | - | |||||||||||||
| 176 | void 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()) {
| 0-34010 | ||||||||||||
| 185 | element = element->nextElement(); | - | ||||||||||||
| 186 | } executed 32325 times by 1 test: end of blockExecuted by:
| 32325 | ||||||||||||
| 187 | while (element) {
| 1685-34010 | ||||||||||||
| 188 | hasChildren = element->childElements(); | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | if (element->elementType() != QTest::LET_Benchmark) {
| 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)
| 1470-32464 | ||||||||||||
| 200 | outputElements(element->childElements(), true); executed 1470 times by 1 test: outputElements(element->childElements(), true);Executed by:
| 1470 | ||||||||||||
| 201 | - | |||||||||||||
| 202 | formatEnd(element, &buf); | - | ||||||||||||
| 203 | outputString(buf.data()); | - | ||||||||||||
| 204 | } executed 33934 times by 1 test: end of blockExecuted by:
| 33934 | ||||||||||||
| 205 | element = element->previousElement(); | - | ||||||||||||
| 206 | } executed 34010 times by 1 test: end of blockExecuted by:
| 34010 | ||||||||||||
| 207 | } executed 1685 times by 1 test: end of blockExecuted by:
| 1685 | ||||||||||||
| 208 | - | |||||||||||||
| 209 | void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const | - | ||||||||||||
| 210 | { | - | ||||||||||||
| 211 | QTestCharBuffer buf; | - | ||||||||||||
| 212 | while (attribute) {
| 33934-88028 | ||||||||||||
| 213 | formatAttributes(element, attribute, &buf); | - | ||||||||||||
| 214 | outputString(buf.data()); | - | ||||||||||||
| 215 | attribute = attribute->nextElement(); | - | ||||||||||||
| 216 | } executed 88028 times by 1 test: end of blockExecuted by:
| 88028 | ||||||||||||
| 217 | } executed 33934 times by 1 test: end of blockExecuted by:
| 33934 | ||||||||||||
| 218 | - | |||||||||||||
| 219 | void QTestXunitStreamer::outputString(const char *msg) const | - | ||||||||||||
| 220 | { | - | ||||||||||||
| 221 | testLogger->outputString(msg); | - | ||||||||||||
| 222 | } executed 190045 times by 1 test: end of blockExecuted by:
| 190045 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |