diff options
Diffstat (limited to 'src/testlib/qjunittestlogger.cpp')
-rw-r--r-- | src/testlib/qjunittestlogger.cpp | 82 |
1 files changed, 24 insertions, 58 deletions
diff --git a/src/testlib/qjunittestlogger.cpp b/src/testlib/qjunittestlogger.cpp index 9352cc2180..4ee5788bee 100644 --- a/src/testlib/qjunittestlogger.cpp +++ b/src/testlib/qjunittestlogger.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include <QtTest/private/qjunittestlogger_p.h> #include <QtTest/private/qtestelement_p.h> @@ -45,18 +9,21 @@ #include <QtTest/private/qbenchmark_p.h> #include <QtTest/private/qtestlog_p.h> -#ifdef min // windows.h without NOMINMAX is included by the benchmark headers. -# undef min -#endif -#ifdef max -# undef max -#endif - #include <QtCore/qlibraryinfo.h> #include <string.h> QT_BEGIN_NAMESPACE +/*! \internal + \class QJUnitTestLogger + \inmodule QtTest + + QJUnitTestLogger implements logging in a JUnit-compatible XML format. + + The \l{JUnit XML} format was originally developed for Java testing. + It is supported by \l{Test Center}. +*/ +// QTBUG-95424 links to further useful documentation. QJUnitTestLogger::QJUnitTestLogger(const char *filename) : QAbstractTestLogger(filename) @@ -71,7 +38,7 @@ QJUnitTestLogger::~QJUnitTestLogger() // We track test timing per test case, so we // need to maintain our own elapsed timer. -static QElapsedTimer elapsedTestcaseTime; +Q_CONSTINIT static QElapsedTimer elapsedTestcaseTime; static qreal elapsedTestCaseSeconds() { return elapsedTestcaseTime.nsecsElapsed() / 1e9; @@ -205,7 +172,7 @@ void QJUnitTestLogger::leaveTestFunction() void QJUnitTestLogger::leaveTestCase() { currentTestCase->addAttribute(QTest::AI_Time, - toSecondsFormat(elapsedTestCaseSeconds()).constData()); + toSecondsFormat(elapsedTestCaseSeconds() * 1000).constData()); if (!systemOutputElement->childElements().empty()) currentTestCase->addChild(systemOutputElement); @@ -224,7 +191,7 @@ void QJUnitTestLogger::leaveTestCase() void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description, const char *file, int line) { - if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) { + if (type == Fail || type == XPass) { auto failureType = [&]() { switch (type) { case QAbstractTestLogger::Fail: return "fail"; @@ -234,10 +201,14 @@ void QJUnitTestLogger::addIncident(IncidentTypes type, const char *description, }(); addFailure(QTest::LET_Failure, failureType, QString::fromUtf8(description)); - } else if (type == QAbstractTestLogger::XFail) { + } else if (type == XFail) { // Since XFAIL does not add a failure to the testlog in JUnit XML we add a // message, so we still have some information about the expected failure. - addMessage(QAbstractTestLogger::Info, QString::fromUtf8(description), file, line); + addMessage(Info, QString::fromUtf8(description), file, line); + } else if (type == Skip) { + auto skippedElement = new QTestElement(QTest::LET_Skipped); + skippedElement->addAttribute(QTest::AI_Message, description); + currentTestCase->addChild(skippedElement); } } @@ -258,8 +229,8 @@ void QJUnitTestLogger::addFailure(QTest::LogElementType elementType, failureElement->addAttribute(QTest::AI_Type, failureType); // Assume the first line is the message, and the remainder are details - QString message = failureDescription.section(QLatin1Char('\n'), 0, 0); - QString details = failureDescription.section(QLatin1Char('\n'), 1); + QString message = failureDescription.section(u'\n', 0, 0); + QString details = failureDescription.section(u'\n', 1); failureElement->addAttribute(QTest::AI_Message, message.toUtf8().constData()); @@ -283,12 +254,7 @@ void QJUnitTestLogger::addMessage(MessageTypes type, const QString &message, con Q_UNUSED(file); Q_UNUSED(line); - if (type == QAbstractTestLogger::Skip) { - auto skippedElement = new QTestElement(QTest::LET_Skipped); - skippedElement->addAttribute(QTest::AI_Message, message.toUtf8().constData()); - currentTestCase->addChild(skippedElement); - return; - } else if (type == QAbstractTestLogger::QFatal) { + if (type == QFatal) { addFailure(QTest::LET_Error, "qfatal", message); return; } |