| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qxmltestlogger.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 <stdio.h> | - | ||||||||||||
| 41 | #include <string.h> | - | ||||||||||||
| 42 | #include <QtCore/qglobal.h> | - | ||||||||||||
| 43 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | #include <QtTest/private/qtestlog_p.h> | - | ||||||||||||
| 46 | #include <QtTest/private/qxmltestlogger_p.h> | - | ||||||||||||
| 47 | #include <QtTest/private/qtestresult_p.h> | - | ||||||||||||
| 48 | #include <QtTest/private/qbenchmark_p.h> | - | ||||||||||||
| 49 | #include <QtTest/private/qbenchmarkmetric_p.h> | - | ||||||||||||
| 50 | #include <QtTest/qtestcase.h> | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | namespace QTest { | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | static const char* xmlMessageType2String(QAbstractTestLogger::MessageTypes type) | - | ||||||||||||
| 57 | { | - | ||||||||||||
| 58 | switch (type) { | - | ||||||||||||
| 59 | case QAbstractTestLogger::Warn: executed 24 times by 1 test: case QAbstractTestLogger::Warn:Executed by:
| 24 | ||||||||||||
| 60 | return "warn"; executed 24 times by 1 test: return "warn";Executed by:
| 24 | ||||||||||||
| 61 | case QAbstractTestLogger::QSystem: executed 12 times by 1 test: case QAbstractTestLogger::QSystem:Executed by:
| 12 | ||||||||||||
| 62 | return "system"; executed 12 times by 1 test: return "system";Executed by:
| 12 | ||||||||||||
| 63 | case QAbstractTestLogger::QDebug: executed 1077 times by 1 test: case QAbstractTestLogger::QDebug:Executed by:
| 1077 | ||||||||||||
| 64 | return "qdebug"; executed 1077 times by 1 test: return "qdebug";Executed by:
| 1077 | ||||||||||||
| 65 | case QAbstractTestLogger::QInfo: executed 24 times by 1 test: case QAbstractTestLogger::QInfo:Executed by:
| 24 | ||||||||||||
| 66 | return "qinfo"; executed 24 times by 1 test: return "qinfo";Executed by:
| 24 | ||||||||||||
| 67 | case QAbstractTestLogger::QWarning: executed 24048 times by 1 test: case QAbstractTestLogger::QWarning:Executed by:
| 24048 | ||||||||||||
| 68 | return "qwarn"; executed 24048 times by 1 test: return "qwarn";Executed by:
| 24048 | ||||||||||||
| 69 | case QAbstractTestLogger::QFatal: executed 24 times by 1 test: case QAbstractTestLogger::QFatal:Executed by:
| 24 | ||||||||||||
| 70 | return "qfatal"; executed 24 times by 1 test: return "qfatal";Executed by:
| 24 | ||||||||||||
| 71 | case QAbstractTestLogger::Skip: executed 444 times by 1 test: case QAbstractTestLogger::Skip:Executed by:
| 444 | ||||||||||||
| 72 | return "skip"; executed 444 times by 1 test: return "skip";Executed by:
| 444 | ||||||||||||
| 73 | case QAbstractTestLogger::Info: executed 372 times by 1 test: case QAbstractTestLogger::Info:Executed by:
| 372 | ||||||||||||
| 74 | return "info"; executed 372 times by 1 test: return "info";Executed by:
| 372 | ||||||||||||
| 75 | } | - | ||||||||||||
| 76 | return "??????"; never executed: return "??????"; | 0 | ||||||||||||
| 77 | } | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | static const char* xmlIncidentType2String(QAbstractTestLogger::IncidentTypes type) | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | switch (type) { | - | ||||||||||||
| 82 | case QAbstractTestLogger::Pass: executed 2247 times by 1 test: case QAbstractTestLogger::Pass:Executed by:
| 2247 | ||||||||||||
| 83 | return "pass"; executed 2247 times by 1 test: return "pass";Executed by:
| 2247 | ||||||||||||
| 84 | case QAbstractTestLogger::XFail: executed 180 times by 1 test: case QAbstractTestLogger::XFail:Executed by:
| 180 | ||||||||||||
| 85 | return "xfail"; executed 180 times by 1 test: return "xfail";Executed by:
| 180 | ||||||||||||
| 86 | case QAbstractTestLogger::Fail: executed 1245 times by 1 test: case QAbstractTestLogger::Fail:Executed by:
| 1245 | ||||||||||||
| 87 | return "fail"; executed 1245 times by 1 test: return "fail";Executed by:
| 1245 | ||||||||||||
| 88 | case QAbstractTestLogger::XPass: executed 48 times by 1 test: case QAbstractTestLogger::XPass:Executed by:
| 48 | ||||||||||||
| 89 | return "xpass"; executed 48 times by 1 test: return "xpass";Executed by:
| 48 | ||||||||||||
| 90 | case QAbstractTestLogger::BlacklistedPass: never executed: case QAbstractTestLogger::BlacklistedPass: | 0 | ||||||||||||
| 91 | return "bpass"; never executed: return "bpass"; | 0 | ||||||||||||
| 92 | case QAbstractTestLogger::BlacklistedFail: never executed: case QAbstractTestLogger::BlacklistedFail: | 0 | ||||||||||||
| 93 | return "bfail"; never executed: return "bfail"; | 0 | ||||||||||||
| 94 | } | - | ||||||||||||
| 95 | return "??????"; never executed: return "??????"; | 0 | ||||||||||||
| 96 | } | - | ||||||||||||
| 97 | - | |||||||||||||
| 98 | } | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | - | |||||||||||||
| 101 | QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename) | - | ||||||||||||
| 102 | : QAbstractTestLogger(filename), xmlmode(mode) | - | ||||||||||||
| 103 | { | - | ||||||||||||
| 104 | } executed 369 times by 1 test: end of blockExecuted by:
| 369 | ||||||||||||
| 105 | - | |||||||||||||
| 106 | QXmlTestLogger::~QXmlTestLogger() | - | ||||||||||||
| 107 | { | - | ||||||||||||
| 108 | } | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | void QXmlTestLogger::startLogging() | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | QAbstractTestLogger::startLogging(); | - | ||||||||||||
| 113 | QTestCharBuffer buf; | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | if (xmlmode == QXmlTestLogger::Complete) {
| 184-185 | ||||||||||||
| 116 | QTestCharBuffer quotedTc; | - | ||||||||||||
| 117 | xmlQuote("edTc, QTestResult::currentTestObjectName()); | - | ||||||||||||
| 118 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 119 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" | - | ||||||||||||
| 120 | "<TestCase name=\"%s\">\n", quotedTc.constData()); | - | ||||||||||||
| 121 | outputString(buf.constData()); | - | ||||||||||||
| 122 | } executed 184 times by 1 test: end of blockExecuted by:
| 184 | ||||||||||||
| 123 | - | |||||||||||||
| 124 | QTestCharBuffer quotedBuild; | - | ||||||||||||
| 125 | xmlQuote("edBuild, QLibraryInfo::build()); | - | ||||||||||||
| 126 | - | |||||||||||||
| 127 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 128 | "<Environment>\n" | - | ||||||||||||
| 129 | " <QtVersion>%s</QtVersion>\n" | - | ||||||||||||
| 130 | " <QtBuild>%s</QtBuild>\n" | - | ||||||||||||
| 131 | " <QTestVersion>" QTEST_VERSION_STR "</QTestVersion>\n" | - | ||||||||||||
| 132 | "</Environment>\n", qVersion(), quotedBuild.constData()); | - | ||||||||||||
| 133 | outputString(buf.constData()); | - | ||||||||||||
| 134 | } executed 369 times by 1 test: end of blockExecuted by:
| 369 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | void QXmlTestLogger::stopLogging() | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | QTestCharBuffer buf; | - | ||||||||||||
| 139 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 140 | "<Duration msecs=\"%f\"/>\n", QTestLog::msecsTotalTime()); | - | ||||||||||||
| 141 | outputString(buf.constData()); | - | ||||||||||||
| 142 | if (xmlmode == QXmlTestLogger::Complete) {
| 184-185 | ||||||||||||
| 143 | outputString("</TestCase>\n"); | - | ||||||||||||
| 144 | } executed 184 times by 1 test: end of blockExecuted by:
| 184 | ||||||||||||
| 145 | - | |||||||||||||
| 146 | QAbstractTestLogger::stopLogging(); | - | ||||||||||||
| 147 | } executed 369 times by 1 test: end of blockExecuted by:
| 369 | ||||||||||||
| 148 | - | |||||||||||||
| 149 | void QXmlTestLogger::enterTestFunction(const char *function) | - | ||||||||||||
| 150 | { | - | ||||||||||||
| 151 | QTestCharBuffer buf; | - | ||||||||||||
| 152 | QTestCharBuffer quotedFunction; | - | ||||||||||||
| 153 | xmlQuote("edFunction, function); | - | ||||||||||||
| 154 | QTest::qt_asprintf(&buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData()); | - | ||||||||||||
| 155 | outputString(buf.constData()); | - | ||||||||||||
| 156 | } executed 2274 times by 1 test: end of blockExecuted by:
| 2274 | ||||||||||||
| 157 | - | |||||||||||||
| 158 | void QXmlTestLogger::leaveTestFunction() | - | ||||||||||||
| 159 | { | - | ||||||||||||
| 160 | QTestCharBuffer buf; | - | ||||||||||||
| 161 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 162 | " <Duration msecs=\"%f\"/>\n" | - | ||||||||||||
| 163 | "</TestFunction>\n", | - | ||||||||||||
| 164 | QTestLog::msecsFunctionTime()); | - | ||||||||||||
| 165 | - | |||||||||||||
| 166 | outputString(buf.constData()); | - | ||||||||||||
| 167 | } executed 2274 times by 1 test: end of blockExecuted by:
| 2274 | ||||||||||||
| 168 | - | |||||||||||||
| 169 | namespace QTest | - | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | inline static bool isEmpty(const char *str) | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 | return !str || !str[0]; executed 59406 times by 1 test: return !str || !str[0];Executed by:
| 59406 | ||||||||||||
| 175 | } | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | static const char *incidentFormatString(bool noDescription, bool noTag) | - | ||||||||||||
| 178 | { | - | ||||||||||||
| 179 | if (noDescription) {
| 1473-2247 | ||||||||||||
| 180 | if (noTag)
| 879-1368 | ||||||||||||
| 181 | return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n"; executed 879 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";Executed by:
| 879 | ||||||||||||
| 182 | else | - | ||||||||||||
| 183 | return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" executed 1368 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";Executed by:
| 1368 | ||||||||||||
| 184 | " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" executed 1368 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";Executed by:
| 1368 | ||||||||||||
| 185 | "</Incident>\n"; executed 1368 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Incident>\n";Executed by:
| 1368 | ||||||||||||
| 186 | } else { | - | ||||||||||||
| 187 | if (noTag)
| 549-924 | ||||||||||||
| 188 | return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" executed 549 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";Executed by:
| 549 | ||||||||||||
| 189 | " <Description><![CDATA[%s%s%s%s]]></Description>\n" executed 549 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";Executed by:
| 549 | ||||||||||||
| 190 | "</Incident>\n"; executed 549 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Incident>\n";Executed by:
| 549 | ||||||||||||
| 191 | else | - | ||||||||||||
| 192 | return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" executed 924 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";Executed by:
| 924 | ||||||||||||
| 193 | " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" executed 924 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";Executed by:
| 924 | ||||||||||||
| 194 | " <Description><![CDATA[%s]]></Description>\n" executed 924 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";Executed by:
| 924 | ||||||||||||
| 195 | "</Incident>\n"; executed 924 times by 1 test: return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Incident>\n";Executed by:
| 924 | ||||||||||||
| 196 | } | - | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | static const char *benchmarkResultFormatString() | - | ||||||||||||
| 200 | { | - | ||||||||||||
| 201 | return "<BenchmarkResult metric=\"%s\" tag=\"%s\" value=\"%s\" iterations=\"%d\" />\n"; executed 132 times by 1 test: return "<BenchmarkResult metric=\"%s\" tag=\"%s\" value=\"%s\" iterations=\"%d\" />\n";Executed by:
| 132 | ||||||||||||
| 202 | } | - | ||||||||||||
| 203 | - | |||||||||||||
| 204 | static const char *messageFormatString(bool noDescription, bool noTag) | - | ||||||||||||
| 205 | { | - | ||||||||||||
| 206 | if (noDescription) {
| 0-26025 | ||||||||||||
| 207 | if (noTag)
| 0 | ||||||||||||
| 208 | return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n"; never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n"; | 0 | ||||||||||||
| 209 | else | - | ||||||||||||
| 210 | return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n"; | 0 | ||||||||||||
| 211 | " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n"; | 0 | ||||||||||||
| 212 | "</Message>\n"; never executed: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n" "</Message>\n"; | 0 | ||||||||||||
| 213 | } else { | - | ||||||||||||
| 214 | if (noTag)
| 1524-24501 | ||||||||||||
| 215 | return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";Executed by:
| 24501 | ||||||||||||
| 216 | " <Description><![CDATA[%s%s%s%s]]></Description>\n" executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";Executed by:
| 24501 | ||||||||||||
| 217 | "</Message>\n"; executed 24501 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <Description><![CDATA[%s%s%s%s]]></Description>\n" "</Message>\n";Executed by:
| 24501 | ||||||||||||
| 218 | else | - | ||||||||||||
| 219 | return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";Executed by:
| 1524 | ||||||||||||
| 220 | " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";Executed by:
| 1524 | ||||||||||||
| 221 | " <Description><![CDATA[%s]]></Description>\n" executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";Executed by:
| 1524 | ||||||||||||
| 222 | "</Message>\n"; executed 1524 times by 1 test: return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n" " <DataTag><![CDATA[%s%s%s]]></DataTag>\n" " <Description><![CDATA[%s]]></Description>\n" "</Message>\n";Executed by:
| 1524 | ||||||||||||
| 223 | } | - | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | } // namespace | - | ||||||||||||
| 227 | - | |||||||||||||
| 228 | void QXmlTestLogger::addIncident(IncidentTypes type, const char *description, | - | ||||||||||||
| 229 | const char *file, int line) | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 | QTestCharBuffer buf; | - | ||||||||||||
| 232 | const char *tag = QTestResult::currentDataTag(); | - | ||||||||||||
| 233 | const char *gtag = QTestResult::currentGlobalDataTag(); | - | ||||||||||||
| 234 | const char *filler = (tag && gtag) ? ":" : "";
| 84-2292 | ||||||||||||
| 235 | const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
| 0-2292 | ||||||||||||
| 236 | - | |||||||||||||
| 237 | QTestCharBuffer quotedFile; | - | ||||||||||||
| 238 | QTestCharBuffer cdataGtag; | - | ||||||||||||
| 239 | QTestCharBuffer cdataTag; | - | ||||||||||||
| 240 | QTestCharBuffer cdataDescription; | - | ||||||||||||
| 241 | - | |||||||||||||
| 242 | xmlQuote("edFile, file); | - | ||||||||||||
| 243 | xmlCdata(&cdataGtag, gtag); | - | ||||||||||||
| 244 | xmlCdata(&cdataTag, tag); | - | ||||||||||||
| 245 | xmlCdata(&cdataDescription, description); | - | ||||||||||||
| 246 | - | |||||||||||||
| 247 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 248 | QTest::incidentFormatString(QTest::isEmpty(description), notag), | - | ||||||||||||
| 249 | QTest::xmlIncidentType2String(type), | - | ||||||||||||
| 250 | quotedFile.constData(), line, | - | ||||||||||||
| 251 | cdataGtag.constData(), | - | ||||||||||||
| 252 | filler, | - | ||||||||||||
| 253 | cdataTag.constData(), | - | ||||||||||||
| 254 | cdataDescription.constData()); | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | outputString(buf.constData()); | - | ||||||||||||
| 257 | } executed 3720 times by 1 test: end of blockExecuted by:
| 3720 | ||||||||||||
| 258 | - | |||||||||||||
| 259 | void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result) | - | ||||||||||||
| 260 | { | - | ||||||||||||
| 261 | QTestCharBuffer buf; | - | ||||||||||||
| 262 | QTestCharBuffer quotedMetric; | - | ||||||||||||
| 263 | QTestCharBuffer quotedTag; | - | ||||||||||||
| 264 | - | |||||||||||||
| 265 | xmlQuote("edMetric, | - | ||||||||||||
| 266 | benchmarkMetricName(result.metric)); | - | ||||||||||||
| 267 | xmlQuote("edTag, result.context.tag.toUtf8().constData()); | - | ||||||||||||
| 268 | - | |||||||||||||
| 269 | const qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); | - | ||||||||||||
| 270 | QTest::qt_asprintf( | - | ||||||||||||
| 271 | &buf, | - | ||||||||||||
| 272 | QTest::benchmarkResultFormatString(), | - | ||||||||||||
| 273 | quotedMetric.constData(), | - | ||||||||||||
| 274 | quotedTag.constData(), | - | ||||||||||||
| 275 | QByteArray::number(valuePerIteration).constData(), //no 64-bit qsnprintf support | - | ||||||||||||
| 276 | result.iterations); | - | ||||||||||||
| 277 | outputString(buf.constData()); | - | ||||||||||||
| 278 | } executed 132 times by 1 test: end of blockExecuted by:
| 132 | ||||||||||||
| 279 | - | |||||||||||||
| 280 | void QXmlTestLogger::addMessage(MessageTypes type, const QString &message, | - | ||||||||||||
| 281 | const char *file, int line) | - | ||||||||||||
| 282 | { | - | ||||||||||||
| 283 | QTestCharBuffer buf; | - | ||||||||||||
| 284 | const char *tag = QTestResult::currentDataTag(); | - | ||||||||||||
| 285 | const char *gtag = QTestResult::currentGlobalDataTag(); | - | ||||||||||||
| 286 | const char *filler = (tag && gtag) ? ":" : "";
| 408-24513 | ||||||||||||
| 287 | const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
| 12-24513 | ||||||||||||
| 288 | - | |||||||||||||
| 289 | QTestCharBuffer quotedFile; | - | ||||||||||||
| 290 | QTestCharBuffer cdataGtag; | - | ||||||||||||
| 291 | QTestCharBuffer cdataTag; | - | ||||||||||||
| 292 | QTestCharBuffer cdataDescription; | - | ||||||||||||
| 293 | - | |||||||||||||
| 294 | xmlQuote("edFile, file); | - | ||||||||||||
| 295 | xmlCdata(&cdataGtag, gtag); | - | ||||||||||||
| 296 | xmlCdata(&cdataTag, tag); | - | ||||||||||||
| 297 | xmlCdata(&cdataDescription, message.toUtf8().constData()); | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | QTest::qt_asprintf(&buf, | - | ||||||||||||
| 300 | QTest::messageFormatString(message.isEmpty(), notag), | - | ||||||||||||
| 301 | QTest::xmlMessageType2String(type), | - | ||||||||||||
| 302 | quotedFile.constData(), line, | - | ||||||||||||
| 303 | cdataGtag.constData(), | - | ||||||||||||
| 304 | filler, | - | ||||||||||||
| 305 | cdataTag.constData(), | - | ||||||||||||
| 306 | cdataDescription.constData()); | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | outputString(buf.constData()); | - | ||||||||||||
| 309 | } executed 26025 times by 1 test: end of blockExecuted by:
| 26025 | ||||||||||||
| 310 | - | |||||||||||||
| 311 | /* | - | ||||||||||||
| 312 | Copy up to n characters from the src string into dest, escaping any special | - | ||||||||||||
| 313 | XML characters as necessary so that dest is suitable for use in an XML | - | ||||||||||||
| 314 | quoted attribute string. | - | ||||||||||||
| 315 | */ | - | ||||||||||||
| 316 | int QXmlTestLogger::xmlQuote(QTestCharBuffer* destBuf, char const* src, size_t n) | - | ||||||||||||
| 317 | { | - | ||||||||||||
| 318 | if (n == 0) return 0; never executed: return 0;
| 0-71069 | ||||||||||||
| 319 | - | |||||||||||||
| 320 | char *dest = destBuf->data(); | - | ||||||||||||
| 321 | *dest = 0; | - | ||||||||||||
| 322 | if (!src) return 0; executed 27597 times by 1 test: return 0;Executed by:
| 27597-43472 | ||||||||||||
| 323 | - | |||||||||||||
| 324 | char* begin = dest; | - | ||||||||||||
| 325 | char* end = dest + n; | - | ||||||||||||
| 326 | - | |||||||||||||
| 327 | while (dest < end) {
| 28-471029 | ||||||||||||
| 328 | switch (*src) { | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 | #define MAP_ENTITY(chr, ent) \ | - | ||||||||||||
| 331 | case chr: \ | - | ||||||||||||
| 332 | if (dest + sizeof(ent) < end) { \ | - | ||||||||||||
| 333 | strcpy(dest, ent); \ | - | ||||||||||||
| 334 | dest += sizeof(ent) - 1; \ | - | ||||||||||||
| 335 | } \ | - | ||||||||||||
| 336 | else { \ | - | ||||||||||||
| 337 | *dest = 0; \ | - | ||||||||||||
| 338 | return (dest+sizeof(ent)-begin); \ | - | ||||||||||||
| 339 | } \ | - | ||||||||||||
| 340 | ++src; \ | - | ||||||||||||
| 341 | break; | - | ||||||||||||
| 342 | - | |||||||||||||
| 343 | MAP_ENTITY('>', ">"); executed 253 times by 1 test: end of blockExecuted by:
never executed: return (dest+sizeof(">")-begin);executed 253 times by 1 test: break;Executed by:
executed 253 times by 1 test: case '>':Executed by:
| 0-253 | ||||||||||||
| 344 | MAP_ENTITY('<', "<"); executed 187 times by 1 test: end of blockExecuted by:
never executed: return (dest+sizeof("<")-begin);executed 187 times by 1 test: break;Executed by:
executed 187 times by 1 test: case '<':Executed by:
| 0-187 | ||||||||||||
| 345 | MAP_ENTITY('\'', "'"); executed 588 times by 1 test: end of blockExecuted by:
never executed: return (dest+sizeof("'")-begin);executed 588 times by 1 test: break;Executed by:
executed 588 times by 1 test: case '\'':Executed by:
| 0-588 | ||||||||||||
| 346 | MAP_ENTITY('"', """); executed 666 times by 1 test: end of blockExecuted by:
never executed: return (dest+sizeof(""")-begin);executed 666 times by 1 test: break;Executed by:
executed 666 times by 1 test: case '"':Executed by:
| 0-666 | ||||||||||||
| 347 | MAP_ENTITY('&', "&"); never executed: end of blocknever executed: return (dest+sizeof("&")-begin);never executed: break;
never executed: case '&': | 0 | ||||||||||||
| 348 | - | |||||||||||||
| 349 | // not strictly necessary, but allows handling of comments without | - | ||||||||||||
| 350 | // having to explicitly look for `--' | - | ||||||||||||
| 351 | MAP_ENTITY('-', "-"); executed 1217 times by 1 test: end of blockExecuted by:
never executed: return (dest+sizeof("-")-begin);executed 1217 times by 1 test: break;Executed by:
executed 1217 times by 1 test: case '-':Executed by:
| 0-1217 | ||||||||||||
| 352 | - | |||||||||||||
| 353 | #undef MAP_ENTITY | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | case 0: executed 43444 times by 1 test: case 0:Executed by:
| 43444 | ||||||||||||
| 356 | *dest = 0; | - | ||||||||||||
| 357 | return (dest-begin); executed 43444 times by 1 test: return (dest-begin);Executed by:
| 43444 | ||||||||||||
| 358 | - | |||||||||||||
| 359 | default: executed 424674 times by 1 test: default:Executed by:
| 424674 | ||||||||||||
| 360 | *dest = *src; | - | ||||||||||||
| 361 | ++dest; | - | ||||||||||||
| 362 | ++src; | - | ||||||||||||
| 363 | break; executed 424674 times by 1 test: break;Executed by:
| 424674 | ||||||||||||
| 364 | } | - | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | - | |||||||||||||
| 367 | // If we get here, dest was completely filled (dest == end) | - | ||||||||||||
| 368 | *(dest-1) = 0; | - | ||||||||||||
| 369 | return (dest-begin); executed 28 times by 1 test: return (dest-begin);Executed by:
| 28 | ||||||||||||
| 370 | } | - | ||||||||||||
| 371 | - | |||||||||||||
| 372 | /* | - | ||||||||||||
| 373 | Copy up to n characters from the src string into dest, escaping any | - | ||||||||||||
| 374 | special strings such that dest is suitable for use in an XML CDATA section. | - | ||||||||||||
| 375 | */ | - | ||||||||||||
| 376 | int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n) | - | ||||||||||||
| 377 | { | - | ||||||||||||
| 378 | if (!n) return 0; never executed: return 0;
| 0-104566 | ||||||||||||
| 379 | - | |||||||||||||
| 380 | char *dest = destBuf->data(); | - | ||||||||||||
| 381 | - | |||||||||||||
| 382 | if (!src || n == 1) {
| 0-55182 | ||||||||||||
| 383 | *dest = 0; | - | ||||||||||||
| 384 | return 0; executed 55182 times by 1 test: return 0;Executed by:
| 55182 | ||||||||||||
| 385 | } | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | static char const CDATA_END[] = "]]>"; | - | ||||||||||||
| 388 | static char const CDATA_END_ESCAPED[] = "]]]><![CDATA[]>"; | - | ||||||||||||
| 389 | - | |||||||||||||
| 390 | char* begin = dest; | - | ||||||||||||
| 391 | char* end = dest + n; | - | ||||||||||||
| 392 | while (dest < end) {
| 48-457940 | ||||||||||||
| 393 | if (!*src) {
| 49336-408604 | ||||||||||||
| 394 | *dest = 0; | - | ||||||||||||
| 395 | return (dest-begin); executed 49336 times by 1 test: return (dest-begin);Executed by:
| 49336 | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | - | |||||||||||||
| 398 | if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
| 250-408354 | ||||||||||||
| 399 | if (dest + sizeof(CDATA_END_ESCAPED) < end) {
| 0-250 | ||||||||||||
| 400 | strcpy(dest, CDATA_END_ESCAPED); | - | ||||||||||||
| 401 | src += sizeof(CDATA_END)-1; | - | ||||||||||||
| 402 | dest += sizeof(CDATA_END_ESCAPED) - 1; | - | ||||||||||||
| 403 | } executed 250 times by 1 test: end of blockExecuted by:
| 250 | ||||||||||||
| 404 | else { | - | ||||||||||||
| 405 | *dest = 0; | - | ||||||||||||
| 406 | return (dest+sizeof(CDATA_END_ESCAPED)-begin); never executed: return (dest+sizeof(CDATA_END_ESCAPED)-begin); | 0 | ||||||||||||
| 407 | } | - | ||||||||||||
| 408 | continue; executed 250 times by 1 test: continue;Executed by:
| 250 | ||||||||||||
| 409 | } | - | ||||||||||||
| 410 | - | |||||||||||||
| 411 | *dest = *src; | - | ||||||||||||
| 412 | ++src; | - | ||||||||||||
| 413 | ++dest; | - | ||||||||||||
| 414 | } executed 408354 times by 1 test: end of blockExecuted by:
| 408354 | ||||||||||||
| 415 | - | |||||||||||||
| 416 | // If we get here, dest was completely filled (dest == end) | - | ||||||||||||
| 417 | *(dest-1) = 0; | - | ||||||||||||
| 418 | return (dest-begin); executed 48 times by 1 test: return (dest-begin);Executed by:
| 48 | ||||||||||||
| 419 | } | - | ||||||||||||
| 420 | - | |||||||||||||
| 421 | typedef int (*StringFormatFunction)(QTestCharBuffer*,char const*,size_t); | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | /* | - | ||||||||||||
| 424 | A wrapper for string functions written to work with a fixed size buffer so they can be called | - | ||||||||||||
| 425 | with a dynamically allocated buffer. | - | ||||||||||||
| 426 | */ | - | ||||||||||||
| 427 | int allocateStringFn(QTestCharBuffer* str, char const* src, StringFormatFunction func) | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | static const int MAXSIZE = 1024*1024*2; | - | ||||||||||||
| 430 | - | |||||||||||||
| 431 | int size = str->size(); | - | ||||||||||||
| 432 | - | |||||||||||||
| 433 | int res = 0; | - | ||||||||||||
| 434 | - | |||||||||||||
| 435 | for (;;) { | - | ||||||||||||
| 436 | res = func(str, src, size); | - | ||||||||||||
| 437 | str->data()[size - 1] = '\0'; | - | ||||||||||||
| 438 | if (res < size) {
| 76-175559 | ||||||||||||
| 439 | // We succeeded or fatally failed | - | ||||||||||||
| 440 | break; executed 175559 times by 1 test: break;Executed by:
| 175559 | ||||||||||||
| 441 | } | - | ||||||||||||
| 442 | // buffer wasn't big enough, try again | - | ||||||||||||
| 443 | size *= 2; | - | ||||||||||||
| 444 | if (size > MAXSIZE) {
| 0-76 | ||||||||||||
| 445 | break; never executed: break; | 0 | ||||||||||||
| 446 | } | - | ||||||||||||
| 447 | if (!str->reset(size))
| 0-76 | ||||||||||||
| 448 | break; // ran out of memory - bye never executed: break; | 0 | ||||||||||||
| 449 | } executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||
| 450 | - | |||||||||||||
| 451 | return res; executed 175559 times by 1 test: return res;Executed by:
| 175559 | ||||||||||||
| 452 | } | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | int QXmlTestLogger::xmlQuote(QTestCharBuffer* str, char const* src) | - | ||||||||||||
| 455 | { | - | ||||||||||||
| 456 | return allocateStringFn(str, src, QXmlTestLogger::xmlQuote); executed 71041 times by 1 test: return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);Executed by:
| 71041 | ||||||||||||
| 457 | } | - | ||||||||||||
| 458 | - | |||||||||||||
| 459 | int QXmlTestLogger::xmlCdata(QTestCharBuffer* str, char const* src) | - | ||||||||||||
| 460 | { | - | ||||||||||||
| 461 | return allocateStringFn(str, src, QXmlTestLogger::xmlCdata); executed 104518 times by 1 test: return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);Executed by:
| 104518 | ||||||||||||
| 462 | } | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |