diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-09-06 10:49:40 +0200 |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-09-06 10:55:40 +0200 |
commit | a6b6e760ac2f019b9ca42847b9535207966811aa (patch) | |
tree | cdba2823eb3708f7a40593ff69b81d2be88515ea /src/testlib | |
parent | 48ba459580c9e4ce28dbb2c3ce433175148da5a1 (diff) | |
parent | 8ed47d961dc7e6f161030654d11cd330a542eadf (diff) |
Merge remote branch 'gerrit/master' into HEAD
Conflicts:
configure.exe
src/corelib/global/qglobal.h
src/gui/kernel/qplatformnativeinterface_qpa.h
src/gui/widgets/qlinecontrol.cpp
src/gui/widgets/qmenu_mac.mm
src/gui/widgets/qmenu_p.h
src/gui/widgets/qmenubar.cpp
src/gui/widgets/qmenubar_p.h
src/gui/widgets/widgets.pri
src/plugins/platforms/wayland/qwaylandnativeinterface.cpp
src/plugins/platforms/wayland/qwaylandnativeinterface.h
src/src.pro
tests/auto/qdir/tst_qdir.cpp
tests/auto/qfileinfo/tst_qfileinfo.cpp
tests/auto/qsslsocket/tst_qsslsocket.cpp
tests/auto/qstring/tst_qstring.cpp
Change-Id: I64cf2cefa532ba87a92f632e3595ce6914183e9b
Diffstat (limited to 'src/testlib')
35 files changed, 296 insertions, 1126 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index d71addb655..e2f253c22e 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -54,18 +54,8 @@ QT_BEGIN_NAMESPACE -void QAbstractTestLogger::outputString(const char *msg) +QAbstractTestLogger::QAbstractTestLogger(const char *filename) { - QTEST_ASSERT(stream); - - ::fputs(msg, stream); - ::fflush(stream); -} - -void QAbstractTestLogger::startLogging(const char *filename) -{ - QTEST_ASSERT(!stream); - if (!filename) { stream = stdout; return; @@ -81,7 +71,7 @@ void QAbstractTestLogger::startLogging(const char *filename) } } -void QAbstractTestLogger::stopLogging() +QAbstractTestLogger::~QAbstractTestLogger() { QTEST_ASSERT(stream); if (stream != stdout) { @@ -97,6 +87,22 @@ void QAbstractTestLogger::stopLogging() stream = 0; } +void QAbstractTestLogger::outputString(const char *msg) +{ + QTEST_ASSERT(stream); + + ::fputs(msg, stream); + ::fflush(stream); +} + +void QAbstractTestLogger::startLogging() +{ +} + +void QAbstractTestLogger::stopLogging() +{ +} + namespace QTest { diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 3ac6787754..3e11863012 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -80,10 +80,10 @@ public: Info }; - QAbstractTestLogger() : stream(0) {} - virtual ~QAbstractTestLogger() {} + QAbstractTestLogger(const char *filename); + virtual ~QAbstractTestLogger(); - virtual void startLogging(const char *filename); + virtual void startLogging(); virtual void stopLogging(); virtual void enterTestFunction(const char *function) = 0; @@ -98,7 +98,7 @@ public: void outputString(const char *msg); -private: +protected: FILE *stream; }; diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp index 1cb10a7ac6..49fad5da4d 100644 --- a/src/testlib/qbenchmark.cpp +++ b/src/testlib/qbenchmark.cpp @@ -119,7 +119,6 @@ QBenchmarkTestMethodData *QBenchmarkTestMethodData::current; QBenchmarkTestMethodData::QBenchmarkTestMethodData() :resultAccepted(false), runOnce(false), iterationCount(-1) { - } QBenchmarkTestMethodData::~QBenchmarkTestMethodData() @@ -134,7 +133,6 @@ void QBenchmarkTestMethodData::beginDataRun() void QBenchmarkTestMethodData::endDataRun() { - } int QBenchmarkTestMethodData::adjustIterationCount(int suggestion) @@ -164,7 +162,7 @@ void QBenchmarkTestMethodData::setResult( accepted = true; } - // Test the result directly without calling the measurer if the minimum time + // Test the result directly without calling the measurer if the minimum time // has been specified on the command line with -minimumvalue. else if (QBenchmarkGlobalData::current->walltimeMinimum != -1) accepted = (value > QBenchmarkGlobalData::current->walltimeMinimum); @@ -196,7 +194,7 @@ QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runM { i = 0; if (runMode == RunOnce) - QBenchmarkTestMethodData::current->runOnce = true; + QBenchmarkTestMethodData::current->runOnce = true; QTest::beginBenchmarkMeasurement(); } @@ -265,16 +263,16 @@ void QTest::beginBenchmarkMeasurement() quint64 QTest::endBenchmarkMeasurement() { // the clock is ticking before the line below, don't add code here. - return QBenchmarkGlobalData::current->measurer->stop(); + return QBenchmarkGlobalData::current->measurer->stop(); } /*! Sets the benchmark result for this test function to \a result. - + Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use \a metric to specify how QTestLib should interpret the results. - + The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h index e5e07c0035..36e4b35493 100644 --- a/src/testlib/qbenchmark_p.h +++ b/src/testlib/qbenchmark_p.h @@ -58,7 +58,7 @@ #include <QtCore/qglobal.h> #if (defined(Q_OS_LINUX) || defined Q_OS_MAC) && !defined(QT_NO_PROCESS) -#define QTESTLIB_USE_VALGRIND +#define QTESTLIB_USE_VALGRIND #else #undef QTESTLIB_USE_VALGRIND #endif @@ -119,7 +119,7 @@ public: , valid(true) { } - bool operator<(const QBenchmarkResult &other) const + bool operator<(const QBenchmarkResult &other) const { return (value / iterations) < (other.value / other.iterations); } diff --git a/src/testlib/qbenchmarkevent_p.h b/src/testlib/qbenchmarkevent_p.h index fc0729e82f..2cf17ea6a2 100644 --- a/src/testlib/qbenchmarkevent_p.h +++ b/src/testlib/qbenchmarkevent_p.h @@ -69,12 +69,12 @@ public: bool isMeasurementAccepted(qint64 measurement); int adjustIterationCount(int suggestion); int adjustMedianCount(int suggestion); - bool repeatCount() { return 1; } + bool repeatCount() { return 1; } QTest::QBenchmarkMetric metricType(); static bool eventCountingMechanism(void *message); static qint64 eventCounter; }; QT_END_NAMESPACE - + #endif // QBENCHMARKEVENT_H diff --git a/src/testlib/qbenchmarkmeasurement.cpp b/src/testlib/qbenchmarkmeasurement.cpp index 4aad71da34..2c14f5d3fe 100644 --- a/src/testlib/qbenchmarkmeasurement.cpp +++ b/src/testlib/qbenchmarkmeasurement.cpp @@ -60,7 +60,7 @@ qint64 QBenchmarkTimeMeasurer::checkpoint() } qint64 QBenchmarkTimeMeasurer::stop() -{ +{ return time.elapsed(); } @@ -70,8 +70,8 @@ bool QBenchmarkTimeMeasurer::isMeasurementAccepted(qint64 measurement) } int QBenchmarkTimeMeasurer::adjustIterationCount(int suggestion) -{ - return suggestion; +{ + return suggestion; } bool QBenchmarkTimeMeasurer::needsWarmupIteration() @@ -80,8 +80,8 @@ bool QBenchmarkTimeMeasurer::needsWarmupIteration() } int QBenchmarkTimeMeasurer::adjustMedianCount(int) -{ - return 1; +{ + return 1; } QTest::QBenchmarkMetric QBenchmarkTimeMeasurer::metricType() @@ -114,18 +114,18 @@ bool QBenchmarkTickMeasurer::isMeasurementAccepted(qint64) } int QBenchmarkTickMeasurer::adjustIterationCount(int) -{ - return 1; +{ + return 1; } int QBenchmarkTickMeasurer::adjustMedianCount(int) -{ - return 1; +{ + return 1; } bool QBenchmarkTickMeasurer::needsWarmupIteration() -{ - return true; +{ + return true; } QTest::QBenchmarkMetric QBenchmarkTickMeasurer::metricType() diff --git a/src/testlib/qbenchmarkmeasurement_p.h b/src/testlib/qbenchmarkmeasurement_p.h index 8242365f20..6d7d8c6c0d 100644 --- a/src/testlib/qbenchmarkmeasurement_p.h +++ b/src/testlib/qbenchmarkmeasurement_p.h @@ -72,8 +72,8 @@ public: virtual bool isMeasurementAccepted(qint64 measurement) = 0; virtual int adjustIterationCount(int suggestion) = 0; virtual int adjustMedianCount(int suggestion) = 0; - virtual bool repeatCount() { return 1; } - virtual bool needsWarmupIteration() { return false; } + virtual bool repeatCount() { return 1; } + virtual bool needsWarmupIteration() { return false; } virtual QTest::QBenchmarkMetric metricType() = 0; }; diff --git a/src/testlib/qbenchmarkmetric.cpp b/src/testlib/qbenchmarkmetric.cpp index d4efe84989..fb7f8f857a 100644 --- a/src/testlib/qbenchmarkmetric.cpp +++ b/src/testlib/qbenchmarkmetric.cpp @@ -46,7 +46,7 @@ \since 4.7 This enum lists all the things that can be benchmarked. - + \value FramesPerSecond Frames per second \value BitsPerSecond Bits per second \value BytesPerSecond Bytes per second diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp index 4b260e8597..7e43d555e0 100644 --- a/src/testlib/qbenchmarkvalgrind.cpp +++ b/src/testlib/qbenchmarkvalgrind.cpp @@ -238,7 +238,7 @@ qint64 QBenchmarkCallgrindMeasurer::checkpoint() } qint64 QBenchmarkCallgrindMeasurer::stop() -{ +{ return checkpoint(); } @@ -249,17 +249,17 @@ bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement) } int QBenchmarkCallgrindMeasurer::adjustIterationCount(int) -{ +{ return 1; } int QBenchmarkCallgrindMeasurer::adjustMedianCount(int) -{ +{ return 1; } bool QBenchmarkCallgrindMeasurer::needsWarmupIteration() -{ +{ return true; } diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index bd1bc11582..14fa752c40 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -211,7 +211,7 @@ void QPlainTestLogger::outputMessage(const char *str) OutputDebugString((wchar_t*)tmp.utf16()); strUtf16.remove(0, maxOutputLength); } while (!strUtf16.isEmpty()); - if (QTestLog::outputFileName()) + if (stream != stdout) #elif defined(Q_OS_WIN) EnterCriticalSection(&QTest::outputCriticalSection); // OutputDebugString is not threadsafe @@ -344,7 +344,8 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) outputMessage(buf); } -QPlainTestLogger::QPlainTestLogger() +QPlainTestLogger::QPlainTestLogger(const char *filename) + : QAbstractTestLogger(filename) { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) InitializeCriticalSection(&QTest::outputCriticalSection); @@ -358,9 +359,9 @@ QPlainTestLogger::~QPlainTestLogger() #endif } -void QPlainTestLogger::startLogging(const char *filename) +void QPlainTestLogger::startLogging() { - QAbstractTestLogger::startLogging(filename); + QAbstractTestLogger::startLogging(); char buf[1024]; if (QTestLog::verboseLevel() < 0) { diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index baa1e24828..432e900320 100644 --- a/src/testlib/qplaintestlogger_p.h +++ b/src/testlib/qplaintestlogger_p.h @@ -60,10 +60,10 @@ QT_BEGIN_NAMESPACE class QPlainTestLogger : public QAbstractTestLogger { public: - QPlainTestLogger(); + QPlainTestLogger(const char *filename); ~QPlainTestLogger(); - void startLogging(const char *filename); + void startLogging(); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qtestassert.h b/src/testlib/qtestassert.h index fa1ee0caec..24edab278d 100644 --- a/src/testlib/qtestassert.h +++ b/src/testlib/qtestassert.h @@ -50,9 +50,9 @@ QT_BEGIN_NAMESPACE QT_MODULE(Test) -#define QTEST_ASSERT(cond) do {if(!(cond))qt_assert(#cond,__FILE__,__LINE__);} while (0) +#define QTEST_ASSERT(cond) do { if (!(cond)) qt_assert(#cond,__FILE__,__LINE__); } while (0) -#define QTEST_ASSERT_X(cond, where, what) do {if(!(cond))qt_assert_x(where, what,__FILE__,__LINE__);} while (0) +#define QTEST_ASSERT_X(cond, where, what) do { if (!(cond)) qt_assert_x(where, what,__FILE__,__LINE__); } while (0) QT_END_NAMESPACE diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp deleted file mode 100644 index d371b4d08e..0000000000 --- a/src/testlib/qtestbasicstreamer.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtestbasicstreamer.h" -#include "qtestlogger_p.h" -#include "qtestelement.h" -#include "qtestelementattribute.h" -#include "qtestassert.h" - -#include <stdio.h> -#include <stdlib.h> - -#ifndef Q_OS_WIN -#include <unistd.h> -#endif - -QT_BEGIN_NAMESPACE - -QTestBasicStreamer::QTestBasicStreamer(QTestLogger *logger) - :testLogger(logger) -{ - QTEST_ASSERT(testLogger); -} - -QTestBasicStreamer::~QTestBasicStreamer() -{} - -void QTestBasicStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted ) - return; - formatted->data()[0] = '\0'; -} - -void QTestBasicStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted ) - return; - formatted->data()[0] = '\0'; -} - -void QTestBasicStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted ) - return; - formatted->data()[0] = '\0'; -} - -void QTestBasicStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted ) - return; - formatted->data()[0] = '\0'; -} - -void QTestBasicStreamer::formatAttributes(const QTestElement *, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const -{ - if(!attribute || !formatted ) - return; - formatted->data()[0] = '\0'; -} - -void QTestBasicStreamer::output(QTestElement *element) const -{ - if(!element) - return; - - outputElements(element); -} - -void QTestBasicStreamer::outputElements(QTestElement *element, bool) const -{ - QTestCharBuffer buf; - bool hasChildren; - /* - Elements are in reverse order of occurrence, so start from the end and work - our way backwards. - */ - while (element && element->nextElement()) { - element = element->nextElement(); - } - while (element) { - hasChildren = element->childElements(); - - formatStart(element, &buf); - outputString(buf.data()); - - formatBeforeAttributes(element, &buf); - outputString(buf.data()); - - outputElementAttributes(element, element->attributes()); - - formatAfterAttributes(element, &buf); - outputString(buf.data()); - - if(hasChildren) - outputElements(element->childElements(), true); - - formatEnd(element, &buf); - outputString(buf.data()); - - element = element->previousElement(); - } -} - -void QTestBasicStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const -{ - QTestCharBuffer buf; - while(attribute){ - formatAttributes(element, attribute, &buf); - outputString(buf.data()); - attribute = attribute->nextElement(); - } -} - -void QTestBasicStreamer::outputString(const char *msg) const -{ - testLogger->outputString(msg); -} - -QTestLogger *QTestBasicStreamer::logger() const -{ - return testLogger; -} - -QT_END_NAMESPACE - diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h deleted file mode 100644 index 04bc40638f..0000000000 --- a/src/testlib/qtestbasicstreamer.h +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTESTBASICSTREAMER_H -#define QTESTBASICSTREAMER_H - -#include <QtCore/qglobal.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Test) - -class QTestElement; -class QTestElementAttribute; -class QTestLogger; -struct QTestCharBuffer; - -class QTestBasicStreamer -{ - public: - QTestBasicStreamer(QTestLogger *logger); - virtual ~QTestBasicStreamer(); - - virtual void output(QTestElement *element) const; - - void outputString(const char *msg) const; - - QTestLogger *logger() const; - - protected: - virtual void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; - virtual void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const; - virtual void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const; - virtual void formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const; - virtual void formatAttributes(const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const; - virtual void outputElements(QTestElement *element, bool isChildElement = false) const; - virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const; - - private: - QTestLogger *testLogger; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 3802794281..9bb591989d 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1000,40 +1000,44 @@ static int qToInt(char *str) Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) { + QTestLog::LogMode logFormat = QTestLog::Plain; + const char *logFilename = 0; + const char *testOptions = - " options:\n" - " -functions : Returns a list of current testfunctions\n" - " -xunitxml : Outputs results as XML XUnit document\n" - " -xml : Outputs results as XML document\n" - " -lightxml : Outputs results as stream of XML tags\n" - " -flush : Flushes the results\n" - " -o filename: Writes all output into a file\n" - " -silent : Only outputs warnings and failures\n" - " -v1 : Print enter messages for each testfunction\n" - " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n" - " -vs : Print every signal emitted\n" - " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" - " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" - " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" - " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n" - " -maxwarnings n : Sets the maximum amount of messages to output.\n" - " 0 means unlimited, default: 2000\n" + " Output options:\n" + " -xunitxml : Outputs results as XML XUnit document\n" + " -xml : Outputs results as XML document\n" + " -lightxml : Outputs results as stream of XML tags\n" + " -o filename : Writes all output into a file\n" + " -silent : Only outputs warnings and failures\n" + " -v1 : Print enter messages for each testfunction\n" + " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n" + " -vs : Print every signal emitted\n" + "\n" + " Testing options:\n" + " -functions : Returns a list of current testfunctions\n" + " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" + " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" + " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" + " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n" + " -maxwarnings n : Sets the maximum amount of messages to output.\n" + " 0 means unlimited, default: 2000\n" #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) - " -nocrashhandler : Disables the crash handler\n" + " -nocrashhandler : Disables the crash handler\n" #endif "\n" - " Benchmark related options:\n" + " Benchmarking options:\n" #ifdef QTESTLIB_USE_VALGRIND - " -callgrind : Use callgrind to time benchmarks\n" + " -callgrind : Use callgrind to time benchmarks\n" #endif #ifdef HAVE_TICK_COUNTER - " -tickcounter : Use CPU tick counters to time benchmarks\n" + " -tickcounter : Use CPU tick counters to time benchmarks\n" #endif - " -eventcounter : Counts events received during benchmarks\n" - " -minimumvalue n : Sets the minimum acceptable measurement value\n" - " -iterations n : Sets the number of accumulation iterations.\n" - " -median n : Sets the number of median iterations.\n" - " -vb : Print out verbose benchmarking information.\n"; + " -eventcounter : Counts events received during benchmarks\n" + " -minimumvalue n : Sets the minimum acceptable measurement value\n" + " -iterations n : Sets the number of accumulation iterations.\n" + " -median n : Sets the number of median iterations.\n" + " -vb : Print out verbose benchmarking information.\n"; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 @@ -1043,15 +1047,16 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) "%s", argv[0], testOptions); if (qml) { - printf ("\nqmltest related options:\n" - " -import : Specify an import directory.\n" - " -input : Specify the root directory for test cases.\n" - " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" + printf ("\n" + " QmlTest options:\n" + " -import : Specify an import directory.\n" + " -input : Specify the root directory for test cases.\n" + " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" ); } printf("\n" - " -help : This help\n"); + " -help : This help\n"); exit(0); } else if (strcmp(argv[i], "-functions") == 0) { if (qml) { @@ -1060,14 +1065,12 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) qPrintTestSlots(stdout); exit(0); } - } else if(strcmp(argv[i], "-xunitxml") == 0){ - QTestLog::setLogMode(QTestLog::XunitXML); + } else if (strcmp(argv[i], "-xunitxml") == 0) { + logFormat = QTestLog::XunitXML; } else if (strcmp(argv[i], "-xml") == 0) { - QTestLog::setLogMode(QTestLog::XML); + logFormat = QTestLog::XML; } else if (strcmp(argv[i], "-lightxml") == 0) { - QTestLog::setLogMode(QTestLog::LightXML); - } else if (strcmp(argv[i], "-flush") == 0){ - QTestLog::setFlushMode(QTestLog::FlushOn); + logFormat = QTestLog::LightXML; } else if (strcmp(argv[i], "-silent") == 0) { QTestLog::setVerboseLevel(-1); } else if (strcmp(argv[i], "-v1") == 0) { @@ -1081,7 +1084,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) fprintf(stderr, "-o needs an extra parameter specifying the filename\n"); exit(1); } else { - QTestLog::redirectOutput(argv[++i]); + logFilename = argv[++i]; } } else if (strcmp(argv[i], "-eventdelay") == 0) { if (i + 1 >= argc) { @@ -1192,7 +1195,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) // we load the QML files. So just store the data for now. int colon = -1; int offset; - for(offset = 0; *(argv[i]+offset); ++offset) { + for (offset = 0; *(argv[i]+offset); ++offset) { if (*(argv[i]+offset) == ':') { if (*(argv[i]+offset+1) == ':') { // "::" is used as a test name separator. @@ -1221,13 +1224,13 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) int colon = -1; char buf[512], *data=0; int off; - for(off = 0; *(argv[i]+off); ++off) { + for (off = 0; *(argv[i]+off); ++off) { if (*(argv[i]+off) == ':') { colon = off; break; } } - if(colon != -1) { + if (colon != -1) { data = qstrdup(argv[i]+colon+1); } QTest::qt_snprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf @@ -1244,6 +1247,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTEST_ASSERT(QTest::testFuncCount < 512); } } + + // Create the logger + QTestLog::initLogger(logFormat, logFilename); } QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container) @@ -1428,7 +1434,7 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) if (data && !foundFunction) { fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); fprintf(stderr, "Available testdata:\n"); - for(int i = 0; i < table.dataCount(); ++i) + for (int i = 0; i < table.dataCount(); ++i) fprintf(stderr, "%s\n", table.testData(i)->dataTag()); return false; } @@ -1479,7 +1485,7 @@ void *fetchData(QTestData *data, const char *tagName, int typeId) */ char *toHexRepresentation(const char *ba, int length) { - if(length == 0) + if (length == 0) return qstrdup(""); /* We output at maximum about maxLen characters in order to avoid @@ -1493,7 +1499,7 @@ char *toHexRepresentation(const char *ba, int length) const int len = qMin(maxLen, length); char *result = 0; - if(length > maxLen) { + if (length > maxLen) { const int size = len * 3 + 4; result = new char[size]; @@ -1514,7 +1520,7 @@ char *toHexRepresentation(const char *ba, int length) int i = 0; int o = 0; - while(true) { + while (true) { const char at = ba[i]; result[o] = toHex[(at >> 4) & 0x0F]; @@ -1523,7 +1529,7 @@ char *toHexRepresentation(const char *ba, int length) ++i; ++o; - if(i == len) + if (i == len) break; else { result[o] = ' '; @@ -1552,7 +1558,7 @@ static void qInvokeTestMethods(QObject *testObject) const bool previousFailed = QTestResult::testFailed(); QTestResult::finishedCurrentTestFunction(); - if(!QTestResult::skipCurrentTest() && !previousFailed) { + if (!QTestResult::skipCurrentTest() && !previousFailed) { if (QTest::testFuncs) { for (int i = 0; i != QTest::testFuncCount; i++) { @@ -1725,18 +1731,18 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) #endif #ifdef Q_WS_MAC - bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); + bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); #ifdef QT_MAC_USE_COCOA - IOPMAssertionID powerID; + IOPMAssertionID powerID; #endif #endif #ifndef QT_NO_EXCEPTIONS try { #endif - #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); - #endif +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); +#endif #ifdef Q_WS_MAC // Starting with Qt 4.4, applications launched from the command line @@ -1745,13 +1751,13 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) if (macNeedsActivate) { ProcessSerialNumber psn = { 0, kCurrentProcess }; SetFrontProcess(&psn); -# ifdef QT_MAC_USE_COCOA +#ifdef QT_MAC_USE_COCOA IOReturn ok = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &powerID); if (ok != kIOReturnSuccess) macNeedsActivate = false; // no need to release the assertion on exit. -# else +#else UpdateSystemActivity(1); // Wake the display. -# endif +#endif } #endif @@ -1813,7 +1819,7 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) throw; return 1; } -# endif +#endif currentTestObject = 0; #ifdef QT_MAC_USE_COCOA @@ -1846,7 +1852,7 @@ int QTest::qExec(QObject *testObject, const QStringList &arguments) QVector<QByteArray> args; args.reserve(argc); - for(int i = 0; i < argc; ++i) + for (int i = 0; i < argc; ++i) { args.append(arguments.at(i).toLocal8Bit().constData()); argv[i] = args.last().data(); diff --git a/src/testlib/qtestcoreelement.h b/src/testlib/qtestcoreelement.h index ecd088ad12..1d06c8d8cd 100644 --- a/src/testlib/qtestcoreelement.h +++ b/src/testlib/qtestcoreelement.h @@ -87,10 +87,7 @@ QTestCoreElement<ElementType>::~QTestCoreElement() template <class ElementType> void QTestCoreElement<ElementType>::addAttribute(const QTest::AttributeIndex attributeIndex, const char *value) { - if(attributeIndex == -1) - return; - - if (attribute(attributeIndex)) + if (attributeIndex == -1 || attribute(attributeIndex)) return; QTestElementAttribute *testAttribute = new QTestElementAttribute; @@ -108,7 +105,7 @@ template <class ElementType> const char *QTestCoreElement<ElementType>::attributeValue(QTest::AttributeIndex index) const { const QTestElementAttribute *attrb = attribute(index); - if(attrb) + if (attrb) return attrb->value(); return 0; @@ -118,7 +115,7 @@ template <class ElementType> const char *QTestCoreElement<ElementType>::attributeName(QTest::AttributeIndex index) const { const QTestElementAttribute *attrb = attribute(index); - if(attrb) + if (attrb) return attrb->name(); return 0; @@ -139,7 +136,7 @@ const char *QTestCoreElement<ElementType>::elementName() const "system-err" }; - if(type != QTest::LET_Undefined) + if (type != QTest::LET_Undefined) return xmlElementNames[type]; return 0; @@ -155,8 +152,8 @@ template <class ElementType> const QTestElementAttribute *QTestCoreElement<ElementType>::attribute(QTest::AttributeIndex index) const { QTestElementAttribute *iterator = listOfAttributes; - while(iterator){ - if(iterator->index() == index) + while (iterator) { + if (iterator->index() == index) return iterator; iterator = iterator->nextElement(); diff --git a/src/testlib/qtestcorelist.h b/src/testlib/qtestcorelist.h index 0790ea5c39..5027e4fcf9 100644 --- a/src/testlib/qtestcorelist.h +++ b/src/testlib/qtestcorelist.h @@ -70,8 +70,8 @@ class QTestCoreList template <class T> QTestCoreList<T>::QTestCoreList() -:next(0) -,prev(0) + : next(0) + , prev(0) { } @@ -121,7 +121,7 @@ int QTestCoreList<T>::count() int numOfElements = 0; T *it = next; - while(it){ + while (it) { ++numOfElements; it = it->nextElement(); } diff --git a/src/testlib/qtestdata.cpp b/src/testlib/qtestdata.cpp index d32a591eff..6797abf1d0 100644 --- a/src/testlib/qtestdata.cpp +++ b/src/testlib/qtestdata.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE class QTestDataPrivate { public: - QTestDataPrivate(): tag(0), parent(0), data(0), dataCount(0) {} + QTestDataPrivate() : tag(0), parent(0), data(0), dataCount(0) {} char *tag; QTestTable *parent; diff --git a/src/testlib/qtestelement.cpp b/src/testlib/qtestelement.cpp index 3dc5ba60a8..a3c002f964 100644 --- a/src/testlib/qtestelement.cpp +++ b/src/testlib/qtestelement.cpp @@ -44,9 +44,9 @@ QT_BEGIN_NAMESPACE QTestElement::QTestElement(int type) - :QTestCoreElement<QTestElement>(type), - listOfChildren(0), - parent(0) + : QTestCoreElement<QTestElement>(type) + , listOfChildren(0) + , parent(0) { } @@ -57,10 +57,10 @@ QTestElement::~QTestElement() bool QTestElement::addLogElement(QTestElement *element) { - if(!element) + if (!element) return false; - if(element->elementType() != QTest::LET_Undefined){ + if (element->elementType() != QTest::LET_Undefined) { element->addToList(&listOfChildren); element->setParent(this); return true; diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp index dcd518ca2a..9799ade577 100644 --- a/src/testlib/qtestelementattribute.cpp +++ b/src/testlib/qtestelementattribute.cpp @@ -50,37 +50,37 @@ QT_BEGIN_NAMESPACE This enum numbers the different tests. \value AI_Undefined - + \value AI_Name - + \value AI_Result - + \value AI_Tests - + \value AI_Failures - + \value AI_Errors - + \value AI_Type - + \value AI_Description - + \value AI_PropertyValue - + \value AI_QTestVersion - + \value AI_QtVersion - + \value AI_File - + \value AI_Line - + \value AI_Metric - + \value AI_Tag - + \value AI_Value - + \value AI_Iterations */ @@ -144,7 +144,7 @@ const char *QTestElementAttribute::name() const "iterations" }; - if(attributeIndex != QTest::AI_Undefined) + if (attributeIndex != QTest::AI_Undefined) return AttributeNames[attributeIndex]; return 0; @@ -162,7 +162,7 @@ bool QTestElementAttribute::isNull() const bool QTestElementAttribute::setPair(QTest::AttributeIndex index, const char *value) { - if(!value) + if (!value) return false; delete[] attributeValue; diff --git a/src/testlib/qtestkeyboard.h b/src/testlib/qtestkeyboard.h index be141642e8..9f8bf2536a 100644 --- a/src/testlib/qtestkeyboard.h +++ b/src/testlib/qtestkeyboard.h @@ -75,7 +75,7 @@ namespace QTest if (delay == -1 || delay < defaultKeyDelay()) delay = defaultKeyDelay(); - if(delay > 0) + if (delay > 0) QTest::qWait(delay); QKeyEvent a(press ? QEvent::KeyPress : QEvent::KeyRelease, code, modifier, text, repeat); diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp deleted file mode 100644 index c0010cc522..0000000000 --- a/src/testlib/qtestlightxmlstreamer.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtestlightxmlstreamer.h" -#include "qtestelement.h" -#include "qtestelementattribute.h" -#include "qtestlogger_p.h" - -#include "QtTest/private/qtestlog_p.h" -#include "QtTest/private/qtestresult_p.h" -#include "QtTest/private/qxmltestlogger_p.h" - -#include <string.h> - -QT_BEGIN_NAMESPACE - -QTestLightXmlStreamer::QTestLightXmlStreamer(QTestLogger *logger) - : QTestBasicStreamer(logger) -{ -} - -QTestLightXmlStreamer::~QTestLightXmlStreamer() -{} - -void QTestLightXmlStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted) - return; - - switch(element->elementType()){ - case QTest::LET_TestCase: { - QTestCharBuffer quotedTf; - QXmlTestLogger::xmlQuote("edTf, element->attributeValue(QTest::AI_Name)); - - QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData()); - break; - } - case QTest::LET_Failure: { - QTestCharBuffer cdataDesc; - QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); - - QTest::qt_asprintf(formatted, " <Description><![CDATA[%s]]></Description>\n", - cdataDesc.constData()); - break; - } - case QTest::LET_Error: { - // assuming type and attribute names don't need quoting - QTestCharBuffer quotedFile; - QTestCharBuffer cdataDesc; - QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); - QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); - - QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n <Description><![CDATA[%s]]></Description>\n</Message>\n", - element->attributeValue(QTest::AI_Type), - element->attributeName(QTest::AI_File), - quotedFile.constData(), - element->attributeName(QTest::AI_Line), - element->attributeValue(QTest::AI_Line), - cdataDesc.constData()); - break; - } - case QTest::LET_Benchmark: { - // assuming value and iterations don't need quoting - QTestCharBuffer quotedMetric; - QTestCharBuffer quotedTag; - QXmlTestLogger::xmlQuote("edMetric, element->attributeValue(QTest::AI_Metric)); - QXmlTestLogger::xmlQuote("edTag, element->attributeValue(QTest::AI_Tag)); - - QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n", - element->attributeName(QTest::AI_Metric), - quotedMetric.constData(), - element->attributeName(QTest::AI_Tag), - quotedTag.constData(), - element->attributeName(QTest::AI_Value), - element->attributeValue(QTest::AI_Value), - element->attributeName(QTest::AI_Iterations), - element->attributeValue(QTest::AI_Iterations) ); - break; - } - default: - formatted->data()[0] = '\0'; - } -} - -void QTestLightXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted) - return; - - if (element->elementType() == QTest::LET_TestCase) { - if( element->attribute(QTest::AI_Result) && element->childElements()) - QTest::qt_asprintf(formatted, "</Incident>\n</TestFunction>\n"); - else - QTest::qt_asprintf(formatted, "</TestFunction>\n"); - } else { - formatted->data()[0] = '\0'; - } -} - -void QTestLightXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted) - return; - - if (element->elementType() == QTest::LET_TestCase && element->attribute(QTest::AI_Result)) { - QTestCharBuffer buf; - QTestCharBuffer quotedFile; - QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); - - QTest::qt_asprintf(&buf, "%s=\"%s\" %s=\"%s\"", - element->attributeName(QTest::AI_File), - quotedFile.constData(), - element->attributeName(QTest::AI_Line), - element->attributeValue(QTest::AI_Line)); - - if( !element->childElements() ) - QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s/>\n", - element->attributeValue(QTest::AI_Result), buf.constData()); - else - QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n", - element->attributeValue(QTest::AI_Result), buf.constData()); - } else { - formatted->data()[0] = '\0'; - } -} - -void QTestLightXmlStreamer::output(QTestElement *element) const -{ - QTestCharBuffer buf; - QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n", - qVersion(), QTEST_VERSION_STR ); - outputString(buf.constData()); - - QTest::qt_asprintf(&buf, "</Environment>\n"); - outputString(buf.constData()); - - QTestBasicStreamer::output(element); -} - -QT_END_NAMESPACE - diff --git a/src/testlib/qtestlightxmlstreamer.h b/src/testlib/qtestlightxmlstreamer.h deleted file mode 100644 index b3076c1623..0000000000 --- a/src/testlib/qtestlightxmlstreamer.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTESTLIGHTXMLSTREAMER_H -#define QTESTLIGHTXMLSTREAMER_H - -#include <QtTest/qtestbasicstreamer.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Test) - -class QTestElement; -class QTestElementAttribute; - -class QTestLightXmlStreamer: public QTestBasicStreamer -{ - public: - QTestLightXmlStreamer(QTestLogger *logger); - ~QTestLightXmlStreamer(); - - void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; - void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const; - void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const; - void output(QTestElement *element) const; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 0a87a4ce14..d53b00ca7f 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -45,7 +45,7 @@ #include "QtTest/private/qtestresult_p.h" #include "QtTest/private/qabstracttestlogger_p.h" #include "QtTest/private/qplaintestlogger_p.h" -#include "QtTest/private/qtestlogger_p.h" +#include "QtTest/private/qxunittestlogger_p.h" #include "QtTest/private/qxmltestlogger_p.h" #include <QtCore/qatomic.h> #include <QtCore/qbytearray.h> @@ -83,12 +83,10 @@ namespace QTest { static IgnoreResultList *ignoreResultList = 0; static QTestLog::LogMode logMode = QTestLog::Plain; - static QTestLog::FlushMode flushMode = QTestLog::NoFlush; static int verbosity = 0; static int maxWarnings = 2002; static QAbstractTestLogger *testLogger = 0; - static const char *outFile = 0; static QtMsgHandler oldMessageHandler; @@ -165,30 +163,6 @@ namespace QTest { break; } } - - void initLogger() - { - switch (QTest::logMode) { - case QTestLog::Plain: - QTest::testLogger = new QPlainTestLogger; - break; - case QTestLog::XML: - if (QTest::flushMode == QTestLog::FlushOn) - QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete); - else - QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML); - break; - case QTestLog::LightXML: - if (QTest::flushMode == QTestLog::FlushOn) - QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light); - else - QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml); - break; - case QTestLog::XunitXML: - QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml); - } - } - } void QTestLog::enterTestFunction(const char* function) @@ -283,9 +257,8 @@ void QTestLog::addBenchmarkResult(const QBenchmarkResult &result) void QTestLog::startLogging() { - QTEST_ASSERT(!QTest::testLogger); - QTest::initLogger(); - QTest::testLogger->startLogging(QTest::outFile); + QTEST_ASSERT(QTest::testLogger); + QTest::testLogger->startLogging(); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } @@ -299,6 +272,27 @@ void QTestLog::stopLogging() QTest::testLogger = 0; } +void QTestLog::initLogger(LogMode mode, const char *filename) +{ + QTest::logMode = mode; + + switch (mode) { + case QTestLog::Plain: + QTest::testLogger = new QPlainTestLogger(filename); + break; + case QTestLog::XML: + QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete, filename); + break; + case QTestLog::LightXML: + QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light, filename); + break; + case QTestLog::XunitXML: + QTest::testLogger = new QXunitTestLogger(filename); + break; + } + QTEST_ASSERT(QTest::testLogger); +} + void QTestLog::warn(const char *msg) { QTEST_ASSERT(QTest::testLogger); @@ -315,11 +309,6 @@ void QTestLog::info(const char *msg, const char *file, int line) QTest::testLogger->addMessage(QAbstractTestLogger::Info, msg, file, line); } -void QTestLog::setLogMode(LogMode mode) -{ - QTest::logMode = mode; -} - QTestLog::LogMode QTestLog::logMode() { return QTest::logMode; @@ -351,26 +340,9 @@ void QTestLog::addIgnoreMessage(QtMsgType type, const char *msg) list->next = item; } -void QTestLog::redirectOutput(const char *fileName) -{ - QTEST_ASSERT(fileName); - - QTest::outFile = fileName; -} - -const char *QTestLog::outputFileName() -{ - return QTest::outFile; -} - void QTestLog::setMaxWarnings(int m) { QTest::maxWarnings = m <= 0 ? INT_MAX : m + 2; } -void QTestLog::setFlushMode(FlushMode mode) -{ - QTest::flushMode = mode; -} - QT_END_NAMESPACE diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index 9b580eb8cc..f06382978f 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -63,7 +63,6 @@ class Q_TESTLIB_EXPORT QTestLog { public: enum LogMode { Plain = 0, XML, LightXML, XunitXML }; - enum FlushMode { NoFlush = 0, FlushOn }; static void enterTestFunction(const char* function); static void leaveTestFunction(); @@ -84,18 +83,15 @@ public: static void startLogging(); static void stopLogging(); - static void setLogMode(LogMode mode); + static void initLogger(LogMode mode, const char *filename); + static LogMode logMode(); static void setVerboseLevel(int level); static int verboseLevel(); - static void redirectOutput(const char *fileName); - static const char *outputFileName(); - static void setMaxWarnings(int max); - static void setFlushMode(FlushMode mode); private: QTestLog(); ~QTestLog(); diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h index c8fe0b4849..1bdb0241c0 100644 --- a/src/testlib/qtestmouse.h +++ b/src/testlib/qtestmouse.h @@ -76,7 +76,7 @@ namespace QTest if (delay == -1 || delay < defaultMouseDelay()) delay = defaultMouseDelay(); - if(delay > 0) + if (delay > 0) QTest::qWait(delay); if (pos.isNull()) diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp deleted file mode 100644 index 47c4463b5a..0000000000 --- a/src/testlib/qtestxmlstreamer.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtestxmlstreamer.h" -#include "qtestelement.h" -#include "qtestelementattribute.h" -#include "qtestlogger_p.h" - -#include "QtTest/private/qtestlog_p.h" -#include "QtTest/private/qtestresult_p.h" -#include "QtTest/private/qxmltestlogger_p.h" - -#include <string.h> -#include <stdio.h> - -QT_BEGIN_NAMESPACE - -QTestXmlStreamer::QTestXmlStreamer(QTestLogger *logger) - : QTestBasicStreamer(logger) -{ -} - -QTestXmlStreamer::~QTestXmlStreamer() -{} - -void QTestXmlStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted) - return; - - switch(element->elementType()){ - case QTest::LET_TestCase: { - QTestCharBuffer quotedTf; - QXmlTestLogger::xmlQuote("edTf, element->attributeValue(QTest::AI_Name)); - - QTest::qt_asprintf(formatted, "<TestFunction name=\"%s\">\n", quotedTf.constData()); - break; - } - case QTest::LET_Failure: { - QTestCharBuffer cdataDesc; - QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); - - QTestCharBuffer location; - QTestCharBuffer quotedFile; - QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); - - QTest::qt_asprintf(&location, "%s=\"%s\" %s=\"%s\"", - element->attributeName(QTest::AI_File), - quotedFile.constData(), - element->attributeName(QTest::AI_Line), - element->attributeValue(QTest::AI_Line)); - - if (element->attribute(QTest::AI_Tag)) { - QTestCharBuffer cdataTag; - QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag)); - QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n" - " <DataTag><![CDATA[%s]]></DataTag>\n" - " <Description><![CDATA[%s]]></Description>\n" - "</Incident>\n", element->attributeValue(QTest::AI_Result), - location.constData(), cdataTag.constData(), cdataDesc.constData()); - } - else { - QTest::qt_asprintf(formatted, "<Incident type=\"%s\" %s>\n" - " <Description><![CDATA[%s]]></Description>\n" - "</Incident>\n", element->attributeValue(QTest::AI_Result), - location.constData(), cdataDesc.constData()); - } - break; - } - case QTest::LET_Error: { - // assuming type and attribute names don't need quoting - QTestCharBuffer quotedFile; - QTestCharBuffer cdataDesc; - QXmlTestLogger::xmlQuote("edFile, element->attributeValue(QTest::AI_File)); - QXmlTestLogger::xmlCdata(&cdataDesc, element->attributeValue(QTest::AI_Description)); - - QTestCharBuffer tagbuf; - if (element->attribute(QTest::AI_Tag)) { - QTestCharBuffer cdataTag; - QXmlTestLogger::xmlCdata(&cdataTag, element->attributeValue(QTest::AI_Tag)); - QTest::qt_asprintf(&tagbuf, " <DataTag><![CDATA[%s]]></DataTag>\n", cdataTag.constData()); - } - - QTest::qt_asprintf(formatted, "<Message type=\"%s\" %s=\"%s\" %s=\"%s\">\n%s <Description><![CDATA[%s]]></Description>\n</Message>\n", - element->attributeValue(QTest::AI_Type), - element->attributeName(QTest::AI_File), - quotedFile.constData(), - element->attributeName(QTest::AI_Line), - element->attributeValue(QTest::AI_Line), - tagbuf.constData(), - cdataDesc.constData()); - break; - } - case QTest::LET_Benchmark: { - // assuming value and iterations don't need quoting - QTestCharBuffer quotedMetric; - QTestCharBuffer quotedTag; - QXmlTestLogger::xmlQuote("edMetric, element->attributeValue(QTest::AI_Metric)); - QXmlTestLogger::xmlQuote("edTag, element->attributeValue(QTest::AI_Tag)); - - QTest::qt_asprintf(formatted, "<BenchmarkResult %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\" />\n", - element->attributeName(QTest::AI_Metric), - quotedMetric.constData(), - element->attributeName(QTest::AI_Tag), - quotedTag.constData(), - element->attributeName(QTest::AI_Value), - element->attributeValue(QTest::AI_Value), - element->attributeName(QTest::AI_Iterations), - element->attributeValue(QTest::AI_Iterations) ); - break; - } - default: - formatted->data()[0] = '\0'; - } -} - -void QTestXmlStreamer::formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const -{ - if(!element || !formatted) - return; - - if (element->elementType() == QTest::LET_TestCase) { - bool failed = false; - for (QTestElement* child = element->childElements(); child; child = child->nextElement()) { - if ( child->elementType() == QTest::LET_Failure - && child->attribute(QTest::AI_Result) - && ( !strcmp(child->attributeValue(QTest::AI_Result), "fail") - || !strcmp(child->attributeValue(QTest::AI_Result), "xpass")) - ) - { - failed = true; - break; - } - } - - // For passing functions, no Incident has been output yet. - // For failing functions, we already output one. - // Please note: we are outputting "pass" even if there was an xfail etc. - // This is by design (arguably bad design, but dangerous to change now!) - if (element->attribute(QTest::AI_Result) && !failed) { - QTest::qt_asprintf(formatted, "<Incident type=\"pass\" file=\"\" line=\"0\" />\n</TestFunction>\n"); - } - else { - QTest::qt_asprintf(formatted, "</TestFunction>\n"); - } - } else { - formatted->data()[0] = '\0'; - } -} - -void QTestXmlStreamer::formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const -{ - Q_UNUSED(element); - if (!formatted) - return; - - formatted->data()[0] = '\0'; -} - -void QTestXmlStreamer::output(QTestElement *element) const -{ - QTestCharBuffer buf; - QTestCharBuffer quotedTc; - QXmlTestLogger::xmlQuote("edTc, QTestResult::currentTestObjectName()); - - QTest::qt_asprintf(&buf, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<TestCase name=\"%s\">\n", - quotedTc.constData()); - outputString(buf.constData()); - - QTest::qt_asprintf(&buf, "<Environment>\n <QtVersion>%s</QtVersion>\n <QTestVersion>%s</QTestVersion>\n", - qVersion(), QTEST_VERSION_STR ); - outputString(buf.constData()); - - QTest::qt_asprintf(&buf, "</Environment>\n"); - outputString(buf.constData()); - - QTestBasicStreamer::output(element); - - QTest::qt_asprintf(&buf, "</TestCase>\n"); - outputString(buf.constData()); -} - -QT_END_NAMESPACE - diff --git a/src/testlib/qtestxmlstreamer.h b/src/testlib/qtestxmlstreamer.h deleted file mode 100644 index 96e8246779..0000000000 --- a/src/testlib/qtestxmlstreamer.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTESTXMLSTREAMER_H -#define QTESTXMLSTREAMER_H - -#include <QtTest/qtestbasicstreamer.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Test) - -class QTestElement; -class QTestElementAttribute; - -class QTestXmlStreamer: public QTestBasicStreamer -{ - public: - QTestXmlStreamer(QTestLogger *logger); - ~QTestXmlStreamer(); - - void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; - void formatEnd(const QTestElement *element, QTestCharBuffer *formatted) const; - void formatBeforeAttributes(const QTestElement *element, QTestCharBuffer *formatted) const; - void output(QTestElement *element) const; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp index fb9699eef1..3e9c2feffc 100644 --- a/src/testlib/qtestxunitstreamer.cpp +++ b/src/testlib/qtestxunitstreamer.cpp @@ -40,7 +40,10 @@ ****************************************************************************/ #include "qtestxunitstreamer.h" +#include "qxunittestlogger_p.h" #include "qtestelement.h" +#include "qtestelementattribute.h" +#include "qtestassert.h" #include "QtTest/private/qtestlog_p.h" #include "QtTest/private/qtestresult_p.h" @@ -48,9 +51,11 @@ QT_BEGIN_NAMESPACE -QTestXunitStreamer::QTestXunitStreamer(QTestLogger *logger) - : QTestBasicStreamer(logger) -{} +QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger) + : testLogger(logger) +{ + QTEST_ASSERT(testLogger); +} QTestXunitStreamer::~QTestXunitStreamer() {} @@ -75,7 +80,7 @@ void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf void QTestXunitStreamer::formatStart(const QTestElement *element, QTestCharBuffer *formatted) const { - if(!element || !formatted ) + if (!element || !formatted ) return; char indent[20]; @@ -99,7 +104,7 @@ void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer if (!element || !formatted ) return; - if (!element->childElements()){ + if (!element->childElements()) { formatted->data()[0] = '\0'; return; } @@ -112,7 +117,7 @@ void QTestXunitStreamer::formatEnd(const QTestElement *element, QTestCharBuffer void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const { - if(!attribute || !formatted ) + if (!attribute || !formatted ) return; QTest::AttributeIndex attrindex = attribute->index(); @@ -144,7 +149,7 @@ void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTe void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTestCharBuffer *formatted) const { - if(!element || !formatted ) + if (!element || !formatted ) return; // Errors are written as CDATA within system-err, comments elsewhere @@ -157,7 +162,7 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTes return; } - if(!element->childElements()) + if (!element->childElements()) QTest::qt_asprintf(formatted, "/>\n"); else QTest::qt_asprintf(formatted, ">\n"); @@ -165,8 +170,10 @@ void QTestXunitStreamer::formatAfterAttributes(const QTestElement *element, QTes void QTestXunitStreamer::output(QTestElement *element) const { + QTEST_ASSERT(element); + outputString("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); - QTestBasicStreamer::output(element); + outputElements(element); } void QTestXunitStreamer::outputElements(QTestElement *element, bool) const @@ -183,19 +190,16 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const while (element) { hasChildren = element->childElements(); - if(element->elementType() != QTest::LET_Benchmark){ + if (element->elementType() != QTest::LET_Benchmark) { formatStart(element, &buf); outputString(buf.data()); - formatBeforeAttributes(element, &buf); - outputString(buf.data()); - outputElementAttributes(element, element->attributes()); formatAfterAttributes(element, &buf); outputString(buf.data()); - if(hasChildren) + if (hasChildren) outputElements(element->childElements(), true); formatEnd(element, &buf); @@ -205,5 +209,19 @@ void QTestXunitStreamer::outputElements(QTestElement *element, bool) const } } -QT_END_NAMESPACE +void QTestXunitStreamer::outputElementAttributes(const QTestElement* element, QTestElementAttribute *attribute) const +{ + QTestCharBuffer buf; + while (attribute) { + formatAttributes(element, attribute, &buf); + outputString(buf.data()); + attribute = attribute->nextElement(); + } +} +void QTestXunitStreamer::outputString(const char *msg) const +{ + testLogger->outputString(msg); +} + +QT_END_NAMESPACE diff --git a/src/testlib/qtestxunitstreamer.h b/src/testlib/qtestxunitstreamer.h index 4d1cb2734a..127c9b1780 100644 --- a/src/testlib/qtestxunitstreamer.h +++ b/src/testlib/qtestxunitstreamer.h @@ -42,7 +42,7 @@ #ifndef QTESTXUNITSTREAMER_H #define QTESTXUNITSTREAMER_H -#include <QtTest/qtestbasicstreamer.h> +#include <QtCore/qglobal.h> QT_BEGIN_HEADER @@ -50,12 +50,15 @@ QT_BEGIN_NAMESPACE QT_MODULE(Test) -class QTestLogger; +class QTestElement; +class QTestElementAttribute; +class QXunitTestLogger; +struct QTestCharBuffer; -class QTestXunitStreamer: public QTestBasicStreamer +class QTestXunitStreamer { public: - QTestXunitStreamer(QTestLogger *logger); + QTestXunitStreamer(QXunitTestLogger *logger); ~QTestXunitStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; @@ -64,10 +67,15 @@ class QTestXunitStreamer: public QTestBasicStreamer void formatAttributes(const QTestElement *element, const QTestElementAttribute *attribute, QTestCharBuffer *formatted) const; void output(QTestElement *element) const; void outputElements(QTestElement *element, bool isChildElement = false) const; + void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const; + + void outputString(const char *msg) const; private: void displayXunitXmlHeader() const; static void indentForElement(const QTestElement* element, char* buf, int size); + + QXunitTestLogger *testLogger; }; QT_END_NAMESPACE diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index 5ed7079ab6..304cd0a0ef 100644 --- a/src/testlib/qxmltestlogger.cpp +++ b/src/testlib/qxmltestlogger.cpp @@ -92,8 +92,8 @@ namespace QTest { } -QXmlTestLogger::QXmlTestLogger(XmlMode mode ) - : xmlmode(mode) +QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename) + : QAbstractTestLogger(filename), xmlmode(mode) { } @@ -101,9 +101,9 @@ QXmlTestLogger::~QXmlTestLogger() { } -void QXmlTestLogger::startLogging(const char *filename) +void QXmlTestLogger::startLogging() { - QAbstractTestLogger::startLogging(filename); + QAbstractTestLogger::startLogging(); QTestCharBuffer buf; if (xmlmode == QXmlTestLogger::Complete) { @@ -115,7 +115,7 @@ void QXmlTestLogger::startLogging(const char *filename) outputString(buf.constData()); } - QTest::qt_asprintf(&buf, + QTest::qt_asprintf(&buf, "<Environment>\n" " <QtVersion>%s</QtVersion>\n" " <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n" diff --git a/src/testlib/qxmltestlogger_p.h b/src/testlib/qxmltestlogger_p.h index c08f5e469e..c273493c48 100644 --- a/src/testlib/qxmltestlogger_p.h +++ b/src/testlib/qxmltestlogger_p.h @@ -63,10 +63,10 @@ class QXmlTestLogger : public QAbstractTestLogger public: enum XmlMode { Complete = 0, Light }; - QXmlTestLogger(XmlMode mode = Complete); + QXmlTestLogger(XmlMode mode, const char *filename); ~QXmlTestLogger(); - void startLogging(const char *filename); + void startLogging(); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qxunittestlogger.cpp index 385fb866c2..f923b2334b 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qxunittestlogger.cpp @@ -39,11 +39,9 @@ ** ****************************************************************************/ -#include "qtestlogger_p.h" +#include "qxunittestlogger_p.h" #include "qtestelement.h" #include "qtestxunitstreamer.h" -#include "qtestxmlstreamer.h" -#include "qtestlightxmlstreamer.h" #include "QtTest/qtestcase.h" #include "QtTest/private/qtestresult_p.h" @@ -53,102 +51,84 @@ QT_BEGIN_NAMESPACE -QTestLogger::QTestLogger(int fm) - : listOfTestcases(0) +QXunitTestLogger::QXunitTestLogger(const char *filename) + : QAbstractTestLogger(filename) + , listOfTestcases(0) , currentLogElement(0) , errorLogElement(0) , logFormatter(0) - , format( (TestLoggerFormat)fm ) , testCounter(0) , failureCounter(0) , errorCounter(0) { } -QTestLogger::~QTestLogger() +QXunitTestLogger::~QXunitTestLogger() { - if(format == TLF_XunitXml) - delete currentLogElement; - else - delete listOfTestcases; - + delete currentLogElement; delete logFormatter; } -void QTestLogger::startLogging(const char *filename) +void QXunitTestLogger::startLogging() { - QAbstractTestLogger::startLogging(filename); + QAbstractTestLogger::startLogging(); - switch(format){ - case TLF_LightXml: - logFormatter = new QTestLightXmlStreamer(this); - break; - case TLF_XML: - logFormatter = new QTestXmlStreamer(this); - break; - case TLF_XunitXml: - logFormatter = new QTestXunitStreamer(this); - delete errorLogElement; - errorLogElement = new QTestElement(QTest::LET_SystemError); - break; - } + logFormatter = new QTestXunitStreamer(this); + delete errorLogElement; + errorLogElement = new QTestElement(QTest::LET_SystemError); } -void QTestLogger::stopLogging() +void QXunitTestLogger::stopLogging() { QTestElement *iterator = listOfTestcases; - if(format == TLF_XunitXml ){ - char buf[10]; + char buf[10]; - currentLogElement = new QTestElement(QTest::LET_TestSuite); - currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName()); + currentLogElement = new QTestElement(QTest::LET_TestSuite); + currentLogElement->addAttribute(QTest::AI_Name, QTestResult::currentTestObjectName()); - QTest::qt_snprintf(buf, sizeof(buf), "%i", testCounter); - currentLogElement->addAttribute(QTest::AI_Tests, buf); + QTest::qt_snprintf(buf, sizeof(buf), "%i", testCounter); + currentLogElement->addAttribute(QTest::AI_Tests, buf); - QTest::qt_snprintf(buf, sizeof(buf), "%i", failureCounter); - currentLogElement->addAttribute(QTest::AI_Failures, buf); + QTest::qt_snprintf(buf, sizeof(buf), "%i", failureCounter); + currentLogElement->addAttribute(QTest::AI_Failures, buf); - QTest::qt_snprintf(buf, sizeof(buf), "%i", errorCounter); - currentLogElement->addAttribute(QTest::AI_Errors, buf); + QTest::qt_snprintf(buf, sizeof(buf), "%i", errorCounter); + currentLogElement->addAttribute(QTest::AI_Errors, buf); - QTestElement *property; - QTestElement *properties = new QTestElement(QTest::LET_Properties); + QTestElement *property; + QTestElement *properties = new QTestElement(QTest::LET_Properties); - property = new QTestElement(QTest::LET_Property); - property->addAttribute(QTest::AI_Name, "QTestVersion"); - property->addAttribute(QTest::AI_PropertyValue, QTEST_VERSION_STR); - properties->addLogElement(property); + property = new QTestElement(QTest::LET_Property); + property->addAttribute(QTest::AI_Name, "QTestVersion"); + property->addAttribute(QTest::AI_PropertyValue, QTEST_VERSION_STR); + properties->addLogElement(property); - property = new QTestElement(QTest::LET_Property); - property->addAttribute(QTest::AI_Name, "QtVersion"); - property->addAttribute(QTest::AI_PropertyValue, qVersion()); - properties->addLogElement(property); + property = new QTestElement(QTest::LET_Property); + property->addAttribute(QTest::AI_Name, "QtVersion"); + property->addAttribute(QTest::AI_PropertyValue, qVersion()); + properties->addLogElement(property); - currentLogElement->addLogElement(properties); + currentLogElement->addLogElement(properties); - currentLogElement->addLogElement(iterator); + currentLogElement->addLogElement(iterator); - /* For correct indenting, make sure every testcase knows its parent */ - QTestElement* testcase = iterator; - while (testcase) { - testcase->setParent(currentLogElement); - testcase = testcase->nextElement(); - } + /* For correct indenting, make sure every testcase knows its parent */ + QTestElement* testcase = iterator; + while (testcase) { + testcase->setParent(currentLogElement); + testcase = testcase->nextElement(); + } - currentLogElement->addLogElement(errorLogElement); + currentLogElement->addLogElement(errorLogElement); - QTestElement *it = currentLogElement; - logFormatter->output(it); - }else{ - logFormatter->output(iterator); - } + QTestElement *it = currentLogElement; + logFormatter->output(it); QAbstractTestLogger::stopLogging(); } -void QTestLogger::enterTestFunction(const char *function) +void QXunitTestLogger::enterTestFunction(const char *function) { currentLogElement = new QTestElement(QTest::LET_TestCase); currentLogElement->addAttribute(QTest::AI_Name, function); @@ -157,12 +137,12 @@ void QTestLogger::enterTestFunction(const char *function) ++testCounter; } -void QTestLogger::leaveTestFunction() +void QXunitTestLogger::leaveTestFunction() { } -void QTestLogger::addIncident(IncidentTypes type, const char *description, - const char *file, int line) +void QXunitTestLogger::addIncident(IncidentTypes type, const char *description, + const char *file, int line) { const char *typeBuf = 0; char buf[100]; @@ -187,11 +167,10 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, break; } - if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass - || ((format != TLF_XunitXml) && (type == QAbstractTestLogger::XFail))) { + if (type == QAbstractTestLogger::Fail || type == QAbstractTestLogger::XPass) { QTestElement *failureElement = new QTestElement(QTest::LET_Failure); failureElement->addAttribute(QTest::AI_Result, typeBuf); - if(file) + if (file) failureElement->addAttribute(QTest::AI_File, file); else failureElement->addAttribute(QTest::AI_File, ""); @@ -229,7 +208,7 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, currentLogElement->addAttribute(QTest::AI_Result, typeBuf); } - if(file) + if (file) currentLogElement->addAttribute(QTest::AI_File, file); else currentLogElement->addAttribute(QTest::AI_File, ""); @@ -241,12 +220,12 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, Since XFAIL does not add a failure to the testlog in xunitxml, add a message, so we still have some information about the expected failure. */ - if (format == TLF_XunitXml && type == QAbstractTestLogger::XFail) { - QTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line); + if (type == QAbstractTestLogger::XFail) { + QXunitTestLogger::addMessage(QAbstractTestLogger::Info, description, file, line); } } -void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) +void QXunitTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark); @@ -262,7 +241,7 @@ void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) currentLogElement->addLogElement(benchmarkElement); } -void QTestLogger::addTag(QTestElement* element) +void QXunitTestLogger::addTag(QTestElement* element) { const char *tag = QTestResult::currentDataTag(); const char *gtag = QTestResult::currentGlobalDataTag(); @@ -283,7 +262,7 @@ void QTestLogger::addTag(QTestElement* element) element->addAttribute(QTest::AI_Tag, buf.constData()); } -void QTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line) +void QXunitTestLogger::addMessage(MessageTypes type, const char *message, const char *file, int line) { QTestElement *errorElement = new QTestElement(QTest::LET_Error); const char *typeBuf = 0; @@ -319,7 +298,7 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char errorElement->addAttribute(QTest::AI_Description, message); addTag(errorElement); - if(file) + if (file) errorElement->addAttribute(QTest::AI_File, file); else errorElement->addAttribute(QTest::AI_File, ""); diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qxunittestlogger_p.h index 5e5b0f2f3f..a51d70533d 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qxunittestlogger_p.h @@ -57,23 +57,16 @@ QT_BEGIN_NAMESPACE -class QTestBasicStreamer; +class QTestXunitStreamer; class QTestElement; -class QTestLogger : public QAbstractTestLogger +class QXunitTestLogger : public QAbstractTestLogger { public: - QTestLogger(int fm = 0); - ~QTestLogger(); + QXunitTestLogger(const char *filename); + ~QXunitTestLogger(); - enum TestLoggerFormat - { - TLF_XML = 0, - TLF_LightXml = 1, - TLF_XunitXml = 2 - }; - - void startLogging(const char *filename); + void startLogging(); void stopLogging(); void enterTestFunction(const char *function); @@ -91,8 +84,7 @@ class QTestLogger : public QAbstractTestLogger QTestElement *listOfTestcases; QTestElement *currentLogElement; QTestElement *errorLogElement; - QTestBasicStreamer *logFormatter; - TestLoggerFormat format; + QTestXunitStreamer *logFormatter; int testCounter; int failureCounter; diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index a65510f567..e8858ea1c4 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -18,7 +18,6 @@ HEADERS = qbenchmark.h \ qsignalspy.h \ qtestaccessible.h \ qtestassert.h \ - qtestbasicstreamer.h \ qtestcase.h \ qtestcoreelement.h \ qtestcorelist.h \ @@ -31,12 +30,10 @@ HEADERS = qbenchmark.h \ qtest_gui.h \ qtest.h \ qtestkeyboard.h \ - qtestlightxmlstreamer.h \ qtestmouse.h \ qtestspontaneevent.h \ qtestsystem.h \ qtesttouch.h \ - qtestxmlstreamer.h \ qtestxunitstreamer.h SOURCES = qtestcase.cpp \ qtestlog.cpp \ @@ -55,11 +52,8 @@ SOURCES = qtestcase.cpp \ qbenchmarkmetric.cpp \ qtestelement.cpp \ qtestelementattribute.cpp \ - qtestbasicstreamer.cpp \ qtestxunitstreamer.cpp \ - qtestxmlstreamer.cpp \ - qtestlightxmlstreamer.cpp \ - qtestlogger.cpp + qxunittestlogger.cpp DEFINES *= QT_NO_CAST_TO_ASCII \ QT_NO_CAST_FROM_ASCII \ QTESTLIB_MAKEDLL \ |