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