summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/configure.json6
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp48
-rw-r--r--src/testlib/doc/src/qttestlib-manual.qdoc5
-rw-r--r--src/testlib/qabstracttestlogger.cpp2
-rw-r--r--src/testlib/qabstracttestlogger_p.h11
-rw-r--r--src/testlib/qbenchmark.cpp32
-rw-r--r--src/testlib/qbenchmark_p.h54
-rw-r--r--src/testlib/qbenchmarkevent.cpp13
-rw-r--r--src/testlib/qbenchmarkevent_p.h6
-rw-r--r--src/testlib/qbenchmarkmeasurement_p.h4
-rw-r--r--src/testlib/qbenchmarkperfevents.cpp7
-rw-r--r--src/testlib/qbenchmarkperfevents_p.h22
-rw-r--r--src/testlib/qbenchmarkvalgrind.cpp8
-rw-r--r--src/testlib/qbenchmarkvalgrind_p.h2
-rw-r--r--src/testlib/qcsvbenchmarklogger.cpp4
-rw-r--r--src/testlib/qcsvbenchmarklogger_p.h4
-rw-r--r--src/testlib/qplaintestlogger.cpp4
-rw-r--r--src/testlib/qplaintestlogger_p.h6
-rw-r--r--src/testlib/qsignaldumper.cpp15
-rw-r--r--src/testlib/qsignalspy.h71
-rw-r--r--src/testlib/qsignalspy.qdoc22
-rw-r--r--src/testlib/qtaptestlogger.cpp28
-rw-r--r--src/testlib/qtaptestlogger_p.h4
-rw-r--r--src/testlib/qteamcitylogger.cpp10
-rw-r--r--src/testlib/qteamcitylogger_p.h4
-rw-r--r--src/testlib/qtest.h80
-rw-r--r--src/testlib/qtest_gui.h16
-rw-r--r--src/testlib/qtestaccessible.h2
-rw-r--r--src/testlib/qtestblacklist.cpp9
-rw-r--r--src/testlib/qtestcase.cpp277
-rw-r--r--src/testlib/qtestcase.h44
-rw-r--r--src/testlib/qtestcoreelement_p.h12
-rw-r--r--src/testlib/qtestcorelist_p.h8
-rw-r--r--src/testlib/qtestdata.cpp10
-rw-r--r--src/testlib/qtestelement.cpp2
-rw-r--r--src/testlib/qtestelement_p.h4
-rw-r--r--src/testlib/qtestelementattribute.cpp10
-rw-r--r--src/testlib/qtestelementattribute_p.h4
-rw-r--r--src/testlib/qtesteventloop.h9
-rw-r--r--src/testlib/qtestlog.cpp16
-rw-r--r--src/testlib/qtestlog_p.h7
-rw-r--r--src/testlib/qtestresult.cpp178
-rw-r--r--src/testlib/qtestresult_p.h32
-rw-r--r--src/testlib/qtesttable.cpp24
-rw-r--r--src/testlib/qtestxunitstreamer.cpp5
-rw-r--r--src/testlib/qxmltestlogger.cpp29
-rw-r--r--src/testlib/qxmltestlogger_p.h4
-rw-r--r--src/testlib/qxunittestlogger.cpp11
-rw-r--r--src/testlib/qxunittestlogger_p.h18
-rw-r--r--src/testlib/testlib.pro9
50 files changed, 778 insertions, 434 deletions
diff --git a/src/testlib/configure.json b/src/testlib/configure.json
index df6132cdc2..726f614ee5 100644
--- a/src/testlib/configure.json
+++ b/src/testlib/configure.json
@@ -16,6 +16,12 @@
"purpose": "Provides a utility to test item models.",
"condition": "features.itemmodel",
"output": [ "publicFeature" ]
+ },
+ "valgrind": {
+ "label": "Valgrind",
+ "purpose": "Profiling support with callgrind.",
+ "condition": "(config.linux || config.darwin) && features.process && features.regularexpression",
+ "output": [ "publicFeature" ]
}
},
diff --git a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp
index a4513a55a9..37aba2715b 100644
--- a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp
+++ b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp
@@ -98,3 +98,51 @@ QVERIFY(spy.wait(1000));
QSignalSpy spy(myPushButton, &QPushButton::clicked);
//! [6]
+//! [7]
+QObject object;
+auto mo = object.metaObject();
+auto signalIndex = mo->indexOfSignal("objectNameChanged(QString)");
+auto signal = mo->method(signalIndex);
+
+QSignalSpy spy(&object, signal);
+object.setObjectName("A new object name");
+QCOMPARE(spy.count(), 1);
+//! [7]
+
+//! [8]
+void tst_QWindow::writeMinMaxDimensionalProps_data()
+ QTest::addColumn<int>("propertyIndex");
+
+ // Collect all relevant properties
+ static const auto mo = QWindow::staticMetaObject;
+ for (int i = mo.propertyOffset(); i < mo.propertyCount(); ++i) {
+ auto property = mo.property(i);
+
+ // ...that have type int
+ if (property.type() == QVariant::Int) {
+ static const QRegularExpression re("^minimum|maximum");
+ const auto name = property.name();
+
+ // ...and start with "minimum" or "maximum"
+ if (re.match(name).hasMatch()) {
+ QTest::addRow("%s", name) << i;
+ }
+ }
+ }
+}
+
+void tst_QWindow::writeMinMaxDimensionalProps()
+{
+ QFETCH(int, propertyIndex);
+
+ auto property = QWindow::staticMetaObject.property(propertyIndex);
+ QVERIFY(property.isWritable());
+ QVERIFY(property.hasNotifySignal());
+
+ QWindow window;
+ QSignalSpy spy(&window, property.notifySignal());
+
+ QVERIFY(property.write(&window, 42));
+ QCOMPARE(spy.count(), 1);
+}
+//! [8]
diff --git a/src/testlib/doc/src/qttestlib-manual.qdoc b/src/testlib/doc/src/qttestlib-manual.qdoc
index ee7767b5a5..bb379fe029 100644
--- a/src/testlib/doc/src/qttestlib-manual.qdoc
+++ b/src/testlib/doc/src/qttestlib-manual.qdoc
@@ -109,6 +109,11 @@
Example:
\snippet code/doc_src_qtestlib.cpp 0
+ Finally, if the test class has a static public \c{void initMain()} method,
+ it is called by the QTEST_MAIN macros before the QApplication object
+ is instantiated. For example, this allows for setting application
+ attributes like Qt::AA_DisableHighDpiScaling. This was added in 5.14.
+
For more examples, refer to the \l{Qt Test Tutorial}.
\if !defined(qtforpython)
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index 2b54cd410b..ff05dd88c7 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -87,7 +87,7 @@ QAbstractTestLogger::~QAbstractTestLogger()
if (stream != stdout) {
fclose(stream);
}
- stream = 0;
+ stream = nullptr;
}
void QAbstractTestLogger::filterUnprintable(char *str) const
diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h
index a64e7ea96f..e5a1404c16 100644
--- a/src/testlib/qabstracttestlogger_p.h
+++ b/src/testlib/qabstracttestlogger_p.h
@@ -97,14 +97,14 @@ public:
virtual void enterTestData(QTestData *) {}
virtual void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) = 0;
+ const char *file = nullptr, int line = 0) = 0;
virtual void addBenchmarkResult(const QBenchmarkResult &result) = 0;
virtual void addMessage(QtMsgType, const QMessageLogContext &,
const QString &);
virtual void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) = 0;
+ const char *file = nullptr, int line = 0) = 0;
void outputString(const char *msg);
@@ -117,8 +117,7 @@ struct QTestCharBuffer
{
enum { InitialSize = 512 };
- inline QTestCharBuffer()
- : _size(InitialSize), buf(staticBuf)
+ inline QTestCharBuffer() : buf(staticBuf)
{
staticBuf[0] = '\0';
}
@@ -151,7 +150,7 @@ struct QTestCharBuffer
inline bool reset(int newSize)
{
- char *newBuf = 0;
+ char *newBuf = nullptr;
if (buf == staticBuf) {
// if we point to our internal buffer, we need to malloc first
newBuf = reinterpret_cast<char *>(malloc(newSize));
@@ -170,7 +169,7 @@ struct QTestCharBuffer
}
private:
- int _size;
+ int _size = InitialSize;
char* buf;
char staticBuf[InitialSize];
};
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp
index d49d07bb70..aafdc64831 100644
--- a/src/testlib/qbenchmark.cpp
+++ b/src/testlib/qbenchmark.cpp
@@ -51,14 +51,6 @@ QT_BEGIN_NAMESPACE
QBenchmarkGlobalData *QBenchmarkGlobalData::current;
QBenchmarkGlobalData::QBenchmarkGlobalData()
- : measurer(0)
- , walltimeMinimum(-1)
- , iterationCount(-1)
- , medianIterationCount(-1)
- , createChart(false)
- , verboseOutput(false)
- , minimumTotal(-1)
- , mode_(WallTime)
{
setMode(mode_);
}
@@ -66,23 +58,23 @@ QBenchmarkGlobalData::QBenchmarkGlobalData()
QBenchmarkGlobalData::~QBenchmarkGlobalData()
{
delete measurer;
- QBenchmarkGlobalData::current = 0;
+ if (QBenchmarkGlobalData::current == this)
+ QBenchmarkGlobalData::current = nullptr;
}
void QBenchmarkGlobalData::setMode(Mode mode)
{
mode_ = mode;
- if (measurer)
- delete measurer;
+ delete measurer;
measurer = createMeasurer();
}
QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer()
{
- QBenchmarkMeasurerBase *measurer = 0;
+ QBenchmarkMeasurerBase *measurer = nullptr;
if (0) {
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
} else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
measurer = new QBenchmarkCallgrindMeasurer;
#endif
@@ -105,24 +97,18 @@ QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer()
int QBenchmarkGlobalData::adjustMedianIterationCount()
{
- if (medianIterationCount != -1) {
- return medianIterationCount;
- } else {
- return measurer->adjustMedianCount(1);
- }
+ return medianIterationCount != -1
+ ? medianIterationCount : measurer->adjustMedianCount(1);
}
QBenchmarkTestMethodData *QBenchmarkTestMethodData::current;
-QBenchmarkTestMethodData::QBenchmarkTestMethodData()
-:resultAccepted(false), runOnce(false), iterationCount(-1)
-{
-}
+QBenchmarkTestMethodData::QBenchmarkTestMethodData() = default;
QBenchmarkTestMethodData::~QBenchmarkTestMethodData()
{
- QBenchmarkTestMethodData::current = 0;
+ QBenchmarkTestMethodData::current = nullptr;
}
void QBenchmarkTestMethodData::beginDataRun()
diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h
index 3fa9c5f534..93b5becb2b 100644
--- a/src/testlib/qbenchmark_p.h
+++ b/src/testlib/qbenchmark_p.h
@@ -55,12 +55,6 @@
#include <QtCore/qglobal.h>
-#if (defined(Q_OS_LINUX) || defined Q_OS_MACOS) && QT_CONFIG(process)
-#define QTESTLIB_USE_VALGRIND
-#else
-#undef QTESTLIB_USE_VALGRIND
-#endif
-
#if defined(Q_OS_LINUX) && !defined(QT_LINUXBASE) && !defined(Q_OS_ANDROID)
#define QTESTLIB_USE_PERF_EVENTS
#else
@@ -70,7 +64,7 @@
#include <QtTest/private/qbenchmarkmeasurement_p.h>
#include <QtCore/QMap>
#include <QtTest/qttestglobal.h>
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
#include <QtTest/private/qbenchmarkvalgrind_p.h>
#endif
#ifdef QTESTLIB_USE_PERF_EVENTS
@@ -87,7 +81,7 @@ struct QBenchmarkContext
QString slotName;
QString tag; // from _data() function
- int checkpointIndex;
+ int checkpointIndex = -1;
QString toString() const
{
@@ -95,7 +89,7 @@ struct QBenchmarkContext
.arg(slotName, tag, QString::number(checkpointIndex));
}
- QBenchmarkContext() : checkpointIndex(-1) {}
+ QBenchmarkContext() = default;
};
Q_DECLARE_TYPEINFO(QBenchmarkContext, Q_MOVABLE_TYPE);
@@ -103,19 +97,13 @@ class QBenchmarkResult
{
public:
QBenchmarkContext context;
- qreal value;
- int iterations;
- QTest::QBenchmarkMetric metric;
- bool setByMacro;
- bool valid;
-
- QBenchmarkResult()
- : value(-1)
- , iterations(-1)
- , metric(QTest::FramesPerSecond)
- , setByMacro(true)
- , valid(false)
- { }
+ qreal value = -1;
+ int iterations = -1;
+ QTest::QBenchmarkMetric metric = QTest::FramesPerSecond;
+ bool setByMacro = true;
+ bool valid = false;
+
+ QBenchmarkResult() = default;
QBenchmarkResult(
const QBenchmarkContext &context, const qreal value, const int iterations,
@@ -153,17 +141,17 @@ public:
QBenchmarkMeasurerBase *createMeasurer();
int adjustMedianIterationCount();
- QBenchmarkMeasurerBase *measurer;
+ QBenchmarkMeasurerBase *measurer = nullptr;
QBenchmarkContext context;
- int walltimeMinimum;
- int iterationCount;
- int medianIterationCount;
- bool createChart;
- bool verboseOutput;
+ int walltimeMinimum = -1;
+ int iterationCount = -1;
+ int medianIterationCount = -1;
+ bool createChart = false;
+ bool verboseOutput = false;
QString callgrindOutFileBase;
- int minimumTotal;
+ int minimumTotal = -1;
private:
- Mode mode_;
+ Mode mode_ = WallTime;
};
/*
@@ -190,9 +178,9 @@ public:
void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true);
QBenchmarkResult result;
- bool resultAccepted;
- bool runOnce;
- int iterationCount;
+ bool resultAccepted = false;
+ bool runOnce = false;
+ int iterationCount = -1;
};
// low-level API:
diff --git a/src/testlib/qbenchmarkevent.cpp b/src/testlib/qbenchmarkevent.cpp
index f696f8b1eb..bcae9325cd 100644
--- a/src/testlib/qbenchmarkevent.cpp
+++ b/src/testlib/qbenchmarkevent.cpp
@@ -44,14 +44,9 @@
QT_BEGIN_NAMESPACE
-QBenchmarkEvent::QBenchmarkEvent()
- : eventCounter(0)
-{
-}
+QBenchmarkEvent::QBenchmarkEvent() = default;
-QBenchmarkEvent::~QBenchmarkEvent()
-{
-}
+QBenchmarkEvent::~QBenchmarkEvent() = default;
void QBenchmarkEvent::start()
{
@@ -96,7 +91,11 @@ QTest::QBenchmarkMetric QBenchmarkEvent::metricType()
}
// This could be done in a much better way, this is just the beginning.
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
+#else
bool QBenchmarkEvent::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
+#endif
{
Q_UNUSED(eventType);
Q_UNUSED(message);
diff --git a/src/testlib/qbenchmarkevent_p.h b/src/testlib/qbenchmarkevent_p.h
index af42a17141..9fe3daa33b 100644
--- a/src/testlib/qbenchmarkevent_p.h
+++ b/src/testlib/qbenchmarkevent_p.h
@@ -71,8 +71,12 @@ public:
int adjustMedianCount(int suggestion) override;
bool repeatCount() override { return 1; }
QTest::QBenchmarkMetric metricType() override;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
+#else
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
- qint64 eventCounter;
+#endif
+ qint64 eventCounter = 0;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qbenchmarkmeasurement_p.h b/src/testlib/qbenchmarkmeasurement_p.h
index 8dbfd4b618..1e2b82c25d 100644
--- a/src/testlib/qbenchmarkmeasurement_p.h
+++ b/src/testlib/qbenchmarkmeasurement_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
class QBenchmarkMeasurerBase
{
public:
- virtual ~QBenchmarkMeasurerBase() {}
+ virtual ~QBenchmarkMeasurerBase() = default;
virtual void init() {}
virtual void start() = 0;
virtual qint64 checkpoint() = 0;
@@ -66,7 +66,7 @@ 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 repeatCount() { return true; }
virtual bool needsWarmupIteration() { return false; }
virtual QTest::QBenchmarkMetric metricType() = 0;
};
diff --git a/src/testlib/qbenchmarkperfevents.cpp b/src/testlib/qbenchmarkperfevents.cpp
index 91f0792338..e8c6969d4a 100644
--- a/src/testlib/qbenchmarkperfevents.cpp
+++ b/src/testlib/qbenchmarkperfevents.cpp
@@ -147,7 +147,7 @@ bool QBenchmarkPerfEventsMeasurer::isAvailable()
{
// this generates an EFAULT because attr == NULL if perf_event_open is available
// if the kernel is too old, it generates ENOSYS
- return perf_event_open(0, 0, 0, 0, 0) == -1 && errno != ENOSYS;
+ return perf_event_open(nullptr, 0, 0, 0, 0) == -1 && errno != ENOSYS;
}
/* Event list structure
@@ -500,10 +500,7 @@ void QBenchmarkPerfEventsMeasurer::listCounters()
"Attributes can be combined, for example: -perfcounter branch-mispredicts:kh\n");
}
-QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer()
- : fd(-1)
-{
-}
+QBenchmarkPerfEventsMeasurer::QBenchmarkPerfEventsMeasurer() = default;
QBenchmarkPerfEventsMeasurer::~QBenchmarkPerfEventsMeasurer()
{
diff --git a/src/testlib/qbenchmarkperfevents_p.h b/src/testlib/qbenchmarkperfevents_p.h
index 86ba556549..3f27161ef5 100644
--- a/src/testlib/qbenchmarkperfevents_p.h
+++ b/src/testlib/qbenchmarkperfevents_p.h
@@ -60,23 +60,23 @@ class QBenchmarkPerfEventsMeasurer : public QBenchmarkMeasurerBase
public:
QBenchmarkPerfEventsMeasurer();
~QBenchmarkPerfEventsMeasurer();
- virtual void init() override;
- virtual void start() override;
- virtual qint64 checkpoint() override;
- virtual qint64 stop() override;
- virtual bool isMeasurementAccepted(qint64 measurement) override;
- virtual int adjustIterationCount(int suggestion) override;
- virtual int adjustMedianCount(int suggestion) override;
- virtual bool repeatCount() override { return 1; }
- virtual bool needsWarmupIteration() override { return true; }
- virtual QTest::QBenchmarkMetric metricType() override;
+ void init() override;
+ void start() override;
+ qint64 checkpoint() override;
+ qint64 stop() override;
+ bool isMeasurementAccepted(qint64 measurement) override;
+ int adjustIterationCount(int suggestion) override;
+ int adjustMedianCount(int suggestion) override;
+ bool repeatCount() override { return true; }
+ bool needsWarmupIteration() override { return true; }
+ QTest::QBenchmarkMetric metricType() override;
static bool isAvailable();
static QTest::QBenchmarkMetric metricForEvent(quint32 type, quint64 event_id);
static void setCounter(const char *name);
static void listCounters();
private:
- int fd;
+ int fd = -1;
qint64 readValue();
};
diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp
index 7d24eb8293..44888c4d30 100644
--- a/src/testlib/qbenchmarkvalgrind.cpp
+++ b/src/testlib/qbenchmarkvalgrind.cpp
@@ -39,8 +39,6 @@
#include <QtTest/private/qbenchmark_p.h>
-#ifdef QTESTLIB_USE_VALGRIND
-
#include <QtTest/private/qbenchmarkvalgrind_p.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qcoreapplication.h>
@@ -170,7 +168,7 @@ QString QBenchmarkValgrindUtils::outFileBase(qint64 pid)
// Returns \c true upon success, otherwise false.
bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode)
{
- const QString execFile(origAppArgs.at(0));
+ const QString &execFile = origAppArgs.at(0);
QStringList args;
args << QLatin1String("--tool=callgrind") << QLatin1String("--instr-atstart=yes")
<< QLatin1String("--quiet")
@@ -179,7 +177,7 @@ bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppA
// pass on original arguments that make sense (e.g. avoid wasting time producing output
// that will be ignored anyway) ...
for (int i = 1; i < origAppArgs.size(); ++i) {
- const QString arg(origAppArgs.at(i));
+ const QString &arg = origAppArgs.at(i);
if (arg == QLatin1String("-callgrind"))
continue;
args << arg; // ok to pass on
@@ -243,5 +241,3 @@ QTest::QBenchmarkMetric QBenchmarkCallgrindMeasurer::metricType()
}
QT_END_NAMESPACE
-
-#endif // QTESTLIB_USE_VALGRIND
diff --git a/src/testlib/qbenchmarkvalgrind_p.h b/src/testlib/qbenchmarkvalgrind_p.h
index 69219b9a65..0619be9f22 100644
--- a/src/testlib/qbenchmarkvalgrind_p.h
+++ b/src/testlib/qbenchmarkvalgrind_p.h
@@ -58,6 +58,8 @@
class QStringList;
+QT_REQUIRE_CONFIG(valgrind);
+
QT_BEGIN_NAMESPACE
class QBenchmarkValgrindUtils
diff --git a/src/testlib/qcsvbenchmarklogger.cpp b/src/testlib/qcsvbenchmarklogger.cpp
index ee7270b634..f410ec6e3d 100644
--- a/src/testlib/qcsvbenchmarklogger.cpp
+++ b/src/testlib/qcsvbenchmarklogger.cpp
@@ -46,9 +46,7 @@ QCsvBenchmarkLogger::QCsvBenchmarkLogger(const char *filename)
{
}
-QCsvBenchmarkLogger::~QCsvBenchmarkLogger()
-{
-}
+QCsvBenchmarkLogger::~QCsvBenchmarkLogger() = default;
void QCsvBenchmarkLogger::startLogging()
{
diff --git a/src/testlib/qcsvbenchmarklogger_p.h b/src/testlib/qcsvbenchmarklogger_p.h
index 5840aee0f5..83e465c859 100644
--- a/src/testlib/qcsvbenchmarklogger_p.h
+++ b/src/testlib/qcsvbenchmarklogger_p.h
@@ -68,11 +68,11 @@ public:
void leaveTestFunction() override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &result) override;
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp
index ed53dcdde8..c2e0bebaa0 100644
--- a/src/testlib/qplaintestlogger.cpp
+++ b/src/testlib/qplaintestlogger.cpp
@@ -316,9 +316,7 @@ QPlainTestLogger::QPlainTestLogger(const char *filename)
{
}
-QPlainTestLogger::~QPlainTestLogger()
-{
-}
+QPlainTestLogger::~QPlainTestLogger() = default;
void QPlainTestLogger::startLogging()
{
diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h
index 55755830b2..80ef4864c1 100644
--- a/src/testlib/qplaintestlogger_p.h
+++ b/src/testlib/qplaintestlogger_p.h
@@ -68,17 +68,17 @@ public:
void leaveTestFunction() override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &result) override;
void addMessage(QtMsgType, const QMessageLogContext &,
const QString &) override;
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
private:
- void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0);
+ void printMessage(const char *type, const char *msg, const char *file = nullptr, int line = 0);
void outputMessage(const char *str);
void printBenchmarkResult(const QBenchmarkResult &result);
};
diff --git a/src/testlib/qsignaldumper.cpp b/src/testlib/qsignaldumper.cpp
index 8305c5d424..70f4d5e63d 100644
--- a/src/testlib/qsignaldumper.cpp
+++ b/src/testlib/qsignaldumper.cpp
@@ -56,7 +56,7 @@ namespace QTest
inline static void qPrintMessage(const QByteArray &ba)
{
- QTestLog::info(ba.constData(), 0, 0);
+ QTestLog::info(ba.constData(), nullptr, 0);
}
Q_GLOBAL_STATIC(QList<QByteArray>, ignoreClasses)
@@ -87,7 +87,7 @@ static void qSignalDumperCallback(QObject *caller, int signal_index, void **argv
str += objname.toLocal8Bit();
if (!objname.isEmpty())
str += ' ';
- str += QByteArray::number(quintptr(caller), 16);
+ str += QByteArray::number(quintptr(caller), 16).rightJustified(8, '0');
str += ") ";
str += member.name();
@@ -105,7 +105,7 @@ static void qSignalDumperCallback(QObject *caller, int signal_index, void **argv
str += '@';
quintptr addr = quintptr(*reinterpret_cast<void **>(argv[i + 1]));
- str.append(QByteArray::number(addr, 16));
+ str.append(QByteArray::number(addr, 16).rightJustified(8, '0'));
} else if (typeId != QMetaType::UnknownType) {
Q_ASSERT(typeId != QMetaType::Void); // void parameter => metaobject is corrupt
str.append(arg)
@@ -144,7 +144,7 @@ static void qSignalDumperCallbackSlot(QObject *caller, int method_index, void **
str += objname.toLocal8Bit();
if (!objname.isEmpty())
str += ' ';
- str += QByteArray::number(quintptr(caller), 16);
+ str += QByteArray::number(quintptr(caller), 16).rightJustified(8, '0');
str += ") ";
str += member.methodSignature();
@@ -169,14 +169,13 @@ static void qSignalDumperCallbackEndSignal(QObject *caller, int /*signal_index*/
void QSignalDumper::startDump()
{
static QSignalSpyCallbackSet set = { QTest::qSignalDumperCallback,
- QTest::qSignalDumperCallbackSlot, QTest::qSignalDumperCallbackEndSignal, 0 };
- qt_register_signal_spy_callbacks(set);
+ QTest::qSignalDumperCallbackSlot, QTest::qSignalDumperCallbackEndSignal, nullptr };
+ qt_register_signal_spy_callbacks(&set);
}
void QSignalDumper::endDump()
{
- static QSignalSpyCallbackSet nset = { 0, 0, 0 ,0 };
- qt_register_signal_spy_callbacks(nset);
+ qt_register_signal_spy_callbacks(nullptr);
}
void QSignalDumper::ignoreClass(const QByteArray &klass)
diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h
index 218a26ec5c..dc0c58044f 100644
--- a/src/testlib/qsignalspy.h
+++ b/src/testlib/qsignalspy.h
@@ -59,11 +59,8 @@ public:
explicit QSignalSpy(const QObject *obj, const char *aSignal)
: m_waiting(false)
{
- static const int memberOffset = QObject::staticMetaObject.methodCount();
- if (!obj) {
- qWarning("QSignalSpy: Cannot spy on a null object");
+ if (!isObjectValid(obj))
return;
- }
if (!aSignal) {
qWarning("QSignalSpy: Null signal name is not valid");
@@ -83,11 +80,9 @@ public:
return;
}
- if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
- Qt::DirectConnection, nullptr)) {
- qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
+ if (!connectToSignal(obj, sigIndex))
return;
- }
+
sig = ba;
initArgs(mo->method(sigIndex), obj);
}
@@ -100,11 +95,8 @@ public:
QSignalSpy(const typename QtPrivate::FunctionPointer<Func>::Object *obj, Func signal0)
: m_waiting(false)
{
- static const int memberOffset = QObject::staticMetaObject.methodCount();
- if (!obj) {
- qWarning("QSignalSpy: Cannot spy on a null object");
+ if (!isObjectValid(obj))
return;
- }
if (!signal0) {
qWarning("QSignalSpy: Null signal name is not valid");
@@ -114,23 +106,28 @@ public:
const QMetaObject * const mo = obj->metaObject();
const QMetaMethod signalMetaMethod = QMetaMethod::fromSignal(signal0);
const int sigIndex = signalMetaMethod.methodIndex();
- if (!signalMetaMethod.isValid() ||
- signalMetaMethod.methodType() != QMetaMethod::Signal) {
- qWarning("QSignalSpy: Not a valid signal: '%s'",
- signalMetaMethod.methodSignature().constData());
+
+ if (!isSignalMetaMethodValid(signalMetaMethod))
return;
- }
- if (!QMetaObject::connect(obj, sigIndex, this, memberOffset,
- Qt::DirectConnection, 0)) {
- qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
+ if (!connectToSignal(obj, sigIndex))
return;
- }
+
sig = signalMetaMethod.methodSignature();
initArgs(mo->method(sigIndex), obj);
}
#endif // Q_CLANG_QDOC
+ QSignalSpy(const QObject *obj, const QMetaMethod &signal)
+ : m_waiting(false)
+ {
+ if (isObjectValid(obj) && isSignalMetaMethodValid(signal) &&
+ connectToSignal(obj, signal.methodIndex())) {
+ sig = signal.methodSignature();
+ initArgs(signal, obj);
+ }
+ }
+
inline bool isValid() const { return !sig.isEmpty(); }
inline QByteArray signal() const { return sig; }
@@ -160,6 +157,38 @@ public:
}
private:
+ bool connectToSignal(const QObject *sender, int sigIndex)
+ {
+ static const int memberOffset = QObject::staticMetaObject.methodCount();
+ const bool connected = QMetaObject::connect(
+ sender, sigIndex, this, memberOffset, Qt::DirectConnection, nullptr);
+
+ if (!connected)
+ qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect.");
+
+ return connected;
+ }
+
+ static bool isSignalMetaMethodValid(const QMetaMethod &signal)
+ {
+ const bool valid = signal.isValid() && signal.methodType() == QMetaMethod::Signal;
+
+ if (!valid)
+ qWarning("QSignalSpy: Not a valid signal: '%s'", signal.methodSignature().constData());
+
+ return valid;
+ }
+
+ static bool isObjectValid(const QObject *object)
+ {
+ const bool valid = !!object;
+
+ if (!valid)
+ qWarning("QSignalSpy: Cannot spy on a null object");
+
+ return valid;
+ }
+
void initArgs(const QMetaMethod &member, const QObject *obj)
{
args.reserve(member.parameterCount());
diff --git a/src/testlib/qsignalspy.qdoc b/src/testlib/qsignalspy.qdoc
index 39639d0a09..d532ad478d 100644
--- a/src/testlib/qsignalspy.qdoc
+++ b/src/testlib/qsignalspy.qdoc
@@ -98,6 +98,28 @@
\snippet code/doc_src_qsignalspy.cpp 6
*/
+/*! \fn QSignalSpy(const QObject *obj, const QMetaMethod &signal)
+ \since 5.14
+
+ Constructs a new QSignalSpy that listens for emissions of the \a signal
+ from the QObject \a object. If QSignalSpy is not able to listen for a
+ valid signal (for example, because \a object is \nullptr or \a signal does
+ not denote a valid signal of \a object), an explanatory warning message
+ will be output using qWarning() and subsequent calls to \c isValid() will
+ return false.
+
+ This constructor is convenient to use when Qt's meta-object system is
+ heavily used in a test.
+
+ Basic usage example:
+ \snippet code/doc_src_qsignalspy.cpp 7
+
+ Imagine we need to check whether all properties of the QWindow class
+ that represent minimum and maximum dimensions are properly writable.
+ The following example demonstrates one of the approaches:
+ \snippet code/doc_src_qsignalspy.cpp 8
+*/
+
/*! \fn QSignalSpy::isValid() const
Returns \c true if the signal spy listens to a valid signal, otherwise false.
diff --git a/src/testlib/qtaptestlogger.cpp b/src/testlib/qtaptestlogger.cpp
index 540b36e273..5b5a3c4875 100644
--- a/src/testlib/qtaptestlogger.cpp
+++ b/src/testlib/qtaptestlogger.cpp
@@ -55,9 +55,7 @@ QTapTestLogger::QTapTestLogger(const char *filename)
{
}
-QTapTestLogger::~QTapTestLogger()
-{
-}
+QTapTestLogger::~QTapTestLogger() = default;
void QTapTestLogger::startLogging()
{
@@ -154,10 +152,10 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description,
// This is fragile, but unfortunately testlib doesn't plumb
// the expected and actual values to the loggers (yet).
static QRegularExpression verifyRegex(
- QLatin1Literal("^'(?<actualexpression>.*)' returned (?<actual>\\w+).+\\((?<message>.*)\\)$"));
+ QLatin1String("^'(?<actualexpression>.*)' returned (?<actual>\\w+).+\\((?<message>.*)\\)$"));
static QRegularExpression comparRegex(
- QLatin1Literal("^(?<message>.*)\n"
+ QLatin1String("^(?<message>.*)\n"
"\\s*Actual\\s+\\((?<actualexpression>.*)\\)\\s*: (?<actual>.*)\n"
"\\s*Expected\\s+\\((?<expectedexpresssion>.*)\\)\\s*: (?<expected>.*)$"));
@@ -168,22 +166,22 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description,
if (match.hasMatch()) {
bool isVerify = match.regularExpression() == verifyRegex;
- QString message = match.captured(QLatin1Literal("message"));
+ QString message = match.captured(QLatin1String("message"));
QString expected;
QString actual;
if (isVerify) {
- QString expression = QLatin1Literal(" (")
- % match.captured(QLatin1Literal("actualexpression")) % QLatin1Char(')') ;
- actual = match.captured(QLatin1Literal("actual")).toLower() % expression;
- expected = (actual.startsWith(QLatin1Literal("true")) ? QLatin1Literal("false") : QLatin1Literal("true")) % expression;
+ QString expression = QLatin1String(" (")
+ % match.captured(QLatin1String("actualexpression")) % QLatin1Char(')') ;
+ actual = match.captured(QLatin1String("actual")).toLower() % expression;
+ expected = (actual.startsWith(QLatin1String("true")) ? QLatin1String("false") : QLatin1String("true")) % expression;
if (message.isEmpty())
- message = QLatin1Literal("Verification failed");
+ message = QLatin1String("Verification failed");
} else {
- expected = match.captured(QLatin1Literal("expected"))
- % QLatin1Literal(" (") % match.captured(QLatin1Literal("expectedexpresssion")) % QLatin1Char(')');
- actual = match.captured(QLatin1Literal("actual"))
- % QLatin1Literal(" (") % match.captured(QLatin1Literal("actualexpression")) % QLatin1Char(')');
+ expected = match.captured(QLatin1String("expected"))
+ % QLatin1String(" (") % match.captured(QLatin1String("expectedexpresssion")) % QLatin1Char(')');
+ actual = match.captured(QLatin1String("actual"))
+ % QLatin1String(" (") % match.captured(QLatin1String("actualexpression")) % QLatin1Char(')');
}
QTestCharBuffer diagnosticsYamlish;
diff --git a/src/testlib/qtaptestlogger_p.h b/src/testlib/qtaptestlogger_p.h
index b51343e4fe..967c724b51 100644
--- a/src/testlib/qtaptestlogger_p.h
+++ b/src/testlib/qtaptestlogger_p.h
@@ -70,9 +70,9 @@ public:
void enterTestData(QTestData *data) override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &) override {};
private:
diff --git a/src/testlib/qteamcitylogger.cpp b/src/testlib/qteamcitylogger.cpp
index 577c8e70cd..8a77143454 100644
--- a/src/testlib/qteamcitylogger.cpp
+++ b/src/testlib/qteamcitylogger.cpp
@@ -103,9 +103,7 @@ QTeamCityLogger::QTeamCityLogger(const char *filename)
{
}
-QTeamCityLogger::~QTeamCityLogger()
-{
-}
+QTeamCityLogger::~QTeamCityLogger() = default;
void QTeamCityLogger::startLogging()
{
@@ -224,9 +222,7 @@ QString QTeamCityLogger::tcEscapedString(const QString &str) const
{
QString formattedString;
- for (int i = 0; i < str.length(); i++) {
- QChar ch = str.at(i);
-
+ for (QChar ch : str) {
switch (ch.toLatin1()) {
case '\n':
formattedString.append(QLatin1String("|n"));
@@ -251,7 +247,7 @@ QString QTeamCityLogger::tcEscapedString(const QString &str) const
}
}
- return qMove(formattedString).simplified();
+ return std::move(formattedString).simplified();
}
QString QTeamCityLogger::escapedTestFuncName() const
diff --git a/src/testlib/qteamcitylogger_p.h b/src/testlib/qteamcitylogger_p.h
index 80f2454724..dd7c0cdcf0 100644
--- a/src/testlib/qteamcitylogger_p.h
+++ b/src/testlib/qteamcitylogger_p.h
@@ -70,11 +70,11 @@ public:
void leaveTestFunction() override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &result) override;
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
private:
QString currTestFuncName;
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index ebd94939ce..27fe08e8f4 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -46,12 +46,15 @@
#include <QtTest/qtestdata.h>
#include <QtTest/qbenchmark.h>
+#include <QtCore/qbitarray.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qcborcommon.h>
#include <QtCore/qdatetime.h>
+#if QT_CONFIG(itemmodel)
#include <QtCore/qabstractitemmodel.h>
+#endif
#include <QtCore/qobject.h>
#include <QtCore/qvariant.h>
#include <QtCore/qurl.h>
@@ -89,25 +92,35 @@ template<> inline char *toString(const QByteArray &ba)
return QTest::toPrettyCString(ba.constData(), ba.length());
}
+template<> inline char *toString(const QBitArray &ba)
+{
+ qsizetype size = ba.size();
+ char *str = static_cast<char *>(malloc(size + 1));
+ for (qsizetype i = 0; i < size; ++i)
+ str[i] = "01"[ba.testBit(i)];
+ str[size] = '\0';
+ return str;
+}
+
#if QT_CONFIG(datestring)
template<> inline char *toString(const QTime &time)
{
return time.isValid()
- ? qstrdup(qPrintable(time.toString(QStringViewLiteral("hh:mm:ss.zzz"))))
+ ? qstrdup(qPrintable(time.toString(u"hh:mm:ss.zzz")))
: qstrdup("Invalid QTime");
}
template<> inline char *toString(const QDate &date)
{
return date.isValid()
- ? qstrdup(qPrintable(date.toString(QStringViewLiteral("yyyy/MM/dd"))))
+ ? qstrdup(qPrintable(date.toString(u"yyyy/MM/dd")))
: qstrdup("Invalid QDate");
}
template<> inline char *toString(const QDateTime &dateTime)
{
return dateTime.isValid()
- ? qstrdup(qPrintable(dateTime.toString(QStringViewLiteral("yyyy/MM/dd hh:mm:ss.zzz[t]"))))
+ ? qstrdup(qPrintable(dateTime.toString(u"yyyy/MM/dd hh:mm:ss.zzz[t]")))
: qstrdup("Invalid QDateTime");
}
#endif // datestring
@@ -129,12 +142,14 @@ template<> inline char *toString(const QChar &c)
return qstrdup(qPrintable(QString::fromLatin1("QChar: '%1' (0x%2)").arg(c).arg(QString::number(static_cast<int>(c.unicode()), 16))));
}
+#if QT_CONFIG(itemmodel)
template<> inline char *toString(const QModelIndex &idx)
{
char msg[128];
qsnprintf(msg, sizeof(msg), "QModelIndex(%d,%d,%p,%p)", idx.row(), idx.column(), idx.internalPointer(), idx.model());
return qstrdup(msg);
}
+#endif
template<> inline char *toString(const QPoint &p)
{
@@ -364,8 +379,36 @@ inline bool qCompare(quint32 const &t1, quint64 const &t2, const char *actual,
{
return qCompare(static_cast<quint64>(t1), t2, actual, expected, file, line);
}
+namespace Internal {
+template <typename T>
+class HasInitMain // SFINAE test for the presence of initMain()
+{
+private:
+ using YesType = char[1];
+ using NoType = char[2];
+
+ template <typename C> static YesType& test( decltype(&C::initMain) ) ;
+ template <typename C> static NoType& test(...);
+
+public:
+ enum { value = sizeof(test<T>(nullptr)) == sizeof(YesType) };
+};
+
+template<typename T>
+typename std::enable_if<HasInitMain<T>::value, void>::type callInitMain()
+{
+ T::initMain();
+}
+
+template<typename T>
+typename std::enable_if<!HasInitMain<T>::value, void>::type callInitMain()
+{
}
+
+} // namespace Internal
+
+} // namespace QTest
QT_END_NAMESPACE
#ifdef QT_TESTCASE_BUILDDIR
@@ -424,52 +467,53 @@ int main(int argc, char *argv[]) \
# define QTEST_DISABLE_KEYPAD_NAVIGATION
#endif
-#define QTEST_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
+#define QTEST_MAIN_IMPL(TestObject) \
TESTLIB_SELFCOVERAGE_START(#TestObject) \
+ QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
QApplication app(argc, argv); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
QTEST_DISABLE_KEYPAD_NAVIGATION \
TestObject tc; \
QTEST_SET_MAIN_SOURCE_PATH \
- return QTest::qExec(&tc, argc, argv); \
-}
+ return QTest::qExec(&tc, argc, argv);
#elif defined(QT_GUI_LIB)
#include <QtTest/qtest_gui.h>
-#define QTEST_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
+#define QTEST_MAIN_IMPL(TestObject) \
TESTLIB_SELFCOVERAGE_START(#TestObject) \
+ QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
QGuiApplication app(argc, argv); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \
QTEST_SET_MAIN_SOURCE_PATH \
- return QTest::qExec(&tc, argc, argv); \
-}
+ return QTest::qExec(&tc, argc, argv);
#else
-#define QTEST_MAIN(TestObject) \
-int main(int argc, char *argv[]) \
-{ \
+#define QTEST_MAIN_IMPL(TestObject) \
TESTLIB_SELFCOVERAGE_START(#TestObject) \
+ QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
QCoreApplication app(argc, argv); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \
QTEST_SET_MAIN_SOURCE_PATH \
- return QTest::qExec(&tc, argc, argv); \
-}
+ return QTest::qExec(&tc, argc, argv);
#endif // QT_GUI_LIB
+#define QTEST_MAIN(TestObject) \
+int main(int argc, char *argv[]) \
+{ \
+ QTEST_MAIN_IMPL(TestObject) \
+}
+
#define QTEST_GUILESS_MAIN(TestObject) \
int main(int argc, char *argv[]) \
{ \
TESTLIB_SELFCOVERAGE_START(#TestObject) \
+ QT_PREPEND_NAMESPACE(QTest::Internal::callInitMain)<TestObject>(); \
QCoreApplication app(argc, argv); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
TestObject tc; \
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h
index e5101e6955..d1efde54b1 100644
--- a/src/testlib/qtest_gui.h
+++ b/src/testlib/qtest_gui.h
@@ -162,6 +162,14 @@ inline bool qCompare(QImage const &t1, QImage const &t2,
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line);
+ if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) {
+ qsnprintf(msg, 1024, "Compared QImages differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatioF(),
+ expected, t2.devicePixelRatioF());
+ return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line);
+ }
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QImages differ in size.\n"
" Actual (%s): %dx%d\n"
@@ -196,6 +204,14 @@ inline bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, c
}
if (t1Null && t2Null)
return compare_helper(true, nullptr, nullptr, nullptr, actual, expected, file, line);
+ if (!qFuzzyCompare(t1.devicePixelRatioF(), t2.devicePixelRatioF())) {
+ qsnprintf(msg, 1024, "Compared QPixmaps differ in device pixel ratio.\n"
+ " Actual (%s): %g\n"
+ " Expected (%s): %g",
+ actual, t1.devicePixelRatioF(),
+ expected, t2.devicePixelRatioF());
+ return compare_helper(false, msg, nullptr, nullptr, actual, expected, file, line);
+ }
if (t1.width() != t2.width() || t1.height() != t2.height()) {
qsnprintf(msg, 1024, "Compared QPixmaps differ in size.\n"
" Actual (%s): %dx%d\n"
diff --git a/src/testlib/qtestaccessible.h b/src/testlib/qtestaccessible.h
index d14dcec031..bd77ee77a1 100644
--- a/src/testlib/qtestaccessible.h
+++ b/src/testlib/qtestaccessible.h
@@ -65,7 +65,7 @@ QT_BEGIN_NAMESPACE
class QObject;
// Use pointers since we subclass QAccessibleEvent
-typedef QList<QAccessibleEvent*> EventList;
+using EventList = QList<QAccessibleEvent*>;
bool operator==(const QAccessibleEvent &l, const QAccessibleEvent &r)
{
diff --git a/src/testlib/qtestblacklist.cpp b/src/testlib/qtestblacklist.cpp
index 6642699758..9b7c2495d4 100644
--- a/src/testlib/qtestblacklist.cpp
+++ b/src/testlib/qtestblacklist.cpp
@@ -169,12 +169,14 @@ static QSet<QByteArray> keywords()
#endif
;
+#if QT_CONFIG(properties)
QCoreApplication *app = QCoreApplication::instance();
if (app) {
const QVariant platformName = app->property("platformName");
if (platformName.isValid())
set << platformName.toByteArray();
}
+#endif
return set;
}
@@ -208,11 +210,10 @@ static bool checkCondition(const QByteArray &condition)
static const QSet<QByteArray> matchedConditions = activeConditions();
QList<QByteArray> conds = condition.split(' ');
- for (int i = 0; i < conds.size(); ++i) {
- QByteArray c = conds.at(i);
+ for (QByteArray c : conds) {
bool result = c.startsWith('!');
if (result)
- c = c.mid(1);
+ c.remove(0, 1);
result ^= matchedConditions.contains(c);
if (!result)
@@ -222,7 +223,7 @@ static bool checkCondition(const QByteArray &condition)
}
static bool ignoreAll = false;
-static std::set<QByteArray> *ignoredTests = 0;
+static std::set<QByteArray> *ignoredTests = nullptr;
namespace QTestPrivate {
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 05a3dbbbcb..908155e8b5 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -289,7 +289,7 @@ namespace QTest
{
class WatchDog;
-static QObject *currentTestObject = 0;
+static QObject *currentTestObject = nullptr;
static QString mainSourcePath;
#if defined(Q_OS_MACOS)
@@ -301,7 +301,7 @@ class TestMethods {
public:
Q_DISABLE_COPY_MOVE(TestMethods)
- typedef std::vector<QMetaMethod> MetaMethods;
+ using MetaMethods = std::vector<QMetaMethod>;
explicit TestMethods(const QObject *o, const MetaMethods &m = MetaMethods());
@@ -423,7 +423,7 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false;
Q_TESTLIB_EXPORT QStringList testFunctions;
Q_TESTLIB_EXPORT QStringList testTags;
-static void qPrintTestSlots(FILE *stream, const char *filter = 0)
+static void qPrintTestSlots(FILE *stream, const char *filter = nullptr)
{
for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i);
@@ -516,7 +516,7 @@ static int qToInt(const char *str)
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool qml)
{
int logFormat = -1; // Not set
- const char *logFilename = 0;
+ const char *logFilename = nullptr;
QTest::testFunctions.clear();
QTest::testTags.clear();
@@ -574,7 +574,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool
" -nocrashhandler : Disables the crash handler. Useful for debugging crashes.\n"
"\n"
" Benchmarking options:\n"
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
" -callgrind : Use callgrind to time benchmarks\n"
#endif
#ifdef QTESTLIB_USE_PERF_EVENTS
@@ -717,7 +717,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool
}
} else if (strcmp(argv[i], "-nocrashhandler") == 0) {
QTest::noCrashHandler = true;
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
} else if (strcmp(argv[i], "-callgrind") == 0) {
if (QBenchmarkValgrindUtils::haveValgrind())
if (QFileInfo(QDir::currentPath()).isWritable()) {
@@ -897,7 +897,7 @@ struct QTestDataSetter
}
~QTestDataSetter()
{
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
}
};
@@ -974,11 +974,11 @@ void TestMethods::invokeTestOnData(int index) const
if (i == -1) {
QTestLog::info(qPrintable(
QString::fromLatin1("warmup stage result : %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
} else {
QTestLog::info(qPrintable(
QString::fromLatin1("accumulation stage result: %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
}
}
}
@@ -1012,14 +1012,14 @@ public:
WatchDog()
{
QMutexLocker locker(&mutex);
- timeout.store(-1);
+ timeout.storeRelaxed(-1);
start();
waitCondition.wait(&mutex);
}
~WatchDog() {
{
QMutexLocker locker(&mutex);
- timeout.store(0);
+ timeout.storeRelaxed(0);
waitCondition.wakeAll();
}
wait();
@@ -1027,21 +1027,21 @@ public:
void beginTest() {
QMutexLocker locker(&mutex);
- timeout.store(defaultTimeout());
+ timeout.storeRelaxed(defaultTimeout());
waitCondition.wakeAll();
}
void testFinished() {
QMutexLocker locker(&mutex);
- timeout.store(-1);
+ timeout.storeRelaxed(-1);
waitCondition.wakeAll();
}
void run() override {
QMutexLocker locker(&mutex);
waitCondition.wakeAll();
- while (1) {
- int t = timeout.load();
+ while (true) {
+ int t = timeout.loadRelaxed();
if (!t)
break;
if (Q_UNLIKELY(!waitCondition.wait(&mutex, t))) {
@@ -1095,7 +1095,7 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
const int globalDataCount = gTable->dataCount();
int curGlobalDataIndex = 0;
- /* For each test function that has a *_data() table/function, do: */
+ /* For each entry in the global data table, do: */
do {
if (!gTable->isEmpty())
QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex));
@@ -1103,50 +1103,49 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
if (curGlobalDataIndex == 0) {
qsnprintf(member, 512, "%s_data()", name.constData());
invokeMethod(QTest::currentTestObject, member);
+ if (QTestResult::skipCurrentTest())
+ break;
}
bool foundFunction = false;
- if (!QTestResult::skipCurrentTest()) {
- int curDataIndex = 0;
- const int dataCount = table.dataCount();
-
- // Data tag requested but none available?
- if (data && !dataCount) {
- // Let empty data tag through.
- if (!*data)
- data = 0;
- else {
- fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), data);
- fprintf(stderr, "Function has no testdata.\n");
- return false;
- }
+ int curDataIndex = 0;
+ const int dataCount = table.dataCount();
+
+ // Data tag requested but none available?
+ if (data && !dataCount) {
+ // Let empty data tag through.
+ if (!*data)
+ data = nullptr;
+ else {
+ fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), data);
+ fprintf(stderr, "Function has no testdata.\n");
+ return false;
}
+ }
- /* For each entry in the data table, do: */
- do {
- QTestResult::setSkipCurrentTest(false);
- QTestResult::setBlacklistCurrentTest(false);
- if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
- foundFunction = true;
+ /* For each entry in this test's data table, do: */
+ do {
+ QTestResult::setSkipCurrentTest(false);
+ QTestResult::setBlacklistCurrentTest(false);
+ if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
+ foundFunction = true;
- QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : 0);
+ QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : nullptr);
- QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
- : table.testData(curDataIndex));
+ QTestDataSetter s(curDataIndex >= dataCount ? nullptr : table.testData(curDataIndex));
- QTestPrivate::qtestMouseButtons = Qt::NoButton;
- if (watchDog)
- watchDog->beginTest();
- invokeTestOnData(index);
- if (watchDog)
- watchDog->testFinished();
+ QTestPrivate::qtestMouseButtons = Qt::NoButton;
+ if (watchDog)
+ watchDog->beginTest();
+ invokeTestOnData(index);
+ if (watchDog)
+ watchDog->testFinished();
- if (data)
- break;
- }
- ++curDataIndex;
- } while (curDataIndex < dataCount);
- }
+ if (data)
+ break;
+ }
+ ++curDataIndex;
+ } while (curDataIndex < dataCount);
if (data && !foundFunction) {
fprintf(stderr, "Unknown testdata for function %s: '%s()'\n", name.constData(), data);
@@ -1156,14 +1155,14 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
return false;
}
- QTestResult::setCurrentGlobalTestData(0);
+ QTestResult::setCurrentGlobalTestData(nullptr);
++curGlobalDataIndex;
} while (curGlobalDataIndex < globalDataCount);
QTestResult::finishedCurrentTestFunction();
QTestResult::setSkipCurrentTest(false);
QTestResult::setBlacklistCurrentTest(false);
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
return true;
}
@@ -1241,7 +1240,7 @@ char *toHexRepresentation(const char *ba, int length)
* */
const int maxLen = 50;
const int len = qMin(maxLen, length);
- char *result = 0;
+ char *result = nullptr;
if (length > maxLen) {
const int size = len * 3 + 4;
@@ -1274,10 +1273,8 @@ char *toHexRepresentation(const char *ba, int length)
++o;
if (i == len)
break;
- else {
- result[o] = ' ';
- ++o;
- }
+ result[o] = ' ';
+ ++o;
}
return result;
@@ -1459,7 +1456,7 @@ void TestMethods::invokeTests(QObject *testObject) const
QScopedPointer<WatchDog> watchDog;
if (!debuggerPresent()
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
&& QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindChildProcess
#endif
) {
@@ -1497,7 +1494,7 @@ void TestMethods::invokeTests(QObject *testObject) const
QTestResult::finishedCurrentTestDataCleanup();
}
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
#if defined(Q_OS_UNIX)
@@ -1567,7 +1564,7 @@ FatalSignalHandler::FatalSignalHandler()
stack.ss_flags = 0;
stack.ss_size = sizeof alternate_stack;
stack.ss_sp = alternate_stack;
- sigaltstack(&stack, 0);
+ sigaltstack(&stack, nullptr);
act.sa_flags |= SA_ONSTACK;
#endif
@@ -1586,7 +1583,7 @@ FatalSignalHandler::FatalSignalHandler()
oldact.sa_flags & SA_SIGINFO ||
#endif
oldact.sa_handler != SIG_DFL) {
- sigaction(fatalSignals[i], &oldact, 0);
+ sigaction(fatalSignals[i], &oldact, nullptr);
} else
{
sigaddset(&handledSignals, fatalSignals[i]);
@@ -1611,7 +1608,7 @@ FatalSignalHandler::~FatalSignalHandler()
// If someone overwrote it in the mean time, put it back
if (oldact.sa_handler != FatalSignalHandler::signal)
- sigaction(i, &oldact, 0);
+ sigaction(i, &oldact, nullptr);
}
}
@@ -1866,7 +1863,7 @@ int QTest::qRun()
{
QTEST_ASSERT(currentTestObject);
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
int callgrindChildExitCode = 0;
#endif
@@ -1886,7 +1883,7 @@ int QTest::qRun()
} // !noCrashHandler
#endif // Q_OS_WIN
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
if (Q_UNLIKELY(!qApp))
qFatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN");
@@ -1927,7 +1924,7 @@ int QTest::qRun()
QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
if (QTestResult::currentTestFunction()) {
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
QTestLog::stopLogging();
@@ -1936,7 +1933,7 @@ int QTest::qRun()
IOPMAssertionRelease(powerID);
}
#endif
- currentTestObject = 0;
+ currentTestObject = nullptr;
// Rethrow exception to make debugging easier.
throw;
@@ -1944,7 +1941,7 @@ int QTest::qRun()
}
#endif
-#ifdef QTESTLIB_USE_VALGRIND
+#if QT_CONFIG(valgrind)
if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
return callgrindChildExitCode;
#endif
@@ -1957,13 +1954,13 @@ int QTest::qRun()
*/
void QTest::qCleanup()
{
- currentTestObject = 0;
+ currentTestObject = nullptr;
QTestTable::clearGlobalTestTable();
QTestLog::stopLogging();
delete QBenchmarkGlobalData::current;
- QBenchmarkGlobalData::current = 0;
+ QBenchmarkGlobalData::current = nullptr;
QSignalDumper::endDump();
@@ -2148,7 +2145,7 @@ QSharedPointer<QTemporaryDir> QTest::qExtractTestData(const QString &dirName)
}
}
- result = qMove(tempDir);
+ result = std::move(tempDir);
return result;
}
@@ -2206,7 +2203,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co
}
// 3. relative to test source.
- if (found.isEmpty()) {
+ if (found.isEmpty() && qstrncmp(file, ":/", 2) != 0) {
// srcdir is the directory containing the calling source file.
QFileInfo srcdir = QFileInfo(QFile::decodeName(file)).path();
@@ -2519,13 +2516,28 @@ bool QTest::compare_helper(bool success, const char *failureMsg,
return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line);
}
+template <typename T>
+static bool floatingCompare(const T &t1, const T &t2)
+{
+ switch (qFpClassify(t1))
+ {
+ case FP_INFINITE:
+ return (t1 < 0) == (t2 < 0) && qFpClassify(t2) == FP_INFINITE;
+ case FP_NAN:
+ return qFpClassify(t2) == FP_NAN;
+ default:
+ return qFuzzyCompare(t1, t2);
+ }
+}
+
/*! \fn bool QTest::qCompare(const qfloat16 &t1, const qfloat16 &t2, const char *actual, const char *expected, const char *file, int line)
\internal
*/
bool QTest::qCompare(qfloat16 const &t1, qfloat16 const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(qFuzzyCompare(t1, t2), "Compared qfloat16s are not the same (fuzzy compare)",
+ return compare_helper(floatingCompare(t1, t2),
+ "Compared qfloat16s are not the same (fuzzy compare)",
toString(t1), toString(t2), actual, expected, file, line);
}
@@ -2535,17 +2547,9 @@ bool QTest::qCompare(qfloat16 const &t1, qfloat16 const &t2, const char *actual,
bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- bool equal = false;
- int cl1 = std::fpclassify(t1);
- int cl2 = std::fpclassify(t2);
- if (cl1 == FP_INFINITE)
- equal = ((t1 < 0) == (t2 < 0)) && cl2 == FP_INFINITE;
- else if (cl1 == FP_NAN)
- equal = (cl2 == FP_NAN);
- else
- equal = qFuzzyCompare(t1, t2);
- return compare_helper(equal, "Compared floats are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared floats are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
}
/*! \fn bool QTest::qCompare(const double &t1, const double &t2, const char *actual, const char *expected, const char *file, int line)
@@ -2554,19 +2558,86 @@ bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const
bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- bool equal = false;
- int cl1 = std::fpclassify(t1);
- int cl2 = std::fpclassify(t2);
- if (cl1 == FP_INFINITE)
- equal = ((t1 < 0) == (t2 < 0)) && cl2 == FP_INFINITE;
- else if (cl1 == FP_NAN)
- equal = (cl2 == FP_NAN);
- else
- equal = qFuzzyCompare(t1, t2);
- return compare_helper(equal, "Compared doubles are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared doubles are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
}
+/*! \fn bool QTest::qCompare(const QString &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QString &t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
/*! \fn bool QTest::qCompare(const double &t1, const float &t2, const char *actual, const char *expected, const char *file, int line)
\internal
*/
@@ -2633,7 +2704,7 @@ static void massageExponent(char *text)
template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \
{ \
char *msg = new char[128]; \
- switch (std::fpclassify(t)) { \
+ switch (qFpClassify(t)) { \
case FP_INFINITE: \
qstrncpy(msg, (t < 0 ? "-inf" : "inf"), 128); \
break; \
@@ -2641,22 +2712,16 @@ template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \
qstrncpy(msg, "nan", 128); \
break; \
default: \
- qsnprintf(msg, 128, #FORMAT, t); \
+ qsnprintf(msg, 128, #FORMAT, double(t)); \
massageExponent(msg); \
break; \
} \
return msg; \
}
+TO_STRING_FLOAT(qfloat16, %.3g)
TO_STRING_FLOAT(float, %g)
-TO_STRING_FLOAT(double, %.12lg)
-
-template <> Q_TESTLIB_EXPORT char *QTest::toString<qfloat16>(const qfloat16 &t)
-{
- char *msg = new char[16];
- qsnprintf(msg, 16, "%.3g", static_cast<float>(t));
- return msg;
-}
+TO_STRING_FLOAT(double, %.12g)
template <> Q_TESTLIB_EXPORT char *QTest::toString<char>(const char &t)
{
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h
index 19a7975750..e1518708e8 100644
--- a/src/testlib/qtestcase.h
+++ b/src/testlib/qtestcase.h
@@ -189,16 +189,8 @@ do {\
return;\
} while (false)
-#ifdef Q_COMPILER_VARIADIC_MACROS
-
#define QSKIP(statement, ...) QSKIP_INTERNAL(statement)
-#else
-
-#define QSKIP(statement) QSKIP_INTERNAL(statement)
-
-#endif
-
#define QEXPECT_FAIL(dataIndex, comment, mode)\
do {\
if (!QTest::qExpectFail(dataIndex, static_cast<const char *>(comment), QTest::mode, __FILE__, __LINE__))\
@@ -344,7 +336,7 @@ namespace QTest
template <typename T>
inline void addColumn(const char *name, T * = nullptr)
{
- typedef std::is_same<T, const char*> QIsSameTConstChar;
+ using QIsSameTConstChar = std::is_same<T, const char*>;
Q_STATIC_ASSERT_X(!QIsSameTConstChar::value, "const char* is not allowed as a test data format.");
addColumnInternal(qMetaTypeId<T>(), name);
}
@@ -371,6 +363,40 @@ namespace QTest
Q_TESTLIB_EXPORT bool qCompare(double const &t1, double const &t2,
const char *actual, const char *expected, const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(int t1, int t2, const char *actual, const char *expected,
+ const char *file, int line);
+
+ Q_TESTLIB_EXPORT bool qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
+ const char *file, int line);
+
+ Q_TESTLIB_EXPORT bool qCompare(QStringView t1, QStringView t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(QStringView t1, const QLatin1String &t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ Q_TESTLIB_EXPORT bool qCompare(const QLatin1String &t1, QStringView t2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ inline bool qCompare(const QString &t1, const QString &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(QStringView(t1), QStringView(t2), actual, expected, file, line);
+ }
+ inline bool qCompare(const QString &t1, const QLatin1String &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(QStringView(t1), t2, actual, expected, file, line);
+ }
+ inline bool qCompare(const QLatin1String &t1, const QString &t2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+ {
+ return qCompare(t1, QStringView(t2), actual, expected, file, line);
+ }
+
inline bool compare_ptr_helper(const volatile void *t1, const volatile void *t2, const char *actual,
const char *expected, const char *file, int line)
{
diff --git a/src/testlib/qtestcoreelement_p.h b/src/testlib/qtestcoreelement_p.h
index e79efdd87f..a101ab5ea3 100644
--- a/src/testlib/qtestcoreelement_p.h
+++ b/src/testlib/qtestcoreelement_p.h
@@ -74,13 +74,13 @@ class QTestCoreElement: public QTestCoreList<ElementType>
QTest::LogElementType elementType() const;
private:
- QTestElementAttribute *listOfAttributes;
+ QTestElementAttribute *listOfAttributes = nullptr;
QTest::LogElementType type;
};
template<class ElementType>
QTestCoreElement<ElementType>::QTestCoreElement(int t)
- :listOfAttributes(0), type(QTest::LogElementType(t))
+ : type(QTest::LogElementType(t))
{
}
@@ -114,7 +114,7 @@ const char *QTestCoreElement<ElementType>::attributeValue(QTest::AttributeIndex
if (attrb)
return attrb->value();
- return 0;
+ return nullptr;
}
template <class ElementType>
@@ -124,7 +124,7 @@ const char *QTestCoreElement<ElementType>::attributeName(QTest::AttributeIndex i
if (attrb)
return attrb->name();
- return 0;
+ return nullptr;
}
template <class ElementType>
@@ -145,7 +145,7 @@ const char *QTestCoreElement<ElementType>::elementName() const
if (type != QTest::LET_Undefined)
return xmlElementNames[type];
- return 0;
+ return nullptr;
}
template <class ElementType>
@@ -165,7 +165,7 @@ const QTestElementAttribute *QTestCoreElement<ElementType>::attribute(QTest::Att
iterator = iterator->nextElement();
}
- return 0;
+ return nullptr;
}
QT_END_NAMESPACE
diff --git a/src/testlib/qtestcorelist_p.h b/src/testlib/qtestcorelist_p.h
index 4d080f6758..daeb293644 100644
--- a/src/testlib/qtestcorelist_p.h
+++ b/src/testlib/qtestcorelist_p.h
@@ -73,8 +73,8 @@ class QTestCoreList
template <class T>
QTestCoreList<T>::QTestCoreList()
- : next(0)
- , prev(0)
+ : next(nullptr)
+ , prev(nullptr)
{
}
@@ -82,12 +82,12 @@ template <class T>
QTestCoreList<T>::~QTestCoreList()
{
if (prev) {
- prev->next = 0;
+ prev->next = nullptr;
}
delete prev;
if (next) {
- next->prev = 0;
+ next->prev = nullptr;
}
delete next;
}
diff --git a/src/testlib/qtestdata.cpp b/src/testlib/qtestdata.cpp
index a8ee130a7d..3a1c6d7e7b 100644
--- a/src/testlib/qtestdata.cpp
+++ b/src/testlib/qtestdata.cpp
@@ -51,12 +51,10 @@ QT_BEGIN_NAMESPACE
class QTestDataPrivate
{
public:
- QTestDataPrivate() : tag(0), parent(0), data(0), dataCount(0) {}
-
- char *tag;
- QTestTable *parent;
- void **data;
- int dataCount;
+ char *tag = nullptr;
+ QTestTable *parent = nullptr;
+ void **data = nullptr;
+ int dataCount = 0;
};
QTestData::QTestData(const char *tag, QTestTable *parent)
diff --git a/src/testlib/qtestelement.cpp b/src/testlib/qtestelement.cpp
index 622e5344f3..b468295917 100644
--- a/src/testlib/qtestelement.cpp
+++ b/src/testlib/qtestelement.cpp
@@ -43,8 +43,6 @@ QT_BEGIN_NAMESPACE
QTestElement::QTestElement(int type)
: QTestCoreElement<QTestElement>(type)
- , listOfChildren(0)
- , parent(0)
{
}
diff --git a/src/testlib/qtestelement_p.h b/src/testlib/qtestelement_p.h
index dacbe6c106..a6b2791a42 100644
--- a/src/testlib/qtestelement_p.h
+++ b/src/testlib/qtestelement_p.h
@@ -69,8 +69,8 @@ class QTestElement: public QTestCoreElement<QTestElement>
void setParent(const QTestElement *p);
private:
- QTestElement *listOfChildren;
- const QTestElement * parent;
+ QTestElement *listOfChildren = nullptr;
+ const QTestElement * parent = nullptr;
};
diff --git a/src/testlib/qtestelementattribute.cpp b/src/testlib/qtestelementattribute.cpp
index 9d752bf26a..e194ee50f7 100644
--- a/src/testlib/qtestelementattribute.cpp
+++ b/src/testlib/qtestelementattribute.cpp
@@ -104,11 +104,7 @@ QT_BEGIN_NAMESPACE
\value LET_SystemError
*/
-QTestElementAttribute::QTestElementAttribute()
- :attributeValue(0),
- attributeIndex(QTest::AI_Undefined)
-{
-}
+QTestElementAttribute::QTestElementAttribute() = default;
QTestElementAttribute::~QTestElementAttribute()
{
@@ -145,7 +141,7 @@ const char *QTestElementAttribute::name() const
if (attributeIndex != QTest::AI_Undefined)
return AttributeNames[attributeIndex];
- return 0;
+ return nullptr;
}
QTest::AttributeIndex QTestElementAttribute::index() const
@@ -168,7 +164,7 @@ bool QTestElementAttribute::setPair(QTest::AttributeIndex index, const char *val
attributeIndex = index;
attributeValue = qstrdup(value);
- return attributeValue != 0;
+ return attributeValue != nullptr;
}
QT_END_NAMESPACE
diff --git a/src/testlib/qtestelementattribute_p.h b/src/testlib/qtestelementattribute_p.h
index cb4dbb5f16..f3815b72d1 100644
--- a/src/testlib/qtestelementattribute_p.h
+++ b/src/testlib/qtestelementattribute_p.h
@@ -106,8 +106,8 @@ class QTestElementAttribute: public QTestCoreList<QTestElementAttribute>
bool setPair(QTest::AttributeIndex attributeIndex, const char *value);
private:
- char *attributeValue;
- QTest::AttributeIndex attributeIndex;
+ char *attributeValue = nullptr;
+ QTest::AttributeIndex attributeIndex = QTest::AI_Undefined;
};
QT_END_NAMESPACE
diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h
index a77b47cd7f..b194e24c3a 100644
--- a/src/testlib/qtesteventloop.h
+++ b/src/testlib/qtesteventloop.h
@@ -56,8 +56,7 @@ class Q_TESTLIB_EXPORT QTestEventLoop : public QObject
Q_OBJECT
public:
- inline QTestEventLoop(QObject *aParent = nullptr)
- : QObject(aParent), inLoop(false), _timeout(false), timerId(-1), loop(nullptr) {}
+ using QObject::QObject;
inline void enterLoopMSecs(int ms);
inline void enterLoop(int secs) { enterLoopMSecs(secs * 1000); }
@@ -84,10 +83,10 @@ protected:
private:
Q_DECL_UNUSED_MEMBER bool inLoop; // ### Qt 6: remove
- bool _timeout;
- int timerId;
+ bool _timeout = false;
+ int timerId = -1;
- QEventLoop *loop;
+ QEventLoop *loop = nullptr;
};
inline void QTestEventLoop::enterLoopMSecs(int ms)
diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp
index faef3912c4..f3ebf343c5 100644
--- a/src/testlib/qtestlog.cpp
+++ b/src/testlib/qtestlog.cpp
@@ -111,7 +111,7 @@ namespace QTest {
struct IgnoreResultList
{
inline IgnoreResultList(QtMsgType tp, const QVariant &patternIn)
- : type(tp), pattern(patternIn), next(0) {}
+ : type(tp), pattern(patternIn) {}
static inline void clearList(IgnoreResultList *&list)
{
@@ -163,10 +163,10 @@ namespace QTest {
QtMsgType type;
QVariant pattern;
- IgnoreResultList *next;
+ IgnoreResultList *next = nullptr;
};
- static IgnoreResultList *ignoreResultList = 0;
+ static IgnoreResultList *ignoreResultList = nullptr;
static QVector<QAbstractTestLogger*> loggers;
static bool loggerUsingStdout = false;
@@ -181,7 +181,7 @@ namespace QTest {
{
if (!ignoreResultList)
return false;
- IgnoreResultList *last = 0;
+ IgnoreResultList *last = nullptr;
IgnoreResultList *list = ignoreResultList;
while (list) {
if (list->matches(type, message)) {
@@ -191,7 +191,7 @@ namespace QTest {
else if (list->next)
ignoreResultList = list->next;
else
- ignoreResultList = 0;
+ ignoreResultList = nullptr;
delete list;
return true;
@@ -219,7 +219,7 @@ namespace QTest {
}
if (type != QtFatalMsg) {
- if (counter.load() <= 0)
+ if (counter.loadRelaxed() <= 0)
return;
if (!counter.deref()) {
@@ -438,11 +438,11 @@ void QTestLog::stopLogging()
void QTestLog::addLogger(LogMode mode, const char *filename)
{
if (filename && strcmp(filename, "-") == 0)
- filename = 0;
+ filename = nullptr;
if (!filename)
QTest::loggerUsingStdout = true;
- QAbstractTestLogger *logger = 0;
+ QAbstractTestLogger *logger = nullptr;
switch (mode) {
case QTestLog::Plain:
logger = new QPlainTestLogger(filename);
diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h
index e63e89a78e..fff36f290d 100644
--- a/src/testlib/qtestlog_p.h
+++ b/src/testlib/qtestlog_p.h
@@ -66,6 +66,10 @@ class QTestData;
class Q_TESTLIB_EXPORT QTestLog
{
public:
+ QTestLog() = delete;
+ ~QTestLog() = delete;
+ Q_DISABLE_COPY_MOVE(QTestLog)
+
enum LogMode {
Plain = 0, XML, LightXML, XunitXML, CSV, TeamCity, TAP
#if defined(QT_USE_APPLE_UNIFIED_LOGGING)
@@ -135,9 +139,6 @@ public:
static qreal msecsFunctionTime() { return QTestLog::nsecsFunctionTime() / 1000000.; }
private:
- QTestLog();
- ~QTestLog();
-
static bool printAvailableTags;
};
diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp
index a7a4807e06..88028aac6e 100644
--- a/src/testlib/qtestresult.cpp
+++ b/src/testlib/qtestresult.cpp
@@ -39,42 +39,45 @@
#include <QtTest/private/qtestresult_p.h>
#include <QtCore/qglobal.h>
+#include <QtCore/qstringview.h>
#include <QtTest/private/qtestlog_p.h>
+#include <QtTest/qtest.h> // toString() specializations for QStringView
#include <QtTest/qtestdata.h>
+#include <QtTest/qtestcase.h>
#include <QtTest/qtestassert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-static const char *currentAppName = 0;
+static const char *currentAppName = nullptr;
QT_BEGIN_NAMESPACE
namespace QTest
{
- static QTestData *currentTestData = 0;
- static QTestData *currentGlobalTestData = 0;
- static const char *currentTestFunc = 0;
- static const char *currentTestObjectName = 0;
+ static QTestData *currentTestData = nullptr;
+ static QTestData *currentGlobalTestData = nullptr;
+ static const char *currentTestFunc = nullptr;
+ static const char *currentTestObjectName = nullptr;
static bool failed = false;
static bool skipCurrentTest = false;
static bool blacklistCurrentTest = false;
- static const char *expectFailComment = 0;
+ static const char *expectFailComment = nullptr;
static int expectFailMode = 0;
}
void QTestResult::reset()
{
- QTest::currentTestData = 0;
- QTest::currentGlobalTestData = 0;
- QTest::currentTestFunc = 0;
- QTest::currentTestObjectName = 0;
+ QTest::currentTestData = nullptr;
+ QTest::currentGlobalTestData = nullptr;
+ QTest::currentTestFunc = nullptr;
+ QTest::currentTestObjectName = nullptr;
QTest::failed = false;
- QTest::expectFailComment = 0;
+ QTest::expectFailComment = nullptr;
QTest::expectFailMode = 0;
QTest::blacklistCurrentTest = false;
@@ -126,18 +129,18 @@ static void clearExpectFail()
{
QTest::expectFailMode = 0;
delete [] const_cast<char *>(QTest::expectFailComment);
- QTest::expectFailComment = 0;
+ QTest::expectFailComment = nullptr;
}
void QTestResult::finishedCurrentTestData()
{
if (QTest::expectFailMode)
- addFailure("QEXPECT_FAIL was called without any subsequent verification statements", 0, 0);
+ addFailure("QEXPECT_FAIL was called without any subsequent verification statements", nullptr, 0);
clearExpectFail();
if (!QTest::failed && QTestLog::unhandledIgnoreMessages()) {
QTestLog::printUnhandledIgnoreMessages();
- addFailure("Not all expected messages were received", 0, 0);
+ addFailure("Not all expected messages were received", nullptr, 0);
}
QTestLog::clearIgnoreMessages();
}
@@ -157,7 +160,7 @@ void QTestResult::finishedCurrentTestDataCleanup()
void QTestResult::finishedCurrentTestFunction()
{
- QTest::currentTestFunc = 0;
+ QTest::currentTestFunc = nullptr;
QTest::failed = false;
QTestLog::leaveTestFunction();
@@ -170,14 +173,12 @@ const char *QTestResult::currentTestFunction()
const char *QTestResult::currentDataTag()
{
- return QTest::currentTestData ? QTest::currentTestData->dataTag()
- : static_cast<const char *>(0);
+ return QTest::currentTestData ? QTest::currentTestData->dataTag() : nullptr;
}
const char *QTestResult::currentGlobalDataTag()
{
- return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag()
- : static_cast<const char *>(0);
+ return QTest::currentGlobalTestData ? QTest::currentGlobalTestData->dataTag() : nullptr;
}
static bool isExpectFailData(const char *dataIndex)
@@ -265,17 +266,54 @@ bool QTestResult::verify(bool statement, const char *statementStr,
return checkStatement(statement, msg, file, line);
}
-bool QTestResult::compare(bool success, const char *failureMsg,
- char *val1, char *val2,
- const char *actual, const char *expected,
- const char *file, int line)
+// Format failures using the toString() template
+template <class Actual, class Expected>
+void formatFailMessage(char *msg, size_t maxMsgLen,
+ const char *failureMsg,
+ const Actual &val1, const Expected &val2,
+ const char *actual, const char *expected)
{
- QTEST_ASSERT(expected);
- QTEST_ASSERT(actual);
+ auto val1S = QTest::toString(val1);
+ auto val2S = QTest::toString(val2);
+
+ size_t len1 = mbstowcs(nullptr, actual, maxMsgLen); // Last parameter is not ignored on QNX
+ size_t len2 = mbstowcs(nullptr, expected, maxMsgLen); // (result is never larger than this).
+ qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
+ failureMsg,
+ actual, qMax(len1, len2) - len1 + 1, ":", val1S ? val1S : "<null>",
+ expected, qMax(len1, len2) - len2 + 1, ":", val2S ? val2S : "<null>");
+
+ delete [] val1S;
+ delete [] val2S;
+}
+
+// Overload to format failures for "const char *" - no need to strdup().
+void formatFailMessage(char *msg, size_t maxMsgLen,
+ const char *failureMsg,
+ const char *val1, const char *val2,
+ const char *actual, const char *expected)
+{
+ size_t len1 = mbstowcs(nullptr, actual, maxMsgLen); // Last parameter is not ignored on QNX
+ size_t len2 = mbstowcs(nullptr, expected, maxMsgLen); // (result is never larger than this).
+ qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
+ failureMsg,
+ actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
+ expected, qMax(len1, len2) - len2 + 1, ":", val2 ? val2 : "<null>");
+}
+template <class Actual, class Expected>
+static bool compareHelper(bool success, const char *failureMsg,
+ const Actual &val1, const Expected &val2,
+ const char *actual, const char *expected,
+ const char *file, int line,
+ bool hasValues = true)
+{
const size_t maxMsgLen = 1024;
char msg[maxMsgLen] = {'\0'};
+ QTEST_ASSERT(expected);
+ QTEST_ASSERT(actual);
+
if (QTestLog::verboseLevel() >= 2) {
qsnprintf(msg, maxMsgLen, "QCOMPARE(%s, %s)", actual, expected);
QTestLog::info(msg, file, line);
@@ -289,20 +327,92 @@ bool QTestResult::compare(bool success, const char *failureMsg,
qsnprintf(msg, maxMsgLen,
"QCOMPARE(%s, %s) returned TRUE unexpectedly.", actual, expected);
}
- } else if (val1 || val2) {
- size_t len1 = mbstowcs(NULL, actual, maxMsgLen); // Last parameter is not ignored on QNX
- size_t len2 = mbstowcs(NULL, expected, maxMsgLen); // (result is never larger than this).
- qsnprintf(msg, maxMsgLen, "%s\n Actual (%s)%*s %s\n Expected (%s)%*s %s",
- failureMsg,
- actual, qMax(len1, len2) - len1 + 1, ":", val1 ? val1 : "<null>",
- expected, qMax(len1, len2) - len2 + 1, ":", val2 ? val2 : "<null>");
- } else
+ return checkStatement(success, msg, file, line);
+ }
+
+
+ if (!hasValues) {
qsnprintf(msg, maxMsgLen, "%s", failureMsg);
+ return checkStatement(success, msg, file, line);
+ }
+
+ formatFailMessage(msg, maxMsgLen, failureMsg, val1, val2, actual, expected);
+
+ return checkStatement(success, msg, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ char *val1, char *val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ const bool result = compareHelper(success, failureMsg,
+ val1 != nullptr ? val1 : "<null>",
+ val2 != nullptr ? val2 : "<null>",
+ actual, expected, file, line,
+ val1 != nullptr && val2 != nullptr);
+ // Our caller got these from QTest::toString()
delete [] val1;
delete [] val2;
- return checkStatement(success, msg, file, line);
+ return result;
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ double val1, double val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ float val1, float val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ int val1, int val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ unsigned val1, unsigned val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ QStringView val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ QStringView val1, const QLatin1String &val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
+}
+
+bool QTestResult::compare(bool success, const char *failureMsg,
+ const QLatin1String & val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return compareHelper(success, failureMsg, val1, val2, actual, expected, file, line);
}
void QTestResult::addFailure(const char *message, const char *file, int line)
diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h
index 4df75b2805..38a3024a0f 100644
--- a/src/testlib/qtestresult_p.h
+++ b/src/testlib/qtestresult_p.h
@@ -55,6 +55,9 @@
QT_BEGIN_NAMESPACE
+class QLatin1String;
+class QStringView;
+
class QTestResultPrivate;
class QTestData;
@@ -79,7 +82,34 @@ public:
char *val1, char *val2,
const char *actual, const char *expected,
const char *file, int line);
-
+ static bool compare(bool success, const char *failureMsg,
+ double val1, double val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ float val1, float val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ int val1, int val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ unsigned val1, unsigned val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ QStringView val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ const QLatin1String &val1, QStringView val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
+ static bool compare(bool success, const char *failureMsg,
+ QStringView val1, const QLatin1String &val2,
+ const char *actual, const char *expected,
+ const char *file, int line);
static void setCurrentGlobalTestData(QTestData *data);
static void setCurrentTestData(QTestData *data);
static void setCurrentTestFunction(const char *func);
diff --git a/src/testlib/qtesttable.cpp b/src/testlib/qtesttable.cpp
index 8d42668a5b..85dff17017 100644
--- a/src/testlib/qtesttable.cpp
+++ b/src/testlib/qtesttable.cpp
@@ -58,17 +58,17 @@ public:
}
struct Element {
- Element() : name(nullptr), type(0) {}
+ Element() = default;
Element(const char *n, int t) : name(n), type(t) {}
- const char *name;
- int type;
+ const char *name = nullptr;
+ int type = 0;
};
- typedef std::vector<Element> ElementList;
+ using ElementList = std::vector<Element>;
ElementList elementList;
- typedef std::vector<QTestData *> DataList;
+ using DataList = std::vector<QTestData *>;
DataList dataList;
void addColumn(int elemType, const char *elemName) { elementList.push_back(Element(elemName, elemType)); }
@@ -78,8 +78,8 @@ public:
static QTestTable *gTable;
};
-QTestTable *QTestTablePrivate::currentTestTable = 0;
-QTestTable *QTestTablePrivate::gTable = 0;
+QTestTable *QTestTablePrivate::currentTestTable = nullptr;
+QTestTable *QTestTablePrivate::gTable = nullptr;
void QTestTable::addColumn(int type, const char *name)
{
@@ -119,7 +119,7 @@ QTestTable::QTestTable()
QTestTable::~QTestTable()
{
- QTestTablePrivate::currentTestTable = 0;
+ QTestTablePrivate::currentTestTable = nullptr;
delete d;
}
@@ -152,14 +152,12 @@ private:
int QTestTable::indexOf(const char *elementName) const
{
- typedef QTestTablePrivate::ElementList::const_iterator It;
-
QTEST_ASSERT(elementName);
const QTestTablePrivate::ElementList &elementList = d->elementList;
- const It it = std::find_if(elementList.begin(), elementList.end(),
- NamePredicate(elementName));
+ const auto it = std::find_if(elementList.begin(), elementList.end(),
+ NamePredicate(elementName));
return it != elementList.end() ?
int(it - elementList.begin()) : -1;
}
@@ -174,7 +172,7 @@ QTestTable *QTestTable::globalTestTable()
void QTestTable::clearGlobalTestTable()
{
delete QTestTablePrivate::gTable;
- QTestTablePrivate::gTable = 0;
+ QTestTablePrivate::gTable = nullptr;
}
QTestTable *QTestTable::currentTestTable()
diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp
index fe9a6e21cc..bdbdfa9610 100644
--- a/src/testlib/qtestxunitstreamer.cpp
+++ b/src/testlib/qtestxunitstreamer.cpp
@@ -54,8 +54,7 @@ QTestXunitStreamer::QTestXunitStreamer(QXunitTestLogger *logger)
QTEST_ASSERT(testLogger);
}
-QTestXunitStreamer::~QTestXunitStreamer()
-{}
+QTestXunitStreamer::~QTestXunitStreamer() = default;
void QTestXunitStreamer::indentForElement(const QTestElement* element, char* buf, int size)
{
@@ -129,7 +128,7 @@ void QTestXunitStreamer::formatAttributes(const QTestElement* element, const QTe
return;
}
- char const* key = 0;
+ char const* key = nullptr;
if (attrindex == QTest::AI_Description)
key = "message";
else if (attrindex != QTest::AI_File && attrindex != QTest::AI_Line)
diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp
index c47042c3a0..763cea327b 100644
--- a/src/testlib/qxmltestlogger.cpp
+++ b/src/testlib/qxmltestlogger.cpp
@@ -107,9 +107,7 @@ QXmlTestLogger::QXmlTestLogger(XmlMode mode, const char *filename)
{
}
-QXmlTestLogger::~QXmlTestLogger()
-{
-}
+QXmlTestLogger::~QXmlTestLogger() = default;
void QXmlTestLogger::startLogging()
{
@@ -182,23 +180,20 @@ inline static bool isEmpty(const char *str)
static const char *incidentFormatString(bool noDescription, bool noTag)
{
if (noDescription) {
- if (noTag)
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
- else
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ return noTag
+ ? "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n"
+ : "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
" <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
"</Incident>\n";
- } else {
- if (noTag)
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
- " <Description><![CDATA[%s%s%s%s]]></Description>\n"
- "</Incident>\n";
- else
- return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
- " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
- " <Description><![CDATA[%s]]></Description>\n"
- "</Incident>\n";
}
+ return noTag
+ ? "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ " <Description><![CDATA[%s%s%s%s]]></Description>\n"
+ "</Incident>\n"
+ : "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
+ " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
+ " <Description><![CDATA[%s]]></Description>\n"
+ "</Incident>\n";
}
static const char *benchmarkResultFormatString()
diff --git a/src/testlib/qxmltestlogger_p.h b/src/testlib/qxmltestlogger_p.h
index b85742f939..04ed57d587 100644
--- a/src/testlib/qxmltestlogger_p.h
+++ b/src/testlib/qxmltestlogger_p.h
@@ -71,11 +71,11 @@ public:
void leaveTestFunction() override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &result) override;
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
static int xmlCdata(QTestCharBuffer *dest, char const* src);
static int xmlQuote(QTestCharBuffer *dest, char const* src);
diff --git a/src/testlib/qxunittestlogger.cpp b/src/testlib/qxunittestlogger.cpp
index 336edb5994..b3cac9cb82 100644
--- a/src/testlib/qxunittestlogger.cpp
+++ b/src/testlib/qxunittestlogger.cpp
@@ -59,13 +59,6 @@ QT_BEGIN_NAMESPACE
QXunitTestLogger::QXunitTestLogger(const char *filename)
: QAbstractTestLogger(filename)
- , listOfTestcases(0)
- , currentLogElement(0)
- , errorLogElement(0)
- , logFormatter(0)
- , testCounter(0)
- , failureCounter(0)
- , errorCounter(0)
{
}
@@ -155,7 +148,7 @@ void QXunitTestLogger::leaveTestFunction()
void QXunitTestLogger::addIncident(IncidentTypes type, const char *description,
const char *file, int line)
{
- const char *typeBuf = 0;
+ const char *typeBuf = nullptr;
char buf[100];
switch (type) {
@@ -299,7 +292,7 @@ void QXunitTestLogger::addTag(QTestElement* element)
void QXunitTestLogger::addMessage(MessageTypes type, const QString &message, const char *file, int line)
{
QTestElement *errorElement = new QTestElement(QTest::LET_Error);
- const char *typeBuf = 0;
+ const char *typeBuf = nullptr;
switch (type) {
case QAbstractTestLogger::Warn:
diff --git a/src/testlib/qxunittestlogger_p.h b/src/testlib/qxunittestlogger_p.h
index 8fb01fbe61..518ba098f4 100644
--- a/src/testlib/qxunittestlogger_p.h
+++ b/src/testlib/qxunittestlogger_p.h
@@ -71,22 +71,22 @@ class QXunitTestLogger : public QAbstractTestLogger
void leaveTestFunction() override;
void addIncident(IncidentTypes type, const char *description,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
void addBenchmarkResult(const QBenchmarkResult &result) override;
void addTag(QTestElement* element);
void addMessage(MessageTypes type, const QString &message,
- const char *file = 0, int line = 0) override;
+ const char *file = nullptr, int line = 0) override;
private:
- QTestElement *listOfTestcases;
- QTestElement *currentLogElement;
- QTestElement *errorLogElement;
- QTestXunitStreamer *logFormatter;
+ QTestElement *listOfTestcases = nullptr;
+ QTestElement *currentLogElement = nullptr;
+ QTestElement *errorLogElement = nullptr;
+ QTestXunitStreamer *logFormatter = nullptr;
- int testCounter;
- int failureCounter;
- int errorCounter;
+ int testCounter = 0;
+ int failureCounter = 0;
+ int errorCounter = 0;
};
QT_END_NAMESPACE
diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro
index f52a913a08..530bc6b425 100644
--- a/src/testlib/testlib.pro
+++ b/src/testlib/testlib.pro
@@ -17,7 +17,6 @@ HEADERS = \
qbenchmark_p.h \
qbenchmarkmeasurement_p.h \
qbenchmarktimemeasurers_p.h \
- qbenchmarkvalgrind_p.h \
qbenchmarkevent_p.h \
qbenchmarkperfevents_p.h \
qbenchmarkmetric.h \
@@ -70,7 +69,6 @@ SOURCES = \
qabstracttestlogger.cpp \
qbenchmark.cpp \
qbenchmarkmeasurement.cpp \
- qbenchmarkvalgrind.cpp \
qbenchmarkevent.cpp \
qbenchmarkperfevents.cpp \
qbenchmarkmetric.cpp \
@@ -92,6 +90,13 @@ qtConfig(itemmodeltester) {
qabstractitemmodeltester.cpp
}
+qtConfig(valgrind) {
+ HEADERS += \
+ qbenchmarkvalgrind_p.h
+ SOURCES += \
+ qbenchmarkvalgrind.cpp
+}
+
DEFINES *= QT_NO_CAST_TO_ASCII \
QT_NO_CAST_FROM_ASCII \
QT_NO_FOREACH \