| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qxunittestlogger.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/qxunittestlogger_p.h> | - | ||||||||||||||||||||||||
| 35 | #include <QtTest/private/qtestelement_p.h> | - | ||||||||||||||||||||||||
| 36 | #include <QtTest/private/qtestxunitstreamer_p.h> | - | ||||||||||||||||||||||||
| 37 | #include <QtTest/qtestcase.h> | - | ||||||||||||||||||||||||
| 38 | #include <QtTest/private/qtestresult_p.h> | - | ||||||||||||||||||||||||
| 39 | #include <QtTest/private/qbenchmark_p.h> | - | ||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | #ifdef min // windows.h without NOMINMAX is included by the benchmark headers. | - | ||||||||||||||||||||||||
| 42 | # undef min | - | ||||||||||||||||||||||||
| 43 | #endif | - | ||||||||||||||||||||||||
| 44 | #ifdef max | - | ||||||||||||||||||||||||
| 45 | # undef max | - | ||||||||||||||||||||||||
| 46 | #endif | - | ||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||
| 48 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | #include <string.h> | - | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | QXunitTestLogger::QXunitTestLogger(const char *filename) | - | ||||||||||||||||||||||||
| 55 | : QAbstractTestLogger(filename) | - | ||||||||||||||||||||||||
| 56 | , listOfTestcases(0) | - | ||||||||||||||||||||||||
| 57 | , currentLogElement(0) | - | ||||||||||||||||||||||||
| 58 | , errorLogElement(0) | - | ||||||||||||||||||||||||
| 59 | , logFormatter(0) | - | ||||||||||||||||||||||||
| 60 | , testCounter(0) | - | ||||||||||||||||||||||||
| 61 | , failureCounter(0) | - | ||||||||||||||||||||||||
| 62 | , errorCounter(0) | - | ||||||||||||||||||||||||
| 63 | { | - | ||||||||||||||||||||||||
| 64 | } executed 215 times by 1 test: end of blockExecuted by:
| 215 | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | QXunitTestLogger::~QXunitTestLogger() | - | ||||||||||||||||||||||||
| 67 | { | - | ||||||||||||||||||||||||
| 68 | delete currentLogElement; | - | ||||||||||||||||||||||||
| 69 | delete logFormatter; | - | ||||||||||||||||||||||||
| 70 | } executed 215 times by 1 test: end of blockExecuted by:
| 215 | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | void QXunitTestLogger::startLogging() | - | ||||||||||||||||||||||||
| 73 | { | - | ||||||||||||||||||||||||
| 74 | QAbstractTestLogger::startLogging(); | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | logFormatter = new QTestXunitStreamer(this); | - | ||||||||||||||||||||||||
| 77 | delete errorLogElement; | - | ||||||||||||||||||||||||
| 78 | errorLogElement = new QTestElement(QTest::LET_SystemError); | - | ||||||||||||||||||||||||
| 79 | } executed 215 times by 1 test: end of blockExecuted by:
| 215 | ||||||||||||||||||||||||
| 80 | - | |||||||||||||||||||||||||
| 81 | void QXunitTestLogger::stopLogging() | - | ||||||||||||||||||||||||
| 82 | { | - | ||||||||||||||||||||||||
| 83 | QTestElement *iterator = listOfTestcases; | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | char buf[10]; | - | ||||||||||||||||||||||||
| 86 | - | |||||||||||||||||||||||||
| 87 | currentLogElement = new QTestElement(QTest::LET_TestSuite); | - | ||||||||||||||||||||||||
| 88 | currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName()); | - | ||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||
| 90 | qsnprintf(buf, sizeof(buf), "%i", testCounter); | - | ||||||||||||||||||||||||
| 91 | currentLogElement->addAttribute(QTest::AI_Tests, buf); | - | ||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | qsnprintf(buf, sizeof(buf), "%i", failureCounter); | - | ||||||||||||||||||||||||
| 94 | currentLogElement->addAttribute(QTest::AI_Failures, buf); | - | ||||||||||||||||||||||||
| 95 | - | |||||||||||||||||||||||||
| 96 | qsnprintf(buf, sizeof(buf), "%i", errorCounter); | - | ||||||||||||||||||||||||
| 97 | currentLogElement->addAttribute(QTest::AI_Errors, buf); | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | QTestElement *property; | - | ||||||||||||||||||||||||
| 100 | QTestElement *properties = new QTestElement(QTest::LET_Properties); | - | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | property = new QTestElement(QTest::LET_Property); | - | ||||||||||||||||||||||||
| 103 | property->addAttribute(QTest::AI_Name, "QTestVersion"); | - | ||||||||||||||||||||||||
| 104 | property->addAttribute(QTest::AI_PropertyValue, QTEST_VERSION_STR); | - | ||||||||||||||||||||||||
| 105 | properties->addLogElement(property); | - | ||||||||||||||||||||||||
| 106 | - | |||||||||||||||||||||||||
| 107 | property = new QTestElement(QTest::LET_Property); | - | ||||||||||||||||||||||||
| 108 | property->addAttribute(QTest::AI_Name, "QtVersion"); | - | ||||||||||||||||||||||||
| 109 | property->addAttribute(QTest::AI_PropertyValue, qVersion()); | - | ||||||||||||||||||||||||
| 110 | properties->addLogElement(property); | - | ||||||||||||||||||||||||
| 111 | - | |||||||||||||||||||||||||
| 112 | property = new QTestElement(QTest::LET_Property); | - | ||||||||||||||||||||||||
| 113 | property->addAttribute(QTest::AI_Name, "QtBuild"); | - | ||||||||||||||||||||||||
| 114 | property->addAttribute(QTest::AI_PropertyValue, QLibraryInfo::build()); | - | ||||||||||||||||||||||||
| 115 | properties->addLogElement(property); | - | ||||||||||||||||||||||||
| 116 | - | |||||||||||||||||||||||||
| 117 | currentLogElement->addLogElement(properties); | - | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | currentLogElement->addLogElement(iterator); | - | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | /* For correct indenting, make sure every testcase knows its parent */ | - | ||||||||||||||||||||||||
| 122 | QTestElement* testcase = iterator; | - | ||||||||||||||||||||||||
| 123 | while (testcase) {
| 215-1519 | ||||||||||||||||||||||||
| 124 | testcase->setParent(currentLogElement); | - | ||||||||||||||||||||||||
| 125 | testcase = testcase->nextElement(); | - | ||||||||||||||||||||||||
| 126 | } executed 1519 times by 1 test: end of blockExecuted by:
| 1519 | ||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | currentLogElement->addLogElement(errorLogElement); | - | ||||||||||||||||||||||||
| 129 | - | |||||||||||||||||||||||||
| 130 | QTestElement *it = currentLogElement; | - | ||||||||||||||||||||||||
| 131 | logFormatter->output(it); | - | ||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | QAbstractTestLogger::stopLogging(); | - | ||||||||||||||||||||||||
| 134 | } executed 215 times by 1 test: end of blockExecuted by:
| 215 | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | void QXunitTestLogger::enterTestFunction(const char *function) | - | ||||||||||||||||||||||||
| 137 | { | - | ||||||||||||||||||||||||
| 138 | currentLogElement = new QTestElement(QTest::LET_TestCase); | - | ||||||||||||||||||||||||
| 139 | currentLogElement->addAttribute(QTest::AI_Name, function); | - | ||||||||||||||||||||||||
| 140 | currentLogElement->addToList(&listOfTestcases); | - | ||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||
| 142 | ++testCounter; | - | ||||||||||||||||||||||||
| 143 | } executed 1304 times by 1 test: end of blockExecuted by:
| 1304 | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | void QXunitTestLogger::leaveTestFunction() | - | ||||||||||||||||||||||||
| 146 | { | - | ||||||||||||||||||||||||
| 147 | } | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | void QXunitTestLogger::addIncident(IncidentTypes type, const char *description, | - | ||||||||||||||||||||||||
| 150 | const char *file, int line) | - | ||||||||||||||||||||||||
| 151 | { | - | ||||||||||||||||||||||||
| 152 | const char *typeBuf = 0; | - | ||||||||||||||||||||||||
| 153 | char buf[100]; | - | ||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | switch (type) { | - | ||||||||||||||||||||||||
| 156 | case QAbstractTestLogger::XPass: executed 28 times by 1 test: case QAbstractTestLogger::XPass:Executed by:
| 28 | ||||||||||||||||||||||||
| 157 | ++failureCounter; | - | ||||||||||||||||||||||||
| 158 | typeBuf = "xpass"; | - | ||||||||||||||||||||||||
| 159 | break; executed 28 times by 1 test: break;Executed by:
| 28 | ||||||||||||||||||||||||
| 160 | case QAbstractTestLogger::Pass: executed 1294 times by 1 test: case QAbstractTestLogger::Pass:Executed by:
| 1294 | ||||||||||||||||||||||||
| 161 | typeBuf = "pass"; | - | ||||||||||||||||||||||||
| 162 | break; executed 1294 times by 1 test: break;Executed by:
| 1294 | ||||||||||||||||||||||||
| 163 | case QAbstractTestLogger::XFail: executed 105 times by 1 test: case QAbstractTestLogger::XFail:Executed by:
| 105 | ||||||||||||||||||||||||
| 164 | typeBuf = "xfail"; | - | ||||||||||||||||||||||||
| 165 | break; executed 105 times by 1 test: break;Executed by:
| 105 | ||||||||||||||||||||||||
| 166 | case QAbstractTestLogger::Fail: executed 697 times by 1 test: case QAbstractTestLogger::Fail:Executed by:
| 697 | ||||||||||||||||||||||||
| 167 | ++failureCounter; | - | ||||||||||||||||||||||||
| 168 | typeBuf = "fail"; | - | ||||||||||||||||||||||||
| 169 | break; executed 697 times by 1 test: break;Executed by:
| 697 | ||||||||||||||||||||||||
| 170 | case QAbstractTestLogger::BlacklistedPass: never executed: case QAbstractTestLogger::BlacklistedPass: | 0 | ||||||||||||||||||||||||
| 171 | typeBuf = "bpass"; | - | ||||||||||||||||||||||||
| 172 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 173 | case QAbstractTestLogger::BlacklistedFail: never executed: case QAbstractTestLogger::BlacklistedFail: | 0 | ||||||||||||||||||||||||
| 174 | ++failureCounter; | - | ||||||||||||||||||||||||
| 175 | typeBuf = "bfail"; | - | ||||||||||||||||||||||||
| 176 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 177 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 178 | typeBuf = "??????"; | - | ||||||||||||||||||||||||
| 179 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 180 | } | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) {
| 28-1427 | ||||||||||||||||||||||||
| 183 | QTestElement *failureElement = new QTestElement(QTest::LET_Failure); | - | ||||||||||||||||||||||||
| 184 | failureElement->addAttribute(QTest::AI_Result, typeBuf); | - | ||||||||||||||||||||||||
| 185 | if (file)
| 47-678 | ||||||||||||||||||||||||
| 186 | failureElement->addAttribute(QTest::AI_File, file); executed 678 times by 1 test: failureElement->addAttribute(QTest::AI_File, file);Executed by:
| 678 | ||||||||||||||||||||||||
| 187 | else | - | ||||||||||||||||||||||||
| 188 | failureElement->addAttribute(QTest::AI_File, ""); executed 47 times by 1 test: failureElement->addAttribute(QTest::AI_File, "");Executed by:
| 47 | ||||||||||||||||||||||||
| 189 | qsnprintf(buf, sizeof(buf), "%i", line); | - | ||||||||||||||||||||||||
| 190 | failureElement->addAttribute(QTest::AI_Line, buf); | - | ||||||||||||||||||||||||
| 191 | failureElement->addAttribute(QTest::AI_Description, description); | - | ||||||||||||||||||||||||
| 192 | addTag(failureElement); | - | ||||||||||||||||||||||||
| 193 | currentLogElement->addLogElement(failureElement); | - | ||||||||||||||||||||||||
| 194 | } executed 725 times by 1 test: end of blockExecuted by:
| 725 | ||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | /* | - | ||||||||||||||||||||||||
| 197 | Only one result can be shown for the whole testfunction. | - | ||||||||||||||||||||||||
| 198 | Check if we currently have a result, and if so, overwrite it | - | ||||||||||||||||||||||||
| 199 | iff the new result is worse. | - | ||||||||||||||||||||||||
| 200 | */ | - | ||||||||||||||||||||||||
| 201 | QTestElementAttribute* resultAttr = | - | ||||||||||||||||||||||||
| 202 | const_cast<QTestElementAttribute*>(currentLogElement->attribute(QTest::AI_Result)); | - | ||||||||||||||||||||||||
| 203 | if (resultAttr) {
| 911-1213 | ||||||||||||||||||||||||
| 204 | const char* oldResult = resultAttr->value(); | - | ||||||||||||||||||||||||
| 205 | bool overwrite = false; | - | ||||||||||||||||||||||||
| 206 | if (!strcmp(oldResult, "pass")) {
| 400-511 | ||||||||||||||||||||||||
| 207 | overwrite = true; | - | ||||||||||||||||||||||||
| 208 | } executed 400 times by 1 test: end of blockExecuted by:
| 400 | ||||||||||||||||||||||||
| 209 | else if (!strcmp(oldResult, "bpass")) {
| 0-511 | ||||||||||||||||||||||||
| 210 | overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail) || (type == QAbstractTestLogger::XFail)
| 0 | ||||||||||||||||||||||||
| 211 | || (type == QAbstractTestLogger::BlacklistedFail);
| 0 | ||||||||||||||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 213 | else if (!strcmp(oldResult, "bfail")) {
| 0-511 | ||||||||||||||||||||||||
| 214 | overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail) || (type == QAbstractTestLogger::XFail);
| 0 | ||||||||||||||||||||||||
| 215 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 216 | else if (!strcmp(oldResult, "xfail")) {
| 126-385 | ||||||||||||||||||||||||
| 217 | overwrite = (type == QAbstractTestLogger::XPass || type == QAbstractTestLogger::Fail);
| 0-126 | ||||||||||||||||||||||||
| 218 | } executed 126 times by 1 test: end of blockExecuted by:
| 126 | ||||||||||||||||||||||||
| 219 | else if (!strcmp(oldResult, "xpass")) {
| 14-371 | ||||||||||||||||||||||||
| 220 | overwrite = (type == QAbstractTestLogger::Fail); | - | ||||||||||||||||||||||||
| 221 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 222 | if (overwrite) {
| 407-504 | ||||||||||||||||||||||||
| 223 | resultAttr->setPair(QTest::AI_Result, typeBuf); | - | ||||||||||||||||||||||||
| 224 | } executed 407 times by 1 test: end of blockExecuted by:
| 407 | ||||||||||||||||||||||||
| 225 | } executed 911 times by 1 test: end of blockExecuted by:
| 911 | ||||||||||||||||||||||||
| 226 | else { | - | ||||||||||||||||||||||||
| 227 | currentLogElement->addAttribute(QTest::AI_Result, typeBuf); | - | ||||||||||||||||||||||||
| 228 | } executed 1213 times by 1 test: end of blockExecuted by:
| 1213 | ||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||
| 230 | if (file)
| 783-1341 | ||||||||||||||||||||||||
| 231 | currentLogElement->addAttribute(QTest::AI_File, file); executed 783 times by 1 test: currentLogElement->addAttribute(QTest::AI_File, file);Executed by:
| 783 | ||||||||||||||||||||||||
| 232 | else | - | ||||||||||||||||||||||||
| 233 | currentLogElement->addAttribute(QTest::AI_File, ""); executed 1341 times by 1 test: currentLogElement->addAttribute(QTest::AI_File, "");Executed by:
| 1341 | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | qsnprintf(buf, sizeof(buf), "%i", line); | - | ||||||||||||||||||||||||
| 236 | currentLogElement->addAttribute(QTest::AI_Line, buf); | - | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | /* | - | ||||||||||||||||||||||||
| 239 | Since XFAIL does not add a failure to the testlog in xunitxml, add a message, so we still | - | ||||||||||||||||||||||||
| 240 | have some information about the expected failure. | - | ||||||||||||||||||||||||
| 241 | */ | - | ||||||||||||||||||||||||
| 242 | if (type == QAbstractTestLogger::XFail) {
| 105-2019 | ||||||||||||||||||||||||
| 243 | QXunitTestLogger::addMessage(QAbstractTestLogger::Info, QString::fromUtf8(description), file, line); | - | ||||||||||||||||||||||||
| 244 | } executed 105 times by 1 test: end of blockExecuted by:
| 105 | ||||||||||||||||||||||||
| 245 | } executed 2124 times by 1 test: end of blockExecuted by:
| 2124 | ||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||
| 247 | void QXunitTestLogger::addBenchmarkResult(const QBenchmarkResult &result) | - | ||||||||||||||||||||||||
| 248 | { | - | ||||||||||||||||||||||||
| 249 | QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark); | - | ||||||||||||||||||||||||
| 250 | - | |||||||||||||||||||||||||
| 251 | benchmarkElement->addAttribute( | - | ||||||||||||||||||||||||
| 252 | QTest::AI_Metric, | - | ||||||||||||||||||||||||
| 253 | QTest::benchmarkMetricName(QBenchmarkTestMethodData::current->result.metric)); | - | ||||||||||||||||||||||||
| 254 | benchmarkElement->addAttribute(QTest::AI_Tag, result.context.tag.toUtf8().data()); | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | const qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); | - | ||||||||||||||||||||||||
| 257 | benchmarkElement->addAttribute(QTest::AI_Value, QByteArray::number(valuePerIteration).constData()); | - | ||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||
| 259 | char buf[100]; | - | ||||||||||||||||||||||||
| 260 | qsnprintf(buf, sizeof(buf), "%i", result.iterations); | - | ||||||||||||||||||||||||
| 261 | benchmarkElement->addAttribute(QTest::AI_Iterations, buf); | - | ||||||||||||||||||||||||
| 262 | currentLogElement->addLogElement(benchmarkElement); | - | ||||||||||||||||||||||||
| 263 | } executed 76 times by 1 test: end of blockExecuted by:
| 76 | ||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||
| 265 | void QXunitTestLogger::addTag(QTestElement* element) | - | ||||||||||||||||||||||||
| 266 | { | - | ||||||||||||||||||||||||
| 267 | const char *tag = QTestResult::currentDataTag(); | - | ||||||||||||||||||||||||
| 268 | const char *gtag = QTestResult::currentGlobalDataTag(); | - | ||||||||||||||||||||||||
| 269 | const char *filler = (tag && gtag) ? ":" : "";
| 238-14605 | ||||||||||||||||||||||||
| 270 | if ((!tag || !tag[0]) && (!gtag || !gtag[0])) {
| 0-14605 | ||||||||||||||||||||||||
| 271 | return; executed 14598 times by 1 test: return;Executed by:
| 14598 | ||||||||||||||||||||||||
| 272 | } | - | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | if (!tag) {
| 7-1403 | ||||||||||||||||||||||||
| 275 | tag = ""; | - | ||||||||||||||||||||||||
| 276 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||
| 277 | if (!gtag) {
| 245-1165 | ||||||||||||||||||||||||
| 278 | gtag = ""; | - | ||||||||||||||||||||||||
| 279 | } executed 1165 times by 1 test: end of blockExecuted by:
| 1165 | ||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | QTestCharBuffer buf; | - | ||||||||||||||||||||||||
| 282 | QTest::qt_asprintf(&buf, "%s%s%s", gtag, filler, tag); | - | ||||||||||||||||||||||||
| 283 | element->addAttribute(QTest::AI_Tag, buf.constData()); | - | ||||||||||||||||||||||||
| 284 | } executed 1410 times by 1 test: end of blockExecuted by:
| 1410 | ||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||
| 286 | void QXunitTestLogger::addMessage(MessageTypes type, const QString &message, const char *file, int line) | - | ||||||||||||||||||||||||
| 287 | { | - | ||||||||||||||||||||||||
| 288 | QTestElement *errorElement = new QTestElement(QTest::LET_Error); | - | ||||||||||||||||||||||||
| 289 | const char *typeBuf = 0; | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | switch (type) { | - | ||||||||||||||||||||||||
| 292 | case QAbstractTestLogger::Warn: executed 14 times by 1 test: case QAbstractTestLogger::Warn:Executed by:
| 14 | ||||||||||||||||||||||||
| 293 | typeBuf = "warn"; | - | ||||||||||||||||||||||||
| 294 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 295 | case QAbstractTestLogger::QSystem: executed 7 times by 1 test: case QAbstractTestLogger::QSystem:Executed by:
| 7 | ||||||||||||||||||||||||
| 296 | typeBuf = "system"; | - | ||||||||||||||||||||||||
| 297 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||
| 298 | case QAbstractTestLogger::QDebug: executed 625 times by 1 test: case QAbstractTestLogger::QDebug:Executed by:
| 625 | ||||||||||||||||||||||||
| 299 | typeBuf = "qdebug"; | - | ||||||||||||||||||||||||
| 300 | break; executed 625 times by 1 test: break;Executed by:
| 625 | ||||||||||||||||||||||||
| 301 | case QAbstractTestLogger::QInfo: executed 14 times by 1 test: case QAbstractTestLogger::QInfo:Executed by:
| 14 | ||||||||||||||||||||||||
| 302 | typeBuf = "qinfo"; | - | ||||||||||||||||||||||||
| 303 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 304 | case QAbstractTestLogger::QWarning: executed 14028 times by 1 test: case QAbstractTestLogger::QWarning:Executed by:
| 14028 | ||||||||||||||||||||||||
| 305 | typeBuf = "qwarn"; | - | ||||||||||||||||||||||||
| 306 | break; executed 14028 times by 1 test: break;Executed by:
| 14028 | ||||||||||||||||||||||||
| 307 | case QAbstractTestLogger::QFatal: executed 14 times by 1 test: case QAbstractTestLogger::QFatal:Executed by:
| 14 | ||||||||||||||||||||||||
| 308 | typeBuf = "qfatal"; | - | ||||||||||||||||||||||||
| 309 | break; executed 14 times by 1 test: break;Executed by:
| 14 | ||||||||||||||||||||||||
| 310 | case QAbstractTestLogger::Skip: executed 259 times by 1 test: case QAbstractTestLogger::Skip:Executed by:
| 259 | ||||||||||||||||||||||||
| 311 | typeBuf = "skip"; | - | ||||||||||||||||||||||||
| 312 | break; executed 259 times by 1 test: break;Executed by:
| 259 | ||||||||||||||||||||||||
| 313 | case QAbstractTestLogger::Info: executed 322 times by 1 test: case QAbstractTestLogger::Info:Executed by:
| 322 | ||||||||||||||||||||||||
| 314 | typeBuf = "info"; | - | ||||||||||||||||||||||||
| 315 | break; executed 322 times by 1 test: break;Executed by:
| 322 | ||||||||||||||||||||||||
| 316 | default: never executed: default: | 0 | ||||||||||||||||||||||||
| 317 | typeBuf = "??????"; | - | ||||||||||||||||||||||||
| 318 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 319 | } | - | ||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | errorElement->addAttribute(QTest::AI_Type, typeBuf); | - | ||||||||||||||||||||||||
| 322 | errorElement->addAttribute(QTest::AI_Description, message.toUtf8().constData()); | - | ||||||||||||||||||||||||
| 323 | addTag(errorElement); | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | if (file)
| 546-14737 | ||||||||||||||||||||||||
| 326 | errorElement->addAttribute(QTest::AI_File, file); executed 546 times by 1 test: errorElement->addAttribute(QTest::AI_File, file);Executed by:
| 546 | ||||||||||||||||||||||||
| 327 | else | - | ||||||||||||||||||||||||
| 328 | errorElement->addAttribute(QTest::AI_File, ""); executed 14737 times by 1 test: errorElement->addAttribute(QTest::AI_File, "");Executed by:
| 14737 | ||||||||||||||||||||||||
| 329 | - | |||||||||||||||||||||||||
| 330 | char buf[100]; | - | ||||||||||||||||||||||||
| 331 | qsnprintf(buf, sizeof(buf), "%i", line); | - | ||||||||||||||||||||||||
| 332 | errorElement->addAttribute(QTest::AI_Line, buf); | - | ||||||||||||||||||||||||
| 333 | - | |||||||||||||||||||||||||
| 334 | currentLogElement->addLogElement(errorElement); | - | ||||||||||||||||||||||||
| 335 | ++errorCounter; | - | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | // Also add the message to the system error log (i.e. stderr), if one exists | - | ||||||||||||||||||||||||
| 338 | if (errorLogElement) {
| 0-15283 | ||||||||||||||||||||||||
| 339 | QTestElement *systemErrorElement = new QTestElement(QTest::LET_Error); | - | ||||||||||||||||||||||||
| 340 | systemErrorElement->addAttribute(QTest::AI_Description, message.toUtf8().constData()); | - | ||||||||||||||||||||||||
| 341 | errorLogElement->addLogElement(systemErrorElement); | - | ||||||||||||||||||||||||
| 342 | } executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||||||||||||||
| 343 | } executed 15283 times by 1 test: end of blockExecuted by:
| 15283 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |